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 2008 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 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #include "config.h" 32 #include <pthread.h> 33 34 #include "procflow.h" 35 #include "threadflow.h" 36 #include "fileset.h" 37 #include "flowop.h" 38 #include "fb_random.h" 39 #include "filebench.h" 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 #ifdef USE_PROCESS_MODEL 46 #define FILEBENCH_MEMSIZE 4096 47 #else 48 #define FILEBENCH_MEMSIZE 2048 49 #endif /* USE_PROCESS_MODEL */ 50 51 #define FILEBENCH_NFILESETS FILEBENCH_MEMSIZE 52 #define FILEBENCH_NFILESETENTRIES (1024 * 1024) 53 #define FILEBENCH_NPROCFLOWS FILEBENCH_MEMSIZE 54 #define FILEBENCH_NTHREADFLOWS (64 * FILEBENCH_MEMSIZE) 55 #define FILEBENCH_NFLOWOPS (64 * FILEBENCH_MEMSIZE) 56 #define FILEBENCH_NVARS FILEBENCH_MEMSIZE 57 #define FILEBENCH_NRANDDISTS (FILEBENCH_MEMSIZE/4) 58 #define FILEBENCH_FILESETPATHMEMORY (FILEBENCH_NFILESETENTRIES*FSE_MAXPATHLEN) 59 #define FILEBENCH_STRINGMEMORY (FILEBENCH_NVARS * 128) 60 #define FILEBENCH_MAXBITMAP FILEBENCH_NFILESETENTRIES 61 62 #define FILEBENCH_PROCFLOW 0 63 #define FILEBENCH_THREADFLOW 1 64 #define FILEBENCH_FLOWOP 2 65 #define FILEBENCH_AVD 3 66 #define FILEBENCH_VARIABLE 4 67 #define FILEBENCH_FILESET 5 68 #define FILEBENCH_FILESETENTRY 6 69 #define FILEBENCH_RANDDIST 7 70 #define FILEBENCH_TYPES 8 71 72 #define FILEBENCH_NSEMS 128 73 74 #define FILEBENCH_ABORT_ERROR 1 75 #define FILEBENCH_ABORT_DONE 2 76 #define FILEBENCH_ABORT_RSRC 3 77 78 #define FILEBENCH_MODE_TIMEOUT 0x0 79 #define FILEBENCH_MODE_Q1STDONE 0x1 80 #define FILEBENCH_MODE_QALLDONE 0x2 81 82 typedef struct filebench_shm { 83 pthread_mutex_t fileset_lock; 84 pthread_mutex_t procflow_lock; 85 pthread_mutex_t threadflow_lock; 86 pthread_mutex_t flowop_lock; 87 pthread_mutex_t msg_lock; 88 pthread_mutex_t shm_malloc_lock; 89 pthread_mutex_t shm_ism_lock; 90 pthread_rwlock_t run_lock; 91 pthread_rwlock_t flowop_find_lock; 92 93 char *shm_string_ptr; 94 char *shm_path_ptr; 95 fileset_t *filesetlist; 96 flowop_t *flowoplist; 97 procflow_t *proclist; 98 var_t *var_list; 99 var_t *var_dyn_list; 100 randdist_t *shm_rand_list; 101 int debug_level; 102 hrtime_t epoch; 103 hrtime_t shm_starttime; 104 int bequiet; 105 key_t semkey; 106 int seminit; 107 int semid_seq; 108 int utid; 109 int log_fd; 110 int dump_fd; 111 char dump_filename[MAXPATHLEN]; 112 pthread_mutex_t eventgen_lock; 113 pthread_cond_t eventgen_cv; 114 int eventgen_hz; 115 uint64_t eventgen_q; 116 char fscriptname[1024]; 117 int shm_id; 118 size_t shm_required; 119 size_t shm_allocated; 120 caddr_t shm_addr; 121 char *shm_ptr; 122 int shm_running; 123 int f_abort; 124 int shm_rmode; 125 int shm_1st_err; 126 int shm_bitmap[FILEBENCH_TYPES][FILEBENCH_MAXBITMAP]; 127 int shm_lastbitmapindex[FILEBENCH_TYPES]; 128 129 int shm_marker; 130 131 fileset_t shm_fileset[FILEBENCH_NFILESETS]; 132 filesetentry_t shm_filesetentry[FILEBENCH_NFILESETENTRIES]; 133 char shm_filesetpaths[FILEBENCH_FILESETPATHMEMORY]; 134 procflow_t shm_procflow[FILEBENCH_NPROCFLOWS]; 135 threadflow_t shm_threadflow[FILEBENCH_NTHREADFLOWS]; 136 flowop_t shm_flowop[FILEBENCH_NFLOWOPS]; 137 var_t shm_var[FILEBENCH_NVARS]; 138 randdist_t shm_randdist[FILEBENCH_NRANDDISTS]; 139 struct avd shm_avd_ptrs[FILEBENCH_NVARS * 2]; 140 char shm_strings[FILEBENCH_STRINGMEMORY]; 141 char semids[FILEBENCH_NSEMS]; 142 } filebench_shm_t; 143 144 extern char *shmpath; 145 146 void ipc_init(void); 147 void *ipc_malloc(int type); 148 void ipc_free(int type, char *addr); 149 int ipc_attach(caddr_t shmaddr); 150 pthread_mutexattr_t *ipc_mutexattr(void); 151 pthread_condattr_t *ipc_condattr(void); 152 int ipc_semidalloc(void); 153 void ipc_semidfree(int semid); 154 char *ipc_stralloc(char *string); 155 char *ipc_pathalloc(char *string); 156 int ipc_mutex_lock(pthread_mutex_t *mutex); 157 int ipc_mutex_unlock(pthread_mutex_t *mutex); 158 void ipc_seminit(void); 159 char *ipc_ismmalloc(size_t size); 160 int ipc_ismcreate(size_t size); 161 void ipc_ismdelete(void); 162 void ipc_cleanup(void); 163 164 extern filebench_shm_t *filebench_shm; 165 166 #ifdef __cplusplus 167 } 168 #endif 169 170 #endif /* _FB_IPC_H */ 171