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