xref: /onnv-gate/usr/src/cmd/filebench/common/flowop.h (revision 6212:d9dcad6dd79c)
15184Sek110237 /*
25184Sek110237  * CDDL HEADER START
35184Sek110237  *
45184Sek110237  * The contents of this file are subject to the terms of the
55184Sek110237  * Common Development and Distribution License (the "License").
65184Sek110237  * You may not use this file except in compliance with the License.
75184Sek110237  *
85184Sek110237  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95184Sek110237  * or http://www.opensolaris.org/os/licensing.
105184Sek110237  * See the License for the specific language governing permissions
115184Sek110237  * and limitations under the License.
125184Sek110237  *
135184Sek110237  * When distributing Covered Code, include this CDDL HEADER in each
145184Sek110237  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155184Sek110237  * If applicable, add the following below this CDDL HEADER, with the
165184Sek110237  * fields enclosed by brackets "[]" replaced with your own identifying
175184Sek110237  * information: Portions Copyright [yyyy] [name of copyright owner]
185184Sek110237  *
195184Sek110237  * CDDL HEADER END
205184Sek110237  */
215184Sek110237 /*
226084Saw148015  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
235184Sek110237  * Use is subject to license terms.
245184Sek110237  */
255184Sek110237 
265184Sek110237 #ifndef	_FB_FLOWOP_H
275184Sek110237 #define	_FB_FLOWOP_H
285184Sek110237 
295184Sek110237 
305184Sek110237 #pragma ident	"%Z%%M%	%I%	%E% SMI"
315184Sek110237 
325184Sek110237 #include "config.h"
335184Sek110237 
345184Sek110237 #include <stdio.h>
355184Sek110237 #include <stdlib.h>
365184Sek110237 #include <unistd.h>
375184Sek110237 #include <sys/stat.h>
385184Sek110237 #include <sys/types.h>
395184Sek110237 #include <sys/param.h>
405184Sek110237 #include <sys/resource.h>
415184Sek110237 #include <pthread.h>
425184Sek110237 #ifndef HAVE_SYSV_SEM
435184Sek110237 #include <semaphore.h>
445184Sek110237 #endif
455184Sek110237 #include "stats.h"
465184Sek110237 #include "threadflow.h"
475184Sek110237 #include "vars.h"
485184Sek110237 #include "fileset.h"
495184Sek110237 #include "filebench.h"
505184Sek110237 
515184Sek110237 #ifdef	__cplusplus
525184Sek110237 extern "C" {
535184Sek110237 #endif
545184Sek110237 
555184Sek110237 typedef struct flowop {
565184Sek110237 	char		fo_name[128];	/* Name */
575184Sek110237 	int		fo_instance;	/* Instance number */
585184Sek110237 	struct flowop	*fo_next;	/* Next in global list */
595184Sek110237 	struct flowop	*fo_threadnext;	/* Next in thread's list */
605184Sek110237 	struct flowop	*fo_resultnext;	/* List of flowops in result */
615184Sek110237 	struct threadflow *fo_thread;	/* Backpointer to thread */
625184Sek110237 	int		(*fo_func)();	/* Method */
635184Sek110237 	int		(*fo_init)();	/* Init Method */
645184Sek110237 	void		(*fo_destruct)(); /* Destructor Method */
655184Sek110237 	int		fo_type;	/* Type */
665184Sek110237 	int		fo_attrs;	/* Flow op attribute */
67*6212Saw148015 	avd_t		fo_filename;	/* file/fileset name */
685184Sek110237 	fileset_t	*fo_fileset;	/* Fileset for op */
695184Sek110237 	int		fo_fd;		/* File descriptor */
705184Sek110237 	int		fo_fdnumber;	/* User specified file descriptor */
715184Sek110237 	int		fo_srcfdnumber;	/* User specified src file descriptor */
72*6212Saw148015 	fbint_t		fo_constvalue;	/* constant version of fo_value */
73*6212Saw148015 	fbint_t		fo_constwss;	/* constant version of fo_wss */
74*6212Saw148015 	avd_t		fo_iosize;	/* Size of operation */
75*6212Saw148015 	avd_t		fo_wss;		/* Flow op working set size */
765184Sek110237 	char		fo_targetname[128]; /* Target, for wakeup etc... */
775184Sek110237 	struct flowop	*fo_targets;	/* List of targets matching name */
785184Sek110237 	struct flowop	*fo_targetnext;	/* List of targets matching name */
79*6212Saw148015 	avd_t		fo_iters;	/* Number of iterations of op */
80*6212Saw148015 	avd_t		fo_value;	/* Attr */
81*6212Saw148015 	avd_t		fo_sequential;	/* Attr */
82*6212Saw148015 	avd_t		fo_random;	/* Attr */
83*6212Saw148015 	avd_t		fo_stride;	/* Attr */
84*6212Saw148015 	avd_t		fo_backwards;	/* Attr */
85*6212Saw148015 	avd_t		fo_dsync;	/* Attr */
86*6212Saw148015 	avd_t		fo_blocking;	/* Attr */
87*6212Saw148015 	avd_t		fo_directio;	/* Attr */
88*6212Saw148015 	avd_t		fo_rotatefd;	/* Attr */
895184Sek110237 	flowstat_t	fo_stats;	/* Flow statistics */
905184Sek110237 	pthread_cond_t	fo_cv;		/* Block/wakeup cv */
915184Sek110237 	pthread_mutex_t	fo_lock;	/* Mutex around flowop */
92*6212Saw148015 	void		*fo_private;	/* Flowop private scratch pad area */
935184Sek110237 	char		*fo_buf;	/* Per-flowop buffer */
945673Saw148015 	uint64_t	fo_buf_size;	/* current size of buffer */
955184Sek110237 #ifdef HAVE_SYSV_SEM
965184Sek110237 	int		fo_semid_lw;	/* sem id */
975184Sek110237 	int		fo_semid_hw;	/* sem id for highwater block */
985184Sek110237 #else
995184Sek110237 	sem_t		fo_sem;		/* sem_t for posix semaphores */
1005184Sek110237 #endif /* HAVE_SYSV_SEM */
101*6212Saw148015 	avd_t		fo_highwater;	/* value of highwater paramter */
1025184Sek110237 	void		*fo_idp;	/* id, for sems etc */
1035184Sek110237 	hrtime_t	fo_timestamp;	/* for ratecontrol, etc... */
1045184Sek110237 	int		fo_initted;	/* Set to one if initialized */
1055184Sek110237 	int64_t		fo_tputbucket;	/* Throughput bucket, for limiter */
1065184Sek110237 	uint64_t	fo_tputlast;	/* Throughput count, for delta's */
1075184Sek110237 
1085184Sek110237 } flowop_t;
1095184Sek110237 
1105184Sek110237 /* Flow Op Attrs */
1115184Sek110237 #define	FLOW_ATTR_SEQUENTIAL	0x1
1125184Sek110237 #define	FLOW_ATTR_RANDOM	0x2
1135184Sek110237 #define	FLOW_ATTR_STRIDE	0x4
1145184Sek110237 #define	FLOW_ATTR_BACKWARDS	0x8
1155184Sek110237 #define	FLOW_ATTR_DSYNC		0x10
1165184Sek110237 #define	FLOW_ATTR_BLOCKING	0x20
1175184Sek110237 #define	FLOW_ATTR_DIRECTIO	0x40
1185184Sek110237 #define	FLOW_ATTR_READ		0x80
1195184Sek110237 #define	FLOW_ATTR_WRITE		0x100
1205184Sek110237 
1215184Sek110237 #define	FLOW_MASTER -1	    /* Declaration of thread from script */
1225184Sek110237 #define	FLOW_DEFINITION 0   /* Prototype definition of flowop from library */
1235184Sek110237 
1245184Sek110237 #define	FLOW_TYPES	5
1255184Sek110237 #define	FLOW_TYPE_GLOBAL	0  /* Rolled up statistics */
1265184Sek110237 #define	FLOW_TYPE_IO		1  /* Op is an I/O, reflected in iops and lat */
1275184Sek110237 #define	FLOW_TYPE_AIO		2  /* Op is an async I/O, reflected in iops */
1285184Sek110237 #define	FLOW_TYPE_SYNC		3  /* Op is a sync event */
1295184Sek110237 #define	FLOW_TYPE_OTHER		4  /* Op is a something else */
1305184Sek110237 
1315184Sek110237 extern flowstat_t controlstats;
132*6212Saw148015 extern pthread_mutex_t controlstats_lock;
1335184Sek110237 
1345184Sek110237 void flowop_init(void);
1355184Sek110237 flowop_t *flowop_define(threadflow_t *, char *name, flowop_t *inherit,
1365184Sek110237     int instance, int type);
1375184Sek110237 flowop_t *flowop_find(char *name);
1385184Sek110237 flowop_t *flowop_find_one(char *name, int instance);
1395184Sek110237 void flowoplib_usage(void);
1405184Sek110237 void flowoplib_init(void);
1415184Sek110237 void flowop_delete_all(flowop_t **threadlist);
1425673Saw148015 void flowop_endop(threadflow_t *threadflow, flowop_t *flowop, int64_t bytes);
1435184Sek110237 void flowop_beginop(threadflow_t *threadflow, flowop_t *flowop);
1446084Saw148015 void flowop_destruct_all_flows(threadflow_t *threadflow);
145*6212Saw148015 void flowop_printall(void);
1465184Sek110237 
1475184Sek110237 #ifdef	__cplusplus
1485184Sek110237 }
1495184Sek110237 #endif
1505184Sek110237 
1515184Sek110237 #endif	/* _FB_FLOWOP_H */
152