PadicoTM

Documentation

« back to PM2 home.
Shm.h
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
29#ifndef PADICO_SHM_H
30#define PADICO_SHM_H
31
32#include <sys/types.h>
33#include <semaphore.h>
34#include <unistd.h>
35
36#define SHM_USE_POSIX
37
38#if defined(SHM_USE_POSIX)
39# include <sys/mman.h>
40# include <fcntl.h>
41#elif defined(SHM_USE_IPC)
42# warning "Using IPC shm"
43# include <sys/shm.h>
44#else
45# error "No shm method defined"
46#endif
47
48#include <Padico/Puk.h>
49#include <Padico/Topology.h>
50
51#include <Padico/Puk.h>
52
54#undef PADICO_LAST_MODULE_NAME
55#define PADICO_LAST_MODULE_NAME Shm
56
57/* ********************************************************* */
58
59#define PADICO_SHM_NUMNODES 128
63#define PADICO_SHM_NUMBLOCKS 4096
65#define PADICO_SHM_BLOCKSIZE (16 * 1024)
67#define PADICO_SHM_QUEUESIZE 64
69#define PADICO_SHM_NUMQUEUES 512
72#define PADICO_SHM_BLOCK_CACHE_SIZE 16
73#define PADICO_YIELD_ON_WAIT
74
75#define PADICO_SHM_ALIGN 4096
76
81
86
95
98
103{
105 int pid;
106 int rank;
107 volatile int enabled;
108};
109
113{
114 /* note: drivers are expected to use either shared_queue or per-node short_queues[], not both */
118 struct
119 {
123
126{
127 struct
128 {
129 char date[16];
130 char time[16];
132 struct
133 {
137
151
159
163{
164 volatile uint32_t from;
165 volatile uint32_t size;
166};
167
168#define PADICO_SHM_SHORT_PAYLOAD (PADICO_SHM_BLOCKSIZE - sizeof(struct padico_shm_short_header_s))
169
183
184/* ********************************************************* */
185
189extern struct padico_shm_s*padico_shm_init(const char*name, ssize_t payload);
190
191extern void padico_shm_close(struct padico_shm_s*shm);
192
194
196extern void padico_shm_directory_dump(struct padico_shm_s*shm);
197
198extern void padico_shm_large_send(struct padico_shm_s*shm, const void*bytes, size_t size, struct padico_shm_node_s*dest);
200extern int padico_shm_large_recv_poll(struct padico_shm_s*shm, void*bytes, size_t size, padico_shm_queue_t queue);
201extern void padico_shm_large_recv(struct padico_shm_s*shm, void*bytes, size_t size, int from);
202
203
204/* ********************************************************* */
205/* ** shared memory blocks allocator */
206
209
212{
213 const uintptr_t offset = (uintptr_t)block;
214 assert(shm->seg_mbox != NULL);
215 assert(offset > 0);
216 assert(offset < sizeof(struct padico_shm_seg_full_s));
217 return ((void*)shm->seg_mbox) + offset;
218}
219
222{
223#ifdef DEBUG
224 assert(shm->seg_mbox != NULL);
225 const void*ptr = padico_shm_block_get_ptr(shm, block);
226 const int b = (ptr - (void*)&shm->seg_mbox->buffer.block[0]) / PADICO_SHM_BLOCKSIZE;
227 assert(&shm->seg_mbox->buffer.block[b * PADICO_SHM_BLOCKSIZE] == ptr); /* assume given offset is a block */
228#endif /* DEBUG */
229}
230
233{
234 const intptr_t offset = (intptr_t)(ptr - ((void*)shm->seg_mbox));
235 assert(shm->seg_mbox != NULL);
236 assert(offset > 0);
237 assert(offset < sizeof(struct padico_shm_seg_full_s));
240 return block;
241}
242
253
268
269/* ** queues */
270
272{
273 assert(queue_num >= 0);
275 const uintptr_t offset = ((void*)&shm->seg_mbox->buffer.queues[queue_num]) - (void*)shm->seg_mbox;
277 return queue;
278}
279
281{
282 const uintptr_t offset = (uintptr_t)queue;
283 assert(offset > 0);
284 assert(offset < sizeof(struct padico_shm_seg_full_s));
285 return ((void*)shm->seg_mbox) + offset;
286}
287
288
289/* ********************************************************* */
290/* ** messaging */
291
293{
297 shm_header->size = size;
298 int rc = -1, retry = 0;
299 while(rc)
300 {
301 if(shared)
303 else
305 if(rc)
306 {
307 retry++;
308 if(retry > 10)
309 {
310 /* queue may not be actually full, rc=-1 may be a memory consistency
311 * artefact. Retry immediately, and issue a warning and reduce
312 * throttle only in case error persists.
313 */
314 puk_usleep(1);
315 }
316 if(retry > 11)
317 {
318 return rc;
319 }
320 }
321 }
322 return rc;
323}
340{
341 assert(shm->seg_mbox != NULL);
342 /* from == NULL => shared queue */
343 if(from == NULL)
344 {
346 return block;
347 }
348 else
349 {
350 assert(from->rank >= 0);
352 return block;
353 }
354}
355
356
357/* ********************************************************* */
358
359#endif /* PADICO_SHM_H */
assert(slab_size > 0)
struct ns_rulebucket_hash_entry_s * b
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
#define PADICO_SHM_BLOCK_CACHE_SIZE
size of the block cache in each process; to avoid starvation, we need: block_cache_size * numnodes < ...
Definition Shm.h:72
static padico_shm_block_t padico_shm_block_from_short_ptr(struct padico_shm_s *shm, void *short_ptr)
Definition Shm.h:331
return NULL
Definition Shm.h:88
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
static struct padico_shm_large_lfqueue_s * padico_shm_queue_get_lfqueue(struct padico_shm_s *shm, padico_shm_queue_t queue)
Definition Shm.h:280
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_close(struct padico_shm_s *shm)
Definition shm-sysdep.c:201
goto retry
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
#define PADICO_SHM_NUMBLOCKS
Number of blocks allocated in shm buffer.
Definition Shm.h:63
struct padico_shm_seg_directory_s __attribute__
#define PADICO_SHM_QUEUESIZE
number of pending packets per queue (short & large)
Definition Shm.h:67
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 padico_shm_block_t padico_shm_block_from_ptr(struct padico_shm_s *shm, void *ptr)
get the block given its pointer
Definition Shm.h:232
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
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
struct padico_shm_queue_s * padico_shm_queue_t
offset of a queue in the shared segment, stored in a pointer.
Definition Shm.h:85
static void * padico_shm_short_get_ptr(struct padico_shm_s *shm, padico_shm_block_t block)
Definition Shm.h:324
#define PADICO_LAST_MODULE_NAME
Definition Shm.h:55
#define PADICO_SHM_NUMNODES
Definition Shm.h:59
static void padico_shm_block_assert(struct padico_shm_s *shm, padico_shm_block_t block)
assert given offset is a valid block
Definition Shm.h:221
static padico_shm_queue_t padico_shm_queue_from_num(struct padico_shm_s *shm, int queue_num)
Definition Shm.h:271
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
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
int padico_shm_large_recv_poll(struct padico_shm_s *shm, void *bytes, size_t size, padico_shm_queue_t queue)
Definition shm-sysdep.c:486
padico_shm_queue_t padico_shm_large_recv_post(struct padico_shm_s *shm, int from)
Definition shm-sysdep.c:476
static padico_shm_block_t padico_shm_block_from_num(struct padico_shm_s *shm, int block_num)
Definition Shm.h:243
#define PADICO_SHM_BLOCKSIZE
size of data block in segment
Definition Shm.h:65
void padico_shm_directory_dump(struct padico_shm_s *shm)
dump content of shm directory, for debug
Definition shm-sysdep.c:408
#define PADICO_SHM_NUMQUEUES
number of queues for large packets in segment
Definition Shm.h:69
#define PADICO_SHM_ALIGN
Definition Shm.h:75
PUK_MOD_AUTO_DEP(SysIO, PADICO_LAST_MODULE_NAME)
struct padico_addrkey_hash_entry_block_lfstack_cell_s block[]
static int done
Definition console-mod.c:49
static int size
Definition datacheck.c:34
char * name
Definition PadicoTM.h:168
padico_rc_t rc
Definition PadicoTM.h:146
#define PADICO_TOPO_UUID_SIZE
Definition Topology.h:73
padico_topo_node_t node
Definition na-control.c:65
struct padico_shm_s * shm
Definition psp-shm.c:95
a mailbox for a node
Definition Shm.h:113
struct padico_shm_mbox_s::@66 large[128]
large messages mbox; unlocked acces, valid when pipeline != -1
struct padico_shm_short_lfqueue_s shared_queue
shared queue for short messages sent eagerly; contains block index
Definition Shm.h:115
volatile padico_shm_queue_t pipeline
allocated queue for transfer
Definition Shm.h:120
struct padico_shm_blockcache_lfqueue_s block_cache
free blocks cache
Definition Shm.h:117
struct padico_shm_short_lfqueue_s short_queues[128]
queues for short messages sent eagerly; contains block index
Definition Shm.h:116
A node descriptor.
Definition Shm.h:103
char node_uuid[32+1]
UUID identifying the node + null byte.
Definition Shm.h:104
int pid
process id
Definition Shm.h:105
int rank
index of the node in directory
Definition Shm.h:106
volatile int enabled
Definition Shm.h:107
global state of the Shm segment
Definition Shm.h:173
char * sem_path
Definition Shm.h:179
int rank
Definition Shm.h:177
ssize_t seg_size
Definition Shm.h:181
struct padico_shm_seg_directory_s * seg_directory
Definition Shm.h:174
struct padico_shm_node_s * self
Definition Shm.h:176
sem_t * sem
Definition Shm.h:180
char * shm_path
Definition Shm.h:178
struct padico_shm_seg_mbox_s * seg_mbox
mbox part of the segment; may be NULL if the segment does not use mbox (payload != -1 at init)
Definition Shm.h:175
a segment containing only a directory
Definition Shm.h:126
struct padico_shm_node_s nodes[128]
directory of node connected to the shared segment
Definition Shm.h:134
struct padico_shm_seg_directory_s::@68 build_string
build string to ensure all nodes use the same build; this field must be first
struct padico_shm_seg_directory_s::@69 directory
a full segment, including buffers
Definition Shm.h:155
struct padico_shm_seg_mbox_s seg_mbox
Definition Shm.h:157
struct padico_shm_seg_directory_s seg_directory
Definition Shm.h:156
the part of a segment dedicated to mbox & buffer s
Definition Shm.h:140
struct padico_shm_mbox_s mailboxes[128]
Definition Shm.h:141
struct padico_shm_seg_mbox_s::@70 buffer
struct padico_shm_block_lfqueue_s free_blocks
block allocator, i.e.
Definition Shm.h:145
struct padico_shm_block_lfqueue_s pending_blocks[128]
pending blocks to send (used only by nm_strat_shm)
Definition Shm.h:148
struct padico_shm_large_lfqueue_s queues[512]
pool of queues to pipeline large transfers
Definition Shm.h:146
struct padico_shm_queue_lfqueue_s free_queues
queue allocator, i.e.
Definition Shm.h:147
char block[(16 *1024) *4096]
raw blocks of data
Definition Shm.h:144
Generic shm header for short messages in the eager queue.
Definition Shm.h:163
volatile uint32_t size
actual size of data payload in the message (excluding header size)
Definition Shm.h:165
volatile uint32_t from
index of sender in directory
Definition Shm.h:164
char * ptr
Definition vpipe.c:83