summaryrefslogtreecommitdiff
path: root/usr/src/cmd/filebench/common/ipc.h
blob: 0596d177dfa930a500527461f5fee1eb915bb32f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _FB_IPC_H
#define	_FB_IPC_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include "config.h"
#include <pthread.h>

#include "procflow.h"
#include "threadflow.h"
#include "fileset.h"
#include "flowop.h"
#include "fb_random.h"
#include "filebench.h"

#ifdef	__cplusplus
extern "C" {
#endif

#ifdef USE_PROCESS_MODEL
#define	FILEBENCH_MEMSIZE 4096
#else
#define	FILEBENCH_MEMSIZE 2048
#endif /* USE_PROCESS_MODEL */

#define	FILEBENCH_NFILESETS FILEBENCH_MEMSIZE
#define	FILEBENCH_NFILESETENTRIES (1024 * 1024)
#define	FILEBENCH_NPROCFLOWS FILEBENCH_MEMSIZE
#define	FILEBENCH_NTHREADFLOWS (64 * FILEBENCH_MEMSIZE)
#define	FILEBENCH_NFLOWOPS (64 * FILEBENCH_MEMSIZE)
#define	FILEBENCH_NVARS FILEBENCH_MEMSIZE
#define	FILEBENCH_NRANDDISTS (FILEBENCH_MEMSIZE/4)
#define	FILEBENCH_FILESETPATHMEMORY (FILEBENCH_NFILESETENTRIES*FSE_MAXPATHLEN)
#define	FILEBENCH_STRINGMEMORY (FILEBENCH_NVARS * 128)
#define	FILEBENCH_MAXBITMAP FILEBENCH_NFILESETENTRIES

#define	FILEBENCH_PROCFLOW	0
#define	FILEBENCH_THREADFLOW	1
#define	FILEBENCH_FLOWOP	2
#define	FILEBENCH_AVD		3
#define	FILEBENCH_VARIABLE	4
#define	FILEBENCH_FILESET	5
#define	FILEBENCH_FILESETENTRY	6
#define	FILEBENCH_RANDDIST	7
#define	FILEBENCH_TYPES		8

#define	FILEBENCH_NSEMS 128

#define	FILEBENCH_ABORT_ERROR  	1
#define	FILEBENCH_ABORT_DONE   	2
#define	FILEBENCH_ABORT_RSRC	3

#define	FILEBENCH_MODE_TIMEOUT	0x0
#define	FILEBENCH_MODE_Q1STDONE	0x1
#define	FILEBENCH_MODE_QALLDONE	0x2

typedef struct filebench_shm {
	pthread_mutex_t fileset_lock;
	pthread_mutex_t procflow_lock;
	pthread_mutex_t threadflow_lock;
	pthread_mutex_t flowop_lock;
	pthread_mutex_t msg_lock;
	pthread_mutex_t malloc_lock;
	pthread_mutex_t ism_lock;
	pthread_rwlock_t run_lock;
	pthread_rwlock_t flowop_find_lock;

	char		*string_ptr;
	char		*path_ptr;
	fileset_t	*filesetlist;
	flowop_t	*flowoplist;
	procflow_t	*proclist;
	var_t		*var_list;
	var_t		*var_dyn_list;
	randdist_t	*shm_rand_list;
	int		debug_level;
	hrtime_t	epoch;
	hrtime_t	starttime;
	int		bequiet;
	key_t		semkey;
	int		seminit;
	int		semid_seq;
	int		utid;
	int		log_fd;
	int		dump_fd;
	char		dump_filename[MAXPATHLEN];
	pthread_mutex_t	eventgen_lock;
	pthread_cond_t	eventgen_cv;
	int		eventgen_hz;
	uint64_t	eventgen_q;
	char		fscriptname[1024];
	int		shm_id;
	size_t		shm_required;
	size_t		shm_allocated;
	caddr_t		shm_addr;
	char		*shm_ptr;
	int		shm_running;
	int		f_abort;
	int		shm_rmode;
	int		shm_1st_err;

	int		marker;

	fileset_t	fileset[FILEBENCH_NFILESETS];
	filesetentry_t	filesetentry[FILEBENCH_NFILESETENTRIES];
	char		filesetpaths[FILEBENCH_FILESETPATHMEMORY];
	procflow_t	procflow[FILEBENCH_NPROCFLOWS];
	threadflow_t	threadflow[FILEBENCH_NTHREADFLOWS];
	flowop_t	flowop[FILEBENCH_NFLOWOPS];
	var_t		var[FILEBENCH_NVARS];
	randdist_t	shm_randdist[FILEBENCH_NRANDDISTS];
	struct avd	shm_avd_ptrs[FILEBENCH_NVARS * 2];
	char		strings[FILEBENCH_STRINGMEMORY];
	char		semids[FILEBENCH_NSEMS];
	int		bitmap[FILEBENCH_TYPES][FILEBENCH_MAXBITMAP];
} filebench_shm_t;

extern char *shmpath;

void ipc_init(void);
void *ipc_malloc(int type);
void ipc_free(int type, char *addr);
int ipc_attach(caddr_t shmaddr);
pthread_mutexattr_t *ipc_mutexattr(void);
pthread_condattr_t *ipc_condattr(void);
int ipc_semidalloc(void);
void ipc_semidfree(int semid);
char *ipc_stralloc(char *string);
char *ipc_pathalloc(char *string);
int ipc_mutex_lock(pthread_mutex_t *mutex);
int ipc_mutex_unlock(pthread_mutex_t *mutex);
void ipc_seminit(void);
char *ipc_ismmalloc(size_t size);
int ipc_ismcreate(size_t size);
void ipc_ismdelete(void);
void ipc_cleanup(void);

extern filebench_shm_t *filebench_shm;

#ifdef	__cplusplus
}
#endif

#endif	/* _FB_IPC_H */