-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfox-stats.c
More file actions
491 lines (413 loc) · 14.8 KB
/
Copy pathfox-stats.c
File metadata and controls
491 lines (413 loc) · 14.8 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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
/* - FOX - A tool for testing Open-Channel SSDs
* - Statistics
*
* Copyright (C) 2016, IT University of Copenhagen. All rights reserved.
* Written by Ivan Luiz Picoli <ivpi@itu.dk>
*
* Funding support provided by CAPES Foundation, Ministry of Education
* of Brazil, Brasilia - DF 70040-020, Brazil.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <pthread.h>
#include <string.h>
#include "fox.h"
int fox_init_stats (struct fox_stats *st)
{
memset (st, 0, sizeof (struct fox_stats));
if (pthread_mutex_init (&st->s_mutex, NULL) != 0)
return -1;
return 0;
}
void fox_exit_stats (struct fox_stats *st)
{
pthread_mutex_destroy (&st->s_mutex);
}
static uint16_t fox_get_progress (struct fox_stats *st)
{
uint8_t prog;
pthread_mutex_lock(&st->s_mutex);
prog = st->progress;
pthread_mutex_unlock(&st->s_mutex);
return prog;
}
static uint64_t fox_get_tot_runtime (struct fox_node *nodes)
{
int i;
uint64_t tot = 0;
for (i = 0; i < nodes[0].wl->nthreads; i++) {
tot += nodes[i].stats.runtime;
}
return tot / (uint64_t) nodes[0].wl->nthreads;
}
void fox_set_progress (struct fox_stats *st, uint16_t val)
{
pthread_mutex_lock(&st->s_mutex);
st->progress = val;
pthread_mutex_unlock(&st->s_mutex);
}
void fox_set_stats (uint8_t type, struct fox_stats *st, int64_t val)
{
pthread_mutex_lock(&st->s_mutex);
switch (type) {
case FOX_STATS_RUNTIME:
st->runtime = (uint64_t) val;
break;
case FOX_STATS_RW_SECT:
st->rw_sect += (uint64_t) val;
break;
case FOX_STATS_ERASE_T:
st->erase_t += (uint64_t) val;
break;
case FOX_STATS_READ_T:
st->read_t += (uint64_t) val;
break;
case FOX_STATS_WRITE_T:
st->write_t += (uint64_t) val;
break;
case FOX_STATS_ERASED_BLK:
st->erased_blks += (uint32_t) val;
break;
case FOX_STATS_PGS_R:
st->pgs_r += (uint32_t) val;
break;
case FOX_STATS_PGS_W:
st->pgs_w += (uint32_t) val;
break;
case FOX_STATS_BREAD:
st->bread += (uint64_t) val;
break;
case FOX_STATS_BWRITTEN:
st->bwritten += (uint64_t) val;
break;
case FOX_STATS_BRW_SEC:
st->brw_sec += (uint64_t) val;
break;
case FOX_STATS_IOPS:
st->iops += (uint32_t) val;
st->io_count += (uint32_t) val;
break;
case FOX_STATS_FAIL_CMP:
st->fail_cmp += (uint32_t) val;
break;
case FOX_STATS_FAIL_E:
st->fail_e += (uint32_t) val;
break;
case FOX_STATS_FAIL_R:
st->fail_r += (uint32_t) val;
break;
case FOX_STATS_FAIL_W:
st->fail_w += (uint32_t) val;
break;
}
pthread_mutex_unlock(&st->s_mutex);
}
void fox_timestamp_start (struct fox_stats *st)
{
gettimeofday(&st->tval, NULL);
}
uint64_t fox_timestamp_tmp_start (struct fox_stats *st)
{
uint64_t usec;
gettimeofday(&st->tval_tmp, NULL);
usec = st->tval_tmp.tv_sec * SEC64;
usec += st->tval_tmp.tv_usec;
return usec;
}
uint64_t fox_timestamp_end (uint8_t type, struct fox_stats *st)
{
struct timeval te;
struct timeval *ts;
int64_t usec_s, usec_e, tot;
gettimeofday(&te, NULL);
ts = (type == FOX_STATS_RUNTIME) ? &st->tval : &st->tval_tmp;
usec_e = te.tv_sec * SEC64;
usec_e += te.tv_usec;
usec_s = ts->tv_sec * SEC64;
usec_s += ts->tv_usec;
tot = usec_e - usec_s;
fox_set_stats (type, st, tot);
return usec_e;
}
void fox_start_node (struct fox_node *node)
{
node->stats.flags |= FOX_FLAG_READY;
fox_wait_for_ready (node->wl);
fox_timestamp_start(&node->stats);
}
void fox_end_node (struct fox_node *node)
{
fox_timestamp_end(FOX_STATS_RUNTIME, &node->stats);
node->stats.flags |= FOX_FLAG_DONE;
node->stats.progress = 100;
}
void fox_merge_stats (struct fox_node *nodes, struct fox_stats *st)
{
int i;
for (i = 0; i < nodes[0].wl->nthreads; i++) {
st->bread += nodes[i].stats.bread;
st->bwritten += nodes[i].stats.bwritten;
st->erase_t += nodes[i].stats.erase_t;
st->read_t += nodes[i].stats.read_t;
st->pgs_r += nodes[i].stats.pgs_r;
st->pgs_w += nodes[i].stats.pgs_w;
st->write_t += nodes[i].stats.write_t;
st->erased_blks += nodes[i].stats.erased_blks;
st->fail_e += nodes[i].stats.fail_e;
st->fail_w += nodes[i].stats.fail_w;
st->fail_r += nodes[i].stats.fail_r;
st->fail_cmp += nodes[i].stats.fail_cmp;
st->io_count += nodes[i].stats.io_count;
}
fox_timestamp_end (FOX_STATS_RUNTIME, st);
st->runtime = fox_get_tot_runtime(nodes);
}
static void fox_show_progress (struct fox_node *node)
{
int node_i, i;
uint16_t n_prog, wl_prog = 0;
long double th_sec, tot_sec = 0, totalb = 0, th = 0, iops = 0;
uint64_t usec, io_count = 0;
struct fox_output_row_rt **rt = NULL;
usec = fox_timestamp_end (FOX_STATS_RUNTIME, node[0].wl->stats);
if (node->wl->output) {
rt = malloc (sizeof(void *) * (node->wl->nthreads + 1));
if (!rt)
return;
for (i = 0; i < node->wl->nthreads + 1; i++)
rt[i] = fox_output_new_rt();
}
printf ("\r");
for (node_i = 0; node_i < node[0].wl->nthreads; node_i++) {
n_prog = fox_get_progress(&node[node_i].stats);
wl_prog += n_prog;
pthread_mutex_lock(&node[node_i].stats.s_mutex);
if (node->wl->output) {
rt[node_i + 1]->thpt = (node[node_i].stats.brw_sec == 0 ||
node[node_i].stats.rw_sect == 0) ? 0 :
(node[node_i].stats.brw_sec / (long double) (1024 * 1024))
/ (node[node_i].stats.rw_sect / (long double) SEC64);
rt[node_i + 1]->iops = (node[node_i].stats.iops == 0 ||
node[node_i].stats.rw_sect == 0) ? 0 :
((long double) node[node_i].stats.iops) /
(node[node_i].stats.rw_sect / (long double) SEC64);
rt[node_i + 1]->timestp = usec;
fox_output_append_rt (rt[node_i + 1], node[node_i].nid + 1);
}
totalb = node[node_i].stats.brw_sec;
th_sec = node[node_i].stats.rw_sect;
io_count = node[node_i].stats.iops;
node[node_i].stats.rw_sect -= th_sec;
node[node_i].stats.brw_sec -= totalb;
th_sec /= (long double) SEC64;
tot_sec += th_sec;
th += (totalb == 0 || th_sec == 0) ? 0 : totalb / th_sec;
iops += (io_count == 0 || th_sec == 0) ?
0 : (long double) io_count / th_sec;
node[node_i].stats.iops = 0;
pthread_mutex_unlock(&node[node_i].stats.s_mutex);
printf(" [%d:%d%%]", node[node_i].nid, n_prog);
}
wl_prog = (uint16_t) ((double) wl_prog / (double) node[0].wl->nthreads);
th = th / (long double) (1024 * 1024);
if (node->wl->output) {
rt[0]->thpt = th;
rt[0]->iops = iops;
rt[0]->timestp = usec;
fox_output_append_rt (rt[0], 0);
}
free (rt);
printf(" [%d%%|%.2Lf MB/s|%.1Lf]", wl_prog, th, iops);
fflush(stdout);
}
static uint8_t fox_check_runtime (struct fox_workload *wl)
{
if (wl->runtime) {
fox_timestamp_end (FOX_STATS_RUNTIME, wl->stats);
if (wl->stats->runtime / SEC64 > wl->runtime)
return 1;
}
return 0;
}
void fox_monitor (struct fox_node *nodes)
{
int i, ndone, show;
int nn;
struct fox_workload *wl = nodes[0].wl;
nn = wl->nthreads;
printf ("\n - Synchronizing threads... (%s engine)\n", wl->engine->name);
if (wl->engine->id == 3)
printf ("\n");
/* Monitor is ready */
wl->stats->flags |= FOX_FLAG_MONITOR;
pthread_mutex_lock (&wl->monitor_mut);
pthread_cond_broadcast(&wl->monitor_con);
pthread_mutex_unlock (&wl->monitor_mut);
/* wait to all threads be ready to start */
do {
usleep(10000);
ndone = 0;
for (i = 0; i < nn; i++) {
if (nodes[i].stats.flags & FOX_FLAG_READY)
ndone++;
}
} while (ndone < nn);
/* start all threads */
wl->stats->flags |= FOX_FLAG_READY;
pthread_mutex_lock (&wl->start_mut);
pthread_cond_broadcast(&wl->start_con);
pthread_mutex_unlock (&wl->start_mut);
fox_timestamp_start (wl->stats);
printf ("\n - Workload started.\n\n");
/* show progress and wait until all threads are done */
show = 0;
fox_show_progress (nodes);
do {
usleep(50000);
show++;
if (show % 10 == 0) {
fox_show_progress (nodes);
show = 0;
}
if (fox_check_runtime (wl))
wl->stats->flags |= FOX_FLAG_DONE;
ndone = 0;
for (i = 0; i < nn; i++) {
if (nodes[i].stats.flags & FOX_FLAG_DONE)
ndone++;
}
} while (ndone < nn);
fox_show_progress (nodes);
}
void fox_show_stats (struct fox_workload *wl, struct fox_node *node)
{
long double th = 0, totb = 0, tsec, io_usec = 0;
uint64_t elat, rlat, wlat;
int i;
char line[80];
struct fox_stats *st = wl->stats;
for (i = 0; i < wl->nthreads; i++) {
io_usec += node[i].stats.runtime;
totb += node[i].stats.bread + node[i].stats.bwritten;
}
tsec = st->runtime / (long double) SEC64;
th = totb / tsec;
elat = (st->erased_blks) ? st->erase_t / st->erased_blks : 0;
rlat = (st->pgs_r) ? st->read_t / (st->pgs_r & AND64) : 0;
wlat = (st->pgs_w) ? st->write_t / (st->pgs_w & AND64) : 0;
sprintf (line, "\n\n --- RESULTS ---\n\n");
fox_print (line, wl->output);
sprintf (line, " - Elapsed time : %lu m-sec\n",st->runtime/(1000 & AND64));
fox_print (line, wl->output);
sprintf (line, " - I/O time (sum): %.0Lf m-sec\n", io_usec/(1000 & AND64));
fox_print (line, wl->output);
sprintf (line, " - Read data : %lu KB\n", st->bread / (1024 & AND64));
fox_print (line, wl->output);
sprintf (line, " - Read pages : %d\n", st->pgs_r);
fox_print (line, wl->output);
sprintf (line, " - Written data : %lu KB\n",st->bwritten / (1024 & AND64));
fox_print (line, wl->output);
sprintf (line, " - Written pages : %d\n", st->pgs_w);
fox_print (line, wl->output);
sprintf(line, " - Throughput : %.2Lf MB/sec\n",th/((1024*1024) & AND64));
fox_print (line, wl->output);
sprintf (line, " - IOPS : %.1Lf\n", st->io_count / tsec);
fox_print (line, wl->output);
sprintf (line, " - Erased blocks : %d\n", st->erased_blks);
fox_print (line, wl->output);
sprintf (line, " - Erase latency : %lu u-sec\n", elat);
fox_print (line, wl->output);
sprintf (line, " - Read latency : %lu u-sec\n", rlat);
fox_print (line, wl->output);
sprintf (line, " - Write latency : %lu u-sec\n", wlat);
fox_print (line, wl->output);
sprintf (line, " - Failed memcmp : %d\n", st->fail_cmp);
fox_print (line, wl->output);
sprintf (line, " - Failed writes : %d\n", st->fail_w);
fox_print (line, wl->output);
sprintf (line, " - Failed reads : %d\n", st->fail_r);
fox_print (line, wl->output);
sprintf (line, " - Failed erases : %d\n\n", st->fail_e);
fox_print (line, wl->output);
}
void fox_show_workload (struct fox_workload *wl)
{
char line[80];
char mcname[20];
sprintf (line, "\n --- WORKLOAD ---\n\n");
fox_print (line, wl->output);
sprintf (line, " - Device : %s\n", wl->devname);
fox_print (line, wl->output);
if (wl->runtime)
sprintf (line, " - Runtime : %lu sec\n", wl->runtime);
else
sprintf (line, " - Runtime : 1 iteration\n");
fox_print (line, wl->output);
sprintf (line, " - Num of jobs : %d\n",wl->nthreads);
fox_print (line, wl->output);
sprintf (line, " - N of Channels: %d\n", wl->channels);
fox_print (line, wl->output);
sprintf (line, " - LUNs per Chan: %d\n", wl->luns);
fox_print (line, wl->output);
sprintf (line, " - Blks per LUN : %d\n", wl->blks);
fox_print (line, wl->output);
sprintf (line, " - Pgs per Blk : %d\n", wl->pgs);
fox_print (line, wl->output);
sprintf (line, " - Write factor : %d %%\n", wl->w_factor);
fox_print (line, wl->output);
sprintf (line, " - Read factor : %d %%\n", wl->r_factor);
fox_print (line, wl->output);
sprintf (line, " - Vector PPAs : %d\n", wl->nppas);
fox_print (line, wl->output);
sprintf (line, " - Max I/O delay: %d u-sec\n", wl->max_delay);
fox_print (line, wl->output);
if (wl->output)
sprintf (line, " - Output file : enabled\n");
else
sprintf (line, " - Output file : disabled\n");
fox_print (line, wl->output);
if (wl->memcmp)
sprintf (line, " - Read compare : enabled\n");
else
sprintf (line, " - Read compare : disabled\n");
fox_print (line, wl->output);
switch (wl->memcmp) {
case WB_READABLE:
sprintf (mcname, "human readable");
break;
case WB_GEOMETRY:
sprintf (mcname, "geometry based");
break;
case WB_RANDOM:
case WB_DISABLE:
default:
sprintf (mcname, "random data");
}
sprintf (line, " - Buffer type : %s\n", mcname);
fox_print (line, wl->output);
sprintf (line, " - Engine : %d (%s)\n", wl->engine->id,
wl->engine->name);
fox_print (line, wl->output);
}