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