2 * Copyright 2012 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials
14 * provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
29 * The views and conclusions contained in the software and
30 * documentation are those of the authors and should not be
31 * interpreted as representing official policies, either expressed
32 * or implied, of GRNET S.A.
36 #include <xseg/xseg.h>
40 #include <sys/syscall.h>
41 #include <sys/types.h>
47 #include <bench-xseg.h>
48 #include <bench-lfsr.h>
53 * This macro checks two things:
54 * a) If in-flight requests are less than given iodepth
55 * b) If we have submitted all of the requests
56 * c) If we are not in ping mode
57 * d) If we have been asked to terminate
59 #define CAN_SEND_REQUEST(__p) \
60 ((__p->status->submitted - __p->status->received < __p->iodepth) && \
61 (__p->status->submitted < __p->status->max) && \
62 (GET_FLAG(PING, __p->flags) == PING_MODE_OFF) && \
65 #define CAN_VERIFY(__p) \
66 ((GET_FLAG(VERIFY, __p->flags) != VERIFY_NO) && __p->op == X_READ)
68 #define CAN_PRINT_PROGRESS(__p, __q) \
69 ((GET_FLAG(PROGRESS, __p->flags) == PROGRESS_YES) && \
70 (__p->status->received == __q))
72 void custom_peer_usage()
74 fprintf(stderr, "Custom peer options: \n"
75 " --------------------------------------------\n"
76 " -op | None | XSEG operation [read|write|info|delete]\n"
77 " --pattern | None | I/O pattern [seq|rand]\n"
78 " --verify | no | Verify written requests [no|meta|full]\n"
79 " -rc | None | Request cap\n"
80 " -to | None | Total objects\n"
81 " -ts | None | Total I/O size\n"
82 " -os | 4M | Object size\n"
83 " -bs | 4k | Block size\n"
84 " -tp | None | Target port\n"
85 " --iodepth | 1 | Number of in-flight I/O requests\n"
86 " --seed | None | Initialize LFSR and target names\n"
87 " --insanity| sane | Adjust insanity level of benchmark:\n"
88 " | | [sane|eccentric|manic|paranoid]\n"
89 " --progress| yes | Show progress of requests [yes|no]\n"
90 " --ping | yes | Ping target before starting benchmark\n"
92 " --prefix | 'bench' | Add a common prefix to all object names\n"
93 " --objname | 'bench' | Use only one object with this name\n"
95 "Additional information:\n"
96 " --------------------------------------------\n"
97 " * The -to and -ts options are mutually exclusive\n"
99 " * The object name is always not null-terminated and\n"
100 " defaults to the following structure:\n"
101 " <prefix>-<seed>-<object number>\n"
104 " a. <prefix> is given by user or defaults to 'bench'\n"
105 " b. <seed> is given by user or defaults to a random value.\n"
106 " Its length will be 9 digits, with trailing zeros where\n"
108 " c. <object number> is out of the user's control. It is\n"
109 " calculated during the benchmark and is a 15-digit\n"
110 " number, allowing a maximum of 1 quadrillion objects\n"
112 " So, if bench is called with the arguments:\n"
113 " --prefix obj --seed 999\n"
115 " and <object number> is 9,the resulting object name will\n"
117 " obj-000000999-000000000000009\n"
119 " * The above object name structure can by bypassed with the\n"
120 " --objname <object name> argument. This implies the\n"
123 " a. -to option is strictly restricted to 1\n"
124 " b. -ts option defaults to (and can't be larger than)\n"
125 " the object size (-os argument)\n"
126 " c. --prefix is must be unused. If used, it produces an "
127 " error to alert the user\n"
131 int custom_peer_init(struct peerd *peer, int argc, char *argv[])
134 char request_cap[MAX_ARG_LEN + 1];
135 char total_objects[MAX_ARG_LEN + 1];
136 char total_size[MAX_ARG_LEN + 1];
137 char object_size[MAX_ARG_LEN + 1];
138 char block_size[MAX_ARG_LEN + 1];
139 char op[MAX_ARG_LEN + 1];
140 char pattern[MAX_ARG_LEN + 1];
141 char insanity[MAX_ARG_LEN + 1];
142 char verify[MAX_ARG_LEN + 1];
143 char progress[MAX_ARG_LEN + 1];
144 char ping[MAX_ARG_LEN + 1];
145 char prefix[XSEG_MAX_TARGETLEN + 1];
146 char objname[XSEG_MAX_TARGETLEN + 1];
147 struct xseg *xseg = peer->xseg;
148 struct object_vars *obv;
149 unsigned int xseg_page_size = 1 << xseg->config.page_shift;
152 unsigned long seed = -1;
153 unsigned long seed_max;
161 total_objects[0] = 0;
173 /* allocate struct bench */
174 prefs = malloc(sizeof(struct bench));
179 memset(prefs, 0, sizeof(struct bench));
181 /* allocate struct req_status */
182 prefs->status = malloc(sizeof(struct req_status));
183 if (!prefs->status) {
187 memset(prefs->status, 0, sizeof(struct req_status));
189 /* allocate struct object_name */
190 prefs->objvars = malloc(sizeof(struct object_vars));
191 if (!prefs->objvars) {
193 goto object_name_fail;
195 memset(prefs->objvars, 0, sizeof(struct object_vars));
197 /* allocate a struct timespec for each peer request */
198 for (j = 0; j < peer->nr_ops; j++) {
199 ts = malloc(sizeof(struct timespec));
204 peer->peer_reqs[j].priv = ts;
207 //Begin reading the benchmark-specific arguments
208 BEGIN_READ_ARGS(argc, argv);
209 READ_ARG_STRING("-rc", request_cap, MAX_ARG_LEN);
210 READ_ARG_STRING("-op", op, MAX_ARG_LEN);
211 READ_ARG_STRING("--pattern", pattern, MAX_ARG_LEN);
212 READ_ARG_STRING("-to", total_objects, MAX_ARG_LEN);
213 READ_ARG_STRING("-ts", total_size, MAX_ARG_LEN);
214 READ_ARG_STRING("-os", object_size, MAX_ARG_LEN);
215 READ_ARG_STRING("-bs", block_size, MAX_ARG_LEN);
216 READ_ARG_ULONG("--iodepth", iodepth);
217 READ_ARG_ULONG("-tp", dst_port);
218 READ_ARG_ULONG("--seed", seed);
219 READ_ARG_STRING("--insanity", insanity, MAX_ARG_LEN);
220 READ_ARG_STRING("--verify", verify, MAX_ARG_LEN);
221 READ_ARG_STRING("--progress", progress, MAX_ARG_LEN);
222 READ_ARG_STRING("--ping", ping, MAX_ARG_LEN);
223 READ_ARG_STRING("--prefix", prefix, XSEG_MAX_TARGETLEN);
224 READ_ARG_STRING("--objname", objname, XSEG_MAX_TARGETLEN);
227 /********************************\
228 * Check object name parameters *
229 \********************************/
230 if (objname[0] && prefix[0]) {
231 XSEGLOG2(&lc, E, "--objname and --prefix options cannot be"
236 obv = prefs->objvars;
237 obv->seedlen = SEEDLEN;
238 obv->objnumlen = OBJNUMLEN;
240 strncpy(obv->name, objname, XSEG_MAX_TARGETLEN);
242 obv->namelen = strlen(objname);
244 if (!prefix[0]) /* In this case we use a default value */
245 strcpy(prefix, "bench");
246 strncpy(obv->prefix, prefix, XSEG_MAX_TARGETLEN);
247 obv->prefixlen = strlen(prefix);
248 /* We add 2 for the extra dashes */
249 obv->namelen = obv->prefixlen + obv->seedlen +
253 /* Only --prefix can exceed bounds since --objname is bounded */
254 if (obv->namelen > XSEG_MAX_TARGETLEN) {
255 XSEGLOG2(&lc, E, "--prefix %s: Prefix is too long.", prefix);
259 /*****************************\
260 * Check I/O type parameters *
261 \*****************************/
263 //We support 4 xseg operations: X_READ, X_WRITE, X_DELETE, X_INFO
264 //The I/O pattern of these operations can be either sequential (seq) or
267 XSEGLOG2(&lc, E, "xseg operation needs to be supplied\n");
272 XSEGLOG2(&lc, E, "Invalid syntax: -op %s\n", op);
278 XSEGLOG2(&lc, E, "I/O pattern needs to be supplied\n");
281 r = read_pattern(pattern);
283 XSEGLOG2(&lc, E, "Invalid syntax: --pattern %s\n", pattern);
286 SET_FLAG(PATTERN, prefs->flags, r);
289 strcpy(verify, "no");
290 r = read_verify(verify);
292 XSEGLOG2(&lc, E, "Invalid syntax: --verify %s\n", verify);
295 SET_FLAG(VERIFY, prefs->flags, r);
297 //Default iodepth value is 1
301 prefs->iodepth = iodepth;
303 /**************************\
304 * Check timer parameters *
305 \**************************/
307 //Most of the times, not all timers need to be used.
308 //We can choose which timers will be used by adjusting the "insanity"
309 //level of the benchmark i.e. the obscurity of code paths (get request,
310 //submit request) that will be timed.
312 strcpy(insanity, "sane");
314 r = read_insanity(insanity);
316 XSEGLOG2(&lc, E, "Invalid syntax: --insanity %s\n", insanity);
319 SET_FLAG(INSANITY, prefs->flags, r);
321 /*****************************\
322 * Check I/O size parameters *
323 \*****************************/
325 //Block size (bs): Defaults to 4K.
326 //It must be a number followed by one of these characters:
328 //If not, it will be considered as size in bytes.
329 //Must be integer multiple of segment's page size (typically 4k).
331 strcpy(block_size,"4k");
333 prefs->bs = str2num(block_size);
335 XSEGLOG2(&lc, E, "Invalid syntax: -bs %s\n", block_size);
337 } else if (prefs->bs % xseg_page_size) {
338 XSEGLOG2(&lc, E, "Misaligned block size: %s\n", block_size);
342 //Object size (os): Defaults to 4M.
343 //Must have the same format as "block size"
344 //Must be integer multiple of "block size"
346 strcpy(object_size,"4M");
348 prefs->os = str2num(object_size);
350 XSEGLOG2(&lc, E, "Invalid syntax: -os %s\n", object_size);
352 } else if (prefs->os % prefs->bs) {
353 XSEGLOG2(&lc, E, "Misaligned object size: %s\n", object_size);
357 //Total objects (to) or total I/O size (ts).
358 //Must have the same format as "block size"
359 //They are mutually exclusive
360 if (total_objects[0] && total_size[0]) {
361 XSEGLOG2(&lc, E, "Total objects and total size are "
362 "mutually exclusive\n");
364 } else if (total_objects[0]) {
365 prefs->to = str2num(total_objects);
367 XSEGLOG2(&lc, E, "Invalid syntax: -to %s\n",
371 //In this case, the maximum number of requests is the total
372 //number of objects we will handle
373 prefs->status->max = prefs->to;
374 } else if (total_size[0]) {
375 if (prefs->op != X_READ && prefs->op != X_WRITE) {
376 XSEGLOG2(&lc, E, "Total objects must be supplied "
377 "(required by -op %s)\n", op);
380 prefs->ts = str2num(total_size);
382 XSEGLOG2(&lc, E, "Invalid syntax: -ts %s\n", total_size);
384 } else if (prefs->ts % prefs->bs) {
385 XSEGLOG2(&lc, E, "Misaligned total I/O size: %s\n", total_size);
388 //In this case, the maximum number of requests is the number of
389 //blocks we need to cover the total I/O size
390 prefs->status->max = prefs->ts / prefs->bs;
391 } else if (!objname[0]) {
392 XSEGLOG2(&lc, E, "Total objects or total size must be supplied\n");
397 * Enforce --objname restrictions here.
401 XSEGLOG2(&lc, E, "-to %s: Total objects are restricted "
402 "to 1 due to --objname %s\n",
403 total_objects, objname);
405 } else if (prefs->ts > prefs->os) {
406 XSEGLOG2(&lc, E, "-ts %s: Total size can't be larger "
407 "than object size (%s) due to "
409 total_size, object_size, objname);
411 } else if (prefs->op == X_READ || prefs->op == X_WRITE) {
412 prefs->ts = prefs->os;
413 prefs->status->max = prefs->ts / prefs->bs;
416 prefs->status->max = 1;
420 if (prefs->status->max == 1)
421 SET_FLAG(PATTERN, prefs->flags, PATTERN_SEQ);
423 /*************************\
424 * Check port parameters *
425 \*************************/
428 XSEGLOG2(&lc, E, "Target port must be supplied\n");
432 prefs->src_port = peer->portno_start; //TODO: allow user to change this
433 prefs->dst_port = (xport) dst_port;
435 /*********************************\
436 * Create timers for all metrics *
437 \*********************************/
439 if (init_timer(&prefs->total_tm, INSANITY_SANE))
441 if (init_timer(&prefs->sub_tm, INSANITY_MANIC))
443 if (init_timer(&prefs->get_tm, INSANITY_PARANOID))
445 if (init_timer(&prefs->rec_tm, INSANITY_ECCENTRIC))
448 /***********************\
449 * Initialize the LFSR *
450 \***********************/
452 seed_max = pow(10, obv->seedlen + 1) - 1;
456 } else if (validate_seed(prefs, seed)) {
457 XSEGLOG2(&lc, E, "--seed %lu: Seed larger than %lu. Only its "
458 "first %d digits will be used",
459 seed, seed_max, obv->seedlen);
465 seed = rand() % seed_max + 1;
467 if (GET_FLAG(PATTERN, prefs->flags) == PATTERN_RAND) {
468 prefs->lfsr = malloc(sizeof(struct bench_lfsr));
474 r = lfsr_init(prefs->lfsr, prefs->status->max,
481 XSEGLOG2(&lc, E, "LFSR could not be initialized.\n");
487 /*********************************\
488 * Miscellaneous initializations *
489 \*********************************/
491 /* The request cap must be enforced only after the LFSR is initialized */
492 if (request_cap[0]) {
493 rc = str2num(request_cap);
495 XSEGLOG2(&lc, E, "Invalid syntax: -rc %s\n", request_cap);
497 } else if (rc > prefs->status->max) {
498 XSEGLOG2(&lc, E, "Request cap exceeds current request total.\n");
501 prefs->status->max = rc;
504 /* Benchmarking progress printing is on by default */
506 strcpy(progress, "yes");
507 r = read_progress(progress);
509 XSEGLOG2(&lc, E, "Invalid syntax: --progress %s\n", progress);
512 SET_FLAG(PROGRESS, prefs->flags, r);
514 /* Pinging the target peer is on by default */
519 XSEGLOG2(&lc, E, "Invalid syntax: --ping %s\n", ping);
522 SET_FLAG(PING, prefs->flags, r);
525 peer->peerd_loop = bench_peerd_loop;
526 peer->priv = (void *) prefs;
529 XSEGLOG2(&lc, I, "Seed is %u, prefix is %s",
530 obv->seed, obv->prefix);
532 XSEGLOG2(&lc, I, "Seed is %u, object name is %s",
533 obv->seed, obv->name);
542 free(prefs->total_tm);
548 for (; j >= 0; j--) {
549 free(peer->peer_reqs[j].priv);
552 free(prefs->objvars);
561 static int send_request(struct peerd *peer, struct bench *prefs)
563 struct xseg_request *req;
564 struct xseg *xseg = peer->xseg;
566 struct object_vars *obv = prefs->objvars;
567 xport srcport = prefs->src_port;
568 xport dstport = prefs->dst_port;
573 uint64_t size = prefs->bs;
576 //srcport and dstport must already be provided by the user.
577 //returns struct xseg_request with basic initializations
578 XSEGLOG2(&lc, D, "Get new request\n");
579 timer_start(prefs, prefs->get_tm);
580 req = xseg_get_request(xseg, srcport, dstport, X_ALLOC);
582 XSEGLOG2(&lc, W, "Cannot get request\n");
585 timer_stop(prefs, prefs->get_tm, NULL);
588 * Allocate enough space for the data and the target's name.
589 * Also, allocate one extra byte to prevent buffer overflow due to the
590 * obligatory null termination of snprint(). This extra byte will not be
591 * counted as part of the target's name.
593 XSEGLOG2(&lc, D, "Prepare new request\n");
594 r = xseg_prep_request(xseg, req, obv->namelen + 1, size);
596 XSEGLOG2(&lc, W, "Cannot prepare request! (%lu, %llu)\n",
597 obv->namelen + 1, (unsigned long long)size);
598 goto put_xseg_request;
602 //Determine what the next target/chunk will be, based on I/O pattern
603 new = determine_next(prefs);
605 XSEGLOG2(&lc, I, "Our new request is %lu\n", new);
606 obv->objnum = __get_object(prefs, new);
607 create_target(prefs, req);
609 if (prefs->op == X_WRITE || prefs->op == X_READ) {
611 //Calculate the chunk's offset inside the object
612 req->offset = calculate_offset(prefs, new);
613 XSEGLOG2(&lc, D, "Offset of request %lu is %lu\n", new, req->offset);
615 if (prefs->op == X_WRITE)
616 create_chunk(prefs, req, new);
619 XSEGLOG2(&lc, D, "Allocate peer request\n");
620 pr = alloc_peer_req(peer);
622 XSEGLOG2(&lc, W, "Cannot allocate peer request (%ld remaining)\n",
623 peer->nr_ops - xq_count(&peer->free_reqs));
624 goto put_xseg_request;
627 pr->portno = srcport;
630 //XSEGLOG2(&lc, D, "Set request data\n");
631 r = xseg_set_req_data(xseg, req, pr);
633 XSEGLOG2(&lc, W, "Cannot set request data\n");
634 goto put_peer_request;
638 * Start measuring receive time.
639 * When we receive a request, we need to have its submission time to
640 * measure elapsed time. Thus, we copy its submission time to pr->priv.
641 * QUESTION: Is this the fastest way?
643 timer_start(prefs, prefs->rec_tm);
644 if (prefs->rec_tm->insanity <= GET_FLAG(INSANITY, prefs->flags)) {
645 ts = (struct timespec *)pr->priv;
646 ts->tv_sec = prefs->rec_tm->start_time.tv_sec;
647 ts->tv_nsec = prefs->rec_tm->start_time.tv_nsec;
650 //Submit the request from the source port to the target port
651 XSEGLOG2(&lc, D, "Submit request %lu\n", new);
652 timer_start(prefs, prefs->sub_tm);
653 p = xseg_submit(xseg, req, srcport, X_ALLOC);
655 XSEGLOG2(&lc, W, "Cannot submit request\n");
656 goto put_peer_request;
658 prefs->status->submitted++;
659 timer_stop(prefs, prefs->sub_tm, NULL);
661 //Send SIGIO to the process that has bound this port to inform that
663 r = xseg_signal(xseg, p);
665 // XSEGLOG2(&lc, W, "Cannot signal destination peer (reason %d)\n", r);
670 free_peer_req(peer, pr);
672 if (xseg_put_request(xseg, req, srcport))
673 XSEGLOG2(&lc, W, "Cannot put request\n");
677 static int send_ping_request(struct peerd *peer, struct bench *prefs)
679 struct xseg_request *req;
680 struct xseg *xseg = peer->xseg;
682 xport srcport = prefs->src_port;
683 xport dstport = prefs->dst_port;
687 XSEGLOG2(&lc, I, "Sending ping request...");
688 //srcport and dstport must already be provided by the user.
689 //returns struct xseg_request with basic initializations
690 XSEGLOG2(&lc, D, "Get new request\n");
691 req = xseg_get_request(xseg, srcport, dstport, X_ALLOC);
693 XSEGLOG2(&lc, W, "Cannot get request\n");
698 XSEGLOG2(&lc, D, "Allocate peer request\n");
699 pr = alloc_peer_req(peer);
701 XSEGLOG2(&lc, W, "Cannot allocate peer request (%ld remaining)\n",
702 peer->nr_ops - xq_count(&peer->free_reqs));
703 goto put_xseg_request;
706 pr->portno = srcport;
709 r = xseg_set_req_data(xseg, req, pr);
711 XSEGLOG2(&lc, W, "Cannot set request data\n");
712 goto put_peer_request;
715 //Submit the request from the source port to the target port
716 XSEGLOG2(&lc, D, "Submit ping request");
717 p = xseg_submit(xseg, req, srcport, X_ALLOC);
719 XSEGLOG2(&lc, W, "Cannot submit request\n");
720 goto put_peer_request;
722 timer_stop(prefs, prefs->sub_tm, NULL);
724 //Send SIGIO to the process that has bound this port to inform that
726 r = xseg_signal(xseg, p);
728 // XSEGLOG2(&lc, W, "Cannot signal destination peer (reason %d)\n", r);
733 free_peer_req(peer, pr);
735 if (xseg_put_request(xseg, req, srcport))
736 XSEGLOG2(&lc, W, "Cannot put request\n");
741 * This function substitutes the default generic_peerd_loop of peer.c.
742 * It's plugged to struct peerd at custom peer's initialisation
744 int bench_peerd_loop(void *arg)
747 struct thread *t = (struct thread *) arg;
748 struct peerd *peer = t->peer;
751 struct peerd *peer = (struct peerd *) arg;
752 char id[4] = {'P','e','e','r'};
754 struct xseg *xseg = peer->xseg;
755 struct bench *prefs = peer->priv;
756 xport portno_start = peer->portno_start;
757 xport portno_end = peer->portno_end;
758 pid_t pid = syscall(SYS_gettid);
759 uint64_t threshold=1000/(1 + portno_end - portno_start);
760 uint64_t cached_prog_quantum = 0;
761 uint64_t prog_quantum = 0;
765 if (GET_FLAG(PROGRESS, prefs->flags) == PROGRESS_YES) {
766 prog_quantum = calculate_prog_quantum(prefs);
767 cached_prog_quantum = prog_quantum;
771 XSEGLOG2(&lc, I, "%s has tid %u.\n",id, pid);
772 xseg_init_local_signal(xseg, peer->portno_start);
774 /* If no ping is going to be sent, we can begin the benchmark now. */
775 if (GET_FLAG(PING, prefs->flags) == PING_MODE_OFF)
776 timer_start(prefs, prefs->total_tm);
778 send_ping_request(peer, prefs);
781 while (!(isTerminate() && all_peer_reqs_free(peer))) {
782 while (CAN_SEND_REQUEST(prefs)) {
783 xseg_cancel_wait(xseg, peer->portno_start);
784 XSEGLOG2(&lc, D, "...because %lu < %lu && %lu < %lu\n",
785 prefs->status->submitted - prefs->status->received,
786 prefs->iodepth, prefs->status->received,
788 XSEGLOG2(&lc, D, "Start sending new request\n");
789 r = send_request(peer, prefs);
793 //Heart of peerd_loop. This loop is common for everyone.
794 for (loops = threshold; loops > 0; loops--) {
796 xseg_prepare_wait(xseg, peer->portno_start);
798 if (UNLIKELY(CAN_PRINT_PROGRESS(prefs, prog_quantum))) {
799 prog_quantum += cached_prog_quantum;
800 print_progress(prefs);
803 if (check_ports(peer)) {
804 //If an old request has just been acked, the most sensible
805 //thing to do is to immediately send a new one
806 if (prefs->status->received < prefs->status->max)
812 //struct xseg_port *port = xseg_get_port(xseg, portno_start);
814 //q = XPTR_TAKE(port->request_queue, xseg->segment);
815 //XSEGLOG2(&lc, I, "%s goes to sleep with %u requests pending\n",
817 XSEGLOG2(&lc, I, "%s goes to sleep\n", id);
818 xseg_wait_signal(xseg, 10000000UL);
819 xseg_cancel_wait(xseg, peer->portno_start);
820 XSEGLOG2(&lc, I, "%s woke up\n", id);
823 XSEGLOG2(&lc, I, "peer->free_reqs = %d, peer->nr_ops = %d\n",
824 xq_count(&peer->free_reqs), peer->nr_ops);
828 void custom_peer_finalize(struct peerd *peer)
830 struct bench *prefs = peer->priv;
831 //TODO: Measure mean time, standard variation
833 if (!prefs->total_tm->completed)
834 timer_stop(prefs, prefs->total_tm, NULL);
836 if (GET_FLAG(PROGRESS, prefs->flags) == PROGRESS_YES)
840 print_remaining(prefs);
846 * handle_received: +1 to our received requests.
847 * Do some sanity checks and then check if request is failed.
848 * If not try to verify the request if asked.
850 static void handle_received(struct peerd *peer, struct peer_req *pr)
852 //FIXME: handle null pointer
853 struct bench *prefs = peer->priv;
854 struct timer *rec = prefs->rec_tm;
858 //This is a serious error, so we must stop
859 XSEGLOG2(&lc, E, "Received peer request with no xseg request");
865 * If we were in ping mode, we can now switch off and start the
868 if (GET_FLAG(PING, prefs->flags) == PING_MODE_ON) {
869 XSEGLOG2(&lc, I, "Ping received. Benchmark can start now.");
870 SET_FLAG(PING, prefs->flags, PING_MODE_OFF);
875 prefs->status->received++;
877 if ((GET_FLAG(INSANITY, prefs->flags) < rec->insanity) && !pr->priv) {
878 XSEGLOG2(&lc, W, "Cannot find submission time of request");
882 timer_stop(prefs, rec, (struct timespec *)pr->priv);
884 if (!(pr->req->state & XS_SERVED))
885 prefs->status->failed++;
886 else if (CAN_VERIFY(prefs) && read_chunk(prefs, pr->req))
887 prefs->status->corrupted++;
890 if (xseg_put_request(peer->xseg, pr->req, pr->portno))
891 XSEGLOG2(&lc, W, "Cannot put xseg request\n");
893 free_peer_req(peer, pr);
896 timer_start(prefs, prefs->total_tm);
899 int dispatch(struct peerd *peer, struct peer_req *pr, struct xseg_request *req,
900 enum dispatch_reason reason)
903 case dispatch_accept:
904 //This is wrong, benchmarking peer should not accept requests,
906 XSEGLOG2(&lc, W, "Bench peer should not accept requests\n");
909 case dispatch_receive:
910 handle_received(peer, pr);