PadicoTM

Documentation

« back to PM2 home.
psp-shm.c
Go to the documentation of this file.
1/*
2 * Padico -- a High Performance Parallel and Distributed Computing Environment
3 * Copyright (c) 2002-2026 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/Module.h>
29#include <Padico/PSP.h>
30
31#if defined(MARCEL)
32# warning "Shm: Marcel is enabled- not building module 'Shm'"
33#else /* MARCEL */
34
35static int psp_shm_module_init(void);
36static void psp_shm_module_finalize(void);
37
39 "Shm", "PSP");
40
45#include "Shm.h"
46
47//#define PSP_SHM_PIOMAN
48
49
50/* ********************************************************* */
51/* *** PadicoSimplePackets for Shm */
53static void psp_shm_destroy(void*_instance);
54static void psp_shm_init(void*_instance, uint32_t tag, const char*label, size_t*h_size,
55 padico_psp_handler_t handler, void*key);
58 const char*bytes, size_t size);
60
65 {
66 .instantiate = &psp_shm_instantiate,
67 .destroy = &psp_shm_destroy
68 };
73 {
75 .connect = NULL,
76 .listen = NULL,
77 .new_message = &psp_shm_new_message,
78 .pack = &psp_shm_pack,
79 .end_message = &psp_shm_end_message
80 };
81
86{
89 /* TODO: spinlock in instance to ensure single sender semantics */
90};
91
93static struct
94{
99#ifdef PSP_SHM_PIOMAN
100 struct piom_ltask ltask;
101#endif
103
104/* ********************************************************* */
105
106static void*psp_shm_polling_worker(void*dummy);
108
109static void psp_shm_start_polling(void)
110{
111 if(psp_shm.running == 0)
112 {
113 /* init polling */
114#ifdef PSP_SHM_PIOMAN
117#else /* PSP_SHM_PIOMAN */
118 padico_tm_bgthread_start(psp_shm.pool, &psp_shm_polling_worker, NULL, "psp_shm_polling_worker");
119#endif /* PSP_SHM_PIOMAN */
120 }
121 psp_shm.running++;
122}
123
124/* ********************************************************* */
125/* *** PadicoComponent */
126
128{
130 instance->header_block = NULL;
131 instance->slot = NULL;
133 return instance;
134}
135static void psp_shm_destroy(void*_instance)
136{
138 if(instance->slot->tag != -1)
141}
142
143/* ********************************************************* */
144/* *** PadicoSimplePackets */
145
150
151static void psp_shm_init(void*_instance, uint32_t tag, const char*label, size_t*h_size,
152 padico_psp_handler_t handler, void*key)
153{
155 padico_out(20, "h_size=%d; tag=%d\n", (int)*h_size, tag);
157 assert(sizeof(struct padico_shm_short_header_s) + sizeof(struct psp_shm_header_s) + *h_size <= PADICO_SHM_BLOCKSIZE);
158 instance->slot = padico_psp_slot_insert(&psp_shm.slots, handler, key, tag, *h_size);
159}
160
161
162static void psp_shm_pump(void*_token, void*bytes, size_t b_size)
163{
164 padico_shm_large_recv(psp_shm.shm, bytes, b_size, *(int*)_token);
165}
166
167
169{
172 const int from = shm_header->from;
174 const int tag = psp_header->tag;
176
177 padico_out(40, "ready! from=%d; block #%p\n", from, block);
178 padico_topo_node_t node_from = padico_topo_getnodebyuuid((void*)psp_shm.shm->seg_directory->directory.nodes[from].node_uuid);
180 padico_out(40, "invoking handler...\n");
181 (*instance->handler)(header, node_from, instance->key, &psp_shm_pump , (void*)&from);
182 /* release header block */
184 padico_out(40, "done.\n");
185}
186
187#ifdef PSP_SHM_PIOMAN
188#warning experimental Shm-pioman
190{
192 if(block_num != -1)
193 {
195 }
196 return 0;
197}
198#else /* PSP_SHM_PIOMAN */
199static void*psp_shm_polling_worker(void*dummy)
200{
201 for(;;)
202 {
204 padico_out(40, "waiting...\n");
205 do
206 {
208 if(block == NULL)
209 sched_yield();
210 }
211 while(block == NULL);
213 }
214 return NULL;
215}
216#endif /* PSP_SHM_PIOMAN */
217
219{
220 if(instance->header_block != NULL)
221 {
222 int rc = padico_shm_short_send_commit(psp_shm.shm, dest, instance->header_block, instance->slot->h_size, 1);
223 if(rc)
224 padico_fatal("cannot send- receiver queue full.\n");
225 instance->header_block = NULL;
226 }
227}
228
230{
233 /* preapare header */
235 do
236 {
238 }
239 while(block == NULL);
240 assert(instance->header_block == NULL);
241 instance->header_block = block;
244 psp_header->tag = instance->slot->tag;
246 return (padico_psp_connection_t)dest;
247}
248
250 const char*bytes, size_t size)
251{
253 struct padico_shm_node_s*dest = (struct padico_shm_node_s*)_conn;
255 padico_shm_large_send(psp_shm.shm, bytes, size, dest);
256}
257
264
265
266/* ********************************************************* */
267
269{
270 psp_shm.shm = padico_shm_init("PSP_Shm", -1);
271
272 psp_shm.running = 0;
273 psp_shm.pool = padico_tm_bgthread_pool_create("PSP_Shm");
274 /* init instances index */
276
277 /* declare component */
278 puk_component_declare("PSP_Shm",
279 puk_component_provides("PadicoComponent", "component", &psp_shm_component_driver),
280 puk_component_provides("PadicoSimplePackets", "psp", &psp_shm_driver));
281 return 0;
282}
283
288
289#endif /* MARCEL */
assert(slab_size > 0)
const const struct ns_rule_bucket_s * key
Padico Shared memory common interface.
return NULL
Definition Shm.h:88
static padico_shm_block_t padico_shm_short_recv_poll(struct padico_shm_s *shm, struct padico_shm_node_s *from)
Definition Shm.h:339
struct padico_shm_block_s * padico_shm_block_t
offset of a block in the shared segment, stored in a pointer.
Definition Shm.h:80
static void * padico_shm_block_get_ptr(struct padico_shm_s *shm, padico_shm_block_t block)
get the pointer to a block given its block number
Definition Shm.h:211
static void padico_shm_block_free(struct padico_shm_s *shm, padico_shm_block_t block)
return a free block back to the free blocks pool
Definition Shm.h:255
static int padico_shm_short_send_commit(struct padico_shm_s *shm, struct padico_shm_node_s *dest, padico_shm_block_t block, size_t size, int shared)
Definition Shm.h:292
#define PADICO_SHM_BLOCKSIZE
size of data block in segment
Definition Shm.h:65
struct padico_addrkey_hash_entry_block_lfstack_cell_s block[]
static const int tag
Definition bench_MPI.c:13
static int done
Definition console-mod.c:49
puk_instance_t instance
the listening bootstrap instance
static int size
Definition datacheck.c:34
static const struct padico_psp_driver_s psp_shm_driver
'PadicoSimplePackets' facet for Shm
Definition psp-shm.c:72
static const struct puk_component_driver_s psp_shm_component_driver
instanciation facet for Shm
Definition psp-shm.c:64
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_slot_remove(struct padico_psp_directory_s *d, padico_psp_slot_t slot)
Definition psp.c:84
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
void padico_tm_bgthread_start(padico_tm_bgthread_pool_t pool, padico_thread_fun_t f, void *arg, const char *name)
Definition tm-rttask.c:126
void padico_tm_bgthread_pool_wait(padico_tm_bgthread_pool_t pool)
finalize a pool of threads: waits for all thread to complete
Definition tm-rttask.c:78
padico_tm_bgthread_pool_t padico_tm_bgthread_pool_create(const char *name)
create a new thread pool
Definition tm-rttask.c:56
padico_rc_t rc
Definition PadicoTM.h:146
padico_topo_node_t padico_topo_getnodebyuuid(padico_topo_uuid_t uuid)
node lookup, by UUID
Definition topology.c:2407
padico_topo_node_t node
Definition na-control.c:65
struct padico_ibv_lz_header_s header
static void * psp_shm_polling_worker(void *dummy)
Definition psp-shm.c:199
int psp_shm_polling_ltask(void *_arg)
static void psp_shm_send_header(struct psp_shm_instance_s *instance, struct padico_shm_node_s *dest)
Definition psp-shm.c:218
int running
Definition psp-shm.c:97
static void * psp_shm_instantiate(puk_instance_t ai, puk_context_t context)
Definition psp-shm.c:127
static padico_psp_connection_t psp_shm_new_message(void *_instance, padico_topo_node_t node, void **_sbuf)
Definition psp-shm.c:229
static void psp_shm_module_finalize(void)
Definition psp-shm.c:284
padico_tm_bgthread_pool_t pool
Definition psp-shm.c:98
static int psp_shm_module_init(void)
Definition psp-shm.c:268
static void psp_shm_init(void *_instance, uint32_t tag, const char *label, size_t *h_size, padico_psp_handler_t handler, void *key)
Definition psp-shm.c:151
static struct @65 psp_shm
global state of PSP_Shm
static void psp_shm_start_polling(void)
Definition psp-shm.c:109
static void psp_shm_pack(void *_instance, padico_psp_connection_t _conn, const char *bytes, size_t size)
Definition psp-shm.c:249
static void psp_shm_poll_handler(padico_shm_block_t block)
Definition psp-shm.c:168
static void psp_shm_end_message(void *_instance, padico_psp_connection_t _conn)
Definition psp-shm.c:258
struct padico_shm_s * shm
Definition psp-shm.c:95
static void psp_shm_destroy(void *_instance)
Definition psp-shm.c:135
struct padico_psp_directory_s slots
Definition psp-shm.c:96
static void psp_shm_pump(void *_token, void *bytes, size_t b_size)
Definition psp-shm.c:162
padico_shm_block_t padico_shm_block_alloc(struct padico_shm_s *shm)
allocate a memory block in shm buffer
Definition shm-sysdep.c:423
struct padico_shm_node_s * padico_shm_directory_node_lookup(const struct padico_shm_s *shm, padico_topo_node_t node)
Definition shm-sysdep.c:321
void padico_shm_large_recv(struct padico_shm_s *shm, void *bytes, size_t size, int from)
Definition shm-sysdep.c:515
void padico_shm_large_send(struct padico_shm_s *shm, const void *bytes, size_t size, struct padico_shm_node_s *dest)
Definition shm-sysdep.c:437
struct padico_shm_s * padico_shm_init(const char *name, ssize_t payload)
create a shm segment; payload is the size allocated in addition to the directory.
Definition shm-sysdep.c:59
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
A node descriptor.
Definition Shm.h:103
global state of the Shm segment
Definition Shm.h:173
Generic shm header for short messages in the eager queue.
Definition Shm.h:163
volatile uint32_t from
index of sender in directory
Definition Shm.h:164
a thread pool, to control and wait running threads
Definition PadicoTM.h:174
uint32_t tag
Definition psp-shm.c:148
a PSP_Shm instance
Definition psp-shm.c:86
padico_shm_block_t header_block
block containing the sbuf header; NULL if already sent
Definition psp-shm.c:88
padico_psp_slot_t slot
Definition psp-shm.c:87
char * ptr
Definition vpipe.c:83