Home | History | Annotate | Download | only in libmicro
      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, Version 1.0 only
      6  * (the "License").  You may not use this file except in compliance
      7  * with the License.
      8  *
      9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  * or http://www.opensolaris.org/os/licensing.
     11  * See the License for the specific language governing permissions
     12  * and limitations under the License.
     13  *
     14  * When distributing Covered Code, include this CDDL HEADER in each
     15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  * If applicable, add the following below this CDDL HEADER, with the
     17  * fields enclosed by brackets "[]" replaced with your own identifying
     18  * information: Portions Copyright [yyyy] [name of copyright owner]
     19  *
     20  * CDDL HEADER END
     21  */
     22 
     23 /*
     24  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
     25  * Use is subject to license terms.
     26  */
     27 
     28 #ifndef LIBMICRO_H
     29 #define	LIBMICRO_H
     30 
     31 #include <pthread.h>
     32 
     33 #define	LIBMICRO_VERSION	"0.4.1"
     34 
     35 #define	STRSIZE			1024
     36 
     37 typedef struct {
     38 	long long		re_count;
     39 	long long		re_errors;
     40 	long long		re_t0;
     41 	long long		re_t1;
     42 } result_t;
     43 
     44 typedef struct {
     45 	double			sum;
     46 	long long		count;
     47 } histo_t;
     48 
     49 #define	HISTOSIZE		32
     50 #define	DATASIZE		100000
     51 
     52 /*
     53  * stats we compute on data sets
     54  */
     55 
     56 typedef struct stats {
     57 	double	st_min;
     58 	double	st_max;
     59 	double	st_mean;
     60 	double	st_median;
     61 	double	st_stddev;
     62 	double	st_stderr;
     63 	double	st_99confidence;
     64 	double	st_skew;
     65 	double	st_kurtosis;
     66 	double	st_timecorr;	/* correlation with respect to time */
     67 } stats_t;
     68 
     69 /*
     70  * Barrier stuff
     71  */
     72 
     73 typedef struct {
     74 	int			ba_hwm;		/* barrier setpoint	*/
     75 	int			ba_flag;	/* benchmark while true	*/
     76 	long long		ba_deadline;	/* when to stop		*/
     77 	int			ba_phase;	/* number of time used	*/
     78 	int 			ba_waiters;	/* how many are waiting	*/
     79 
     80 #ifdef USE_SEMOP
     81 	int			ba_semid;
     82 #else
     83 	pthread_mutex_t		ba_lock;
     84 	pthread_cond_t		ba_cv;
     85 #endif
     86 
     87 	long long		ba_count;	/* how many ops		 */
     88 	long long		ba_errors;	/* how many errors	 */
     89 
     90 	int			ba_quant;	/* how many quant errors */
     91 	int			ba_batches;	/* how many samples	 */
     92 
     93 	double			ba_starttime;	/* test time start */
     94 	double			ba_endtime;	/* test time end */
     95 
     96 #ifdef NEVER
     97 	double			ba_tmin;	/* min time taken */
     98 	double			ba_tmax;	/* max time taken */
     99 	double			ba_ctmax;	/* max after outliers */
    100 	double			ba_mean;	/* average value */
    101 	double			ba_median;	/* median value */
    102 	double			ba_rawmedian;	/* raw median value */
    103 	double			ba_stddev;	/* standard deviation */
    104 	double			ba_stderr;	/* standard error */
    105 	double			ba_skew; 	/* skew */
    106 	double			ba_kurtosis;	/* kurtosis */
    107 #endif
    108 	stats_t			ba_raw;		/* raw stats */
    109 	stats_t			ba_corrected;	/* corrected stats */
    110 
    111 	int			ba_outliers;	/* outlier count */
    112 
    113 	long long		ba_t0;		/* first thread/proc */
    114 	long long		ba_t1;		/* time of last thread */
    115 	long long		ba_count0;
    116 	long long		ba_errors0;
    117 
    118 	int			ba_datasize;	/* possible #items data	*/
    119 	double			ba_data[1];	/* start of data ararry	*/
    120 } barrier_t;
    121 
    122 
    123 /*
    124  * Barrier interfaces
    125  */
    126 
    127 barrier_t *barrier_create(int hwm, int datasize);
    128 int barrier_destroy(barrier_t *bar);
    129 int barrier_queue(barrier_t *bar, result_t *res);
    130 
    131 
    132 /*
    133  * Functions that can be provided by the user
    134  */
    135 
    136 int	benchmark(void *tsd, result_t *res);
    137 int	benchmark_init();
    138 int	benchmark_fini();
    139 int	benchmark_initrun();
    140 int	benchmark_finirun();
    141 int	benchmark_initworker();
    142 int	benchmark_finiworker();
    143 int	benchmark_initbatch(void *tsd);
    144 int	benchmark_finibatch(void *tsd);
    145 int	benchmark_optswitch(int opt, char *optarg);
    146 char	*benchmark_result();
    147 
    148 
    149 /*
    150  * Globals exported to the user
    151  */
    152 
    153 extern int			lm_argc;
    154 extern char			**lm_argv;
    155 
    156 extern int			lm_optB;
    157 extern int			lm_optD;
    158 extern int			lm_optH;
    159 extern char			*lm_optN;
    160 extern int			lm_optP;
    161 extern int			lm_optS;
    162 extern int			lm_optT;
    163 
    164 extern int			lm_defB;
    165 extern int			lm_defD;
    166 extern int			lm_defH;
    167 extern char			*lm_defN;
    168 extern int			lm_defP;
    169 extern int			lm_defS;
    170 extern int			lm_defT;
    171 extern int			lm_nsecs_per_op;
    172 
    173 extern char			*lm_procpath;
    174 extern char			lm_procname[STRSIZE];
    175 extern char 			lm_usage[STRSIZE];
    176 extern char 			lm_optstr[STRSIZE];
    177 extern char 			lm_header[STRSIZE];
    178 extern size_t			lm_tsdsize;
    179 
    180 
    181 /*
    182  * Utility functions
    183  */
    184 
    185 int 		getpindex();
    186 int 		gettindex();
    187 void 		*gettsd(int p, int t);
    188 long long 	getusecs();
    189 long long 	getnsecs();
    190 int 		setfdlimit(int limit);
    191 long long 	sizetoll();
    192 int 		sizetoint();
    193 int		fit_line(double *, double *, int, double *, double *);
    194 long long	get_nsecs_resolution();
    195 
    196 #endif /* LIBMICRO_H */
    197