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 2009 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 #include "filebench.h"
30 
31 typedef struct flowop {
32 	char		fo_name[128];	/* Name */
33 	int		fo_instance;	/* Instance number */
34 	struct flowop	*fo_next;	/* Next in global list */
35 	struct flowop	*fo_exec_next;	/* Next in thread's or compfo's list */
36 	struct flowop	*fo_resultnext;	/* List of flowops in result */
37 	struct flowop	*fo_comp_fops;	/* List of flowops in composite fo */
38 	var_t		*fo_lvar_list;	/* List of composite local vars */
39 	struct threadflow *fo_thread;	/* Backpointer to thread */
40 	int		(*fo_func)();	/* Method */
41 	int		(*fo_init)();	/* Init Method */
42 	void		(*fo_destruct)(); /* Destructor Method */
43 	int		fo_type;	/* Type */
44 	int		fo_attrs;	/* Flow op attribute */
45 	avd_t		fo_filename;	/* file/fileset name */
46 	fileset_t	*fo_fileset;	/* Fileset for op */
47 	int		fo_fdnumber;	/* User specified file descriptor */
48 	int		fo_srcfdnumber;	/* User specified src file descriptor */
49 	fbint_t		fo_constvalue;	/* constant version of fo_value */
50 	fbint_t		fo_constwss;	/* constant version of fo_wss */
51 	avd_t		fo_iosize;	/* Size of operation */
52 	avd_t		fo_wss;		/* Flow op working set size */
53 	char		fo_targetname[128]; /* Target, for wakeup etc... */
54 	struct flowop	*fo_targets;	/* List of targets matching name */
55 	struct flowop	*fo_targetnext;	/* List of targets matching name */
56 	avd_t		fo_iters;	/* Number of iterations of op */
57 	avd_t		fo_value;	/* Attr */
58 	avd_t		fo_sequential;	/* Attr */
59 	avd_t		fo_random;	/* Attr */
60 	avd_t		fo_stride;	/* Attr */
61 	avd_t		fo_backwards;	/* Attr */
62 	avd_t		fo_dsync;	/* Attr */
63 	avd_t		fo_blocking;	/* Attr */
64 	avd_t		fo_directio;	/* Attr */
65 	avd_t		fo_rotatefd;	/* Attr */
66 	avd_t		fo_fileindex;	/* Attr */
67 	avd_t		fo_noreadahead; /* Attr */
68 	struct flowstats	fo_stats;	/* Flow statistics */
69 	pthread_cond_t	fo_cv;		/* Block/wakeup cv */
70 	pthread_mutex_t	fo_lock;	/* Mutex around flowop */
71 	void		*fo_private;	/* Flowop private scratch pad area */
72 	char		*fo_buf;	/* Per-flowop buffer */
73 	uint64_t	fo_buf_size;	/* current size of buffer */
74 #ifdef HAVE_SYSV_SEM
75 	int		fo_semid_lw;	/* sem id */
76 	int		fo_semid_hw;	/* sem id for highwater block */
77 #else
78 	sem_t		fo_sem;		/* sem_t for posix semaphores */
79 #endif /* HAVE_SYSV_SEM */
80 	avd_t		fo_highwater;	/* value of highwater paramter */
81 	void		*fo_idp;	/* id, for sems etc */
82 	hrtime_t	fo_timestamp;	/* for ratecontrol, etc... */
83 	int		fo_initted;	/* Set to one if initialized */
84 	int64_t		fo_tputbucket;	/* Throughput bucket, for limiter */
85 	uint64_t	fo_tputlast;	/* Throughput count, for delta's */
86 
87 } flowop_t;
88 
89 /* Flow Op Attrs */
90 #define	FLOW_ATTR_SEQUENTIAL	0x1
91 #define	FLOW_ATTR_RANDOM	0x2
92 #define	FLOW_ATTR_STRIDE	0x4
93 #define	FLOW_ATTR_BACKWARDS	0x8
94 #define	FLOW_ATTR_DSYNC		0x10
95 #define	FLOW_ATTR_BLOCKING	0x20
96 #define	FLOW_ATTR_DIRECTIO	0x40
97 #define	FLOW_ATTR_READ		0x80
98 #define	FLOW_ATTR_WRITE		0x100
99 #define FLOW_ATTR_FADV_RANDOM	0x200
100 
101 /* Flowop Instance Numbers */
102 			    /* Worker flowops have instance numbers > 0 */
103 #define	FLOW_DEFINITION 0   /* Prototype definition of flowop from library */
104 #define	FLOW_INNER_DEF -1   /* Constructed proto flowops within composite */
105 #define	FLOW_MASTER -2	    /* Master flowop based on flowop declaration */
106 			    /* supplied within a thread definition */
107 
108 /* Flowop type definitions */
109 #define	FLOW_TYPES		6
110 #define	FLOW_TYPE_GLOBAL	0  /* Rolled up statistics */
111 #define	FLOW_TYPE_IO		1  /* Op is an I/O, reflected in iops and lat */
112 #define	FLOW_TYPE_AIO		2  /* Op is an async I/O, reflected in iops */
113 #define	FLOW_TYPE_SYNC		3  /* Op is a sync event */
114 #define	FLOW_TYPE_COMPOSITE	4  /* Op is a composite flowop */
115 #define	FLOW_TYPE_OTHER		5  /* Op is a something else */
116 
117 typedef struct flowop_proto {
118 	int	fl_type;
119 	int	fl_attrs;
120 	char	*fl_name;
121 	int	(*fl_init)();
122 	int	(*fl_func)();
123 	void	(*fl_destruct)();
124 } flowop_proto_t;
125 
126 extern struct flowstats controlstats;
127 extern pthread_mutex_t controlstats_lock;
128 
129 flowop_t *flowop_define(threadflow_t *, char *name, flowop_t *inherit,
130 		flowop_t **flowoplist_hdp, int instance, int type);
131 
132 flowop_t *flowop_find(char *name);
133 flowop_t *flowop_find_one(char *name, int instance);
134 flowop_t *flowop_find_from_list(char *name, flowop_t *list);
135 int flowop_init_generic(flowop_t *flowop);
136 void flowop_destruct_generic(flowop_t *flowop);
137 void flowop_add_from_proto(flowop_proto_t *list, int nops);
138 int flowoplib_iosetup(threadflow_t *threadflow, flowop_t *flowop,
139     fbint_t *wssp, caddr_t *iobufp, fb_fdesc_t **filedescp, fbint_t iosize);
140 void flowoplib_flowinit(void);
141 void flowop_delete_all(flowop_t **threadlist);
142 void flowop_endop(threadflow_t *threadflow, flowop_t *flowop, int64_t bytes);
143 void flowop_beginop(threadflow_t *threadflow, flowop_t *flowop);
144 void flowop_destruct_all_flows(threadflow_t *threadflow);
145 flowop_t *flowop_new_composite_define(char *name);
146 void flowop_printall(void);
147 
148 void flowop_init(int ismaster);
149 
150 /* Local file system specific */
151 void fb_lfs_funcvecinit();
152 void fb_lfs_newflowops();
153 
154 #endif	/* _FB_FLOWOP_H */
155