xref: /onnv-gate/usr/src/cmd/filebench/common/ipc.h (revision 6084:d5f45b4dae7e)
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 "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 #define	FILEBENCH_NFILESETS FILEBENCH_MEMSIZE
51 #define	FILEBENCH_NFILESETENTRIES (1024 * 1024)
52 #define	FILEBENCH_NPROCFLOWS FILEBENCH_MEMSIZE
53 #define	FILEBENCH_NTHREADFLOWS 64 * FILEBENCH_MEMSIZE
54 #define	FILEBENCH_NFLOWOPS 64 * FILEBENCH_MEMSIZE
55 #define	FILEBENCH_NVARS FILEBENCH_MEMSIZE
56 #define	FILEBENCH_FILESETPATHMEMORY FILEBENCH_NFILESETENTRIES*FSE_MAXPATHLEN
57 #define	FILEBENCH_STRINGMEMORY FILEBENCH_NVARS * 128
58 #define	FILEBENCH_MAXBITMAP FILEBENCH_NFILESETENTRIES
59 
60 #define	FILEBENCH_PROCFLOW	0
61 #define	FILEBENCH_THREADFLOW	1
62 #define	FILEBENCH_FLOWOP	2
63 #define	FILEBENCH_INTEGER	3
64 #define	FILEBENCH_STRING	4
65 #define	FILEBENCH_VARIABLE	5
66 #define	FILEBENCH_FILESET	6
67 #define	FILEBENCH_FILESETENTRY	7
68 #define	FILEBENCH_TYPES		8
69 
70 #define	FILEBENCH_NSEMS 128
71 
72 #define	FILEBENCH_ABORT_ERROR  	1
73 #define	FILEBENCH_ABORT_DONE   	2
74 #define	FILEBENCH_ABORT_RSRC	3
75 
76 #define	FILEBENCH_MODE_TIMEOUT	0x0
77 #define	FILEBENCH_MODE_Q1STDONE	0x1
78 #define	FILEBENCH_MODE_QALLDONE	0x2
79 
80 typedef struct filebench_shm {
81 	pthread_mutex_t fileset_lock;
82 	pthread_mutex_t procflow_lock;
83 	pthread_mutex_t threadflow_lock;
84 	pthread_mutex_t flowop_lock;
85 	pthread_mutex_t msg_lock;
86 	pthread_mutex_t malloc_lock;
87 	pthread_mutex_t ism_lock;
88 	pthread_rwlock_t run_lock;
89 	pthread_rwlock_t flowop_find_lock;
90 
91 	char		*string_ptr;
92 	char		*path_ptr;
93 	fileset_t	*filesetlist;
94 	flowop_t	*flowoplist;
95 	procflow_t	*proclist;
96 	var_t		*var_list;
97 	var_t		*var_dyn_list;
98 	int		debug_level;
99 	hrtime_t	epoch;
100 	hrtime_t	starttime;
101 	int		bequiet;
102 	key_t		semkey;
103 	int		seminit;
104 	int		semid_seq;
105 	int		utid;
106 	int		log_fd;
107 	int		dump_fd;
108 	char		dump_filename[MAXPATHLEN];
109 	pthread_mutex_t	eventgen_lock;
110 	pthread_cond_t	eventgen_cv;
111 	int		eventgen_hz;
112 	uint64_t	eventgen_q;
113 	char		fscriptname[1024];
114 	int		shm_id;
115 	size_t		shm_required;
116 	size_t		shm_allocated;
117 	caddr_t		shm_addr;
118 	char		*shm_ptr;
119 	int		shm_running;
120 	int		f_abort;
121 	int		shm_rmode;
122 	int		shm_1st_err;
123 
124 	int		marker;
125 
126 	fileset_t	fileset[FILEBENCH_NFILESETS];
127 	filesetentry_t	filesetentry[FILEBENCH_NFILESETENTRIES];
128 	char		filesetpaths[FILEBENCH_FILESETPATHMEMORY];
129 	procflow_t	procflow[FILEBENCH_NPROCFLOWS];
130 	threadflow_t	threadflow[FILEBENCH_NTHREADFLOWS];
131 	flowop_t	flowop[FILEBENCH_NFLOWOPS];
132 	var_t		var[FILEBENCH_NVARS];
133 	vinteger_t	integer_ptrs[FILEBENCH_NVARS];
134 	char		*string_ptrs[FILEBENCH_NVARS];
135 	char		strings[FILEBENCH_STRINGMEMORY];
136 	char		semids[FILEBENCH_NSEMS];
137 	int		bitmap[FILEBENCH_TYPES][FILEBENCH_MAXBITMAP];
138 } filebench_shm_t;
139 
140 extern char *shmpath;
141 
142 void ipc_init(void);
143 void *ipc_malloc(int type);
144 void ipc_free(int type, char *addr);
145 int ipc_attach(caddr_t shmaddr);
146 pthread_mutexattr_t *ipc_mutexattr(void);
147 pthread_condattr_t *ipc_condattr(void);
148 int ipc_semidalloc(void);
149 void ipc_semidfree(int semid);
150 char *ipc_stralloc(char *string);
151 char *ipc_pathalloc(char *string);
152 int ipc_mutex_lock(pthread_mutex_t *mutex);
153 int ipc_mutex_unlock(pthread_mutex_t *mutex);
154 void ipc_seminit(void);
155 char *ipc_ismmalloc(size_t size);
156 int ipc_ismcreate(size_t size);
157 void ipc_ismdelete(void);
158 void ipc_cleanup(void);
159 
160 extern filebench_shm_t *filebench_shm;
161 
162 #ifdef	__cplusplus
163 }
164 #endif
165 
166 #endif	/* _FB_IPC_H */
167