Revision 99ad121f

b/xseg/peers/user/bench-utils.c
226 226
	return -1;
227 227
}
228 228

  
229
int read_progress(char *progress)
230
{
231
	if (strncmp(progress, "no", MAX_ARG_LEN + 1) == 0)
232
		return PROGRESS_NO;
233
	if (strncmp(progress, "yes", MAX_ARG_LEN + 1) == 0)
234
		return PROGRESS_YES;
235
	return -1;
236
}
237

  
229 238
int read_pattern(char *pattern)
230 239
{
231 240
	if (strncmp(pattern, "seq", MAX_ARG_LEN + 1) == 0)
......
241 250

  
242 251
void print_stats(struct bench *prefs)
243 252
{
244
	uint64_t remaining;
245

  
246
	printf("\n");
247
	printf("Requests total:     %10lu\n", prefs->status->max);
248
	printf("Requests submitted: %10lu\n", prefs->status->submitted);
249
	printf("Requests received:  %10lu\n", prefs->status->received);
250
	printf("Requests failed:    %10lu\n", prefs->status->failed);
253
	printf("\n"
254
			"Requests total:     %10lu\n"
255
			"Requests submitted: %10lu\n"
256
			"Requests received:  %10lu\n"
257
			"Requests failed:    %10lu\n",
258
			prefs->status->max,
259
			prefs->status->submitted,
260
			prefs->status->received,
261
			prefs->status->failed);
251 262
	if ((prefs->op == X_READ) && (GET_FLAG(VERIFY, prefs->flags) != VERIFY_NO))
252 263
		printf("Requests corrupted: %10lu\n", prefs->status->corrupted);
253 264
	printf("\n");
265
}
266

  
267
void print_remaining(struct bench *prefs)
268
{
269
	uint64_t remaining;
254 270

  
255 271
	remaining = prefs->status->max - prefs->status->received;
256 272
	if (remaining)
......
285 301
	//TODO: Add std
286 302
}
287 303

  
304
void print_progress(struct bench *prefs)
305
{
306
	int lines = 6;
307

  
308
	if ((prefs->op == X_READ) && (GET_FLAG(VERIFY, prefs->flags) != VERIFY_NO))
309
		lines++;
310

  
311
	printf("\033[%dA\033[J", lines);
312
	print_stats(prefs);
313
}
314

  
288 315
/**************************\
289 316
 * Benchmarking functions *
290 317
\**************************/
......
331 358
		return 0;
332 359
}
333 360

  
361
uint64_t calculate_prog_quantum(struct bench *prefs)
362
{
363
	return round((double)prefs->status->max / 20.0);
364
}
365

  
366

  
334 367
/*
335 368
 * ***********************************************
336 369
 * `create_chunk` handles 3 identifiers:
b/xseg/peers/user/bench-xseg.c
54 54
 * a) If in-flight requests are less than given iodepth
55 55
 * b) If we have submitted all of the requests
56 56
 */
57
#define CAN_SEND_REQUEST(prefs)												  \
58
	((prefs->status->submitted - prefs->status->received < prefs->iodepth) && \
59
	(prefs->status->submitted < prefs->status->max))
57
#define CAN_SEND_REQUEST(__p)											\
58
	((__p->status->submitted - __p->status->received < __p->iodepth) && \
59
	(__p->status->submitted < __p->status->max) &&						\
60
	!isTerminate())
60 61

  
61
#define CAN_VERIFY(prefs)													  \
62
	((GET_FLAG(VERIFY, prefs->flags) != VERIFY_NO) && prefs->op == X_READ)
62
#define CAN_VERIFY(__p)													\
63
	((GET_FLAG(VERIFY, __p->flags) != VERIFY_NO) && __p->op == X_READ)
64

  
65
#define CAN_PRINT_PROGRESS(__p, __q)									\
66
	((GET_FLAG(PROGRESS, __p->flags) == PROGRESS_YES) &&				\
67
	(__p->status->received == __q))
63 68

  
64 69
void custom_peer_usage()
65 70
{
......
78 83
			"    --seed    | None    | Initialize LFSR and target names\n"
79 84
			"    --insanity| sane    | Adjust insanity level of benchmark:\n"
80 85
			"              |         |     [sane|eccentric|manic|paranoid]\n"
86
			"    --progress| yes     | Show progress of requests\n"
81 87
			"\n"
82 88
			"Additional information:\n"
83 89
			"  --------------------------------------------\n"
......
97 103
	char pattern[MAX_ARG_LEN + 1];
98 104
	char insanity[MAX_ARG_LEN + 1];
99 105
	char verify[MAX_ARG_LEN + 1];
106
	char progress[MAX_ARG_LEN + 1];
100 107
	struct xseg *xseg = peer->xseg;
101 108
	unsigned int xseg_page_size = 1 << xseg->config.page_shift;
102 109
	long iodepth = -1;
......
116 123
	insanity[0] = 0;
117 124
	verify[0] = 0;
118 125
	request_cap[0] = 0;
126
	progress[0] = 0;
119 127

  
120 128
#ifdef MT
121 129
	for (i = 0; i < nr_threads; i++) {
......
155 163
	READ_ARG_ULONG("--seed", seed);
156 164
	READ_ARG_STRING("--insanity", insanity, MAX_ARG_LEN);
157 165
	READ_ARG_STRING("--verify", verify, MAX_ARG_LEN);
166
	READ_ARG_STRING("--progress", progress, MAX_ARG_LEN);
158 167
	END_READ_ARGS();
159 168

  
160 169
	/*****************************\
......
348 357
		}
349 358
	}
350 359

  
351
	/****************************\
352
	 * Finalize initializations *
353
	\****************************/
360
	/*********************************\
361
	 * Miscellaneous initializations *
362
	\*********************************/
354 363

  
355 364
	/* The request cap must be enforced only after the LFSR is initialized */
356 365
	if (request_cap[0]) {
......
365 374
		prefs->status->max = rc;
366 375
	}
367 376

  
377
	/* Benchmarking progress printing is on by default */
378
	if (!progress[0])
379
		strcpy(progress, "yes");
380
	r = read_progress(progress);
381
	if (r < 0) {
382
		XSEGLOG2(&lc, E, "Invalid syntax: --progress %s\n", progress);
383
		goto arg_fail;
384
	}
385
	SET_FLAG(PROGRESS, prefs->flags, r);
386

  
368 387
	prefs->peer = peer;
369 388
	peer->peerd_loop = bench_peerd_loop;
370 389
	peer->priv = (void *) prefs;
......
516 535
	struct bench *prefs = peer->priv;
517 536
	xport portno_start = peer->portno_start;
518 537
	xport portno_end = peer->portno_end;
519
	uint64_t threshold=1000/(1 + portno_end - portno_start);
520 538
	pid_t pid = syscall(SYS_gettid);
539
	uint64_t threshold=1000/(1 + portno_end - portno_start);
540
	uint64_t cached_prog_quantum = 0;
541
	uint64_t prog_quantum = 0;
521 542
	int r;
522 543
	uint64_t loops;
523 544

  
545
	if (GET_FLAG(PROGRESS, prefs->flags) == PROGRESS_YES) {
546
		prog_quantum = calculate_prog_quantum(prefs);
547
		cached_prog_quantum = prog_quantum;
548
		print_stats(prefs);
549
	}
550

  
524 551
	XSEGLOG2(&lc, I, "%s has tid %u.\n",id, pid);
525 552
	xseg_init_local_signal(xseg, peer->portno_start);
526 553

  
527 554
	timer_start(prefs, prefs->total_tm);
528 555
send_request:
529
	while (!isTerminate()) {
530
#ifdef MT
531
		if (t->func) {
532
			XSEGLOG2(&lc, D, "%s executes function\n", id);
533
			xseg_cancel_wait(xseg, peer->portno_start);
534
			t->func(t->arg);
535
			t->func = NULL;
536
			t->arg = NULL;
537
			continue;
538
		}
539
#endif
556
	while (!(isTerminate() && all_peer_reqs_free(peer))) {
540 557
		while (CAN_SEND_REQUEST(prefs)) {
541 558
			xseg_cancel_wait(xseg, peer->portno_start);
542 559
			XSEGLOG2(&lc, D, "...because %lu < %lu && %lu < %lu\n",
......
553 570
			if (loops == 1)
554 571
				xseg_prepare_wait(xseg, peer->portno_start);
555 572

  
573
			if (UNLIKELY(CAN_PRINT_PROGRESS(prefs, prog_quantum))) {
574
				prog_quantum += cached_prog_quantum;
575
				print_progress(prefs);
576
			}
577

  
556 578
			if (check_ports(peer)) {
557 579
				//If an old request has just been acked, the most sensible
558 580
				//thing to do is to immediately send a new one
......
568 590
		//XSEGLOG2(&lc, I, "%s goes to sleep with %u requests pending\n",
569 591
		//		id, xq_count(q));
570 592
		XSEGLOG2(&lc, I, "%s goes to sleep\n", id);
571
#ifdef ST_THREADS
572
		if (ta){
573
			st_sleep(0);
574
			continue;
575
		}
576
#endif
577 593
		xseg_wait_signal(xseg, 10000000UL);
578 594
		xseg_cancel_wait(xseg, peer->portno_start);
579 595
		XSEGLOG2(&lc, I, "%s woke up\n", id);
......
592 608
	if (!prefs->total_tm->completed)
593 609
		timer_stop(prefs, prefs->total_tm, NULL);
594 610

  
595
	print_stats(prefs);
611
	if (GET_FLAG(PROGRESS, prefs->flags) == PROGRESS_YES)
612
		print_progress(prefs);
613
	else
614
		print_stats(prefs);
615

  
616
	print_remaining(prefs);
596 617
	print_res(prefs, prefs->total_tm, "Total Requests");
597 618
	return;
598 619
}
b/xseg/peers/user/bench-xseg.h
34 34

  
35 35
#include <bench-lfsr.h>
36 36

  
37

  
38
#ifdef __GNUC__
39
#define LIKELY(x)       __builtin_expect(!!(x),1)
40
#define UNLIKELY(x)     __builtin_expect(!!(x),0)
41
#else
42
#define LIKELY(x)       (x)
43
#define UNLIKELY(x)     (x)
44
#endif
45

  
37 46
/*
38 47
 * If CLOCK_MONOTONIC_RAW is not defined in our system, use CLOCK_MONOTONIC
39 48
 * instead. CLOCK_MONOTONIC_RAW is preferred since we are guaranteed that the
......
76 85
#define INSANITY_MANIC 2
77 86
#define INSANITY_PARANOID 3
78 87

  
88
/* Progress bar option occupies 6th flag bit */
89
#define PROGRESS_FLAG_POS 5
90
#define PROGRESS_BITMASK 1	/* i.e. "11" in binary form */
91
#define PROGRESS_NO 0
92
#define PROGRESS_YES 1
79 93

  
80 94
/*
81 95
 * Current bench flags representation:
82 96
 * 64 7  6  5  4  3  2  1 : bits
83 97
 * ...0  0  0  0  0  0  0
84
 *         |____||____||_|
85
 *			  ^	    ^   ^
86
 *			  |		|   |
87
 *		   insanity	| pattern
88
 *				 verify
98
 *      |_||____||____||_|
99
 *		 ^	  ^	    ^   ^
100
 *		 |	  |		|   |
101
 *		 | insanity	| pattern
102
 *	  progress	 verify
103
 */
104

  
105
/*
106
 * Find position of flag, make it zero, get requested flag value, store it to
107
 * this position
89 108
 */
90
/* Add flag bit according to its position */
91 109
#define SET_FLAG(__ftype, __flag, __val)	\
92
	__flag |= __val << __ftype##_FLAG_POS;
110
	__flag = (__flag & ~(__ftype##_BITMASK << __ftype##_FLAG_POS)) | \
111
	(__val << __ftype##_FLAG_POS);
93 112

  
94 113
/* Apply bitmask to flags, shift result to the right to get correct value */
95 114
#define GET_FLAG(__ftype, __flag)			\
96 115
	(__flag & (__ftype##_BITMASK << __ftype##_FLAG_POS)) >> __ftype##_FLAG_POS
116

  
97 117
/*
98 118
 * The benchark ID (IDLEN) is global for the test, calculated once and is a
99 119
 * string of the following form: {"bench-" + 9-digit number + "\0"}.
......
172 192
	uint64_t offset;
173 193
};
174 194

  
175

  
176 195
int bench_peerd_loop(void *arg);
177 196

  
178 197
void timer_start(struct bench *prefs, struct timer *sample_req);
......
184 203
int read_pattern(char *pattern);
185 204
int read_insanity(char *insanity);
186 205
int read_verify(char *insanity);
206
int read_progress(char *progress);
187 207
void print_res(struct bench *prefs, struct timer *tm, char *type);
188 208
void print_stats(struct bench *prefs);
209
void print_progress(struct bench *prefs);
210
void print_remaining(struct bench *prefs);
189 211
void create_target(struct bench *prefs, struct xseg_request *req,
190 212
		uint64_t new);
191 213
void create_chunk(struct bench *prefs, struct xseg_request *req, uint64_t new);
192 214
int read_chunk(struct bench *prefs, struct xseg_request *req);
193 215
uint64_t determine_next(struct bench *prefs);
194 216
uint64_t calculate_offset(struct bench *prefs, uint64_t new);
217
uint64_t calculate_prog_quantum(struct bench *prefs);
195 218
void create_id(unsigned long seed);
196 219

  

Also available in: Unified diff