xref: /onnv-gate/usr/src/cmd/filebench/common/ipc.h (revision 9801:4a9784073e11)
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 /*
228615SAndrew.W.Wilson@sun.com  * Copyright 2009 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"
378615SAndrew.W.Wilson@sun.com #include "fsplug.h"
385184Sek110237 #include "filebench.h"
395184Sek110237 
405184Sek110237 #ifdef	__cplusplus
415184Sek110237 extern "C" {
425184Sek110237 #endif
435184Sek110237 
445184Sek110237 #ifdef USE_PROCESS_MODEL
455184Sek110237 #define	FILEBENCH_MEMSIZE 4096
465184Sek110237 #else
475184Sek110237 #define	FILEBENCH_MEMSIZE 2048
485184Sek110237 #endif /* USE_PROCESS_MODEL */
495184Sek110237 
507556SAndrew.W.Wilson@sun.com /* Mutex Priority Inheritance and Robustness flags */
517556SAndrew.W.Wilson@sun.com #define	IPC_MUTEX_NORMAL	0x0
527556SAndrew.W.Wilson@sun.com #define	IPC_MUTEX_PRIORITY	0x1
537556SAndrew.W.Wilson@sun.com #define	IPC_MUTEX_ROBUST	0x2
547556SAndrew.W.Wilson@sun.com #define	IPC_MUTEX_PRI_ROB	0x3
557556SAndrew.W.Wilson@sun.com #define	IPC_NUM_MUTEX_ATTRS	4
567556SAndrew.W.Wilson@sun.com 
575184Sek110237 #define	FILEBENCH_NFILESETS FILEBENCH_MEMSIZE
585184Sek110237 #define	FILEBENCH_NFILESETENTRIES (1024 * 1024)
595184Sek110237 #define	FILEBENCH_NPROCFLOWS FILEBENCH_MEMSIZE
606212Saw148015 #define	FILEBENCH_NTHREADFLOWS (64 * FILEBENCH_MEMSIZE)
616212Saw148015 #define	FILEBENCH_NFLOWOPS (64 * FILEBENCH_MEMSIZE)
625184Sek110237 #define	FILEBENCH_NVARS FILEBENCH_MEMSIZE
636212Saw148015 #define	FILEBENCH_NRANDDISTS (FILEBENCH_MEMSIZE/4)
646212Saw148015 #define	FILEBENCH_FILESETPATHMEMORY (FILEBENCH_NFILESETENTRIES*FSE_MAXPATHLEN)
656212Saw148015 #define	FILEBENCH_STRINGMEMORY (FILEBENCH_NVARS * 128)
665184Sek110237 #define	FILEBENCH_MAXBITMAP FILEBENCH_NFILESETENTRIES
675184Sek110237 
685673Saw148015 #define	FILEBENCH_PROCFLOW	0
695673Saw148015 #define	FILEBENCH_THREADFLOW	1
705673Saw148015 #define	FILEBENCH_FLOWOP	2
716212Saw148015 #define	FILEBENCH_AVD		3
726212Saw148015 #define	FILEBENCH_VARIABLE	4
736212Saw148015 #define	FILEBENCH_FILESET	5
746212Saw148015 #define	FILEBENCH_FILESETENTRY	6
756212Saw148015 #define	FILEBENCH_RANDDIST	7
765673Saw148015 #define	FILEBENCH_TYPES		8
775184Sek110237 
785184Sek110237 #define	FILEBENCH_NSEMS 128
795184Sek110237 
806084Saw148015 #define	FILEBENCH_ABORT_ERROR  	1
816084Saw148015 #define	FILEBENCH_ABORT_DONE   	2
826084Saw148015 #define	FILEBENCH_ABORT_RSRC	3
839326SAndrew.W.Wilson@sun.com #define	FILEBENCH_ABORT_FINI	4
846084Saw148015 
859356SAndrew.W.Wilson@sun.com 	/* run modes */
866084Saw148015 #define	FILEBENCH_MODE_TIMEOUT	0x0
876084Saw148015 #define	FILEBENCH_MODE_Q1STDONE	0x1
886084Saw148015 #define	FILEBENCH_MODE_QALLDONE	0x2
896084Saw148015 
909356SAndrew.W.Wilson@sun.com 	/* misc. modes */
919356SAndrew.W.Wilson@sun.com #define	FILEBENCH_MODE_NOUSAGE	0x01
929356SAndrew.W.Wilson@sun.com 
935184Sek110237 typedef struct filebench_shm {
947556SAndrew.W.Wilson@sun.com 	/*
957556SAndrew.W.Wilson@sun.com 	 * All state down to shm_marker are set to zero during filebench
967556SAndrew.W.Wilson@sun.com 	 * initialization
977556SAndrew.W.Wilson@sun.com 	 */
987556SAndrew.W.Wilson@sun.com 
997556SAndrew.W.Wilson@sun.com 	/*
1007556SAndrew.W.Wilson@sun.com 	 * list of defined filesets and related locks.
1017556SAndrew.W.Wilson@sun.com 	 */
1027556SAndrew.W.Wilson@sun.com 	fileset_t	*shm_filesetlist; /* list of defined filesets */
1037556SAndrew.W.Wilson@sun.com 	pthread_mutex_t shm_fileset_lock; /* protects access to list */
1047556SAndrew.W.Wilson@sun.com 
1057556SAndrew.W.Wilson@sun.com 	/*
1067556SAndrew.W.Wilson@sun.com 	 * parallel file allocation  control. Restricts number of spawned
1077556SAndrew.W.Wilson@sun.com 	 * allocation threads and allows waiting for allocation to finish.
1087556SAndrew.W.Wilson@sun.com 	 */
1097556SAndrew.W.Wilson@sun.com 	pthread_cond_t	shm_fsparalloc_cv;    /* cv to wait for alloc threads */
1107556SAndrew.W.Wilson@sun.com 	int		shm_fsparalloc_count; /* active alloc thread count */
1117556SAndrew.W.Wilson@sun.com 	pthread_mutex_t	shm_fsparalloc_lock;  /* lock to protect count */
1127556SAndrew.W.Wilson@sun.com 
1137556SAndrew.W.Wilson@sun.com 	/*
1147556SAndrew.W.Wilson@sun.com 	 * Procflow and process state
1157556SAndrew.W.Wilson@sun.com 	 */
1167556SAndrew.W.Wilson@sun.com 	procflow_t	*shm_proclist;	   /* list of defined procflows */
1177556SAndrew.W.Wilson@sun.com 	pthread_mutex_t shm_procflow_lock; /* protects shm_proclist */
1187556SAndrew.W.Wilson@sun.com 	int		shm_procs_running; /* count of running processes */
1197556SAndrew.W.Wilson@sun.com 	pthread_mutex_t shm_procs_running_lock;	/* protects shm_procs_running */
1207556SAndrew.W.Wilson@sun.com 	int		shm_f_abort;	/* stop the run NOW! */
1217556SAndrew.W.Wilson@sun.com 	pthread_rwlock_t shm_run_lock;	/* used as barrier to sync run */
1227556SAndrew.W.Wilson@sun.com #ifdef USE_PROCESS_MODEL
1237556SAndrew.W.Wilson@sun.com 	pthread_cond_t  shm_procflow_procs_cv;	/* pauses procflow_init till */
1247556SAndrew.W.Wilson@sun.com #endif						/* all procflows are created */
1257556SAndrew.W.Wilson@sun.com 
1267556SAndrew.W.Wilson@sun.com 	/*
1277556SAndrew.W.Wilson@sun.com 	 * flowop state
1287556SAndrew.W.Wilson@sun.com 	 */
1297556SAndrew.W.Wilson@sun.com 	flowop_t	*shm_flowoplist;	/* list of defined flowops */
1307556SAndrew.W.Wilson@sun.com 	pthread_mutex_t shm_flowop_lock;	/* protects flowoplist */
1317556SAndrew.W.Wilson@sun.com 	pthread_rwlock_t shm_flowop_find_lock;	/* prevents flowop_find() */
1327556SAndrew.W.Wilson@sun.com 					    /* during initial flowop creation */
1337556SAndrew.W.Wilson@sun.com 
1347556SAndrew.W.Wilson@sun.com 	/*
1357556SAndrew.W.Wilson@sun.com 	 * lists related to variables
1367556SAndrew.W.Wilson@sun.com 	 */
1377556SAndrew.W.Wilson@sun.com 
1387556SAndrew.W.Wilson@sun.com 	var_t		*shm_var_list;	   /* normal variables */
1397556SAndrew.W.Wilson@sun.com 	var_t		*shm_var_dyn_list; /* special system variables */
1407556SAndrew.W.Wilson@sun.com 	var_t		*shm_var_loc_list; /* variables local to comp flowops */
1417556SAndrew.W.Wilson@sun.com 	randdist_t	*shm_rand_list;	   /* random variables */
1427556SAndrew.W.Wilson@sun.com 
1437556SAndrew.W.Wilson@sun.com 	/*
1447556SAndrew.W.Wilson@sun.com 	 * log and statistics dumping controls and state
1457556SAndrew.W.Wilson@sun.com 	 */
1467556SAndrew.W.Wilson@sun.com 	int		shm_debug_level;
1477556SAndrew.W.Wilson@sun.com 	int		shm_bequiet;	/* pause run while collecting stats */
1487556SAndrew.W.Wilson@sun.com 	int		shm_log_fd;	/* log file descriptor */
1497556SAndrew.W.Wilson@sun.com 	int		shm_dump_fd;	/* dump file descriptor */
1507556SAndrew.W.Wilson@sun.com 	char		shm_dump_filename[MAXPATHLEN];
1517556SAndrew.W.Wilson@sun.com 
1527556SAndrew.W.Wilson@sun.com 	/*
1537556SAndrew.W.Wilson@sun.com 	 * Event generator state
1547556SAndrew.W.Wilson@sun.com 	 */
155*9801SAndrew.W.Wilson@sun.com 	int		shm_eventgen_enabled; /* event gen in operation */
1567946SAndrew.W.Wilson@sun.com 	avd_t		shm_eventgen_hz;   /* number of events per sec. */
1577556SAndrew.W.Wilson@sun.com 	uint64_t	shm_eventgen_q;    /* count of unclaimed events */
1587556SAndrew.W.Wilson@sun.com 	pthread_mutex_t	shm_eventgen_lock; /* lock protecting count */
1597556SAndrew.W.Wilson@sun.com 	pthread_cond_t	shm_eventgen_cv;   /* cv to wait on for more events */
1607556SAndrew.W.Wilson@sun.com 
1617556SAndrew.W.Wilson@sun.com 	/*
1627556SAndrew.W.Wilson@sun.com 	 * System 5 semaphore state
1637556SAndrew.W.Wilson@sun.com 	 */
1647556SAndrew.W.Wilson@sun.com 	key_t		shm_semkey;
1657556SAndrew.W.Wilson@sun.com 	int		shm_sys_semid;
1667556SAndrew.W.Wilson@sun.com 	char		shm_semids[FILEBENCH_NSEMS];
1677556SAndrew.W.Wilson@sun.com 
1687556SAndrew.W.Wilson@sun.com 	/*
1697556SAndrew.W.Wilson@sun.com 	 * Misc. pointers and state
1707556SAndrew.W.Wilson@sun.com 	 */
1717556SAndrew.W.Wilson@sun.com 	char		shm_fscriptname[1024];
1727556SAndrew.W.Wilson@sun.com 	int		shm_id;
1739356SAndrew.W.Wilson@sun.com 	int		shm_rmode;	/* run mode settings */
1749356SAndrew.W.Wilson@sun.com 	int		shm_mmode;	/* misc. mode settings */
1757556SAndrew.W.Wilson@sun.com 	int		shm_1st_err;
1766391Saw148015 	pthread_mutex_t shm_threadflow_lock;
1776391Saw148015 	pthread_mutex_t shm_msg_lock;
1787556SAndrew.W.Wilson@sun.com 	pthread_mutexattr_t shm_mutexattr[IPC_NUM_MUTEX_ATTRS];
1796305Saw148015 	char		*shm_string_ptr;
1806305Saw148015 	char		*shm_path_ptr;
1816391Saw148015 	hrtime_t	shm_epoch;
1826305Saw148015 	hrtime_t	shm_starttime;
1836391Saw148015 	int		shm_utid;
1847556SAndrew.W.Wilson@sun.com 
1857556SAndrew.W.Wilson@sun.com 	/*
1867556SAndrew.W.Wilson@sun.com 	 * Shared memory allocation control
1877556SAndrew.W.Wilson@sun.com 	 */
1887556SAndrew.W.Wilson@sun.com 	pthread_mutex_t shm_malloc_lock;
1897556SAndrew.W.Wilson@sun.com 	pthread_mutex_t shm_ism_lock;
1907556SAndrew.W.Wilson@sun.com 	int		shm_bitmap[FILEBENCH_TYPES][FILEBENCH_MAXBITMAP];
1917556SAndrew.W.Wilson@sun.com 	int		shm_lastbitmapindex[FILEBENCH_TYPES];
1925184Sek110237 	size_t		shm_required;
1935184Sek110237 	size_t		shm_allocated;
1945184Sek110237 	caddr_t		shm_addr;
1955184Sek110237 	char		*shm_ptr;
1967556SAndrew.W.Wilson@sun.com 
1978615SAndrew.W.Wilson@sun.com 	/*
1988615SAndrew.W.Wilson@sun.com 	 * Type of plug-in file system client to use. Defaults to
1998615SAndrew.W.Wilson@sun.com 	 * local file system, which is type "0".
2008615SAndrew.W.Wilson@sun.com 	 */
2018615SAndrew.W.Wilson@sun.com 	fb_plugin_type_t shm_filesys_type;
2028615SAndrew.W.Wilson@sun.com 
2038615SAndrew.W.Wilson@sun.com 	/*
2048615SAndrew.W.Wilson@sun.com 	 * end of pre-zeroed data
2058615SAndrew.W.Wilson@sun.com 	 */
2068615SAndrew.W.Wilson@sun.com 	int		shm_marker;
2075184Sek110237 
2087556SAndrew.W.Wilson@sun.com 	/*
2097556SAndrew.W.Wilson@sun.com 	 * actual storage for shared entities.
2107556SAndrew.W.Wilson@sun.com 	 * These are not zeroed during initialization
2117556SAndrew.W.Wilson@sun.com 	 */
2126305Saw148015 	fileset_t	shm_fileset[FILEBENCH_NFILESETS];
2136305Saw148015 	filesetentry_t	shm_filesetentry[FILEBENCH_NFILESETENTRIES];
2146305Saw148015 	char		shm_filesetpaths[FILEBENCH_FILESETPATHMEMORY];
2156305Saw148015 	procflow_t	shm_procflow[FILEBENCH_NPROCFLOWS];
2166305Saw148015 	threadflow_t	shm_threadflow[FILEBENCH_NTHREADFLOWS];
2176305Saw148015 	flowop_t	shm_flowop[FILEBENCH_NFLOWOPS];
2186305Saw148015 	var_t		shm_var[FILEBENCH_NVARS];
2196212Saw148015 	randdist_t	shm_randdist[FILEBENCH_NRANDDISTS];
2206212Saw148015 	struct avd	shm_avd_ptrs[FILEBENCH_NVARS * 2];
2216305Saw148015 	char		shm_strings[FILEBENCH_STRINGMEMORY];
2225184Sek110237 } filebench_shm_t;
2235184Sek110237 
2245184Sek110237 extern char *shmpath;
2255184Sek110237 
2265184Sek110237 void ipc_init(void);
2275184Sek110237 void *ipc_malloc(int type);
2285184Sek110237 void ipc_free(int type, char *addr);
2295184Sek110237 int ipc_attach(caddr_t shmaddr);
2307556SAndrew.W.Wilson@sun.com pthread_mutexattr_t *ipc_mutexattr(int);
2315184Sek110237 pthread_condattr_t *ipc_condattr(void);
2325184Sek110237 int ipc_semidalloc(void);
2335184Sek110237 void ipc_semidfree(int semid);
2345184Sek110237 char *ipc_stralloc(char *string);
2355184Sek110237 char *ipc_pathalloc(char *string);
2365184Sek110237 int ipc_mutex_lock(pthread_mutex_t *mutex);
2375184Sek110237 int ipc_mutex_unlock(pthread_mutex_t *mutex);
2385184Sek110237 void ipc_seminit(void);
2395184Sek110237 char *ipc_ismmalloc(size_t size);
2405184Sek110237 int ipc_ismcreate(size_t size);
2415184Sek110237 void ipc_ismdelete(void);
2426750Sek110237 void ipc_fini(void);
2435184Sek110237 
2445184Sek110237 extern filebench_shm_t *filebench_shm;
2455184Sek110237 
2465184Sek110237 #ifdef	__cplusplus
2475184Sek110237 }
2485184Sek110237 #endif
2495184Sek110237 
2505184Sek110237 #endif	/* _FB_IPC_H */
251