forked from yszheda/sim-outorder_RRIP-HP-cache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.h
332 lines (299 loc) · 13.4 KB
/
stats.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/* stats.h - statistical package interfaces */
/* SimpleScalar(TM) Tool Suite
* Copyright (C) 1994-2003 by Todd M. Austin, Ph.D. and SimpleScalar, LLC.
* All Rights Reserved.
*
* THIS IS A LEGAL DOCUMENT, BY USING SIMPLESCALAR,
* YOU ARE AGREEING TO THESE TERMS AND CONDITIONS.
*
* No portion of this work may be used by any commercial entity, or for any
* commercial purpose, without the prior, written permission of SimpleScalar,
* LLC (info@simplescalar.com). Nonprofit and noncommercial use is permitted
* as described below.
*
* 1. SimpleScalar is provided AS IS, with no warranty of any kind, express
* or implied. The user of the program accepts full responsibility for the
* application of the program and the use of any results.
*
* 2. Nonprofit and noncommercial use is encouraged. SimpleScalar may be
* downloaded, compiled, executed, copied, and modified solely for nonprofit,
* educational, noncommercial research, and noncommercial scholarship
* purposes provided that this notice in its entirety accompanies all copies.
* Copies of the modified software can be delivered to persons who use it
* solely for nonprofit, educational, noncommercial research, and
* noncommercial scholarship purposes provided that this notice in its
* entirety accompanies all copies.
*
* 3. ALL COMMERCIAL USE, AND ALL USE BY FOR PROFIT ENTITIES, IS EXPRESSLY
* PROHIBITED WITHOUT A LICENSE FROM SIMPLESCALAR, LLC (info@simplescalar.com).
*
* 4. No nonprofit user may place any restrictions on the use of this software,
* including as modified by the user, by any other authorized user.
*
* 5. Noncommercial and nonprofit users may distribute copies of SimpleScalar
* in compiled or executable form as set forth in Section 2, provided that
* either: (A) it is accompanied by the corresponding machine-readable source
* code, or (B) it is accompanied by a written offer, with no time limit, to
* give anyone a machine-readable copy of the corresponding source code in
* return for reimbursement of the cost of distribution. This written offer
* must permit verbatim duplication by anyone, or (C) it is distributed by
* someone who received only the executable form, and is accompanied by a
* copy of the written offer of source code.
*
* 6. SimpleScalar was developed by Todd M. Austin, Ph.D. The tool suite is
* currently maintained by SimpleScalar LLC (info@simplescalar.com). US Mail:
* 2395 Timbercrest Court, Ann Arbor, MI 48105.
*
* Copyright (C) 1994-2003 by Todd M. Austin, Ph.D. and SimpleScalar, LLC.
*/
#ifndef STAT_H
#define STAT_H
#include <stdio.h>
#include "host.h"
#include "machine.h"
#include "eval.h"
/*
* The stats package is a uniform module for handling statistical variables,
* including counters, distributions, and expressions. The user must first
* create a stats database using stat_new(), then statical counters are added
* to the database using the *_reg_*() functions. Interfaces are included to
* allocate and manipulate distributions (histograms) and general expression
* of other statistical variables constants. Statistical variables can be
* located by name using stat_find_stat(). And, statistics can be print in
* a highly standardized and stylized fashion using stat_print_stats().
*/
/* stat variable classes */
enum stat_class_t {
sc_int = 0, /* integer stat */
sc_uint, /* unsigned integer stat */
#ifdef HOST_HAS_QWORD
sc_qword, /* qword integer stat */
sc_sqword, /* signed qword integer stat */
#endif /* HOST_HAS_QWORD */
sc_float, /* single-precision FP stat */
sc_double, /* double-precision FP stat */
sc_dist, /* array distribution stat */
sc_sdist, /* sparse array distribution stat */
sc_formula, /* stat expression formula */
sc_NUM
};
/* sparse array distributions are implemented with a hash table */
#define HTAB_SZ 1024
#define HTAB_HASH(I) ((((I) >> 8) ^ (I)) & (HTAB_SZ - 1))
/* hash table bucket definition */
struct bucket_t {
struct bucket_t *next; /* pointer to the next bucket */
md_addr_t index; /* bucket index - as large as an addr */
unsigned int count; /* bucket count */
};
/* forward declaration */
struct stat_stat_t;
/* enable distribution components: index, count, probability, cumulative */
#define PF_COUNT 0x0001
#define PF_PDF 0x0002
#define PF_CDF 0x0004
#define PF_ALL (PF_COUNT|PF_PDF|PF_CDF)
/* user-defined print function, if this option is selected, a function of this
form is called for each bucket in the distribution, in ascending index
order */
typedef void
(*print_fn_t)(struct stat_stat_t *stat, /* the stat variable being printed */
md_addr_t index, /* entry index to print */
int count, /* entry count */
double sum, /* cumulative sum */
double total); /* total count for distribution */
/* statistical variable definition */
struct stat_stat_t {
struct stat_stat_t *next; /* pointer to next stat in database list */
char *name; /* stat name */
char *desc; /* stat description */
char *format; /* stat output print format */
enum stat_class_t sc; /* stat class */
union stat_variant_t {
/* sc == sc_int */
struct stat_for_int_t {
int *var; /* integer stat variable */
int init_val; /* initial integer value */
} for_int;
/* sc == sc_uint */
struct stat_for_uint_t {
unsigned int *var; /* unsigned integer stat variable */
unsigned int init_val; /* initial unsigned integer value */
} for_uint;
#ifdef HOST_HAS_QWORD
/* sc == sc_qword */
struct stat_for_qword_t {
qword_t *var; /* qword integer stat variable */
qword_t init_val; /* qword integer value */
} for_qword;
/* sc == sc_sqword */
struct stat_for_sqword_t {
sqword_t *var; /* signed qword integer stat variable */
sqword_t init_val; /* signed qword integer value */
} for_sqword;
#endif /* HOST_HAS_QWORD */
/* sc == sc_float */
struct stat_for_float_t {
float *var; /* float stat variable */
float init_val; /* initial float value */
} for_float;
/* sc == sc_double */
struct stat_for_double_t {
double *var; /* double stat variable */
double init_val; /* initial double value */
} for_double;
/* sc == sc_dist */
struct stat_for_dist_t {
unsigned int init_val; /* initial dist value */
unsigned int *arr; /* non-sparse array pointer */
unsigned int arr_sz; /* array size */
unsigned int bucket_sz; /* array bucket size */
int pf; /* printables */
char **imap; /* index -> string map */
print_fn_t print_fn; /* optional user-specified print fn */
unsigned int overflows; /* total overflows in stat_add_samples() */
} for_dist;
/* sc == sc_sdist */
struct stat_for_sdist_t {
unsigned int init_val; /* initial dist value */
struct bucket_t **sarr; /* sparse array pointer */
int pf; /* printables */
print_fn_t print_fn; /* optional user-specified print fn */
} for_sdist;
/* sc == sc_formula */
struct stat_for_formula_t {
char *formula; /* stat formula, see eval.h for format */
} for_formula;
} variant;
};
/* statistical database */
struct stat_sdb_t {
struct stat_stat_t *stats; /* list of stats in database */
struct eval_state_t *evaluator; /* an expression evaluator */
};
/* evaluate a stat as an expression */
struct eval_value_t
stat_eval_ident(struct eval_state_t *es);/* expression stat to evaluate */
/* create a new stats database */
struct stat_sdb_t *stat_new(void);
/* delete a stats database */
void
stat_delete(struct stat_sdb_t *sdb); /* stats database */
/* register an integer statistical variable */
struct stat_stat_t *
stat_reg_int(struct stat_sdb_t *sdb, /* stat database */
char *name, /* stat variable name */
char *desc, /* stat variable description */
int *var, /* stat variable */
int init_val, /* stat variable initial value */
char *format); /* optional variable output format */
/* register an unsigned integer statistical variable */
struct stat_stat_t *
stat_reg_uint(struct stat_sdb_t *sdb, /* stat database */
char *name, /* stat variable name */
char *desc, /* stat variable description */
unsigned int *var, /* stat variable */
unsigned int init_val, /* stat variable initial value */
char *format); /* optional variable output format */
#ifdef HOST_HAS_QWORD
/* register a qword integer statistical variable */
struct stat_stat_t *
stat_reg_qword(struct stat_sdb_t *sdb, /* stat database */
char *name, /* stat variable name */
char *desc, /* stat variable description */
qword_t *var, /* stat variable */
qword_t init_val, /* stat variable initial value */
char *format); /* optional variable output format */
/* register a signed qword integer statistical variable */
struct stat_stat_t *
stat_reg_sqword(struct stat_sdb_t *sdb, /* stat database */
char *name, /* stat variable name */
char *desc, /* stat variable description */
sqword_t *var, /* stat variable */
sqword_t init_val, /* stat variable initial value */
char *format); /* optional variable output format */
#endif /* HOST_HAS_QWORD */
/* register a float statistical variable */
struct stat_stat_t *
stat_reg_float(struct stat_sdb_t *sdb, /* stat database */
char *name, /* stat variable name */
char *desc, /* stat variable description */
float *var, /* stat variable */
float init_val, /* stat variable initial value */
char *format); /* optional variable output format */
/* register a double statistical variable */
struct stat_stat_t *
stat_reg_double(struct stat_sdb_t *sdb, /* stat database */
char *name, /* stat variable name */
char *desc, /* stat variable description */
double *var, /* stat variable */
double init_val, /* stat variable initial value */
char *format); /* optional variable output format */
/* create an array distribution (w/ fixed size buckets) in stat database SDB,
the array distribution has ARR_SZ buckets with BUCKET_SZ indicies in each
bucked, PF specifies the distribution components to print for optional
format FORMAT; the indicies may be optionally replaced with the strings
from IMAP, or the entire distribution can be printed with the optional
user-specified print function PRINT_FN */
struct stat_stat_t *
stat_reg_dist(struct stat_sdb_t *sdb, /* stat database */
char *name, /* stat variable name */
char *desc, /* stat variable description */
unsigned int init_val, /* dist initial value */
unsigned int arr_sz, /* array size */
unsigned int bucket_sz, /* array bucket size */
int pf, /* print format, use PF_* defs */
char *format, /* optional variable output format */
char **imap, /* optional index -> string map */
print_fn_t print_fn); /* optional user print function */
/* create a sparse array distribution in stat database SDB, while the sparse
array consumes more memory per bucket than an array distribution, it can
efficiently map any number of indicies from 0 to 2^32-1, PF specifies the
distribution components to print for optional format FORMAT; the indicies
may be optionally replaced with the strings from IMAP, or the entire
distribution can be printed with the optional user-specified print function
PRINT_FN */
struct stat_stat_t *
stat_reg_sdist(struct stat_sdb_t *sdb, /* stat database */
char *name, /* stat variable name */
char *desc, /* stat variable description */
unsigned int init_val, /* dist initial value */
int pf, /* print format, use PF_* defs */
char *format, /* optional variable output format */
print_fn_t print_fn); /* optional user print function */
/* add NSAMPLES to array or sparse array distribution STAT */
void
stat_add_samples(struct stat_stat_t *stat,/* stat database */
md_addr_t index, /* distribution index of samples */
int nsamples); /* number of samples to add to dist */
/* add a single sample to array or sparse array distribution STAT */
void
stat_add_sample(struct stat_stat_t *stat,/* stat variable */
md_addr_t index); /* index of sample */
/* register a double statistical formula, the formula is evaluated when the
statistic is printed, the formula expression may reference any registered
statistical variable and, in addition, the standard operators '(', ')', '+',
'-', '*', and '/', and literal (i.e., C-format decimal, hexidecimal, and
octal) constants are also supported; NOTE: all terms are immediately
converted to double values and the result is a double value, see eval.h
for more information on formulas */
struct stat_stat_t *
stat_reg_formula(struct stat_sdb_t *sdb,/* stat database */
char *name, /* stat variable name */
char *desc, /* stat variable description */
char *formula, /* formula expression */
char *format); /* optional variable output format */
/* print the value of stat variable STAT */
void
stat_print_stat(struct stat_sdb_t *sdb, /* stat database */
struct stat_stat_t *stat,/* stat variable */
FILE *fd); /* output stream */
/* print the value of all stat variables in stat database SDB */
void
stat_print_stats(struct stat_sdb_t *sdb,/* stat database */
FILE *fd); /* output stream */
/* find a stat variable, returns NULL if it is not found */
struct stat_stat_t *
stat_find_stat(struct stat_sdb_t *sdb, /* stat database */
char *stat_name); /* stat name */
#endif /* STAT_H */