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