-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathdtiobtemplate.c
More file actions
321 lines (271 loc) · 8.5 KB
/
dtiobtemplate.c
File metadata and controls
321 lines (271 loc) · 8.5 KB
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
/*
* dtTOOL.c - I/O Behavior for TOOL tool.
*
* Author: Robin T. Miller
* Date Created: November 5th, 2013
*
* Modification History:
*/
#include "dt.h"
/*
* Definitions:
*/
#define DEFAULT_THREAD_COUNT 1
#define DEFAULT_RUNTIME 0
/*
* TOOL Specific Parameters (options):
*/
typedef struct TOOL_parameters {
/* Add TOOL specific parameters... */
uint64_t param_iterations;
hbool_t param_locking;
hbool_t param_verbose;
} TOOL_parameters_t;
/*
* TOOL Thread Specific Information:
*/
typedef struct TOOL_thread_info {
dinfo_t *dip;
void *TOOL_thread_specific_data;
} TOOL_thread_info_t;
typedef struct TOOL_information {
TOOL_parameters_t TOOL_parameters;
TOOL_thread_info_t TOOL_thread_info;
} TOOL_information_t;
/*
* Forward References:
*/
void TOOL_help(dinfo_t *dip);
int TOOL_thread_setup(dinfo_t *dip);
/* I/O Behavior Support Functions */
int TOOL_initialize(dinfo_t *dip);
int TOOL_parser(dinfo_t *dip, char *option);
void TOOL_cleanup_information(dinfo_t *dip);
int TOOL_clone_information(dinfo_t *dip, dinfo_t *cdip, hbool_t new_thread);
int TOOL_job_finish(dinfo_t *mdip, job_info_t *job);
void TOOL_show_parameters(dinfo_t *dip);
void *TOOL_thread(void *arg);
int TOOL_validate_parameters(dinfo_t *dip);
/*
* Declare the I/O behavior functions:
*/
iobehavior_funcs_t TOOL_iobehavior_funcs = {
"TOOL", /* iob_name */
&TOOL_initialize, /* iob_initialize */
NULL, /* iob_initialize_job */
&TOOL_parser, /* iob_parser */
&TOOL_cleanup_information, /* iob_cleanup */
&TOOL_clone_information, /* iob_clone */
&TOOL_thread, /* iob_thread */
NULL, /* iob_thread1 */
NULL, /* iob_job_init */
NULL, /* iob_job_cleanup */
&TOOL_job_finish, /* iob_job_finish */
NULL, /* iob_job_modify */
&TOOL_job_finish, /* iob_job_query */
NULL, /* iob_job_keepalive */
NULL, /* iob_thread_keepalive */
&TOOL_show_parameters, /* iob_show_parameters */
&TOOL_validate_parameters /* iob_validate_parameters */
};
void
TOOL_set_iobehavior_funcs(dinfo_t *dip)
{
dip->di_iobf = &TOOL_iobehavior_funcs;
return;
}
/* ---------------------------------------------------------------------- */
int
TOOL_parser(dinfo_t *dip, char *option)
{
TOOL_information_t *sip = dip->di_opaque;
TOOL_parameters_t *TOOLp = &sip->TOOL_parameters;
int status = PARSE_MATCH;
if (match(&option, "-")) { /* Optional "-" to match TOOL options! */
;
}
if (match(&option, "help")) {
TOOL_help(dip);
return(STOP_PARSING);
}
if (match(&option, "verbose")) {
dip->di_errors_flag = True;
return(status);
}
if (match(&option, "locking")) {
TOOLp->param_locking = True;
return(status);
}
if (match(&option, "min_hl=")) {
//TOOLp->param_min_hardlinks = (int)number(dip, option, ANY_RADIX, &status, True);
return(status);
}
/* Add TOOL specific parsing here... */
return(PARSE_NOMATCH);
}
/* ---------------------------------------------------------------------- */
int
TOOL_job_finish(dinfo_t *dip, job_info_t *job)
{
TOOL_information_t *sip;
TOOL_thread_info_t *thread_info;
threads_info_t *tip = job->ji_tinfo;
dinfo_t *tdip;
int thread;
/*
* Accumulate the total statistics.
*/
for (thread = 0; (thread < tip->ti_threads); thread++) {
tdip = tip->ti_dts[thread];
sip = tdip->di_opaque;
thread_info = &sip->TOOL_thread_info;
/* Accumulate thread statistics here...*/
}
//TOOL_report_stats(dip, total_info, "Total", sip->TOOL_style);
return(SUCCESS);
}
void *
TOOL_thread(void *arg)
{
dinfo_t *dip = arg;
TOOL_information_t *sip = dip->di_opaque;
TOOL_thread_info_t *tip = &sip->TOOL_thread_info;
TOOL_parameters_t *TOOLp = &sip->TOOL_parameters;
uint64_t iterations = 0;
int status = SUCCESS;
status = do_common_thread_startup(dip);
if (status == FAILURE) goto thread_exit;
status = TOOL_thread_setup(dip);
if (status == FAILURE) goto thread_exit;
if (dip->di_debug_flag || dip->di_tDebugFlag) {
Printf(dip, "Starting TOOL, Job %u, Thread %u, Thread ID "OS_TID_FMT"\n",
dip->di_job->ji_job_id, dip->di_thread_number, (os_tid_t)pthread_self());
}
dip->di_start_time = times(&dip->di_stimes);
if (dip->di_runtime) {
dip->di_runtime_end = time((time_t *)NULL) + dip->di_runtime;
}
while (True) {
PAUSE_THREAD(dip);
if ( THREAD_TERMINATING(dip) ) break;
if (dip->di_terminating) break;
/* Do some I/O here... */
break;
iterations++;
if (TOOLp->param_iterations && (iterations >= TOOLp->param_iterations)) {
break;
}
} /* end while(True) */
if (dip->di_tDebugFlag == True) {
; //TOOL_report_stats(dip, tip, "Thread", sip->TOOL_style);
}
thread_exit:
do_common_thread_exit(dip, status);
/*NOT REACHED*/
return(NULL);
}
void
TOOL_cleanup_information(dinfo_t *dip)
{
TOOL_information_t *sip;
TOOL_thread_info_t *tip;
if ( (sip = dip->di_opaque) == NULL) {
return;
}
tip = &sip->TOOL_thread_info;
/* Do TOOL thread specific cleanup here... */
Free(dip, sip);
dip->di_opaque = NULL;
return;
}
int
TOOL_clone_information(dinfo_t *dip, dinfo_t *cdip, hbool_t new_thread)
{
TOOL_information_t *sip = dip->di_opaque;
TOOL_parameters_t *TOOLp = &sip->TOOL_parameters;
TOOL_information_t *csip; /* clone */
csip = Malloc(dip, sizeof(*csip));
if (csip == NULL) return(FAILURE);
cdip->di_opaque = csip;
*csip = *sip; /* Copy the original information. */
/* Do TOOL thread specific cloning (if any) here... */
return(SUCCESS);
}
int
TOOL_initialize(dinfo_t *dip)
{
TOOL_information_t *sip;
TOOL_parameters_t *TOOLp;
sip = Malloc(dip, sizeof(*sip));
if (sip == NULL) return(FAILURE);
dip->di_opaque = sip;
TOOLp = &sip->TOOL_parameters;
dip->di_threads = DEFAULT_THREAD_COUNT;
dip->di_runtime = DEFAULT_RUNTIME;
/* Note: This is necessary to bypass dt sanity checks! */
dip->di_data_limit = 512;
return(SUCCESS);
}
int
TOOL_thread_setup(dinfo_t *dip)
{
TOOL_information_t *sip = dip->di_opaque;
TOOL_thread_info_t *tip = &sip->TOOL_thread_info;
TOOL_parameters_t *TOOLp = &sip->TOOL_parameters;
char *filename = dip->di_output_file;
int thread_number = dip->di_thread_number;
tip->dip = dip;
return(SUCCESS);
}
int
TOOL_validate_parameters(dinfo_t *dip)
{
TOOL_information_t *sip = dip->di_opaque;
TOOL_parameters_t *TOOLp = &sip->TOOL_parameters;
char *style = NULL;
if (dip->di_output_file == NULL) {
Eprintf(dip, "You must specify an output file.\n");
return(FAILURE);
}
return(SUCCESS);
}
void
TOOL_show_parameters(dinfo_t *dip)
{
TOOL_information_t *sip = dip->di_opaque;
TOOL_parameters_t *TOOLp = &sip->TOOL_parameters;
Lprintf(dip, "TOOL Parameters:\n");
#if 0
Lprintf(dip, " style................%s\n", sip->TOOL_style );
Lprintf(dip, " interval.............%d\n", TOOLp->param_interval );
Lprintf(dip, " iterations...........%d\n", TOOLp->param_iterations );
Lprintf(dip, " verbose..............%d\n", dip->di_errors_flag );
Lprintf(dip, " locking..............%d\n", TOOLp->param_locking );
Lprintf(dip, " seed................." LUF "\n", dip->di_random_seed );
Lprintf(dip, " filename.............%s\n", dip->di_output_file );
Lprintf(dip, " thread count.........%u\n", dip->di_threads );
Lprintf(dip, " runtime..............%u\n", dip->di_runtime );
...
Lprintf(dip, "\n");
#endif /* 0 */
/* Add TOOL parameter display here... */
Lflush(dip);
return;
}
#define P Print
void
TOOL_help(dinfo_t *dip)
{
TOOL_information_t *sip = dip->di_opaque;
TOOL_parameters_t *TOOLp = &sip->TOOL_parameters;
P(dip, "Usage: %s iobehavior=TOOL [options...]\n", cmdname);
P(dip, "\nOptions:\n");
P(dip, "\t-help Show this help text, then exit.\n");
P(dip, "\t-verbose Show errors as they occur.\n");
P(dip, "\t-seed=value Set random seed to use.\n");
P(dip, "\t-noflock Disable file locking/unlocking.\n");
P(dip, "\t-version Print the version, then exit.\n");
/* Add TOOL specific help here! */
P(dip, "\n");
return;
}