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.
39 #include <sys/syscall.h>
40 #include <sys/types.h>
42 #include <xseg/xseg.h>
47 #include <bench-xseg.h>
49 struct timespec delay = {0, 4000000};
52 * Convert string to size in bytes.
53 * If syntax is invalid, return 0. Values such as zero and non-integer
54 * multiples of segment's page size should not be accepted.
56 uint64_t str2num(char *str)
61 num = strtoll(str, &unit, 10);
62 if (strlen(unit) > 1) //Invalid syntax
64 else if (strlen(unit) < 1) //Plain number in bytes
84 int read_insanity(char *insanity)
86 if (strcmp(insanity, "sane") == 0)
88 if (strcmp(insanity, "eccentric") == 0)
90 if (strcmp(insanity, "manic") == 0)
92 if (strcmp(insanity, "paranoid") == 0)
99 if (strcmp(op, "read") == 0)
101 if (strcmp(op, "write") == 0)
103 if (strcmp(op, "info") == 0)
105 if (strcmp(op, "delete") == 0)
110 int read_pattern(char *pattern)
112 if (strcmp(pattern, "seq") == 0)
114 if (strcmp(pattern, "rand") == 0)
119 void print_res(struct tm_result res, char *type)
122 printf(" %s\n", type);
123 printf("================================\n");
124 printf(" |-s-||-ms-|-us-|-ns-|\n");
125 printf("Time: %03lu. %03lu %03lu %03lu\n",
126 res.s, res.ms, res.us, res.ns);
130 * Seperates a timespec struct in seconds, msec, usec, nsec
132 void separate_by_order(struct timespec src, struct tm_result *res)
134 res->ns = src.tv_nsec % 1000;
136 res->us = src.tv_nsec % 1000;
137 res->ms = src.tv_nsec / 1000;
141 void create_target(struct bench *prefs, struct xseg_request *req,
144 struct xseg *xseg = prefs->peer->xseg;
147 req_target = xseg_get_target(xseg, req);
149 //For read/write, the target object does not correspond to `new`, which is
150 //actually the chunk number. We need to div this number with the number of
151 //chunks in an object.
152 //FIXME: Make it more elegant
153 if (prefs->op == X_READ || prefs->op == X_WRITE)
154 new = new / (prefs->os / prefs->bs);
155 snprintf(req_target, TARGETLEN, "%s-%016lu", global_id, new);
156 XSEGLOG2(&lc, D, "Target name of request is %s\n", req_target);
159 void create_chunk(struct bench *prefs, struct xseg_request *req, uint64_t new)
161 struct xseg *xseg = prefs->peer->xseg;
164 //TODO: Fill data depening on validation level
165 req_data = xseg_get_data(xseg, req);
169 uint64_t determine_next(struct bench *prefs)
171 if ((prefs->flags & (1 << PATTERN_FLAG)) == IO_SEQ)
172 return prefs->sub_tm->completed;
174 return lfsr_next(prefs->lfsr);
178 //FIXME: this looks like a hack, handle it more elegantly
181 struct timespec seed;
183 clock_gettime(CLOCK_MONOTONIC_RAW, &seed);
185 global_seed = seed.tv_nsec;
186 //nanoseconds can't be more than 9 digits
187 snprintf(global_id, IDLEN, "bench-%09lu", global_seed);
188 XSEGLOG2(&lc, I, "Global ID is %s\n", global_id);