xref: /onnv-gate/usr/src/cmd/filebench/common/ipc.h (revision 7946:36d7e7afa9fa)
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 #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 "filebench.h"
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 #ifdef USE_PROCESS_MODEL
44 #define	FILEBENCH_MEMSIZE 4096
45 #else
46 #define	FILEBENCH_MEMSIZE 2048
47 #endif /* USE_PROCESS_MODEL */
48 
49 /* Mutex Priority Inheritance and Robustness flags */
50 #define	IPC_MUTEX_NORMAL	0x0
51 #define	IPC_MUTEX_PRIORITY	0x1
52 #define	IPC_MUTEX_ROBUST	0x2
53 #define	IPC_MUTEX_PRI_ROB	0x3
54 #define	IPC_NUM_MUTEX_ATTRS	4
55 
56 #define	FILEBENCH_NFILESETS FILEBENCH_MEMSIZE
57 #define	FILEBENCH_NFILESETENTRIES (1024 * 1024)
58 #define	FILEBENCH_NPROCFLOWS FILEBENCH_MEMSIZE
59 #define	FILEBENCH_NTHREADFLOWS (64 * FILEBENCH_MEMSIZE)
60 #define	FILEBENCH_NFLOWOPS (64 * FILEBENCH_MEMSIZE)
61 #define	FILEBENCH_NVARS FILEBENCH_MEMSIZE
62 #define	FILEBENCH_NRANDDISTS (FILEBENCH_MEMSIZE/4)
63 #define	FILEBENCH_FILESETPATHMEMORY (FILEBENCH_NFILESETENTRIES*FSE_MAXPATHLEN)
64 #define	FILEBENCH_STRINGMEMORY (FILEBENCH_NVARS * 128)
65 #define	FILEBENCH_MAXBITMAP FILEBENCH_NFILESETENTRIES
66 
67 #define	FILEBENCH_PROCFLOW	0
68 #define	FILEBENCH_THREADFLOW	1
69 #define	FILEBENCH_FLOWOP	2
70 #define	FILEBENCH_AVD		3
71 #define	FILEBENCH_VARIABLE	4
72 #define	FILEBENCH_FILESET	5
73 #define	FILEBENCH_FILESETENTRY	6
74 #define	FILEBENCH_RANDDIST	7
75 #define	FILEBENCH_TYPES		8
76 
77 #define	FILEBENCH_NSEMS 128
78 
79 #define	FILEBENCH_ABORT_ERROR  	1
80 #define	FILEBENCH_ABORT_DONE   	2
81 #define	FILEBENCH_ABORT_RSRC	3
82 
83 #define	FILEBENCH_MODE_TIMEOUT	0x0
84 #define	FILEBENCH_MODE_Q1STDONE	0x1
85 #define	FILEBENCH_MODE_QALLDONE	0x2
86 
87 typedef struct filebench_shm {
88 	/*
89 	 * All state down to shm_marker are set to zero during filebench
90 	 * initialization
91 	 */
92 
93 	/*
94 	 * list of defined filesets and related locks.
95 	 */
96 	fileset_t	*shm_filesetlist; /* list of defined filesets */
97 	pthread_mutex_t shm_fileset_lock; /* protects access to list */
98 
99 	/*
100 	 * parallel file allocation  control. Restricts number of spawned
101 	 * allocation threads and allows waiting for allocation to finish.
102 	 */
103 	pthread_cond_t	shm_fsparalloc_cv;    /* cv to wait for alloc threads */
104 	int		shm_fsparalloc_count; /* active alloc thread count */
105 	pthread_mutex_t	shm_fsparalloc_lock;  /* lock to protect count */
106 
107 	/*
108 	 * Procflow and process state
109 	 */
110 	procflow_t	*shm_proclist;	   /* list of defined procflows */
111 	pthread_mutex_t shm_procflow_lock; /* protects shm_proclist */
112 	int		shm_procs_running; /* count of running processes */
113 	pthread_mutex_t shm_procs_running_lock;	/* protects shm_procs_running */
114 	int		shm_f_abort;	/* stop the run NOW! */
115 	pthread_rwlock_t shm_run_lock;	/* used as barrier to sync run */
116 #ifdef USE_PROCESS_MODEL
117 	pthread_cond_t  shm_procflow_procs_cv;	/* pauses procflow_init till */
118 #endif						/* all procflows are created */
119 
120 	/*
121 	 * flowop state
122 	 */
123 	flowop_t	*shm_flowoplist;	/* list of defined flowops */
124 	pthread_mutex_t shm_flowop_lock;	/* protects flowoplist */
125 	pthread_rwlock_t shm_flowop_find_lock;	/* prevents flowop_find() */
126 					    /* during initial flowop creation */
127 
128 	/*
129 	 * lists related to variables
130 	 */
131 
132 	var_t		*shm_var_list;	   /* normal variables */
133 	var_t		*shm_var_dyn_list; /* special system variables */
134 	var_t		*shm_var_loc_list; /* variables local to comp flowops */
135 	randdist_t	*shm_rand_list;	   /* random variables */
136 
137 	/*
138 	 * log and statistics dumping controls and state
139 	 */
140 	int		shm_debug_level;
141 	int		shm_bequiet;	/* pause run while collecting stats */
142 	int		shm_log_fd;	/* log file descriptor */
143 	int		shm_dump_fd;	/* dump file descriptor */
144 	char		shm_dump_filename[MAXPATHLEN];
145 
146 	/*
147 	 * Event generator state
148 	 */
149 	avd_t		shm_eventgen_hz;   /* number of events per sec. */
150 	uint64_t	shm_eventgen_q;    /* count of unclaimed events */
151 	pthread_mutex_t	shm_eventgen_lock; /* lock protecting count */
152 	pthread_cond_t	shm_eventgen_cv;   /* cv to wait on for more events */
153 
154 	/*
155 	 * System 5 semaphore state
156 	 */
157 	key_t		shm_semkey;
158 	int		shm_sys_semid;
159 	char		shm_semids[FILEBENCH_NSEMS];
160 
161 	/*
162 	 * Misc. pointers and state
163 	 */
164 	char		shm_fscriptname[1024];
165 	int		shm_id;
166 	int		shm_rmode;
167 	int		shm_1st_err;
168 	pthread_mutex_t shm_threadflow_lock;
169 	pthread_mutex_t shm_msg_lock;
170 	pthread_mutexattr_t shm_mutexattr[IPC_NUM_MUTEX_ATTRS];
171 	char		*shm_string_ptr;
172 	char		*shm_path_ptr;
173 	hrtime_t	shm_epoch;
174 	hrtime_t	shm_starttime;
175 	int		shm_utid;
176 
177 	/*
178 	 * Shared memory allocation control
179 	 */
180 	pthread_mutex_t shm_malloc_lock;
181 	pthread_mutex_t shm_ism_lock;
182 	int		shm_bitmap[FILEBENCH_TYPES][FILEBENCH_MAXBITMAP];
183 	int		shm_lastbitmapindex[FILEBENCH_TYPES];
184 	size_t		shm_required;
185 	size_t		shm_allocated;
186 	caddr_t		shm_addr;
187 	char		*shm_ptr;
188 
189 	int		shm_marker;	/* end of pre-zeroed data */
190 
191 	/*
192 	 * actual storage for shared entities.
193 	 * These are not zeroed during initialization
194 	 */
195 	fileset_t	shm_fileset[FILEBENCH_NFILESETS];
196 	filesetentry_t	shm_filesetentry[FILEBENCH_NFILESETENTRIES];
197 	char		shm_filesetpaths[FILEBENCH_FILESETPATHMEMORY];
198 	procflow_t	shm_procflow[FILEBENCH_NPROCFLOWS];
199 	threadflow_t	shm_threadflow[FILEBENCH_NTHREADFLOWS];
200 	flowop_t	shm_flowop[FILEBENCH_NFLOWOPS];
201 	var_t		shm_var[FILEBENCH_NVARS];
202 	randdist_t	shm_randdist[FILEBENCH_NRANDDISTS];
203 	struct avd	shm_avd_ptrs[FILEBENCH_NVARS * 2];
204 	char		shm_strings[FILEBENCH_STRINGMEMORY];
205 } filebench_shm_t;
206 
207 extern char *shmpath;
208 
209 void ipc_init(void);
210 void *ipc_malloc(int type);
211 void ipc_free(int type, char *addr);
212 int ipc_attach(caddr_t shmaddr);
213 pthread_mutexattr_t *ipc_mutexattr(int);
214 pthread_condattr_t *ipc_condattr(void);
215 int ipc_semidalloc(void);
216 void ipc_semidfree(int semid);
217 char *ipc_stralloc(char *string);
218 char *ipc_pathalloc(char *string);
219 int ipc_mutex_lock(pthread_mutex_t *mutex);
220 int ipc_mutex_unlock(pthread_mutex_t *mutex);
221 void ipc_seminit(void);
222 char *ipc_ismmalloc(size_t size);
223 int ipc_ismcreate(size_t size);
224 void ipc_ismdelete(void);
225 void ipc_fini(void);
226 
227 extern filebench_shm_t *filebench_shm;
228 
229 #ifdef	__cplusplus
230 }
231 #endif
232 
233 #endif	/* _FB_IPC_H */
234