Revision 4b114b66
b/xseg/peers/user/bench-xseg.c | ||
---|---|---|
52 | 52 |
{ |
53 | 53 |
fprintf(stderr, "Custom peer options: \n" |
54 | 54 |
" --------------------------------------------\n" |
55 |
" -op | None | XSEG operation [read|write|info|delete]\n" |
|
56 |
" --pattern | None | I/O pattern [sync|rand]\n" |
|
55 | 57 |
" -ts | None | Total I/O size\n" |
56 | 58 |
" -os | 4M | Object size\n" |
57 | 59 |
" -bs | 4k | Block size\n" |
... | ... | |
93 | 95 |
return num; |
94 | 96 |
} |
95 | 97 |
|
98 |
int read_op(char *op) { |
|
99 |
if (strcmp(op, "read")) |
|
100 |
return X_READ; |
|
101 |
if (strcmp(op, "write")) |
|
102 |
return X_WRITE; |
|
103 |
if (strcmp(op, "info")) |
|
104 |
return X_INFO; |
|
105 |
if (strcmp(op, "delete")) |
|
106 |
return X_DELETE; |
|
107 |
return -1; |
|
108 |
} |
|
109 |
|
|
110 |
int read_pattern(char *pattern) { |
|
111 |
if (strcmp(pattern, "sync")) |
|
112 |
return IO_SYNC; |
|
113 |
if (strcmp(pattern, "rand")) |
|
114 |
return IO_RAND; |
|
115 |
return -1; |
|
116 |
} |
|
117 |
|
|
96 | 118 |
int custom_peer_init(struct peerd *peer, int argc, char *argv[]) |
97 | 119 |
{ |
98 | 120 |
struct bench *prefs; |
... | ... | |
107 | 129 |
block_size[0] = 0; |
108 | 130 |
object_size[0] = 0; |
109 | 131 |
|
132 |
#ifdef MT |
|
133 |
for (i = 0; i < nr_threads; i++) { |
|
134 |
prefs = peer->thread[i]->priv; |
|
135 |
prefs = malloc(sizeof(struct bench)); |
|
136 |
if (!prefs) { |
|
137 |
perror("malloc"); |
|
138 |
return -1; |
|
139 |
} |
|
140 |
} |
|
141 |
#endif |
|
110 | 142 |
prefs = malloc(sizeof(struct bench)); |
111 | 143 |
if (!prefs) { |
112 | 144 |
perror("malloc"); |
... | ... | |
115 | 147 |
|
116 | 148 |
//Begin reading the benchmark-specific arguments |
117 | 149 |
BEGIN_READ_ARGS(argc, argv); |
150 |
READ_ARG_STRING("-op", op, MAX_ARG_LEN); |
|
151 |
READ_ARG_STRING("--pattern", pattern, MAX_ARG_LEN); |
|
118 | 152 |
READ_ARG_STRING("-ts", total_size, MAX_ARG_LEN); |
119 | 153 |
READ_ARG_STRING("-os", object_size, MAX_ARG_LEN); |
120 | 154 |
READ_ARG_STRING("-bs", block_size, MAX_ARG_LEN); |
... | ... | |
122 | 156 |
READ_ARG_ULONG("-dp", dst_port); |
123 | 157 |
END_READ_ARGS(); |
124 | 158 |
|
159 |
/***************************** |
|
160 |
* Check I/O type parameters * |
|
161 |
*****************************/ |
|
162 |
|
|
163 |
prefs->op = |
|
125 | 164 |
/************************* |
126 | 165 |
* Check size parameters * |
127 | 166 |
*************************/ |
... | ... | |
196 | 235 |
* Create timers for all metrics * |
197 | 236 |
*********************************/ |
198 | 237 |
|
199 |
prefs->total_tm = malloc(sizeof(struct timer)); |
|
200 |
prefs->get_tm = malloc(sizeof(struct timer)); |
|
201 |
prefs->sub_tm = malloc(sizeof(struct timer)); |
|
202 |
prefs->rec_tm = malloc(sizeof(struct timer)); |
|
203 |
if (!prefs->total_tm || !prefs->get_tm || !prefs->sub_tm || |
|
204 |
!prefs->rec_tm) { |
|
205 |
perror("malloc"); |
|
206 |
return -1; |
|
207 |
} |
|
208 |
memset(prefs->total_tm, 0, sizeof(struct timer)); |
|
209 |
memset(prefs->get_tm, 0, sizeof(struct timer)); |
|
210 |
memset(prefs->sub_tm, 0, sizeof(struct timer)); |
|
211 |
memset(prefs->rec_tm, 0, sizeof(struct timer)); |
|
238 |
if (init_timer(prefs->total_tm, TM_SANE)) |
|
239 |
goto tm_fail; |
|
240 |
if (init_timer(prefs->sub_tm, TM_MANIC)) |
|
241 |
goto tm_fail; |
|
242 |
if (init_timer(prefs->get_tm, TM_PARANOID)) |
|
243 |
goto tm_fail; |
|
244 |
if (init_timer(prefs->rec_tm, TM_ECCENTRIC)) |
|
245 |
goto tm_fail; |
|
212 | 246 |
|
213 | 247 |
/************************** |
214 | 248 |
* Customize struct peerd * |
... | ... | |
219 | 253 |
return 0; |
220 | 254 |
|
221 | 255 |
arg_fail: |
222 |
free(prefs); |
|
223 | 256 |
custom_peer_usage(); |
257 |
tm_fail: |
|
258 |
free(prefs->total_tm); |
|
259 |
free(prefs->sub_tm); |
|
260 |
free(prefs->get_tm); |
|
261 |
free(prefs->rec_tm); |
|
262 |
free(prefs); |
|
224 | 263 |
return -1; |
225 | 264 |
} |
226 | 265 |
|
... | ... | |
406 | 445 |
return 0; |
407 | 446 |
} |
408 | 447 |
|
448 |
static void print_res(struct tm_result res, char *type) |
|
449 |
{ |
|
450 |
printf("\n"); |
|
451 |
printf(" %s\n", type); |
|
452 |
printf("================================\n"); |
|
453 |
printf(" |-s-||-ms-|-us-|-ns-|\n"); |
|
454 |
printf("Time: %03lu, %03lu %03lu %03lu\n", |
|
455 |
res.s, res.ms, res.us, res.ns); |
|
456 |
} |
|
457 |
|
|
458 |
static void separate_by_order(struct timespec src, struct tm_result *res) |
|
459 |
{ |
|
460 |
res->ns = src.tv_nsec % 1000; |
|
461 |
src.tv_nsec /= 1000; |
|
462 |
res->us = src.tv_nsec % 1000; |
|
463 |
res->ms = src.tv_nsec / 1000; |
|
464 |
res->s = src.tv_sec; |
|
465 |
} |
|
466 |
|
|
409 | 467 |
void custom_peer_finalize(struct peerd *peer) |
410 | 468 |
{ |
411 | 469 |
struct bench *prefs = peer->priv; |
470 |
//TODO: Measure mean time, standard variation |
|
471 |
struct tm_result total, mean, std; |
|
412 | 472 |
unsigned int s, ms, us, ns; |
413 | 473 |
|
414 | 474 |
if (!prefs->total_tm->completed) |
415 | 475 |
timer_stop(prefs->total_tm, NULL); |
416 | 476 |
|
417 |
struct timespec tm = prefs->total_tm->sum; |
|
418 |
ns = tm.tv_nsec % 1000; |
|
419 |
tm.tv_nsec /= 1000; |
|
420 |
us = tm.tv_nsec % 1000; |
|
421 |
ms = tm.tv_nsec / 1000; |
|
422 |
s = tm.tv_sec; |
|
423 |
|
|
424 |
printf("\n"); |
|
425 |
printf(" Total time spent\n"); |
|
426 |
printf("================================\n"); |
|
427 |
printf(" |-s-||-ms-|-us-|-ns-|\n"); |
|
428 |
printf("Time: %03u, %03u %03u %03u\n", s, ms, us, ns); |
|
477 |
separate_by_order(prefs->total_tm->sum, &total); |
|
478 |
print_res(total, "Total Time"); |
|
429 | 479 |
return; |
430 | 480 |
} |
431 | 481 |
|
b/xseg/peers/user/bench-xseg.h | ||
---|---|---|
34 | 34 |
|
35 | 35 |
#define MAX_ARG_LEN 10 |
36 | 36 |
|
37 |
#define TM_SANE 0 |
|
38 |
#define TM_ECCENTRIC 1 |
|
39 |
#define TM_MANIC 2 |
|
40 |
#define TM_PARANOID 3 |
|
41 |
|
|
42 |
#define IO_SYNC 0 |
|
43 |
#define IO_RAND 1 |
|
44 |
|
|
45 |
|
|
37 | 46 |
struct bench { |
38 | 47 |
uint64_t ts; //Total I/O size |
39 | 48 |
uint64_t os; //Object size |
... | ... | |
41 | 50 |
uint32_t iodepth; //Num of in-flight xseg reqs |
42 | 51 |
xport dst_port; |
43 | 52 |
xport src_port; |
53 |
uint32_t op; //xseg operation |
|
44 | 54 |
uint8_t flags; |
45 |
struct timer *total_tm; |
|
46 |
struct timer *get_tm; |
|
47 |
struct timer *sub_tm; |
|
48 |
struct timer *rec_tm; |
|
55 |
struct timer *total_tm; //Total time for benchmark
|
|
56 |
struct timer *get_tm; //Time for xseg_get_request
|
|
57 |
struct timer *sub_tm; //Time for xseg_submit_request
|
|
58 |
struct timer *rec_tm; //Time for xseg_receive_request
|
|
49 | 59 |
}; |
50 | 60 |
|
51 | 61 |
/* |
52 | 62 |
* Custom timespec. Made to calculate variance, where we need the square of a |
53 |
* timespec structure. This structure should be more than enough to hold the
|
|
54 |
* square of the biggest timespec.
|
|
63 |
* timespec struct. This struct should be more than enough to hold the square
|
|
64 |
* of the biggest timespec. |
|
55 | 65 |
*/ |
56 | 66 |
struct timespec2 { |
57 | 67 |
unsigned long tv_sec2; |
... | ... | |
76 | 86 |
unsigned int insanity; |
77 | 87 |
}; |
78 | 88 |
|
89 |
struct tm_result { |
|
90 |
unsigned long s; |
|
91 |
unsigned long ms; |
|
92 |
unsigned long us; |
|
93 |
unsigned long ns; |
|
94 |
}; |
|
95 |
|
|
79 | 96 |
int custom_peerd_loop(void *arg); |
80 | 97 |
|
81 | 98 |
void timer_start(struct timer *sample_req); |
b/xseg/peers/user/peer.c | ||
---|---|---|
79 | 79 |
int thread_no; |
80 | 80 |
void (*func)(void *arg); |
81 | 81 |
void *arg; |
82 |
void *priv; |
|
82 | 83 |
}; |
83 | 84 |
|
84 | 85 |
inline static struct thread* alloc_thread(struct peerd *peer) |
b/xseg/peers/user/timer.c | ||
---|---|---|
49 | 49 |
#define SEC 1000000000 //1sec = 10^9 nsec |
50 | 50 |
#define SEC2 (uint64_t) SEC*SEC //1sec*1sec = 10^18 nsec^2 |
51 | 51 |
|
52 |
int init_timer(struct timer *tm, int insanity) |
|
53 |
{ |
|
54 |
tm = malloc(sizeof(struct timer)); |
|
55 |
if (!tm) { |
|
56 |
perror("malloc"); |
|
57 |
return -1; |
|
58 |
} |
|
59 |
|
|
60 |
memset(tm, 0, sizeof(struct timer)); |
|
61 |
tm->insanity = insanity; |
|
62 |
return 0; |
|
63 |
} |
|
64 |
|
|
52 | 65 |
void timer_start(struct timer *timer) |
53 | 66 |
{ |
54 | 67 |
//We need a low-latency way to get current time in nanoseconds. |
... | ... | |
115 | 128 |
//TODO: check if we need to make it volatile |
116 | 129 |
timer->completed++; |
117 | 130 |
|
131 |
/* |
|
118 | 132 |
printf("Start: %lu s %lu ns\n", start_time.tv_sec, start_time.tv_nsec); |
119 | 133 |
printf("Elpsd: %lu s %lu ns\n", elapsed_time.tv_sec, elapsed_time.tv_nsec); |
120 | 134 |
printf("End: %lu s %lu ns\n", end_time.tv_sec, end_time.tv_nsec); |
135 |
*/ |
|
121 | 136 |
} |
122 | 137 |
|
123 | 138 |
|
Also available in: Unified diff