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_RANDOM_H 27 #define _FB_RANDOM_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #include "config.h" 32 33 #ifdef HAVE_STDINT_H 34 #include <stdint.h> 35 #endif 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 /* 42 * probability table entry, used while parsing the supplied 43 * probability table 44 */ 45 typedef struct probtabent { 46 struct probtabent *pte_next; 47 avd_t pte_percent; 48 avd_t pte_segmin; 49 avd_t pte_segmax; 50 } probtabent_t; 51 52 /* 53 * The supplied probability table is converted into a probability funtion 54 * lookup table at initialization time. This is the definition for each 55 * entry in the table. 56 */ 57 typedef struct randfunc { 58 double rf_base; 59 double rf_range; 60 } randfunc_t; 61 62 /* Number of entries in the probability function table */ 63 #define PF_TAB_SIZE 100 64 65 /* 66 * Random Distribution definition object. Includes a pointer to the 67 * appropriate function to access the distribution defined by the object, 68 * as well as a function pointer to the specified source of random 69 * numbers. 70 */ 71 typedef struct randdist { 72 double (*rnd_get)(struct randdist *); 73 double (*rnd_src)(unsigned short *); 74 struct randdist *rnd_next; 75 struct var *rnd_var; 76 avd_t rnd_seed; 77 avd_t rnd_mean; 78 avd_t rnd_gamma; 79 avd_t rnd_min; 80 avd_t rnd_round; 81 double rnd_dbl_mean; 82 double rnd_dbl_gamma; 83 fbint_t rnd_vint_min; 84 fbint_t rnd_vint_round; 85 probtabent_t *rnd_probtabs; 86 randfunc_t rnd_rft[PF_TAB_SIZE]; 87 uint16_t rnd_xi[3]; 88 uint16_t rnd_type; 89 } randdist_t; 90 91 #define RAND_TYPE_UNIFORM 0x1 92 #define RAND_TYPE_GAMMA 0x2 93 #define RAND_TYPE_TABLE 0x3 94 #define RAND_TYPE_MASK 0x0fff 95 #define RAND_SRC_URANDOM 0x0000 96 #define RAND_SRC_GENERATOR 0x1000 97 98 #define RAND_PARAM_TYPE 1 99 #define RAND_PARAM_SRC 2 100 #define RAND_PARAM_SEED 3 101 #define RAND_PARAM_MIN 4 102 #define RAND_PARAM_MEAN 5 103 #define RAND_PARAM_GAMMA 6 104 #define RAND_PARAM_ROUND 7 105 106 randdist_t *randdist_alloc(void); 107 void randdist_init(void); 108 int filebench_randomno32(uint32_t *, uint32_t, uint32_t, avd_t); 109 int filebench_randomno64(uint64_t *, uint64_t, uint64_t, avd_t); 110 void fb_random_init(void); 111 112 #ifdef __cplusplus 113 } 114 #endif 115 116 #endif /* _FB_RANDOM_H */