PadicoTM

Documentation

« back to PM2 home.
psp-mx.c
Go to the documentation of this file.
1/*
2 * Padico -- a High Performance Parallel and Distributed Computing Environment
3 * Copyright (c) 2002-2024 INRIA and the University of Rennes 1
4 * Alexandre DENIS <Alexandre.Denis@inria.fr>
5 * Christian PEREZ <Christian.Perez@inria.fr>
6 *
7 * The software has been registered at the Agency for the Protection of
8 * Programs (APP) under the number IDDN.FR.001.260013.000.S.P.2002.000.10000.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
28#include <Padico/Puk.h>
29#include <Padico/Module.h>
30#include <Padico/Topology.h>
31#include <Padico/PSP.h>
32#include <Padico/PM2.h>
33#include <Padico/AddrDB.h>
34#include <myriexpress.h>
35
36/* needed for mx__get_mapper_state */
37#include <mx_internals/mx__driver_interface.h>
38
39#ifdef PIOMAN
40#include <pioman.h>
41#endif /* PIOMAN */
42
43static int psp_mx_module_init(void);
44static void psp_mx_module_finalize(void);
45
47
48
52/* ********************************************************* */
53/* *** PadicoSimplePackets for MXs */
54
56static void psp_mx_destroy(void*_status);
57static void psp_mx_init(void*_status, uint32_t tag, const char*label, size_t*h_size,
58 padico_psp_handler_t handler, void*key);
59static void psp_mx_connect(void*_status, padico_topo_node_t remote_node);
61static void psp_mx_pack(void*_status, padico_psp_connection_t _conn,
62 const char*bytes, size_t size);
63static void psp_mx_end_message(void*_status, padico_psp_connection_t _conn);
64
69 {
70 .instantiate = &psp_mx_instantiate,
71 .destroy = &psp_mx_destroy
72 };
73
78 {
79 .init = &psp_mx_init,
80 .connect = &psp_mx_connect,
81 .new_message = &psp_mx_new_message,
82 .pack = &psp_mx_pack,
83 .end_message = &psp_mx_end_message
84 };
85
97
99
100static struct
101{
105 volatile int power_on;
106#ifdef PIOMAN
107 struct piom_ltask ltask;
108#endif
114 struct
115 {
119 const int timeout;
121} psp_mx = {
122 .power_on = 0,
123 .next_id = 1,
124 .param.board_num = 0, /* MX_ANY_NIC */
125 .param.endpoint_id = 1, /* MX_ANY_ENDPOINT */
126 .param.filter = 0x12341234,
127 .param.timeout = 10
129
130static void*psp_mx_worker(void*dummy);
131#ifdef PIOMAN
132static int psp_mx_fastpoll(void*_dummy);
133
134static inline void psp_mx_piom_lock(void)
135{
136 piom_ltask_mask(&psp_mx.ltask);
137}
138static inline void psp_mx_piom_unlock(void)
139{
141}
142#else
143static inline void psp_mx_piom_lock(void)
144{
145}
146static inline void psp_mx_piom_unlock(void)
147{
148}
149#endif
150
151
152#define PSP_MX_OP_NEWID 0x01
153#define PSP_MX_OP_NEWMSG 0x02
154#define PSP_MX_OP_HDR 0x04
155#define PSP_MX_OP_PACK 0x08
156
157#define PSP_MX_MASK_ID 0x00000000FFFFFF00
158#define PSP_MX_MASK_OP 0x00000000000000FF
159#define PSP_MX_MASK_TAG 0xFFFFFFFF00000000
160
161#define PSP_MX_MAX_HDR 256
162
169
171{
172 return ( (op & 0x00000000000000FF ) |
173 ((id << 8 ) & 0x00000000FFFFFF00 ) |
174 ((tag << 32) & 0xFFFFFFFF00000000 ) );
175}
176static inline uint64_t psp_mx_match(struct psp_mx_status_s*status, uint64_t op)
177{
178 const uint64_t id = status->peer_id;
179 const uint64_t tag = (uint64_t)status->tag;
180 return psp_mx_match_raw(id, tag, op);
181}
182
183/* ********************************************************* */
184/* ** toolbox */
185
186static inline void psp_mx_checkrc(int rc, const char*op)
187{
188 if(rc != MX_SUCCESS)
189 {
190 padico_fatal("error %d in %s: %s\n", rc, op, mx_strerror(rc));
191 }
192}
193
194static inline void psp_mx_send(struct psp_mx_status_s*status, const void*bytes, size_t size, uint64_t match)
195{
200 {
201 .segment_ptr = (void*)bytes,
203 };
205 mx_isend(psp_mx.endpoint, &seg, 1, status->addr, match, NULL, &req);
207 /* mx_wait(psp_mx.endpoint, &req, MX_INFINITE, &stat, &res); */
208 int rc;
209 do {
211 rc = mx_test(psp_mx.endpoint, &req, &stat, &res);
213 if(!res)
214 {
215#ifndef PIOMAN
216 marcel_yield();
217#endif
218 }
219 } while (rc == MX_SUCCESS && !res);
220}
221
222static inline void psp_mx_recv(void*bytes, size_t size, uint64_t mask, uint64_t match)
223{
228 {
229 .segment_ptr = bytes,
230 .segment_length = size
231 };
233 mx_irecv(psp_mx.endpoint, &seg, 1, match, mask, NULL, &req);
235 /*
236 mx_wait(psp_mx.endpoint, &req, MX_INFINITE, &stat, &res);
237 */
238 int rc;
239 do {
241 rc = mx_test(psp_mx.endpoint, &req, &stat, &res);
243 if(!res)
244 {
245#ifndef PIOMAN
246 marcel_yield();
247#endif
248 }
249 } while (rc == MX_SUCCESS && !res);
250}
251
252/* ********************************************************* */
253
254static int psp_mx_module_init(void)
255{
257
258 // padico_setenv("MX_RCACHE", "0");
259 padico_setenv("MX_MONOTHREAD", "1");
260
262 int rc = mx_init();
263 psp_mx_checkrc(rc, "init");
264
265 rc = mx_open_endpoint(psp_mx.param.board_num, psp_mx.param.endpoint_id, psp_mx.param.filter,
266 NULL, 0, &psp_mx.endpoint);
267 psp_mx_checkrc(rc, "open_endpoint");
268
269 /* get the NIC id */
270 rc = mx_board_number_to_nic_id(psp_mx.param.board_num, &psp_mx.nic_id);
271 psp_mx_checkrc(rc, "board_number_to_nic_id");
272
273 /* get the mapper MAC */
275 rc = mx_open_board(psp_mx.param.board_num, &handle);
276 psp_mx_checkrc(rc, "open_board");
277 mx_mapper_state_t mapper = { .board_number = psp_mx.param.board_num, .iport = 0 };
279 psp_mx_checkrc(rc, "get_mapper_state");
280
281 /* decalre the MX network */
283 padico_string_printf(s_net, "MX-[%02X:%02X:%02X:%02X:%02X:%02X]",
284 mapper.mapper_mac[0], mapper.mapper_mac[1],
285 mapper.mapper_mac[2], mapper.mapper_mac[3],
286 mapper.mapper_mac[4], mapper.mapper_mac[5]);
289
290 padico_print("NIC id = %llX; net = %s\n", (unsigned long long)psp_mx.nic_id, padico_string_get(s_net));
291#if 0 /* PIOMAN */
294#endif
295 /* start polling */
296 psp_mx.power_on = 1;
297#ifndef PIOMAN
299
300 puk_component_declare("PSP_MX",
301 puk_component_provides("PadicoComponent", "component", &psp_mx_component_driver),
302 puk_component_provides("PadicoSimplePackets", "psp", &psp_mx_driver));
303#endif
304
305 return 0;
306}
307
308static void psp_mx_module_finalize(void)
309{
310 psp_mx.power_on = 0;
311 marcel_join(psp_mx.worker, NULL);
312}
313
314/* ********************************************************* */
315
317{
318 struct psp_mx_status_s*status = padico_malloc(sizeof(struct psp_mx_status_s));
319 status->slot = NULL;
320 status->peer = NULL;
321 return status;
322}
323
324static void psp_mx_destroy(void*_status)
325{
326 struct psp_mx_status_s*status = _status;
327 padico_free(status);
328}
329
330/* ********************************************************* */
331
332static void psp_mx_init(void*_status, uint32_t tag, const char*label, size_t*h_size,
333 padico_psp_handler_t handler, void*key)
334{
335 struct psp_mx_status_s*status = _status;
336 *h_size += 32;
337 if(status->slot != NULL)
338 {
339 padico_warning("init already done- tag=%x (%x); hsize=%d (%d)\n",
340 status->tag, tag, (int)status->h_size, (int)*h_size);
341 return;
342 }
344 status->tag = tag;
345 status->h_size = *h_size;
346 status->sbuf = padico_malloc(sizeof(struct psp_mx_msghdr_s));
347 status->self_id = psp_mx.next_id++;
348 status->peer_id = 0;
349 status->slot = padico_psp_slot_insert(&psp_mx.slots, handler, key, tag, status->h_size);
350}
351
353{
354 struct psp_mx_status_s*status = _status;
356
357 if(status->peer)
358 {
359 assert(status->peer == remote_node);
360 padico_warning("already connected!\n");
361 return;
362 }
363
365 &psp_mx.param.board_num, sizeof(psp_mx.param.board_num),
366 &psp_mx.nic_id, sizeof(psp_mx.nic_id));
369 &psp_mx.param.board_num, sizeof(psp_mx.param.board_num),
370 &peer_nic, sizeof(peer_nic), req);
372 padico_print("connecting to NIC ID %llX\n", (unsigned long long)peer_nic);
373
374 int rc = mx_connect(psp_mx.endpoint, peer_nic,
375 psp_mx.param.endpoint_id, psp_mx.param.filter, psp_mx.param.timeout, &status->addr);
376 psp_mx_checkrc(rc, "mx_connect");
377 status->peer = remote_node;
378
379 psp_mx_send(status, &status->self_id, sizeof(status->self_id), PSP_MX_OP_NEWID);
380 psp_mx_recv(&status->peer_id, sizeof(status->peer_id), PSP_MX_MASK_OP, PSP_MX_OP_NEWID);
381 psp_mx_conn_vect_put(&psp_mx.conns, status, status->peer_id);
382}
383
385{
386 struct psp_mx_status_s*status = _status;
387 status->hsent = 0;
388 *_sbuf = &status->sbuf->data[0];
389 return status;
390}
391
392static void psp_mx_hsend(struct psp_mx_status_s*status)
393{
394 if(!status->hsent)
395 {
396 status->sbuf->tag = status->tag;
397 status->sbuf->id = status->peer_id;
398 psp_mx_send(status, status->sbuf, sizeof(struct psp_mx_msghdr_s) - (PSP_MX_MAX_HDR - status->h_size), psp_mx_match(status, PSP_MX_OP_NEWMSG));
399 status->hsent = 1;
400 }
401}
402
403static void psp_mx_pack(void*_status, padico_psp_connection_t _conn,
404 const char*bytes, size_t size)
405{
406 struct psp_mx_status_s*status = _status;
407 psp_mx_hsend(status);
408 psp_mx_send(status, bytes, size, psp_mx_match(status, PSP_MX_OP_PACK));
409}
410
412{
413 struct psp_mx_status_s*status = _status;
414 psp_mx_hsend(status);
415}
416
417static void psp_mx_pump(void*token, void*bytes, size_t size)
418{
419 struct psp_mx_msghdr_s*h = token;
421 psp_mx_match_raw(h->id, h->tag, PSP_MX_OP_PACK));
422}
423
424#ifdef PIOMAN
425static int psp_mx_fastpoll(void*_dummy)
426{
429 int rc = mx_test(psp_mx.endpoint, &psp_mx.req, &stat, &res);
430 const int ready = (rc == MX_SUCCESS && res);
431 if(ready)
432 {
434 }
435 return 0;
436}
437#endif
438
439static void*psp_mx_worker(void*dummy)
440{
441 while(psp_mx.power_on)
442 {
443 struct psp_mx_msghdr_s h;
445 {
446 .segment_ptr = &h,
447 .segment_length = sizeof(h)
448 };
452 /* mx_wait(psp_mx.endpoint, &req, MX_INFINITE, &stat, &res); */
453#ifdef PIOMAN
454 piom_ltask_wait(&psp_mx.ltask);
455#else /* PIOMAN */
456 int rc;
459 do {
460 rc = mx_test(psp_mx.endpoint, &psp_mx.req, &stat, &res);
461 if(!res)
462 marcel_yield();
463 if(!psp_mx.power_on)
464 return NULL;
465 } while (rc == MX_SUCCESS && !res);
466#endif /* PIOMAN */
467 struct psp_mx_status_s*status = psp_mx_conn_vect_at(&psp_mx.conns, h.id);
469 (slot->handler)(&h.data[0], status->peer, slot->key, &psp_mx_pump, &h);
470#ifdef PIOMAN
473#endif /* PIOMAN */
474 }
475 return NULL;
476}
assert(slab_size > 0)
ns_rulebucket_hashtable_t h
const const struct ns_rule_bucket_s * key
return NULL
Definition Shm.h:88
static const int tag
Definition bench_MPI.c:13
static struct seg_s * seg
static int done
Definition console-mod.c:49
static int size
Definition datacheck.c:34
void padico_addrdb_get(padico_topo_node_t node, const char *component, const void *instance, size_t instance_size, void *addr, size_t addr_size, padico_req_t req)
get address in static buffer
Definition addrdb.c:246
void padico_addrdb_publish(padico_topo_node_t node, const char *component, const void *instance, size_t instance_size, const void *addr, size_t addr_size)
Definition addrdb.c:164
padico_psp_slot_t padico_psp_slot_insert(struct padico_psp_directory_s *d, padico_psp_handler_t handler, void *key, uint32_t tag, size_t h_size)
Definition psp.c:63
void padico_psp_directory_init(struct padico_psp_directory_s *d)
Definition psp.c:56
void * padico_psp_connection_t
An outgoing connection object, supposed to be opaque for the user.
Definition PSP.h:108
padico_psp_slot_t padico_psp_slot_lookup(struct padico_psp_directory_s *d, uint32_t tag)
Definition psp.c:93
void(* padico_psp_handler_t)(const void *header, padico_topo_node_t from, void *key, padico_psp_pump_t pump, void *token)
A callback for PSP.
Definition PSP.h:103
padico_rc_t padico_tm_req_wait(padico_req_t req)
padico_rc_t rc
Definition PadicoTM.h:146
padico_req_t padico_tm_req_new(padico_task_notifier_t notifier, void *key)
padico_topo_network_t padico_topo_network_create(const char *id, padico_topo_binding_scope_t scope, size_t addr_size, int family)
Definition topology.c:1853
#define padico_topo_getlocalhost()
Definition Topology.h:319
padico_topo_binding_t padico_topo_host_bind(padico_topo_host_t host, padico_topo_network_t network, const void *address)
Declare a new binding for a host.
Definition topology.c:1609
@ PADICO_TOPO_SCOPE_HOST
Definition Topology.h:95
padico_topo_node_t node
Definition na-control.c:65
padico_topo_node_t remote_node
Definition psp-ibv.c:195
static const struct padico_psp_driver_s psp_mx_driver
'SimplePackets' facet for PSP-IBV
Definition psp-mx.c:77
static void psp_mx_init(void *_status, uint32_t tag, const char *label, size_t *h_size, padico_psp_handler_t handler, void *key)
Definition psp-mx.c:332
static void psp_mx_pack(void *_status, padico_psp_connection_t _conn, const char *bytes, size_t size)
Definition psp-mx.c:403
struct @32::@33 param
static void psp_mx_send(struct psp_mx_status_s *status, const void *bytes, size_t size, uint64_t match)
Definition psp-mx.c:194
pthread_t worker
Definition psp-mx.c:104
const uint32_t filter
Definition psp-mx.c:118
static void psp_mx_end_message(void *_status, padico_psp_connection_t _conn)
Definition psp-mx.c:411
static padico_psp_connection_t psp_mx_new_message(void *_status, padico_topo_node_t node, void **_sbuf)
Definition psp-mx.c:384
static void psp_mx_connect(void *_status, padico_topo_node_t remote_node)
Definition psp-mx.c:352
static uint64_t psp_mx_match(struct psp_mx_status_s *status, uint64_t op)
Definition psp-mx.c:176
static int psp_mx_module_init(void)
Definition psp-mx.c:254
uint64_t nic_id
Definition psp-mx.c:112
#define PSP_MX_OP_NEWMSG
Definition psp-mx.c:153
struct psp_mx_conn_vect_s conns
known connections, indexed by peer_id
Definition psp-mx.c:110
static void * psp_mx_worker(void *dummy)
Definition psp-mx.c:439
const uint32_t endpoint_id
Definition psp-mx.c:117
const int timeout
Definition psp-mx.c:119
mx_request_t req
Definition psp-mx.c:103
#define PSP_MX_MASK_OP
Definition psp-mx.c:158
static const struct puk_component_driver_s psp_mx_component_driver
instanciation facet for PSP-IBV
Definition psp-mx.c:68
static void * psp_mx_instantiate(puk_instance_t ai, puk_context_t context)
Definition psp-mx.c:316
#define PSP_MX_MAX_HDR
Definition psp-mx.c:161
static void psp_mx_destroy(void *_status)
Definition psp-mx.c:324
static void psp_mx_checkrc(int rc, const char *op)
Definition psp-mx.c:186
uint32_t next_id
Definition psp-mx.c:111
typdef struct psp_mx_conn_vect_s *static psp_mx_conn_vect_t struct @32 psp_mx
static void psp_mx_module_finalize(void)
Definition psp-mx.c:308
#define PSP_MX_OP_PACK
Definition psp-mx.c:155
static uint64_t psp_mx_match_raw(uint64_t id, uint64_t tag, uint64_t op)
Definition psp-mx.c:170
#define PSP_MX_MASK_ID
Definition psp-mx.c:157
volatile int power_on
set to 0 to ask the worker to stop
Definition psp-mx.c:105
#define PSP_MX_MASK_TAG
Definition psp-mx.c:159
static void psp_mx_piom_lock(void)
Definition psp-mx.c:143
static void psp_mx_recv(void *bytes, size_t size, uint64_t mask, uint64_t match)
Definition psp-mx.c:222
padico_topo_network_t network
Definition psp-mx.c:113
mx_endpoint_t endpoint
Definition psp-mx.c:102
const uint32_t board_num
Definition psp-mx.c:116
struct padico_psp_directory_s slots
PSP demultiplexing.
Definition psp-mx.c:109
static void psp_mx_hsend(struct psp_mx_status_s *status)
Definition psp-mx.c:392
static void psp_mx_pump(void *token, void *bytes, size_t size)
Definition psp-mx.c:417
#define PSP_MX_OP_NEWID
Definition psp-mx.c:152
static void psp_mx_piom_unlock(void)
Definition psp-mx.c:146
PSP slot directory used for multiplexing.
Definition PSP.h:234
driver descriptor for the PSP interface.
Definition PSP.h:113
void(* init)(void *_instance, uint32_t tag, const char *label, size_t *h_size, padico_psp_handler_t handler, void *key)
init a new PSP instance
Definition PSP.h:122
a PSP slot, i.e.
Definition PSP.h:210
void * key
Definition PSP.h:212
padico_psp_handler_t handler
Definition PSP.h:211
uint64_t id
Definition psp-mx.c:165
uint32_t tag
Definition psp-mx.c:166
char data[256]
Definition psp-mx.c:167
size_t h_size
Definition psp-mx.c:90
struct psp_mx_msghdr_s * sbuf
Definition psp-mx.c:93
mx_endpoint_addr_t addr
Definition psp-mx.c:91
uint32_t self_id
Definition psp-mx.c:94
padico_topo_node_t peer
Definition psp-mx.c:92
padico_psp_slot_t slot
Definition psp-mx.c:88
uint32_t tag
Definition psp-mx.c:89
uint32_t peer_id
Definition psp-mx.c:94
a network, containing entities with bindings
int ready
ready flag for loader that needs synch
Definition tm-boot.c:66