1 /* 2 * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana 3 * University Research and Technology 4 * Corporation. All rights reserved. 5 * Copyright (c) 2004-2005 The University of Tennessee and The University 6 * of Tennessee Research Foundation. All rights 7 * reserved. 8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, 9 * University of Stuttgart. All rights reserved. 10 * Copyright (c) 2004-2005 The Regents of the University of California. 11 * All rights reserved. 12 * Copyright (c) 2007-2010 Cisco Systems, Inc. All rights reserved. 13 * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved. 14 * Copyright (c) 2010 IBM Corporation. All rights reserved. 15 * Copyright (c) 2010-2012 Los Alamos National Security, LLC. 16 * All rights reserved. 17 * $COPYRIGHT$ 18 * 19 * Additional copyrights may follow 20 * 21 * $HEADER$ 22 */ 23 24 /** 25 * @file 26 * 27 * shmem (shared memory backing facility) framework types, convenience macros, 28 * etc. 29 */ 30 31 #ifndef OPAL_SHMEM_TYPES_H 32 #define OPAL_SHMEM_TYPES_H 33 34 #include "opal_config.h" 35 36 #include <stddef.h> 37 #include <string.h> 38 39 BEGIN_C_DECLS 40 41 /* ////////////////////////////////////////////////////////////////////////// */ 42 /** 43 * ds_buf: pointer to opal_shmem_ds_t typedef'd struct 44 */ 45 46 /** 47 * flag indicating the state (valid/invalid) of the shmem data structure 48 * 0x0* - reserved for non-internal flags 49 */ 50 #define OPAL_SHMEM_DS_FLAGS_VALID 0x01 51 52 /** 53 * 0x1* - reserved for internal flags. that is, flags that will NOT be 54 * propagated via ds_copy during inter-process information sharing. 55 */ 56 57 /** 58 * masks out internal flags 59 */ 60 #define OPAL_SHMEM_DS_FLAGS_INTERNAL_MASK 0x0F 61 62 /** 63 * invalid id value 64 */ 65 #define OPAL_SHMEM_DS_ID_INVALID -1 66 67 /** 68 * macro that sets all bits in flags to 0 69 */ 70 #define OPAL_SHMEM_DS_RESET_FLAGS(ds_buf) \ 71 do { \ 72 (ds_buf)->flags = 0x00; \ 73 } while (0) 74 75 /** 76 * sets valid bit in flags to 1 77 */ 78 #define OPAL_SHMEM_DS_SET_VALID(ds_buf) \ 79 do { \ 80 (ds_buf)->flags |= OPAL_SHMEM_DS_FLAGS_VALID; \ 81 } while (0) 82 83 /** 84 * sets valid bit in flags to 0 85 */ 86 #define OPAL_SHMEM_DS_INVALIDATE(ds_buf) \ 87 do { \ 88 (ds_buf)->flags &= ~OPAL_SHMEM_DS_FLAGS_VALID; \ 89 } while (0) 90 91 /** 92 * evaluates to 1 if the valid bit in flags is set to 1. evaluates to 0 93 * otherwise. 94 */ 95 #define OPAL_SHMEM_DS_IS_VALID(ds_buf) \ 96 ( (ds_buf)->flags & OPAL_SHMEM_DS_FLAGS_VALID ) 97 98 typedef uint8_t opal_shmem_ds_flag_t; 99 100 /* shared memory segment header */ 101 struct opal_shmem_seg_hdr_t { 102 /* segment lock */ 103 opal_atomic_lock_t lock; 104 /* pid of the segment creator */ 105 pid_t cpid; 106 }; 107 typedef struct opal_shmem_seg_hdr_t opal_shmem_seg_hdr_t; 108 109 struct opal_shmem_ds_t { 110 /* pid of the shared memory segment creator */ 111 pid_t seg_cpid; 112 /* state flags */ 113 opal_shmem_ds_flag_t flags; 114 /* ds id */ 115 int seg_id; 116 /* size of shared memory segment */ 117 size_t seg_size; 118 /* base address of shared memory segment */ 119 unsigned char *seg_base_addr; 120 /* path to backing store -- last element so we can easily calculate the 121 * "real" size of opal_shmem_ds_t. that is, the amount of the struct that 122 * is actually being used. for example: if seg_name is something like: 123 * "foo_baz" and OPAL_PATH_MAX is 4096, we want to know that only a very 124 * limited amount of the seg_name buffer is actually being used. 125 */ 126 char seg_name[OPAL_PATH_MAX]; 127 }; 128 typedef struct opal_shmem_ds_t opal_shmem_ds_t; 129 130 /* ////////////////////////////////////////////////////////////////////////// */ 131 /** 132 * Simply returns the amount of used space. For use when sending the entire 133 * opal_shmem_ds_t payload isn't viable -- due to the potential disparity 134 * between the reserved buffer space and what is actually in use. 135 */ 136 static inline size_t 137 opal_shmem_sizeof_shmem_ds(const opal_shmem_ds_t *ds_bufp) 138 { 139 char *name_base = NULL; 140 size_t name_buf_offset = offsetof(opal_shmem_ds_t, seg_name); 141 142 name_base = (char *)ds_bufp + name_buf_offset; 143 144 return name_buf_offset + strlen(name_base) + 1; 145 } 146 147 END_C_DECLS 148 149 #endif /* OPAL_SHMEM_TYPES_H */