Improve LFSR implementation
[archipelago] / xseg / peers / user / bench-xseg.h
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 #define MAX_ARG_LEN 10
38
39 #define TM_SANE 0
40 #define TM_ECCENTRIC 1
41 #define TM_MANIC 2
42 #define TM_PARANOID 3
43
44 /*
45  * Pattern type occupies first flag bit.
46  * If 1, it's synchronous, if 0, it's random.
47  */
48 #define PATTERN_FLAG 0
49 #define IO_SEQ 0 << PATTERN_FLAG
50 #define IO_RAND 1 << PATTERN_FLAG
51
52 /*
53  * Verify mode occupies second flag bit.
54  * If 1, it uses metadata for verification, if 0, it's off.
55  */
56 #define VERIFY_FLAG 1
57 #define VERIFY_NO 0 << VERIFY_FLAG
58 #define VERIFY_META 1 << VERIFY_FLAG
59
60 /*
61  * The benchark ID (IDLEN) is global for the test, calculated once and is a
62  * string of the following form: {"bench-" + 9-digit number + "\0"}.
63  * The target string (TARGETLEN) is per object, concatenated with the string
64  * above and is of the following form: {"-" +16-digit number + "\0"}.
65  */
66 #define IDLEN 16
67 #define TARGETLEN (IDLEN + 17)
68 extern char global_id[IDLEN];
69
70 struct bench {
71         uint64_t to; //Total number of objects (not for read/write)
72         uint64_t ts; //Total I/O size
73         uint64_t os; //Object size
74         uint64_t bs; //Block size
75         uint64_t max_requests; //Max number of requests for a benchmark
76         uint32_t iodepth; //Num of in-flight xseg reqs
77         int insanity;
78         xport dst_port;
79         xport src_port;
80         uint32_t op;    //xseg operation
81         uint8_t flags;
82         struct peerd *peer;
83         struct bench_lfsr *lfsr;
84         struct timer *total_tm; //Total time for benchmark
85         struct timer *get_tm;   //Time for xseg_get_request
86         struct timer *sub_tm;   //Time for xseg_submit_request
87         struct timer *rec_tm;   //Time for xseg_receive_request
88 };
89
90 /*
91  * Custom timespec. Made to calculate variance, where we need the square of a
92  * timespec struct. This struct should be more than enough to hold the square
93  * of the biggest timespec.
94  */
95 struct timespec2 {
96         unsigned long tv_sec2;
97         uint64_t tv_nsec2;
98 };
99
100 /*
101  * struct timer fields
102  * ====================
103  * completed: number of completed requests
104  * start_time: submission time of a request
105  * sum: the sum of elapsed times of every completed request
106  * sum_sq: the sum of the squares of elapsed times
107  * insanity: benchmarking level, higher means that the request associated with
108  *           this timer is more trivial.
109  */
110 struct timer {
111         struct timespec sum;
112         struct timespec2 sum_sq;
113         struct timespec start_time;
114         uint64_t completed;
115         int insanity;
116 };
117
118 struct tm_result {
119         unsigned int s;
120         unsigned int ms;
121         unsigned int us;
122         unsigned int ns;
123 };
124
125 /* FILLME */
126 struct signature {
127         char obj_name[TARGETLEN];
128         uint64_t offset;
129         uint64_t size;
130
131         //hash of data (heavy)
132 };
133
134
135 int custom_peerd_loop(void *arg);
136
137 void timer_start(struct bench *prefs, struct timer *sample_req);
138 void timer_stop(struct bench *prefs, struct timer *sample_tm,
139                 struct timespec *start);
140 int init_timer(struct timer **tm, int insanity);
141 uint64_t str2num(char *str);
142 int read_op(char *op);
143 int read_pattern(char *pattern);
144 int read_insanity(char *insanity);
145 int read_verify(char *insanity);
146 void print_res(struct bench *prefs, struct timer *tm, char *type);
147 void print_stats(struct bench *prefs);
148 void create_target(struct bench *prefs, struct xseg_request *req,
149                 uint64_t new);
150 void create_chunk(struct bench *prefs, struct xseg_request *req,
151                 uint64_t new);
152 uint64_t determine_next(struct bench *prefs);
153 void create_id(unsigned long seed);
154