-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcodes-recorder-io-wrkld.c
More file actions
425 lines (342 loc) · 12.1 KB
/
codes-recorder-io-wrkld.c
File metadata and controls
425 lines (342 loc) · 12.1 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
/*
* Copyright (C) 2013 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
/* Recorder workload generator that plugs into the general CODES workload
* generator API. This generator consumes a set of input files of Recorder I/O
* traces and passes these traces to the underlying simulator.
*/
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <sys/stat.h>
#include <dirent.h>
#include "ross.h"
#include "codes/codes-workload.h"
#include "codes/quickhash.h"
#include "codes/jenkins-hash.h"
#define RECORDER_NEGLIGIBLE_DELAY .00001
#define RANK_HASH_TABLE_SIZE 397
struct recorder_io_op
{
double start_time;
double end_time;
struct codes_workload_op codes_op;
};
struct file_entry
{
uint64_t file_id;
int fd;
struct qhash_head hash_link;
};
/* structure for storing all context needed to retrieve traces for this rank */
struct rank_traces_context
{
int rank;
double last_op_time;
struct recorder_io_op trace_ops[2048]; /* TODO: this should be extendable */
int trace_list_ndx;
int trace_list_max;
/* hash table link to next rank (if any) */
struct qhash_head hash_link;
};
/* CODES workload API functions for workloads generated from recorder traces*/
static int recorder_io_workload_load(const void *params, int app_id, int rank);
static void recorder_io_workload_get_next(int app_id, int rank, struct codes_workload_op *op);
/* helper functions for recorder workload CODES API */
static int hash_rank_compare(void *key, struct qhash_head *link);
static int hash_file_compare(void *key, struct qhash_head *link);
/* workload method name and function pointers for the CODES workload API */
struct codes_workload_method recorder_io_workload_method =
{
.method_name = "recorder_io_workload",
.codes_workload_read_config = NULL,
.codes_workload_load = recorder_io_workload_load,
.codes_workload_get_next = recorder_io_workload_get_next,
};
static struct qhash_table *rank_tbl = NULL;
static int rank_tbl_pop = 0;
/* load the workload generator for this rank, given input params */
static int recorder_io_workload_load(const void *params, int app_id, int rank)
{
recorder_params *r_params = (recorder_params *) params;
struct rank_traces_context *newv = NULL;
struct qhash_table *file_id_tbl = NULL;
struct qhash_head *link = NULL;
struct file_entry *file;
APP_ID_UNSUPPORTED(app_id, "recorder")
int64_t nprocs = r_params->nprocs;
char *trace_dir = r_params->trace_dir_path;
if(!trace_dir)
return -1;
/* allocate a new trace context for this rank */
newv = (struct rank_traces_context*)malloc(sizeof(*newv));
if(!newv)
return -1;
newv->rank = rank;
newv->trace_list_ndx = 0;
newv->trace_list_max = 0;
#if 0
DIR *dirp;
struct dirent *entry;
dirp = opendir(trace_dir);
while((entry = readdir(dirp)) != NULL) {
if(entry->d_type == DT_REG)
nprocs++;
}
closedir(dirp);
#endif
char trace_file_name[1024] = {'\0'};
sprintf(trace_file_name, "%s/log.%d", trace_dir, rank);
FILE *trace_file = fopen(trace_file_name, "r");
if(trace_file == NULL)
return -1;
char *line = NULL;
size_t len;
ssize_t ret_value;
char function_name[128] = {'\0'};
double wkld_start_time = 0.0;
double io_start_time = 0.0;
while((ret_value = getline(&line, &len, trace_file)) != -1) {
struct recorder_io_op r_op;
char *token = strtok(line, ", \n");
int fd;
if (strcmp(token, "BARRIER") && strcmp(token, "0"))
{
if (wkld_start_time == 0.0)
wkld_start_time = atof(token);
r_op.start_time = atof(token) - wkld_start_time;
token = strtok(NULL, ", ");
}
strcpy(function_name, token);
if(!strcmp(function_name, "open") || !strcmp(function_name, "open64")) {
char *filename = NULL;
char *open_flags = NULL;
filename = strtok(NULL, ", (");
open_flags = strtok(NULL, ", )");
if (!(atoi(open_flags) & O_CREAT))
{
r_op.codes_op.op_type = CODES_WK_BARRIER;
r_op.end_time = r_op.start_time;
r_op.codes_op.u.barrier.count = nprocs;
r_op.codes_op.u.barrier.root = 0;
newv->trace_ops[newv->trace_list_ndx++] = r_op;
if (newv->trace_list_ndx == 2048) break;
}
token = strtok(NULL, ", )");
token = strtok(NULL, ", ");
fd = atoi(token);
token = strtok(NULL, ", \n");
r_op.end_time = r_op.start_time + atof(token);
if (!file_id_tbl)
{
file_id_tbl = qhash_init(hash_file_compare, quickhash_32bit_hash, 11);
if (!file_id_tbl)
{
free(newv);
return -1;
}
}
file = (struct file_entry*)malloc(sizeof(struct file_entry));
if (!file)
{
free(newv);
return -1;
}
uint32_t h1 = 0x00000000, h2 = 0xFFFFFFFF;
bj_hashlittle2(filename, strlen(filename), &h1, &h2);
file->file_id = h1 + (((uint64_t)h2)<<32);
file->fd = fd;
r_op.codes_op.op_type = CODES_WK_OPEN;
r_op.codes_op.u.open.file_id = file->file_id;
r_op.codes_op.u.open.create_flag = atoi(open_flags) & O_CREAT;
qhash_add(file_id_tbl, &fd, &(file->hash_link));
}
else if(!strcmp(function_name, "close")) {
r_op.codes_op.op_type = CODES_WK_CLOSE;
token = strtok(NULL, ", ()");
fd = atoi(token);
token = strtok(NULL, ", ");
token = strtok(NULL, ", \n");
r_op.end_time = r_op.start_time + atof(token);
link = qhash_search(file_id_tbl, &fd);
if (!link)
{
free(newv);
return -1;
}
file = qhash_entry(link, struct file_entry, hash_link);
r_op.codes_op.u.close.file_id = file->file_id;
qhash_del(link);
free(file);
}
else if(!strcmp(function_name, "read") || !strcmp(function_name, "read64")) {
r_op.codes_op.op_type = CODES_WK_READ;
token = strtok(NULL, ", (");
fd = atoi(token);
// Throw out the buffer
token = strtok(NULL, ", ");
token = strtok(NULL, ", )");
r_op.codes_op.u.read.size = atol(token);
token = strtok(NULL, ", )");
r_op.codes_op.u.read.offset = atol(token);
token = strtok(NULL, ", ");
token = strtok(NULL, ", \n");
if (io_start_time == 0.0)
{
r_op.end_time = r_op.start_time + atof(token);
}
else
{
r_op.start_time = r_op.end_time = io_start_time;
}
link = qhash_search(file_id_tbl, &fd);
if (!link)
{
free(newv);
return -1;
}
file = qhash_entry(link, struct file_entry, hash_link);
r_op.codes_op.u.read.file_id = file->file_id;
}
else if(!strcmp(function_name, "write") || !strcmp(function_name, "write64")) {
r_op.codes_op.op_type = CODES_WK_WRITE;
token = strtok(NULL, ", (");
fd = atoi(token);
// Throw out the buffer
token = strtok(NULL, ", ");
token = strtok(NULL, ", )");
r_op.codes_op.u.write.size = atol(token);
token = strtok(NULL, ", )");
r_op.codes_op.u.write.offset = atol(token);
token = strtok(NULL, ", ");
token = strtok(NULL, ", \n");
if (io_start_time == 0.0)
{
r_op.end_time = r_op.start_time + atof(token);
}
else
{
r_op.start_time = r_op.end_time = io_start_time;
}
link = qhash_search(file_id_tbl, &fd);
if (!link)
{
free(newv);
return -1;
}
file = qhash_entry(link, struct file_entry, hash_link);
r_op.codes_op.u.write.file_id = file->file_id;
}
else if(!strcmp(function_name, "BARRIER")) {
r_op.start_time = r_op.end_time = io_start_time;
r_op.codes_op.op_type = CODES_WK_BARRIER;
r_op.codes_op.u.barrier.count = nprocs;
r_op.codes_op.u.barrier.root = 0;
}
else if(!strcmp(function_name, "0")) {
token = strtok (NULL, ", \n");
newv->trace_ops[newv->trace_list_ndx-1].end_time += atof(token);
io_start_time = 0.0;
continue;
}
else{
if (!strcmp(function_name, "MPI_File_write_at_all") ||
!strcmp(function_name, "MPI_File_read_at_all")) {
io_start_time = r_op.start_time;
}
continue;
}
newv->trace_ops[newv->trace_list_ndx++] = r_op;
if (newv->trace_list_ndx == 2048) break;
}
fclose(trace_file);
qhash_finalize(file_id_tbl);
/* reset ndx to 0 and set max to event count */
/* now we can read all events by counting through array from 0 - max */
newv->trace_list_max = newv->trace_list_ndx;
newv->trace_list_ndx = 0;
newv->last_op_time = 0.0;
/* initialize the hash table of rank contexts, if it has not been initialized */
if (!rank_tbl) {
rank_tbl = qhash_init(hash_rank_compare, quickhash_32bit_hash, RANK_HASH_TABLE_SIZE);
if (!rank_tbl) {
free(newv);
return -1;
}
}
/* add this rank context to the hash table */
qhash_add(rank_tbl, &(newv->rank), &(newv->hash_link));
rank_tbl_pop++;
return 0;
}
/* pull the next trace (independent or collective) for this rank from its trace context */
static void recorder_io_workload_get_next(int app_id, int rank, struct codes_workload_op *op)
{
(void)app_id; // no need for this here
struct qhash_head *hash_link = NULL;
struct rank_traces_context *tmp = NULL;
/* Find event context for this rank in the rank hash table */
hash_link = qhash_search(rank_tbl, &rank);
/* terminate the workload if there is no valid rank context */
if(!hash_link) {
op->op_type = CODES_WK_END;
return;
}
tmp = qhash_entry(hash_link, struct rank_traces_context, hash_link);
assert(tmp->rank == rank);
if(tmp->trace_list_ndx == tmp->trace_list_max) {
/* no more events -- just end the workload */
op->op_type = CODES_WK_END;
qhash_del(hash_link);
free(tmp);
rank_tbl_pop--;
if(!rank_tbl_pop)
{
qhash_finalize(rank_tbl);
rank_tbl = NULL;
}
}
else {
struct recorder_io_op *next_r_op = &(tmp->trace_ops[tmp->trace_list_ndx]);
if ((next_r_op->start_time - tmp->last_op_time) <= RECORDER_NEGLIGIBLE_DELAY) {
*op = next_r_op->codes_op;
tmp->trace_list_ndx++;
tmp->last_op_time = next_r_op->end_time;
}
else {
op->op_type = CODES_WK_DELAY;
op->u.delay.seconds = next_r_op->start_time - tmp->last_op_time;
tmp->last_op_time = next_r_op->start_time;
}
}
return;
}
static int hash_rank_compare(void *key, struct qhash_head *link)
{
int *in_rank = (int *)key;
struct rank_traces_context *tmp;
tmp = qhash_entry(link, struct rank_traces_context, hash_link);
if (tmp->rank == *in_rank)
return 1;
return 0;
}
static int hash_file_compare(void *key, struct qhash_head *link)
{
int *in_file = (int *)key;
struct file_entry *tmp;
tmp = qhash_entry(link, struct file_entry, hash_link);
if (tmp->fd == *in_file)
return 1;
return 0;
}
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* End:
*
* vim: ft=c ts=8 sts=4 sw=4 expandtab
*/