Statistics
| Branch: | Tag: | Revision:

root / xseg / peers / user / bench-xseg.h @ 911fec92

History | View | Annotate | Download (6 kB)

1 15a2f01d Alex Pyrgiotis
/*
2 15a2f01d Alex Pyrgiotis
 * Copyright 2012 GRNET S.A. All rights reserved.
3 15a2f01d Alex Pyrgiotis
 *
4 15a2f01d Alex Pyrgiotis
 * Redistribution and use in source and binary forms, with or
5 15a2f01d Alex Pyrgiotis
 * without modification, are permitted provided that the following
6 15a2f01d Alex Pyrgiotis
 * conditions are met:
7 15a2f01d Alex Pyrgiotis
 *
8 15a2f01d Alex Pyrgiotis
 *   1. Redistributions of source code must retain the above
9 15a2f01d Alex Pyrgiotis
 *      copyright notice, this list of conditions and the following
10 15a2f01d Alex Pyrgiotis
 *      disclaimer.
11 15a2f01d Alex Pyrgiotis
 *   2. Redistributions in binary form must reproduce the above
12 15a2f01d Alex Pyrgiotis
 *      copyright notice, this list of conditions and the following
13 15a2f01d Alex Pyrgiotis
 *      disclaimer in the documentation and/or other materials
14 15a2f01d Alex Pyrgiotis
 *      provided with the distribution.
15 15a2f01d Alex Pyrgiotis
 *
16 15a2f01d Alex Pyrgiotis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 15a2f01d Alex Pyrgiotis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 15a2f01d Alex Pyrgiotis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 15a2f01d Alex Pyrgiotis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 15a2f01d Alex Pyrgiotis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 15a2f01d Alex Pyrgiotis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 15a2f01d Alex Pyrgiotis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 15a2f01d Alex Pyrgiotis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 15a2f01d Alex Pyrgiotis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 15a2f01d Alex Pyrgiotis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 15a2f01d Alex Pyrgiotis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 15a2f01d Alex Pyrgiotis
 * POSSIBILITY OF SUCH DAMAGE.
28 15a2f01d Alex Pyrgiotis
 *
29 15a2f01d Alex Pyrgiotis
 * The views and conclusions contained in the software and
30 15a2f01d Alex Pyrgiotis
 * documentation are those of the authors and should not be
31 15a2f01d Alex Pyrgiotis
 * interpreted as representing official policies, either expressed
32 15a2f01d Alex Pyrgiotis
 * or implied, of GRNET S.A.
33 15a2f01d Alex Pyrgiotis
 */
34 15a2f01d Alex Pyrgiotis
35 b28fa3e7 Alex Pyrgiotis
#include <bench-lfsr.h>
36 b28fa3e7 Alex Pyrgiotis
37 911fec92 Alex Pyrgiotis
/*
38 911fec92 Alex Pyrgiotis
 * If CLOCK_MONOTONIC_RAW is not defined in our system, use CLOCK_MONOTONIC
39 911fec92 Alex Pyrgiotis
 * instead. CLOCK_MONOTONIC_RAW is preferred since we are guaranteed that the
40 911fec92 Alex Pyrgiotis
 * clock won't skew.
41 911fec92 Alex Pyrgiotis
 */
42 911fec92 Alex Pyrgiotis
#ifdef CLOCK_MONOTONIC_RAW
43 911fec92 Alex Pyrgiotis
#define CLOCK_BENCH CLOCK_MONOTONIC_RAW
44 911fec92 Alex Pyrgiotis
#else
45 911fec92 Alex Pyrgiotis
#define CLOCK_BENCH CLOCK_MONOTONIC
46 911fec92 Alex Pyrgiotis
#endif
47 911fec92 Alex Pyrgiotis
48 911fec92 Alex Pyrgiotis
49 15a2f01d Alex Pyrgiotis
#define MAX_ARG_LEN 10
50 15a2f01d Alex Pyrgiotis
51 28a16745 Alex Pyrgiotis
/*
52 28a16745 Alex Pyrgiotis
 * Pattern type occupies 1st flag bit.
53 28a16745 Alex Pyrgiotis
 * If 1, it's sequential, if 0, it's random.
54 28a16745 Alex Pyrgiotis
 */
55 28a16745 Alex Pyrgiotis
#define PATTERN_FLAG_POS 0
56 28a16745 Alex Pyrgiotis
#define PATTERN_BITMASK 1
57 28a16745 Alex Pyrgiotis
#define PATTERN_SEQ 0
58 28a16745 Alex Pyrgiotis
#define PATTERN_RAND 1
59 4b114b66 Alex Pyrgiotis
60 0ef9c7ee Alex Pyrgiotis
/*
61 28a16745 Alex Pyrgiotis
 * Verify mode occupies 2nd and 3rd flag bit.
62 28a16745 Alex Pyrgiotis
 * If 01, it uses metadata for verification, if 11 it writes pseudorandom nums
63 28a16745 Alex Pyrgiotis
 * in chunk's memory range and if 00, it's off.
64 0ef9c7ee Alex Pyrgiotis
 */
65 28a16745 Alex Pyrgiotis
#define VERIFY_FLAG_POS 1
66 28a16745 Alex Pyrgiotis
#define VERIFY_BITMASK 3        /* i.e. "11" in binary form */
67 28a16745 Alex Pyrgiotis
#define VERIFY_NO 0
68 28a16745 Alex Pyrgiotis
#define        VERIFY_META 1
69 28a16745 Alex Pyrgiotis
#define        VERIFY_FULL 2
70 28a16745 Alex Pyrgiotis
71 28a16745 Alex Pyrgiotis
/* Timer insanity occupies 4th and 5th flag bit */
72 28a16745 Alex Pyrgiotis
#define INSANITY_FLAG_POS 3
73 28a16745 Alex Pyrgiotis
#define INSANITY_BITMASK 3        /* i.e. "11" in binary form */
74 28a16745 Alex Pyrgiotis
#define INSANITY_SANE 0
75 28a16745 Alex Pyrgiotis
#define INSANITY_ECCENTRIC 1
76 28a16745 Alex Pyrgiotis
#define INSANITY_MANIC 2
77 28a16745 Alex Pyrgiotis
#define INSANITY_PARANOID 3
78 28a16745 Alex Pyrgiotis
79 4b114b66 Alex Pyrgiotis
80 35afde18 Alex Pyrgiotis
/*
81 28a16745 Alex Pyrgiotis
 * Current bench flags representation:
82 28a16745 Alex Pyrgiotis
 * 64 7  6  5  4  3  2  1 : bits
83 28a16745 Alex Pyrgiotis
 * ...0  0  0  0  0  0  0
84 28a16745 Alex Pyrgiotis
 *         |____||____||_|
85 28a16745 Alex Pyrgiotis
 *                          ^            ^   ^
86 28a16745 Alex Pyrgiotis
 *                          |                |   |
87 28a16745 Alex Pyrgiotis
 *                   insanity        | pattern
88 28a16745 Alex Pyrgiotis
 *                                 verify
89 b28fa3e7 Alex Pyrgiotis
 */
90 28a16745 Alex Pyrgiotis
/* Add flag bit according to its position */
91 28a16745 Alex Pyrgiotis
#define SET_FLAG(__ftype, __flag, __val)        \
92 28a16745 Alex Pyrgiotis
        __flag |= __val << __ftype##_FLAG_POS;
93 b28fa3e7 Alex Pyrgiotis
94 28a16745 Alex Pyrgiotis
/* Apply bitmask to flags, shift result to the right to get correct value */
95 28a16745 Alex Pyrgiotis
#define GET_FLAG(__ftype, __flag)                        \
96 28a16745 Alex Pyrgiotis
        (__flag & (__ftype##_BITMASK << __ftype##_FLAG_POS)) >> __ftype##_FLAG_POS
97 b28fa3e7 Alex Pyrgiotis
/*
98 b28fa3e7 Alex Pyrgiotis
 * The benchark ID (IDLEN) is global for the test, calculated once and is a
99 b28fa3e7 Alex Pyrgiotis
 * string of the following form: {"bench-" + 9-digit number + "\0"}.
100 b28fa3e7 Alex Pyrgiotis
 * The target string (TARGETLEN) is per object, concatenated with the string
101 b28fa3e7 Alex Pyrgiotis
 * above and is of the following form: {"-" +16-digit number + "\0"}.
102 35afde18 Alex Pyrgiotis
 */
103 29a2d904 Alex Pyrgiotis
#define IDLEN 16
104 35afde18 Alex Pyrgiotis
#define TARGETLEN (IDLEN + 17)
105 35afde18 Alex Pyrgiotis
extern char global_id[IDLEN];
106 35afde18 Alex Pyrgiotis
107 15a2f01d Alex Pyrgiotis
struct bench {
108 35afde18 Alex Pyrgiotis
        uint64_t to; //Total number of objects (not for read/write)
109 15a2f01d Alex Pyrgiotis
        uint64_t ts; //Total I/O size
110 15a2f01d Alex Pyrgiotis
        uint64_t os; //Object size
111 15a2f01d Alex Pyrgiotis
        uint64_t bs; //Block size
112 15a2f01d Alex Pyrgiotis
        uint32_t iodepth; //Num of in-flight xseg reqs
113 15a2f01d Alex Pyrgiotis
        xport dst_port;
114 15a2f01d Alex Pyrgiotis
        xport src_port;
115 4b114b66 Alex Pyrgiotis
        uint32_t op;        //xseg operation
116 28a16745 Alex Pyrgiotis
        uint64_t flags;
117 35afde18 Alex Pyrgiotis
        struct peerd *peer;
118 28a16745 Alex Pyrgiotis
        struct req_status *status;
119 b28fa3e7 Alex Pyrgiotis
        struct bench_lfsr *lfsr;
120 4b114b66 Alex Pyrgiotis
        struct timer *total_tm; //Total time for benchmark
121 4b114b66 Alex Pyrgiotis
        struct timer *get_tm;        //Time for xseg_get_request
122 4b114b66 Alex Pyrgiotis
        struct timer *sub_tm;        //Time for xseg_submit_request
123 4b114b66 Alex Pyrgiotis
        struct timer *rec_tm;        //Time for xseg_receive_request
124 15a2f01d Alex Pyrgiotis
};
125 15a2f01d Alex Pyrgiotis
126 28a16745 Alex Pyrgiotis
struct req_status {
127 28a16745 Alex Pyrgiotis
        uint64_t max;                /* Max requests for benchmark */
128 28a16745 Alex Pyrgiotis
        uint64_t submitted;
129 28a16745 Alex Pyrgiotis
        uint64_t received;
130 28a16745 Alex Pyrgiotis
        uint64_t corrupted;        /* Requests that did not pass verification */
131 28a16745 Alex Pyrgiotis
        uint64_t failed;
132 28a16745 Alex Pyrgiotis
};
133 28a16745 Alex Pyrgiotis
134 15a2f01d Alex Pyrgiotis
/*
135 15a2f01d Alex Pyrgiotis
 * Custom timespec. Made to calculate variance, where we need the square of a
136 4b114b66 Alex Pyrgiotis
 * timespec struct. This struct should be more than enough to hold the square
137 4b114b66 Alex Pyrgiotis
 * of the biggest timespec.
138 15a2f01d Alex Pyrgiotis
 */
139 15a2f01d Alex Pyrgiotis
struct timespec2 {
140 15a2f01d Alex Pyrgiotis
        unsigned long tv_sec2;
141 15a2f01d Alex Pyrgiotis
        uint64_t tv_nsec2;
142 15a2f01d Alex Pyrgiotis
};
143 15a2f01d Alex Pyrgiotis
144 d12386ab Alex Pyrgiotis
/*
145 d12386ab Alex Pyrgiotis
 * struct timer fields
146 d12386ab Alex Pyrgiotis
 * ====================
147 d12386ab Alex Pyrgiotis
 * completed: number of completed requests
148 d12386ab Alex Pyrgiotis
 * start_time: submission time of a request
149 d12386ab Alex Pyrgiotis
 * sum: the sum of elapsed times of every completed request
150 d12386ab Alex Pyrgiotis
 * sum_sq: the sum of the squares of elapsed times
151 d12386ab Alex Pyrgiotis
 * insanity: benchmarking level, higher means that the request associated with
152 d12386ab Alex Pyrgiotis
 *           this timer is more trivial.
153 d12386ab Alex Pyrgiotis
 */
154 15a2f01d Alex Pyrgiotis
struct timer {
155 15a2f01d Alex Pyrgiotis
        struct timespec sum;
156 15a2f01d Alex Pyrgiotis
        struct timespec2 sum_sq;
157 15a2f01d Alex Pyrgiotis
        struct timespec start_time;
158 d38b3cda Alex Pyrgiotis
        uint64_t completed;
159 d38b3cda Alex Pyrgiotis
        int insanity;
160 15a2f01d Alex Pyrgiotis
};
161 15a2f01d Alex Pyrgiotis
162 4b114b66 Alex Pyrgiotis
struct tm_result {
163 d38b3cda Alex Pyrgiotis
        unsigned int s;
164 d38b3cda Alex Pyrgiotis
        unsigned int ms;
165 d38b3cda Alex Pyrgiotis
        unsigned int us;
166 d38b3cda Alex Pyrgiotis
        unsigned int ns;
167 4b114b66 Alex Pyrgiotis
};
168 4b114b66 Alex Pyrgiotis
169 ee638823 Alex Pyrgiotis
struct signature {
170 28a16745 Alex Pyrgiotis
        uint64_t id;
171 28a16745 Alex Pyrgiotis
        uint64_t object;
172 b28fa3e7 Alex Pyrgiotis
        uint64_t offset;
173 b003d80d Alex Pyrgiotis
};
174 b003d80d Alex Pyrgiotis
175 ee638823 Alex Pyrgiotis
176 28a16745 Alex Pyrgiotis
int bench_peerd_loop(void *arg);
177 15a2f01d Alex Pyrgiotis
178 35afde18 Alex Pyrgiotis
void timer_start(struct bench *prefs, struct timer *sample_req);
179 35afde18 Alex Pyrgiotis
void timer_stop(struct bench *prefs, struct timer *sample_tm,
180 35afde18 Alex Pyrgiotis
                struct timespec *start);
181 0ef9c7ee Alex Pyrgiotis
int init_timer(struct timer **tm, int insanity);
182 b003d80d Alex Pyrgiotis
uint64_t str2num(char *str);
183 b003d80d Alex Pyrgiotis
int read_op(char *op);
184 b003d80d Alex Pyrgiotis
int read_pattern(char *pattern);
185 d38b3cda Alex Pyrgiotis
int read_insanity(char *insanity);
186 b28fa3e7 Alex Pyrgiotis
int read_verify(char *insanity);
187 d38b3cda Alex Pyrgiotis
void print_res(struct bench *prefs, struct timer *tm, char *type);
188 d38b3cda Alex Pyrgiotis
void print_stats(struct bench *prefs);
189 b003d80d Alex Pyrgiotis
void create_target(struct bench *prefs, struct xseg_request *req,
190 b003d80d Alex Pyrgiotis
                uint64_t new);
191 17a413b7 Alex Pyrgiotis
void create_chunk(struct bench *prefs, struct xseg_request *req, uint64_t new);
192 17a413b7 Alex Pyrgiotis
int read_chunk(struct bench *prefs, struct xseg_request *req);
193 b003d80d Alex Pyrgiotis
uint64_t determine_next(struct bench *prefs);
194 ce8bfb92 Alex Pyrgiotis
uint64_t calculate_offset(struct bench *prefs, uint64_t new);
195 b28fa3e7 Alex Pyrgiotis
void create_id(unsigned long seed);