xref: /onnv-gate/usr/src/cmd/filebench/common/ipc.h (revision 6750:bd49b8b8d6f3)
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 shm_fileset_lock;
84 	pthread_mutex_t shm_procflow_lock;
85 	pthread_mutex_t shm_threadflow_lock;
86 	pthread_mutex_t shm_flowop_lock;
87 	pthread_mutex_t shm_msg_lock;
88 	pthread_mutex_t shm_malloc_lock;
89 	pthread_mutex_t shm_ism_lock;
90 	pthread_mutex_t shm_procs_running_lock;	/* protects shm_procs_running */
91 	pthread_rwlock_t shm_run_lock;
92 	pthread_rwlock_t shm_flowop_find_lock;
93 
94 	char		*shm_string_ptr;
95 	char		*shm_path_ptr;
96 	fileset_t	*shm_filesetlist;
97 	flowop_t	*shm_flowoplist;
98 	procflow_t	*shm_proclist;
99 	var_t		*shm_var_list;
100 	var_t		*shm_var_dyn_list;
101 	randdist_t	*shm_rand_list;
102 	var_t		*shm_var_loc_list;
103 	int		shm_debug_level;
104 	hrtime_t	shm_epoch;
105 	hrtime_t	shm_starttime;
106 	int		shm_bequiet;
107 	key_t		shm_semkey;
108 	int		shm_sys_semid;
109 	int		shm_utid;
110 	int		shm_log_fd;
111 	int		shm_dump_fd;
112 	char		shm_dump_filename[MAXPATHLEN];
113 	pthread_mutex_t	shm_eventgen_lock;
114 	pthread_cond_t	shm_eventgen_cv;
115 	int		shm_eventgen_hz;
116 	uint64_t	shm_eventgen_q;
117 	char		shm_fscriptname[1024];
118 	int		shm_id;
119 	size_t		shm_required;
120 	size_t		shm_allocated;
121 	caddr_t		shm_addr;
122 	char		*shm_ptr;
123 	int		shm_procs_running;
124 	int		shm_f_abort;
125 	int		shm_rmode;
126 	int		shm_1st_err;
127 	int		shm_bitmap[FILEBENCH_TYPES][FILEBENCH_MAXBITMAP];
128 	int		shm_lastbitmapindex[FILEBENCH_TYPES];
129 	char		shm_semids[FILEBENCH_NSEMS];
130 
131 	int		shm_marker;
132 
133 	fileset_t	shm_fileset[FILEBENCH_NFILESETS];
134 	filesetentry_t	shm_filesetentry[FILEBENCH_NFILESETENTRIES];
135 	char		shm_filesetpaths[FILEBENCH_FILESETPATHMEMORY];
136 	procflow_t	shm_procflow[FILEBENCH_NPROCFLOWS];
137 	threadflow_t	shm_threadflow[FILEBENCH_NTHREADFLOWS];
138 	flowop_t	shm_flowop[FILEBENCH_NFLOWOPS];
139 	var_t		shm_var[FILEBENCH_NVARS];
140 	randdist_t	shm_randdist[FILEBENCH_NRANDDISTS];
141 	struct avd	shm_avd_ptrs[FILEBENCH_NVARS * 2];
142 	char		shm_strings[FILEBENCH_STRINGMEMORY];
143 } filebench_shm_t;
144 
145 extern char *shmpath;
146 
147 void ipc_init(void);
148 void *ipc_malloc(int type);
149 void ipc_free(int type, char *addr);
150 int ipc_attach(caddr_t shmaddr);
151 pthread_mutexattr_t *ipc_mutexattr(void);
152 pthread_condattr_t *ipc_condattr(void);
153 int ipc_semidalloc(void);
154 void ipc_semidfree(int semid);
155 char *ipc_stralloc(char *string);
156 char *ipc_pathalloc(char *string);
157 int ipc_mutex_lock(pthread_mutex_t *mutex);
158 int ipc_mutex_unlock(pthread_mutex_t *mutex);
159 void ipc_seminit(void);
160 char *ipc_ismmalloc(size_t size);
161 int ipc_ismcreate(size_t size);
162 void ipc_ismdelete(void);
163 void ipc_fini(void);
164 
165 extern filebench_shm_t *filebench_shm;
166 
167 #ifdef	__cplusplus
168 }
169 #endif
170 
171 #endif	/* _FB_IPC_H */
172