xref: /onnv-gate/usr/src/cmd/filebench/common/fb_random.h (revision 6212:d9dcad6dd79c)
1*6212Saw148015 /*
2*6212Saw148015  * CDDL HEADER START
3*6212Saw148015  *
4*6212Saw148015  * The contents of this file are subject to the terms of the
5*6212Saw148015  * Common Development and Distribution License (the "License").
6*6212Saw148015  * You may not use this file except in compliance with the License.
7*6212Saw148015  *
8*6212Saw148015  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*6212Saw148015  * or http://www.opensolaris.org/os/licensing.
10*6212Saw148015  * See the License for the specific language governing permissions
11*6212Saw148015  * and limitations under the License.
12*6212Saw148015  *
13*6212Saw148015  * When distributing Covered Code, include this CDDL HEADER in each
14*6212Saw148015  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*6212Saw148015  * If applicable, add the following below this CDDL HEADER, with the
16*6212Saw148015  * fields enclosed by brackets "[]" replaced with your own identifying
17*6212Saw148015  * information: Portions Copyright [yyyy] [name of copyright owner]
18*6212Saw148015  *
19*6212Saw148015  * CDDL HEADER END
20*6212Saw148015  */
21*6212Saw148015 /*
22*6212Saw148015  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*6212Saw148015  * Use is subject to license terms.
24*6212Saw148015  */
25*6212Saw148015 
26*6212Saw148015 #ifndef _FB_RANDOM_H
27*6212Saw148015 #define	_FB_RANDOM_H
28*6212Saw148015 
29*6212Saw148015 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*6212Saw148015 
31*6212Saw148015 #include "config.h"
32*6212Saw148015 
33*6212Saw148015 #ifdef HAVE_STDINT_H
34*6212Saw148015 #include <stdint.h>
35*6212Saw148015 #endif
36*6212Saw148015 
37*6212Saw148015 #ifdef	__cplusplus
38*6212Saw148015 extern "C" {
39*6212Saw148015 #endif
40*6212Saw148015 
41*6212Saw148015 /*
42*6212Saw148015  * probability table entry, used while parsing the supplied
43*6212Saw148015  * probability table
44*6212Saw148015  */
45*6212Saw148015 typedef struct probtabent {
46*6212Saw148015 	struct probtabent	*pte_next;
47*6212Saw148015 	avd_t			pte_percent;
48*6212Saw148015 	avd_t			pte_segmin;
49*6212Saw148015 	avd_t			pte_segmax;
50*6212Saw148015 } probtabent_t;
51*6212Saw148015 
52*6212Saw148015 /*
53*6212Saw148015  * The supplied probability table is converted into a probability funtion
54*6212Saw148015  * lookup table at initialization time. This is the definition for each
55*6212Saw148015  * entry in the table.
56*6212Saw148015  */
57*6212Saw148015 typedef struct randfunc {
58*6212Saw148015 	double		rf_base;
59*6212Saw148015 	double		rf_range;
60*6212Saw148015 } randfunc_t;
61*6212Saw148015 
62*6212Saw148015 /* Number of entries in the probability function table */
63*6212Saw148015 #define	PF_TAB_SIZE	100
64*6212Saw148015 
65*6212Saw148015 /*
66*6212Saw148015  * Random Distribution definition object. Includes a pointer to the
67*6212Saw148015  * appropriate function to access the distribution defined by the object,
68*6212Saw148015  * as well as a function pointer to the specified source of random
69*6212Saw148015  * numbers.
70*6212Saw148015  */
71*6212Saw148015 typedef struct randdist {
72*6212Saw148015 	double		(*rnd_get)(struct randdist *);
73*6212Saw148015 	double		(*rnd_src)(unsigned short *);
74*6212Saw148015 	struct randdist *rnd_next;
75*6212Saw148015 	struct var	*rnd_var;
76*6212Saw148015 	avd_t		rnd_seed;
77*6212Saw148015 	avd_t		rnd_mean;
78*6212Saw148015 	avd_t		rnd_gamma;
79*6212Saw148015 	avd_t		rnd_min;
80*6212Saw148015 	avd_t		rnd_round;
81*6212Saw148015 	double		rnd_dbl_mean;
82*6212Saw148015 	double		rnd_dbl_gamma;
83*6212Saw148015 	fbint_t		rnd_vint_min;
84*6212Saw148015 	fbint_t		rnd_vint_round;
85*6212Saw148015 	probtabent_t	*rnd_probtabs;
86*6212Saw148015 	randfunc_t	rnd_rft[PF_TAB_SIZE];
87*6212Saw148015 	uint16_t	rnd_xi[3];
88*6212Saw148015 	uint16_t	rnd_type;
89*6212Saw148015 } randdist_t;
90*6212Saw148015 
91*6212Saw148015 #define	RAND_TYPE_UNIFORM	0x1
92*6212Saw148015 #define	RAND_TYPE_GAMMA		0x2
93*6212Saw148015 #define	RAND_TYPE_TABLE		0x3
94*6212Saw148015 #define	RAND_TYPE_MASK		0x0fff
95*6212Saw148015 #define	RAND_SRC_URANDOM	0x0000
96*6212Saw148015 #define	RAND_SRC_GENERATOR	0x1000
97*6212Saw148015 
98*6212Saw148015 #define	RAND_PARAM_TYPE		1
99*6212Saw148015 #define	RAND_PARAM_SRC		2
100*6212Saw148015 #define	RAND_PARAM_SEED		3
101*6212Saw148015 #define	RAND_PARAM_MIN		4
102*6212Saw148015 #define	RAND_PARAM_MEAN		5
103*6212Saw148015 #define	RAND_PARAM_GAMMA	6
104*6212Saw148015 #define	RAND_PARAM_ROUND	7
105*6212Saw148015 
106*6212Saw148015 randdist_t *randdist_alloc(void);
107*6212Saw148015 void randdist_init(void);
108*6212Saw148015 int filebench_randomno32(uint32_t *, uint32_t, uint32_t, avd_t);
109*6212Saw148015 int filebench_randomno64(uint64_t *, uint64_t, uint64_t, avd_t);
110*6212Saw148015 void fb_random_init(void);
111*6212Saw148015 
112*6212Saw148015 #ifdef	__cplusplus
113*6212Saw148015 }
114*6212Saw148015 #endif
115*6212Saw148015 
116*6212Saw148015 #endif	/* _FB_RANDOM_H */
117