1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _FB_IPC_H 27 #define _FB_IPC_H 28 29 #include "config.h" 30 #include <pthread.h> 31 32 #include "procflow.h" 33 #include "threadflow.h" 34 #include "fileset.h" 35 #include "flowop.h" 36 #include "fb_random.h" 37 #include "fsplug.h" 38 #include "filebench.h" 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 #ifdef USE_PROCESS_MODEL 45 #define FILEBENCH_MEMSIZE 4096 46 #else 47 #define FILEBENCH_MEMSIZE 2048 48 #endif /* USE_PROCESS_MODEL */ 49 50 /* Mutex Priority Inheritance and Robustness flags */ 51 #define IPC_MUTEX_NORMAL 0x0 52 #define IPC_MUTEX_PRIORITY 0x1 53 #define IPC_MUTEX_ROBUST 0x2 54 #define IPC_MUTEX_PRI_ROB 0x3 55 #define IPC_NUM_MUTEX_ATTRS 4 56 57 #define FILEBENCH_NFILESETS FILEBENCH_MEMSIZE 58 #define FILEBENCH_NFILESETENTRIES (1024 * 1024) 59 #define FILEBENCH_NPROCFLOWS FILEBENCH_MEMSIZE 60 #define FILEBENCH_NTHREADFLOWS (64 * FILEBENCH_MEMSIZE) 61 #define FILEBENCH_NFLOWOPS (64 * FILEBENCH_MEMSIZE) 62 #define FILEBENCH_NVARS FILEBENCH_MEMSIZE 63 #define FILEBENCH_NRANDDISTS (FILEBENCH_MEMSIZE/4) 64 #define FILEBENCH_FILESETPATHMEMORY (FILEBENCH_NFILESETENTRIES*FSE_MAXPATHLEN) 65 #define FILEBENCH_STRINGMEMORY (FILEBENCH_NVARS * 128) 66 #define FILEBENCH_MAXBITMAP FILEBENCH_NFILESETENTRIES 67 68 #define FILEBENCH_PROCFLOW 0 69 #define FILEBENCH_THREADFLOW 1 70 #define FILEBENCH_FLOWOP 2 71 #define FILEBENCH_AVD 3 72 #define FILEBENCH_VARIABLE 4 73 #define FILEBENCH_FILESET 5 74 #define FILEBENCH_FILESETENTRY 6 75 #define FILEBENCH_RANDDIST 7 76 #define FILEBENCH_TYPES 8 77 78 #define FILEBENCH_NSEMS 128 79 80 #define FILEBENCH_ABORT_ERROR 1 81 #define FILEBENCH_ABORT_DONE 2 82 #define FILEBENCH_ABORT_RSRC 3 83 84 #define FILEBENCH_MODE_TIMEOUT 0x0 85 #define FILEBENCH_MODE_Q1STDONE 0x1 86 #define FILEBENCH_MODE_QALLDONE 0x2 87 88 typedef struct filebench_shm { 89 /* 90 * All state down to shm_marker are set to zero during filebench 91 * initialization 92 */ 93 94 /* 95 * list of defined filesets and related locks. 96 */ 97 fileset_t *shm_filesetlist; /* list of defined filesets */ 98 pthread_mutex_t shm_fileset_lock; /* protects access to list */ 99 100 /* 101 * parallel file allocation control. Restricts number of spawned 102 * allocation threads and allows waiting for allocation to finish. 103 */ 104 pthread_cond_t shm_fsparalloc_cv; /* cv to wait for alloc threads */ 105 int shm_fsparalloc_count; /* active alloc thread count */ 106 pthread_mutex_t shm_fsparalloc_lock; /* lock to protect count */ 107 108 /* 109 * Procflow and process state 110 */ 111 procflow_t *shm_proclist; /* list of defined procflows */ 112 pthread_mutex_t shm_procflow_lock; /* protects shm_proclist */ 113 int shm_procs_running; /* count of running processes */ 114 pthread_mutex_t shm_procs_running_lock; /* protects shm_procs_running */ 115 int shm_f_abort; /* stop the run NOW! */ 116 pthread_rwlock_t shm_run_lock; /* used as barrier to sync run */ 117 #ifdef USE_PROCESS_MODEL 118 pthread_cond_t shm_procflow_procs_cv; /* pauses procflow_init till */ 119 #endif /* all procflows are created */ 120 121 /* 122 * flowop state 123 */ 124 flowop_t *shm_flowoplist; /* list of defined flowops */ 125 pthread_mutex_t shm_flowop_lock; /* protects flowoplist */ 126 pthread_rwlock_t shm_flowop_find_lock; /* prevents flowop_find() */ 127 /* during initial flowop creation */ 128 129 /* 130 * lists related to variables 131 */ 132 133 var_t *shm_var_list; /* normal variables */ 134 var_t *shm_var_dyn_list; /* special system variables */ 135 var_t *shm_var_loc_list; /* variables local to comp flowops */ 136 randdist_t *shm_rand_list; /* random variables */ 137 138 /* 139 * log and statistics dumping controls and state 140 */ 141 int shm_debug_level; 142 int shm_bequiet; /* pause run while collecting stats */ 143 int shm_log_fd; /* log file descriptor */ 144 int shm_dump_fd; /* dump file descriptor */ 145 char shm_dump_filename[MAXPATHLEN]; 146 147 /* 148 * Event generator state 149 */ 150 avd_t shm_eventgen_hz; /* number of events per sec. */ 151 uint64_t shm_eventgen_q; /* count of unclaimed events */ 152 pthread_mutex_t shm_eventgen_lock; /* lock protecting count */ 153 pthread_cond_t shm_eventgen_cv; /* cv to wait on for more events */ 154 155 /* 156 * System 5 semaphore state 157 */ 158 key_t shm_semkey; 159 int shm_sys_semid; 160 char shm_semids[FILEBENCH_NSEMS]; 161 162 /* 163 * Misc. pointers and state 164 */ 165 char shm_fscriptname[1024]; 166 int shm_id; 167 int shm_rmode; 168 int shm_1st_err; 169 pthread_mutex_t shm_threadflow_lock; 170 pthread_mutex_t shm_msg_lock; 171 pthread_mutexattr_t shm_mutexattr[IPC_NUM_MUTEX_ATTRS]; 172 char *shm_string_ptr; 173 char *shm_path_ptr; 174 hrtime_t shm_epoch; 175 hrtime_t shm_starttime; 176 int shm_utid; 177 178 /* 179 * Shared memory allocation control 180 */ 181 pthread_mutex_t shm_malloc_lock; 182 pthread_mutex_t shm_ism_lock; 183 int shm_bitmap[FILEBENCH_TYPES][FILEBENCH_MAXBITMAP]; 184 int shm_lastbitmapindex[FILEBENCH_TYPES]; 185 size_t shm_required; 186 size_t shm_allocated; 187 caddr_t shm_addr; 188 char *shm_ptr; 189 190 /* 191 * Type of plug-in file system client to use. Defaults to 192 * local file system, which is type "0". 193 */ 194 fb_plugin_type_t shm_filesys_type; 195 196 /* 197 * end of pre-zeroed data 198 */ 199 int shm_marker; 200 201 /* 202 * actual storage for shared entities. 203 * These are not zeroed during initialization 204 */ 205 fileset_t shm_fileset[FILEBENCH_NFILESETS]; 206 filesetentry_t shm_filesetentry[FILEBENCH_NFILESETENTRIES]; 207 char shm_filesetpaths[FILEBENCH_FILESETPATHMEMORY]; 208 procflow_t shm_procflow[FILEBENCH_NPROCFLOWS]; 209 threadflow_t shm_threadflow[FILEBENCH_NTHREADFLOWS]; 210 flowop_t shm_flowop[FILEBENCH_NFLOWOPS]; 211 var_t shm_var[FILEBENCH_NVARS]; 212 randdist_t shm_randdist[FILEBENCH_NRANDDISTS]; 213 struct avd shm_avd_ptrs[FILEBENCH_NVARS * 2]; 214 char shm_strings[FILEBENCH_STRINGMEMORY]; 215 } filebench_shm_t; 216 217 extern char *shmpath; 218 219 void ipc_init(void); 220 void *ipc_malloc(int type); 221 void ipc_free(int type, char *addr); 222 int ipc_attach(caddr_t shmaddr); 223 pthread_mutexattr_t *ipc_mutexattr(int); 224 pthread_condattr_t *ipc_condattr(void); 225 int ipc_semidalloc(void); 226 void ipc_semidfree(int semid); 227 char *ipc_stralloc(char *string); 228 char *ipc_pathalloc(char *string); 229 int ipc_mutex_lock(pthread_mutex_t *mutex); 230 int ipc_mutex_unlock(pthread_mutex_t *mutex); 231 void ipc_seminit(void); 232 char *ipc_ismmalloc(size_t size); 233 int ipc_ismcreate(size_t size); 234 void ipc_ismdelete(void); 235 void ipc_fini(void); 236 237 extern filebench_shm_t *filebench_shm; 238 239 #ifdef __cplusplus 240 } 241 #endif 242 243 #endif /* _FB_IPC_H */ 244