Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (6 kB)

1
/*
2
 * Copyright 2012 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
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.
15
 *
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.
28
 *
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.
33
 */
34

    
35
#include <bench-lfsr.h>
36

    
37
/*
38
 * If CLOCK_MONOTONIC_RAW is not defined in our system, use CLOCK_MONOTONIC
39
 * instead. CLOCK_MONOTONIC_RAW is preferred since we are guaranteed that the
40
 * clock won't skew.
41
 */
42
#ifdef CLOCK_MONOTONIC_RAW
43
#define CLOCK_BENCH CLOCK_MONOTONIC_RAW
44
#else
45
#define CLOCK_BENCH CLOCK_MONOTONIC
46
#endif
47

    
48

    
49
#define MAX_ARG_LEN 10
50

    
51
/*
52
 * Pattern type occupies 1st flag bit.
53
 * If 1, it's sequential, if 0, it's random.
54
 */
55
#define PATTERN_FLAG_POS 0
56
#define PATTERN_BITMASK 1
57
#define PATTERN_SEQ 0
58
#define PATTERN_RAND 1
59

    
60
/*
61
 * Verify mode occupies 2nd and 3rd flag bit.
62
 * If 01, it uses metadata for verification, if 11 it writes pseudorandom nums
63
 * in chunk's memory range and if 00, it's off.
64
 */
65
#define VERIFY_FLAG_POS 1
66
#define VERIFY_BITMASK 3        /* i.e. "11" in binary form */
67
#define VERIFY_NO 0
68
#define        VERIFY_META 1
69
#define        VERIFY_FULL 2
70

    
71
/* Timer insanity occupies 4th and 5th flag bit */
72
#define INSANITY_FLAG_POS 3
73
#define INSANITY_BITMASK 3        /* i.e. "11" in binary form */
74
#define INSANITY_SANE 0
75
#define INSANITY_ECCENTRIC 1
76
#define INSANITY_MANIC 2
77
#define INSANITY_PARANOID 3
78

    
79

    
80
/*
81
 * Current bench flags representation:
82
 * 64 7  6  5  4  3  2  1 : bits
83
 * ...0  0  0  0  0  0  0
84
 *         |____||____||_|
85
 *                          ^            ^   ^
86
 *                          |                |   |
87
 *                   insanity        | pattern
88
 *                                 verify
89
 */
90
/* Add flag bit according to its position */
91
#define SET_FLAG(__ftype, __flag, __val)        \
92
        __flag |= __val << __ftype##_FLAG_POS;
93

    
94
/* Apply bitmask to flags, shift result to the right to get correct value */
95
#define GET_FLAG(__ftype, __flag)                        \
96
        (__flag & (__ftype##_BITMASK << __ftype##_FLAG_POS)) >> __ftype##_FLAG_POS
97
/*
98
 * The benchark ID (IDLEN) is global for the test, calculated once and is a
99
 * string of the following form: {"bench-" + 9-digit number + "\0"}.
100
 * The target string (TARGETLEN) is per object, concatenated with the string
101
 * above and is of the following form: {"-" +16-digit number + "\0"}.
102
 */
103
#define IDLEN 16
104
#define TARGETLEN (IDLEN + 17)
105
extern char global_id[IDLEN];
106

    
107
struct bench {
108
        uint64_t to; //Total number of objects (not for read/write)
109
        uint64_t ts; //Total I/O size
110
        uint64_t os; //Object size
111
        uint64_t bs; //Block size
112
        uint32_t iodepth; //Num of in-flight xseg reqs
113
        xport dst_port;
114
        xport src_port;
115
        uint32_t op;        //xseg operation
116
        uint64_t flags;
117
        struct peerd *peer;
118
        struct req_status *status;
119
        struct bench_lfsr *lfsr;
120
        struct timer *total_tm; //Total time for benchmark
121
        struct timer *get_tm;        //Time for xseg_get_request
122
        struct timer *sub_tm;        //Time for xseg_submit_request
123
        struct timer *rec_tm;        //Time for xseg_receive_request
124
};
125

    
126
struct req_status {
127
        uint64_t max;                /* Max requests for benchmark */
128
        uint64_t submitted;
129
        uint64_t received;
130
        uint64_t corrupted;        /* Requests that did not pass verification */
131
        uint64_t failed;
132
};
133

    
134
/*
135
 * Custom timespec. Made to calculate variance, where we need the square of a
136
 * timespec struct. This struct should be more than enough to hold the square
137
 * of the biggest timespec.
138
 */
139
struct timespec2 {
140
        unsigned long tv_sec2;
141
        uint64_t tv_nsec2;
142
};
143

    
144
/*
145
 * struct timer fields
146
 * ====================
147
 * completed: number of completed requests
148
 * start_time: submission time of a request
149
 * sum: the sum of elapsed times of every completed request
150
 * sum_sq: the sum of the squares of elapsed times
151
 * insanity: benchmarking level, higher means that the request associated with
152
 *           this timer is more trivial.
153
 */
154
struct timer {
155
        struct timespec sum;
156
        struct timespec2 sum_sq;
157
        struct timespec start_time;
158
        uint64_t completed;
159
        int insanity;
160
};
161

    
162
struct tm_result {
163
        unsigned int s;
164
        unsigned int ms;
165
        unsigned int us;
166
        unsigned int ns;
167
};
168

    
169
struct signature {
170
        uint64_t id;
171
        uint64_t object;
172
        uint64_t offset;
173
};
174

    
175

    
176
int bench_peerd_loop(void *arg);
177

    
178
void timer_start(struct bench *prefs, struct timer *sample_req);
179
void timer_stop(struct bench *prefs, struct timer *sample_tm,
180
                struct timespec *start);
181
int init_timer(struct timer **tm, int insanity);
182
uint64_t str2num(char *str);
183
int read_op(char *op);
184
int read_pattern(char *pattern);
185
int read_insanity(char *insanity);
186
int read_verify(char *insanity);
187
void print_res(struct bench *prefs, struct timer *tm, char *type);
188
void print_stats(struct bench *prefs);
189
void create_target(struct bench *prefs, struct xseg_request *req,
190
                uint64_t new);
191
void create_chunk(struct bench *prefs, struct xseg_request *req, uint64_t new);
192
int read_chunk(struct bench *prefs, struct xseg_request *req);
193
uint64_t determine_next(struct bench *prefs);
194
uint64_t calculate_offset(struct bench *prefs, uint64_t new);
195
void create_id(unsigned long seed);
196