15184Sek110237 /* 25184Sek110237 * CDDL HEADER START 35184Sek110237 * 45184Sek110237 * The contents of this file are subject to the terms of the 55184Sek110237 * Common Development and Distribution License (the "License"). 65184Sek110237 * You may not use this file except in compliance with the License. 75184Sek110237 * 85184Sek110237 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95184Sek110237 * or http://www.opensolaris.org/os/licensing. 105184Sek110237 * See the License for the specific language governing permissions 115184Sek110237 * and limitations under the License. 125184Sek110237 * 135184Sek110237 * When distributing Covered Code, include this CDDL HEADER in each 145184Sek110237 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155184Sek110237 * If applicable, add the following below this CDDL HEADER, with the 165184Sek110237 * fields enclosed by brackets "[]" replaced with your own identifying 175184Sek110237 * information: Portions Copyright [yyyy] [name of copyright owner] 185184Sek110237 * 195184Sek110237 * CDDL HEADER END 205184Sek110237 */ 215184Sek110237 /* 226084Saw148015 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 235184Sek110237 * Use is subject to license terms. 245184Sek110237 */ 255184Sek110237 265184Sek110237 #ifndef _FB_IPC_H 275184Sek110237 #define _FB_IPC_H 285184Sek110237 295184Sek110237 #include "config.h" 305184Sek110237 #include <pthread.h> 315184Sek110237 325184Sek110237 #include "procflow.h" 335184Sek110237 #include "threadflow.h" 345184Sek110237 #include "fileset.h" 355184Sek110237 #include "flowop.h" 366212Saw148015 #include "fb_random.h" 375184Sek110237 #include "filebench.h" 385184Sek110237 395184Sek110237 #ifdef __cplusplus 405184Sek110237 extern "C" { 415184Sek110237 #endif 425184Sek110237 435184Sek110237 #ifdef USE_PROCESS_MODEL 445184Sek110237 #define FILEBENCH_MEMSIZE 4096 455184Sek110237 #else 465184Sek110237 #define FILEBENCH_MEMSIZE 2048 475184Sek110237 #endif /* USE_PROCESS_MODEL */ 485184Sek110237 49*7556SAndrew.W.Wilson@sun.com /* Mutex Priority Inheritance and Robustness flags */ 50*7556SAndrew.W.Wilson@sun.com #define IPC_MUTEX_NORMAL 0x0 51*7556SAndrew.W.Wilson@sun.com #define IPC_MUTEX_PRIORITY 0x1 52*7556SAndrew.W.Wilson@sun.com #define IPC_MUTEX_ROBUST 0x2 53*7556SAndrew.W.Wilson@sun.com #define IPC_MUTEX_PRI_ROB 0x3 54*7556SAndrew.W.Wilson@sun.com #define IPC_NUM_MUTEX_ATTRS 4 55*7556SAndrew.W.Wilson@sun.com 565184Sek110237 #define FILEBENCH_NFILESETS FILEBENCH_MEMSIZE 575184Sek110237 #define FILEBENCH_NFILESETENTRIES (1024 * 1024) 585184Sek110237 #define FILEBENCH_NPROCFLOWS FILEBENCH_MEMSIZE 596212Saw148015 #define FILEBENCH_NTHREADFLOWS (64 * FILEBENCH_MEMSIZE) 606212Saw148015 #define FILEBENCH_NFLOWOPS (64 * FILEBENCH_MEMSIZE) 615184Sek110237 #define FILEBENCH_NVARS FILEBENCH_MEMSIZE 626212Saw148015 #define FILEBENCH_NRANDDISTS (FILEBENCH_MEMSIZE/4) 636212Saw148015 #define FILEBENCH_FILESETPATHMEMORY (FILEBENCH_NFILESETENTRIES*FSE_MAXPATHLEN) 646212Saw148015 #define FILEBENCH_STRINGMEMORY (FILEBENCH_NVARS * 128) 655184Sek110237 #define FILEBENCH_MAXBITMAP FILEBENCH_NFILESETENTRIES 665184Sek110237 675673Saw148015 #define FILEBENCH_PROCFLOW 0 685673Saw148015 #define FILEBENCH_THREADFLOW 1 695673Saw148015 #define FILEBENCH_FLOWOP 2 706212Saw148015 #define FILEBENCH_AVD 3 716212Saw148015 #define FILEBENCH_VARIABLE 4 726212Saw148015 #define FILEBENCH_FILESET 5 736212Saw148015 #define FILEBENCH_FILESETENTRY 6 746212Saw148015 #define FILEBENCH_RANDDIST 7 755673Saw148015 #define FILEBENCH_TYPES 8 765184Sek110237 775184Sek110237 #define FILEBENCH_NSEMS 128 785184Sek110237 796084Saw148015 #define FILEBENCH_ABORT_ERROR 1 806084Saw148015 #define FILEBENCH_ABORT_DONE 2 816084Saw148015 #define FILEBENCH_ABORT_RSRC 3 826084Saw148015 836084Saw148015 #define FILEBENCH_MODE_TIMEOUT 0x0 846084Saw148015 #define FILEBENCH_MODE_Q1STDONE 0x1 856084Saw148015 #define FILEBENCH_MODE_QALLDONE 0x2 866084Saw148015 875184Sek110237 typedef struct filebench_shm { 88*7556SAndrew.W.Wilson@sun.com /* 89*7556SAndrew.W.Wilson@sun.com * All state down to shm_marker are set to zero during filebench 90*7556SAndrew.W.Wilson@sun.com * initialization 91*7556SAndrew.W.Wilson@sun.com */ 92*7556SAndrew.W.Wilson@sun.com 93*7556SAndrew.W.Wilson@sun.com /* 94*7556SAndrew.W.Wilson@sun.com * list of defined filesets and related locks. 95*7556SAndrew.W.Wilson@sun.com */ 96*7556SAndrew.W.Wilson@sun.com fileset_t *shm_filesetlist; /* list of defined filesets */ 97*7556SAndrew.W.Wilson@sun.com pthread_mutex_t shm_fileset_lock; /* protects access to list */ 98*7556SAndrew.W.Wilson@sun.com 99*7556SAndrew.W.Wilson@sun.com /* 100*7556SAndrew.W.Wilson@sun.com * parallel file allocation control. Restricts number of spawned 101*7556SAndrew.W.Wilson@sun.com * allocation threads and allows waiting for allocation to finish. 102*7556SAndrew.W.Wilson@sun.com */ 103*7556SAndrew.W.Wilson@sun.com pthread_cond_t shm_fsparalloc_cv; /* cv to wait for alloc threads */ 104*7556SAndrew.W.Wilson@sun.com int shm_fsparalloc_count; /* active alloc thread count */ 105*7556SAndrew.W.Wilson@sun.com pthread_mutex_t shm_fsparalloc_lock; /* lock to protect count */ 106*7556SAndrew.W.Wilson@sun.com 107*7556SAndrew.W.Wilson@sun.com /* 108*7556SAndrew.W.Wilson@sun.com * Procflow and process state 109*7556SAndrew.W.Wilson@sun.com */ 110*7556SAndrew.W.Wilson@sun.com procflow_t *shm_proclist; /* list of defined procflows */ 111*7556SAndrew.W.Wilson@sun.com pthread_mutex_t shm_procflow_lock; /* protects shm_proclist */ 112*7556SAndrew.W.Wilson@sun.com int shm_procs_running; /* count of running processes */ 113*7556SAndrew.W.Wilson@sun.com pthread_mutex_t shm_procs_running_lock; /* protects shm_procs_running */ 114*7556SAndrew.W.Wilson@sun.com int shm_f_abort; /* stop the run NOW! */ 115*7556SAndrew.W.Wilson@sun.com pthread_rwlock_t shm_run_lock; /* used as barrier to sync run */ 116*7556SAndrew.W.Wilson@sun.com #ifdef USE_PROCESS_MODEL 117*7556SAndrew.W.Wilson@sun.com pthread_cond_t shm_procflow_procs_cv; /* pauses procflow_init till */ 118*7556SAndrew.W.Wilson@sun.com #endif /* all procflows are created */ 119*7556SAndrew.W.Wilson@sun.com 120*7556SAndrew.W.Wilson@sun.com /* 121*7556SAndrew.W.Wilson@sun.com * flowop state 122*7556SAndrew.W.Wilson@sun.com */ 123*7556SAndrew.W.Wilson@sun.com flowop_t *shm_flowoplist; /* list of defined flowops */ 124*7556SAndrew.W.Wilson@sun.com pthread_mutex_t shm_flowop_lock; /* protects flowoplist */ 125*7556SAndrew.W.Wilson@sun.com pthread_rwlock_t shm_flowop_find_lock; /* prevents flowop_find() */ 126*7556SAndrew.W.Wilson@sun.com /* during initial flowop creation */ 127*7556SAndrew.W.Wilson@sun.com 128*7556SAndrew.W.Wilson@sun.com /* 129*7556SAndrew.W.Wilson@sun.com * lists related to variables 130*7556SAndrew.W.Wilson@sun.com */ 131*7556SAndrew.W.Wilson@sun.com 132*7556SAndrew.W.Wilson@sun.com var_t *shm_var_list; /* normal variables */ 133*7556SAndrew.W.Wilson@sun.com var_t *shm_var_dyn_list; /* special system variables */ 134*7556SAndrew.W.Wilson@sun.com var_t *shm_var_loc_list; /* variables local to comp flowops */ 135*7556SAndrew.W.Wilson@sun.com randdist_t *shm_rand_list; /* random variables */ 136*7556SAndrew.W.Wilson@sun.com 137*7556SAndrew.W.Wilson@sun.com /* 138*7556SAndrew.W.Wilson@sun.com * log and statistics dumping controls and state 139*7556SAndrew.W.Wilson@sun.com */ 140*7556SAndrew.W.Wilson@sun.com int shm_debug_level; 141*7556SAndrew.W.Wilson@sun.com int shm_bequiet; /* pause run while collecting stats */ 142*7556SAndrew.W.Wilson@sun.com int shm_log_fd; /* log file descriptor */ 143*7556SAndrew.W.Wilson@sun.com int shm_dump_fd; /* dump file descriptor */ 144*7556SAndrew.W.Wilson@sun.com char shm_dump_filename[MAXPATHLEN]; 145*7556SAndrew.W.Wilson@sun.com 146*7556SAndrew.W.Wilson@sun.com /* 147*7556SAndrew.W.Wilson@sun.com * Event generator state 148*7556SAndrew.W.Wilson@sun.com */ 149*7556SAndrew.W.Wilson@sun.com int shm_eventgen_hz; /* number of events per sec. */ 150*7556SAndrew.W.Wilson@sun.com uint64_t shm_eventgen_q; /* count of unclaimed events */ 151*7556SAndrew.W.Wilson@sun.com pthread_mutex_t shm_eventgen_lock; /* lock protecting count */ 152*7556SAndrew.W.Wilson@sun.com pthread_cond_t shm_eventgen_cv; /* cv to wait on for more events */ 153*7556SAndrew.W.Wilson@sun.com 154*7556SAndrew.W.Wilson@sun.com /* 155*7556SAndrew.W.Wilson@sun.com * System 5 semaphore state 156*7556SAndrew.W.Wilson@sun.com */ 157*7556SAndrew.W.Wilson@sun.com key_t shm_semkey; 158*7556SAndrew.W.Wilson@sun.com int shm_sys_semid; 159*7556SAndrew.W.Wilson@sun.com char shm_semids[FILEBENCH_NSEMS]; 160*7556SAndrew.W.Wilson@sun.com 161*7556SAndrew.W.Wilson@sun.com /* 162*7556SAndrew.W.Wilson@sun.com * Misc. pointers and state 163*7556SAndrew.W.Wilson@sun.com */ 164*7556SAndrew.W.Wilson@sun.com char shm_fscriptname[1024]; 165*7556SAndrew.W.Wilson@sun.com int shm_id; 166*7556SAndrew.W.Wilson@sun.com int shm_rmode; 167*7556SAndrew.W.Wilson@sun.com int shm_1st_err; 1686391Saw148015 pthread_mutex_t shm_threadflow_lock; 1696391Saw148015 pthread_mutex_t shm_msg_lock; 170*7556SAndrew.W.Wilson@sun.com pthread_mutexattr_t shm_mutexattr[IPC_NUM_MUTEX_ATTRS]; 1716305Saw148015 char *shm_string_ptr; 1726305Saw148015 char *shm_path_ptr; 1736391Saw148015 hrtime_t shm_epoch; 1746305Saw148015 hrtime_t shm_starttime; 1756391Saw148015 int shm_utid; 176*7556SAndrew.W.Wilson@sun.com 177*7556SAndrew.W.Wilson@sun.com /* 178*7556SAndrew.W.Wilson@sun.com * Shared memory allocation control 179*7556SAndrew.W.Wilson@sun.com */ 180*7556SAndrew.W.Wilson@sun.com pthread_mutex_t shm_malloc_lock; 181*7556SAndrew.W.Wilson@sun.com pthread_mutex_t shm_ism_lock; 182*7556SAndrew.W.Wilson@sun.com int shm_bitmap[FILEBENCH_TYPES][FILEBENCH_MAXBITMAP]; 183*7556SAndrew.W.Wilson@sun.com int shm_lastbitmapindex[FILEBENCH_TYPES]; 1845184Sek110237 size_t shm_required; 1855184Sek110237 size_t shm_allocated; 1865184Sek110237 caddr_t shm_addr; 1875184Sek110237 char *shm_ptr; 188*7556SAndrew.W.Wilson@sun.com 189*7556SAndrew.W.Wilson@sun.com int shm_marker; /* end of pre-zeroed data */ 1905184Sek110237 191*7556SAndrew.W.Wilson@sun.com /* 192*7556SAndrew.W.Wilson@sun.com * actual storage for shared entities. 193*7556SAndrew.W.Wilson@sun.com * These are not zeroed during initialization 194*7556SAndrew.W.Wilson@sun.com */ 1956305Saw148015 fileset_t shm_fileset[FILEBENCH_NFILESETS]; 1966305Saw148015 filesetentry_t shm_filesetentry[FILEBENCH_NFILESETENTRIES]; 1976305Saw148015 char shm_filesetpaths[FILEBENCH_FILESETPATHMEMORY]; 1986305Saw148015 procflow_t shm_procflow[FILEBENCH_NPROCFLOWS]; 1996305Saw148015 threadflow_t shm_threadflow[FILEBENCH_NTHREADFLOWS]; 2006305Saw148015 flowop_t shm_flowop[FILEBENCH_NFLOWOPS]; 2016305Saw148015 var_t shm_var[FILEBENCH_NVARS]; 2026212Saw148015 randdist_t shm_randdist[FILEBENCH_NRANDDISTS]; 2036212Saw148015 struct avd shm_avd_ptrs[FILEBENCH_NVARS * 2]; 2046305Saw148015 char shm_strings[FILEBENCH_STRINGMEMORY]; 2055184Sek110237 } filebench_shm_t; 2065184Sek110237 2075184Sek110237 extern char *shmpath; 2085184Sek110237 2095184Sek110237 void ipc_init(void); 2105184Sek110237 void *ipc_malloc(int type); 2115184Sek110237 void ipc_free(int type, char *addr); 2125184Sek110237 int ipc_attach(caddr_t shmaddr); 213*7556SAndrew.W.Wilson@sun.com pthread_mutexattr_t *ipc_mutexattr(int); 2145184Sek110237 pthread_condattr_t *ipc_condattr(void); 2155184Sek110237 int ipc_semidalloc(void); 2165184Sek110237 void ipc_semidfree(int semid); 2175184Sek110237 char *ipc_stralloc(char *string); 2185184Sek110237 char *ipc_pathalloc(char *string); 2195184Sek110237 int ipc_mutex_lock(pthread_mutex_t *mutex); 2205184Sek110237 int ipc_mutex_unlock(pthread_mutex_t *mutex); 2215184Sek110237 void ipc_seminit(void); 2225184Sek110237 char *ipc_ismmalloc(size_t size); 2235184Sek110237 int ipc_ismcreate(size_t size); 2245184Sek110237 void ipc_ismdelete(void); 2256750Sek110237 void ipc_fini(void); 2265184Sek110237 2275184Sek110237 extern filebench_shm_t *filebench_shm; 2285184Sek110237 2295184Sek110237 #ifdef __cplusplus 2305184Sek110237 } 2315184Sek110237 #endif 2325184Sek110237 2335184Sek110237 #endif /* _FB_IPC_H */ 234