Home | History | Annotate | Download | only in common
      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 #define	FILEBENCH_ABORT_FINI	4
     84 
     85 	/* run modes */
     86 #define	FILEBENCH_MODE_TIMEOUT	0x0
     87 #define	FILEBENCH_MODE_Q1STDONE	0x1
     88 #define	FILEBENCH_MODE_QALLDONE	0x2
     89 
     90 	/* misc. modes */
     91 #define	FILEBENCH_MODE_NOUSAGE	0x01
     92 
     93 typedef struct filebench_shm {
     94 	/*
     95 	 * All state down to shm_marker are set to zero during filebench
     96 	 * initialization
     97 	 */
     98 
     99 	/*
    100 	 * list of defined filesets and related locks.
    101 	 */
    102 	fileset_t	*shm_filesetlist; /* list of defined filesets */
    103 	pthread_mutex_t shm_fileset_lock; /* protects access to list */
    104 
    105 	/*
    106 	 * parallel file allocation  control. Restricts number of spawned
    107 	 * allocation threads and allows waiting for allocation to finish.
    108 	 */
    109 	pthread_cond_t	shm_fsparalloc_cv;    /* cv to wait for alloc threads */
    110 	int		shm_fsparalloc_count; /* active alloc thread count */
    111 	pthread_mutex_t	shm_fsparalloc_lock;  /* lock to protect count */
    112 
    113 	/*
    114 	 * Procflow and process state
    115 	 */
    116 	procflow_t	*shm_proclist;	   /* list of defined procflows */
    117 	pthread_mutex_t shm_procflow_lock; /* protects shm_proclist */
    118 	int		shm_procs_running; /* count of running processes */
    119 	pthread_mutex_t shm_procs_running_lock;	/* protects shm_procs_running */
    120 	int		shm_f_abort;	/* stop the run NOW! */
    121 	pthread_rwlock_t shm_run_lock;	/* used as barrier to sync run */
    122 #ifdef USE_PROCESS_MODEL
    123 	pthread_cond_t  shm_procflow_procs_cv;	/* pauses procflow_init till */
    124 #endif						/* all procflows are created */
    125 
    126 	/*
    127 	 * flowop state
    128 	 */
    129 	flowop_t	*shm_flowoplist;	/* list of defined flowops */
    130 	pthread_mutex_t shm_flowop_lock;	/* protects flowoplist */
    131 	pthread_rwlock_t shm_flowop_find_lock;	/* prevents flowop_find() */
    132 					    /* during initial flowop creation */
    133 
    134 	/*
    135 	 * lists related to variables
    136 	 */
    137 
    138 	var_t		*shm_var_list;	   /* normal variables */
    139 	var_t		*shm_var_dyn_list; /* special system variables */
    140 	var_t		*shm_var_loc_list; /* variables local to comp flowops */
    141 	randdist_t	*shm_rand_list;	   /* random variables */
    142 
    143 	/*
    144 	 * log and statistics dumping controls and state
    145 	 */
    146 	int		shm_debug_level;
    147 	int		shm_bequiet;	/* pause run while collecting stats */
    148 	int		shm_log_fd;	/* log file descriptor */
    149 	int		shm_dump_fd;	/* dump file descriptor */
    150 	char		shm_dump_filename[MAXPATHLEN];
    151 
    152 	/*
    153 	 * Event generator state
    154 	 */
    155 	int		shm_eventgen_enabled; /* event gen in operation */
    156 	avd_t		shm_eventgen_hz;   /* number of events per sec. */
    157 	uint64_t	shm_eventgen_q;    /* count of unclaimed events */
    158 	pthread_mutex_t	shm_eventgen_lock; /* lock protecting count */
    159 	pthread_cond_t	shm_eventgen_cv;   /* cv to wait on for more events */
    160 
    161 	/*
    162 	 * System 5 semaphore state
    163 	 */
    164 	key_t		shm_semkey;
    165 	int		shm_sys_semid;
    166 	char		shm_semids[FILEBENCH_NSEMS];
    167 
    168 	/*
    169 	 * Misc. pointers and state
    170 	 */
    171 	char		shm_fscriptname[1024];
    172 	int		shm_id;
    173 	int		shm_rmode;	/* run mode settings */
    174 	int		shm_mmode;	/* misc. mode settings */
    175 	int		shm_1st_err;
    176 	pthread_mutex_t shm_threadflow_lock;
    177 	pthread_mutex_t shm_msg_lock;
    178 	pthread_mutexattr_t shm_mutexattr[IPC_NUM_MUTEX_ATTRS];
    179 	char		*shm_string_ptr;
    180 	char		*shm_path_ptr;
    181 	hrtime_t	shm_epoch;
    182 	hrtime_t	shm_starttime;
    183 	int		shm_utid;
    184 
    185 	/*
    186 	 * Shared memory allocation control
    187 	 */
    188 	pthread_mutex_t shm_malloc_lock;
    189 	pthread_mutex_t shm_ism_lock;
    190 	int		shm_bitmap[FILEBENCH_TYPES][FILEBENCH_MAXBITMAP];
    191 	int		shm_lastbitmapindex[FILEBENCH_TYPES];
    192 	size_t		shm_required;
    193 	size_t		shm_allocated;
    194 	caddr_t		shm_addr;
    195 	char		*shm_ptr;
    196 
    197 	/*
    198 	 * Type of plug-in file system client to use. Defaults to
    199 	 * local file system, which is type "0".
    200 	 */
    201 	fb_plugin_type_t shm_filesys_type;
    202 
    203 	/*
    204 	 * end of pre-zeroed data
    205 	 */
    206 	int		shm_marker;
    207 
    208 	/*
    209 	 * actual storage for shared entities.
    210 	 * These are not zeroed during initialization
    211 	 */
    212 	fileset_t	shm_fileset[FILEBENCH_NFILESETS];
    213 	filesetentry_t	shm_filesetentry[FILEBENCH_NFILESETENTRIES];
    214 	char		shm_filesetpaths[FILEBENCH_FILESETPATHMEMORY];
    215 	procflow_t	shm_procflow[FILEBENCH_NPROCFLOWS];
    216 	threadflow_t	shm_threadflow[FILEBENCH_NTHREADFLOWS];
    217 	flowop_t	shm_flowop[FILEBENCH_NFLOWOPS];
    218 	var_t		shm_var[FILEBENCH_NVARS];
    219 	randdist_t	shm_randdist[FILEBENCH_NRANDDISTS];
    220 	struct avd	shm_avd_ptrs[FILEBENCH_NVARS * 2];
    221 	char		shm_strings[FILEBENCH_STRINGMEMORY];
    222 } filebench_shm_t;
    223 
    224 extern char *shmpath;
    225 
    226 void ipc_init(void);
    227 void *ipc_malloc(int type);
    228 void ipc_free(int type, char *addr);
    229 int ipc_attach(caddr_t shmaddr);
    230 pthread_mutexattr_t *ipc_mutexattr(int);
    231 pthread_condattr_t *ipc_condattr(void);
    232 int ipc_semidalloc(void);
    233 void ipc_semidfree(int semid);
    234 char *ipc_stralloc(char *string);
    235 char *ipc_pathalloc(char *string);
    236 int ipc_mutex_lock(pthread_mutex_t *mutex);
    237 int ipc_mutex_unlock(pthread_mutex_t *mutex);
    238 void ipc_seminit(void);
    239 char *ipc_ismmalloc(size_t size);
    240 int ipc_ismcreate(size_t size);
    241 void ipc_ismdelete(void);
    242 void ipc_fini(void);
    243 
    244 extern filebench_shm_t *filebench_shm;
    245 
    246 #ifdef	__cplusplus
    247 }
    248 #endif
    249 
    250 #endif	/* _FB_IPC_H */
    251