xref: /onnv-gate/usr/src/cmd/filebench/common/flowop.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_FLOWOP_H
27 #define	_FB_FLOWOP_H
28 
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include "config.h"
33 
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include <sys/stat.h>
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/resource.h>
41 #include <pthread.h>
42 #ifndef HAVE_SYSV_SEM
43 #include <semaphore.h>
44 #endif
45 #include "stats.h"
46 #include "threadflow.h"
47 #include "vars.h"
48 #include "fileset.h"
49 #include "filebench.h"
50 
51 #ifdef	__cplusplus
52 extern "C" {
53 #endif
54 
55 typedef struct flowop {
56 	char		fo_name[128];	/* Name */
57 	int		fo_instance;	/* Instance number */
58 	struct flowop	*fo_next;	/* Next in global list */
59 	struct flowop	*fo_threadnext;	/* Next in thread's list */
60 	struct flowop	*fo_resultnext;	/* List of flowops in result */
61 	struct threadflow *fo_thread;	/* Backpointer to thread */
62 	int		(*fo_func)();	/* Method */
63 	int		(*fo_init)();	/* Init Method */
64 	void		(*fo_destruct)(); /* Destructor Method */
65 	int		fo_type;	/* Type */
66 	int		fo_attrs;	/* Flow op attribute */
67 	fileset_t	*fo_fileset;	/* Fileset for op */
68 	int		fo_fd;		/* File descriptor */
69 	int		fo_fdnumber;	/* User specified file descriptor */
70 	int		fo_srcfdnumber;	/* User specified src file descriptor */
71 	var_integer_t	fo_iosize;	/* Size of operation */
72 	var_integer_t	fo_wss;		/* Flow op working set size */
73 	char		fo_targetname[128]; /* Target, for wakeup etc... */
74 	struct flowop	*fo_targets;	/* List of targets matching name */
75 	struct flowop	*fo_targetnext;	/* List of targets matching name */
76 	var_integer_t	fo_iters;	/* Number of iterations of op */
77 	var_integer_t	fo_value;	/* Attr */
78 	var_integer_t	fo_sequential;	/* Attr */
79 	var_integer_t	fo_random;	/* Attr */
80 	var_integer_t	fo_stride;	/* Attr */
81 	var_integer_t	fo_backwards;	/* Attr */
82 	var_integer_t	fo_dsync;	/* Attr */
83 	var_integer_t	fo_blocking;	/* Attr */
84 	var_integer_t	fo_directio;	/* Attr */
85 	var_integer_t	fo_rotatefd;	/* Attr */
86 	flowstat_t	fo_stats;	/* Flow statistics */
87 	pthread_cond_t	fo_cv;		/* Block/wakeup cv */
88 	pthread_mutex_t	fo_lock;	/* Mutex around flowop */
89 	char		*fo_buf;	/* Per-flowop buffer */
90 	uint64_t	fo_buf_size;	/* current size of buffer */
91 #ifdef HAVE_SYSV_SEM
92 	int		fo_semid_lw;	/* sem id */
93 	int		fo_semid_hw;	/* sem id for highwater block */
94 #else
95 	sem_t		fo_sem;		/* sem_t for posix semaphores */
96 #endif /* HAVE_SYSV_SEM */
97 	var_integer_t	fo_highwater;	/* value of highwater paramter */
98 	void		*fo_idp;	/* id, for sems etc */
99 	hrtime_t	fo_timestamp;	/* for ratecontrol, etc... */
100 	int		fo_initted;	/* Set to one if initialized */
101 	int64_t		fo_tputbucket;	/* Throughput bucket, for limiter */
102 	uint64_t	fo_tputlast;	/* Throughput count, for delta's */
103 
104 } flowop_t;
105 
106 /* Flow Op Attrs */
107 #define	FLOW_ATTR_SEQUENTIAL	0x1
108 #define	FLOW_ATTR_RANDOM	0x2
109 #define	FLOW_ATTR_STRIDE	0x4
110 #define	FLOW_ATTR_BACKWARDS	0x8
111 #define	FLOW_ATTR_DSYNC		0x10
112 #define	FLOW_ATTR_BLOCKING	0x20
113 #define	FLOW_ATTR_DIRECTIO	0x40
114 #define	FLOW_ATTR_READ		0x80
115 #define	FLOW_ATTR_WRITE		0x100
116 
117 #define	FLOW_MASTER -1	    /* Declaration of thread from script */
118 #define	FLOW_DEFINITION 0   /* Prototype definition of flowop from library */
119 
120 #define	FLOW_TYPES	5
121 #define	FLOW_TYPE_GLOBAL	0  /* Rolled up statistics */
122 #define	FLOW_TYPE_IO		1  /* Op is an I/O, reflected in iops and lat */
123 #define	FLOW_TYPE_AIO		2  /* Op is an async I/O, reflected in iops */
124 #define	FLOW_TYPE_SYNC		3  /* Op is a sync event */
125 #define	FLOW_TYPE_OTHER		4  /* Op is a something else */
126 
127 extern flowstat_t controlstats;
128 
129 void flowop_init(void);
130 flowop_t *flowop_define(threadflow_t *, char *name, flowop_t *inherit,
131     int instance, int type);
132 flowop_t *flowop_find(char *name);
133 flowop_t *flowop_find_one(char *name, int instance);
134 void flowoplib_usage(void);
135 void flowoplib_init(void);
136 void flowop_delete_all(flowop_t **threadlist);
137 void flowop_endop(threadflow_t *threadflow, flowop_t *flowop, int64_t bytes);
138 void flowop_beginop(threadflow_t *threadflow, flowop_t *flowop);
139 void flowop_destruct_all_flows(threadflow_t *threadflow);
140 
141 #ifdef	__cplusplus
142 }
143 #endif
144 
145 #endif	/* _FB_FLOWOP_H */
146