-
Notifications
You must be signed in to change notification settings - Fork 42
/
test_simple.c
576 lines (483 loc) · 16.8 KB
/
test_simple.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
/*
* File: test_simple.c
* Author: Vasileios Trigonakis <[email protected]>
* Description:
* test_simple.c is part of ASCYLIB
*
* Copyright (c) 2014 Vasileios Trigonakis <[email protected]>,
* Tudor David <[email protected]>
* Distributed Programming Lab (LPD), EPFL
*
* ASCYLIB is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 2
* of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <assert.h>
#include <getopt.h>
#include <limits.h>
#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sched.h>
#include <inttypes.h>
#include <sys/time.h>
#include <unistd.h>
#include <malloc.h>
#include "utils.h"
#include "atomic_ops.h"
#include "rapl_read.h"
#ifdef __sparc__
# include <sys/types.h>
# include <sys/processor.h>
# include <sys/procset.h>
#endif
#include "intset.h"
/* ################################################################### *
* Definition of macros: per data structure
* ################################################################### */
#define DS_CONTAINS(s,k,t) mstack_contains(s, k)
#define DS_ADD(s,k,t) mstack_add(s, k, t)
#define DS_REMOVE(s) mstack_remove(s)
#define DS_SIZE(s) mstack_size(s)
#define DS_NEW() mstack_new()
#define DS_TYPE mstack_t
#define DS_NODE mstack_node_t
/* ################################################################### *
* GLOBALS
* ################################################################### */
RETRY_STATS_VARS_GLOBAL;
size_t initial = DEFAULT_INITIAL;
size_t range = DEFAULT_RANGE;
size_t update = 100;
size_t load_factor;
size_t num_threads = DEFAULT_NB_THREADS;
size_t duration = DEFAULT_DURATION;
size_t print_vals_num = 100;
size_t pf_vals_num = 1023;
size_t put, put_explicit = false;
double update_rate, put_rate, get_rate;
size_t size_after = 0;
int seed = 0;
__thread unsigned long * seeds;
uint32_t rand_max;
#define rand_min 1
static volatile int stop;
TEST_VARS_GLOBAL;
volatile ticks *putting_succ;
volatile ticks *putting_fail;
volatile ticks *getting_succ;
volatile ticks *getting_fail;
volatile ticks *removing_succ;
volatile ticks *removing_fail;
volatile ticks *putting_count;
volatile ticks *putting_count_succ;
volatile ticks *getting_count;
volatile ticks *getting_count_succ;
volatile ticks *removing_count;
volatile ticks *removing_count_succ;
volatile ticks *total;
/* ################################################################### *
* LOCALS
* ################################################################### */
#ifdef DEBUG
extern __thread uint32_t put_num_restarts;
extern __thread uint32_t put_num_failed_expand;
extern __thread uint32_t put_num_failed_on_new;
#endif
barrier_t barrier, barrier_global;
typedef struct thread_data
{
uint32_t id;
DS_TYPE* set;
} thread_data_t;
void*
test(void* thread)
{
thread_data_t* td = (thread_data_t*) thread;
uint32_t ID = td->id;
set_cpu(ID);
ssalloc_init();
DS_TYPE* set = td->set;
THREAD_INIT(ID);
PF_INIT(3, SSPFD_NUM_ENTRIES, ID);
#if defined(COMPUTE_LATENCY)
volatile ticks my_putting_succ = 0;
volatile ticks my_putting_fail = 0;
volatile ticks my_getting_succ = 0;
volatile ticks my_getting_fail = 0;
volatile ticks my_removing_succ = 0;
volatile ticks my_removing_fail = 0;
#endif
uint64_t my_putting_count = 0;
uint64_t my_getting_count = 0;
uint64_t my_removing_count = 0;
uint64_t my_putting_count_succ = 0;
uint64_t my_getting_count_succ = 0;
uint64_t my_removing_count_succ = 0;
#if defined(COMPUTE_LATENCY) && PFD_TYPE == 0
volatile ticks start_acq, end_acq;
volatile ticks correction = getticks_correction_calc();
#endif
seeds = seed_rand();
#if GC == 1
alloc = (ssmem_allocator_t*) malloc(sizeof(ssmem_allocator_t));
assert(alloc != NULL);
ssmem_alloc_init_fs_size(alloc, SSMEM_DEFAULT_MEM_SIZE, SSMEM_GC_FREE_SET_SIZE, ID);
#endif
RR_INIT(phys_id);
barrier_cross(&barrier);
uint64_t key;
int c = 0;
uint32_t scale_rem = (uint32_t) (update_rate * UINT_MAX);
uint32_t scale_put = (uint32_t) (put_rate * UINT_MAX);
int i;
uint32_t num_elems_thread = (uint32_t) (initial / num_threads);
int32_t missing = (uint32_t) initial - (num_elems_thread * num_threads);
if (ID < missing)
{
num_elems_thread++;
}
#if INITIALIZE_FROM_ONE == 1
num_elems_thread = (ID == 0) * initial;
#endif
for(i = 0; i < num_elems_thread; i++)
{
key = (my_random(&(seeds[0]), &(seeds[1]), &(seeds[2])) % (rand_max + 1)) + rand_min;
if(DS_ADD(set, key, key) == false)
{
i--;
}
}
MEM_BARRIER;
barrier_cross(&barrier);
if (!ID)
{
printf("#BEFORE size is: %zu\n", (size_t) DS_SIZE(set));
}
RETRY_STATS_ZERO();
barrier_cross(&barrier_global);
RR_START_SIMPLE();
while (stop == 0)
{
TEST_LOOP_ONLY_UPDATES();
}
barrier_cross(&barrier);
RR_STOP_SIMPLE();
if (!ID)
{
size_after = DS_SIZE(set);
printf("#AFTER size is: %zu\n", size_after);
}
barrier_cross(&barrier);
#if defined(COMPUTE_LATENCY)
putting_succ[ID] += my_putting_succ;
putting_fail[ID] += my_putting_fail;
getting_succ[ID] += my_getting_succ;
getting_fail[ID] += my_getting_fail;
removing_succ[ID] += my_removing_succ;
removing_fail[ID] += my_removing_fail;
#endif
putting_count[ID] += my_putting_count;
getting_count[ID] += my_getting_count;
removing_count[ID]+= my_removing_count;
putting_count_succ[ID] += my_putting_count_succ;
getting_count_succ[ID] += my_getting_count_succ;
removing_count_succ[ID]+= my_removing_count_succ;
OPTIK_STATS_PUBLISH();
EXEC_IN_DEC_ID_ORDER(ID, num_threads)
{
print_latency_stats(ID, SSPFD_NUM_ENTRIES, print_vals_num);
RETRY_STATS_SHARE();
}
EXEC_IN_DEC_ID_ORDER_END(&barrier);
SSPFDTERM();
#if GC == 1
ssmem_term();
free(alloc);
#endif
THREAD_END();
pthread_exit(NULL);
}
OPTIK_STATS_VARS_DEFINITION();
int
main(int argc, char **argv)
{
set_cpu(0);
ssalloc_init();
seeds = seed_rand();
struct option long_options[] = {
// These options don't set a flag
{"help", no_argument, NULL, 'h'},
{"duration", required_argument, NULL, 'd'},
{"initial-size", required_argument, NULL, 'i'},
{"num-threads", required_argument, NULL, 'n'},
{"range", required_argument, NULL, 'r'},
{"update-rate", required_argument, NULL, 'u'},
{"num-buckets", required_argument, NULL, 'b'},
{"print-vals", required_argument, NULL, 'v'},
{"vals-pf", required_argument, NULL, 'f'},
{NULL, 0, NULL, 0}
};
int i, c;
while(1)
{
i = 0;
c = getopt_long(argc, argv, "hAf:d:i:n:r:s:u:m:a:l:p:b:v:f:", long_options, &i);
if(c == -1)
break;
if(c == 0 && long_options[i].flag == 0)
c = long_options[i].val;
switch(c)
{
case 0:
/* Flag is automatically set */
break;
case 'h':
printf("ASCYLIB -- stress test "
"\n"
"\n"
"Usage:\n"
" %s [options...]\n"
"\n"
"Options:\n"
" -h, --help\n"
" Print this message\n"
" -d, --duration <int>\n"
" Test duration in milliseconds\n"
" -i, --initial-size <int>\n"
" Number of elements to insert before test\n"
" -n, --num-threads <int>\n"
" Number of threads\n"
" -r, --range <int>\n"
" Range of integer values inserted in set\n"
" -u, --update-rate <int>\n"
" Percentage of update transactions\n"
" -p, --put-rate <int>\n"
" Percentage of put update transactions (should be less than percentage of updates)\n"
" -b, --num-buckets <int>\n"
" Number of initial buckets (stronger than -l)\n"
" -v, --print-vals <int>\n"
" When using detailed profiling, how many values to print.\n"
" -f, --val-pf <int>\n"
" When using detailed profiling, how many values to keep track of.\n"
, argv[0]);
exit(0);
case 'd':
duration = atoi(optarg);
break;
case 'i':
initial = atoi(optarg);
break;
case 'n':
num_threads = atoi(optarg);
break;
case 'r':
range = atol(optarg);
break;
case 'u':
update = atoi(optarg);
break;
case 'p':
put_explicit = 1;
put = atoi(optarg);
break;
case 'l':
load_factor = atoi(optarg);
break;
case 'v':
print_vals_num = atoi(optarg);
break;
case 'f':
pf_vals_num = pow2roundup(atoi(optarg)) - 1;
break;
case '?':
default:
printf("Use -h or --help for help\n");
exit(1);
}
}
if (!is_power_of_two(initial))
{
size_t initial_pow2 = pow2roundup(initial);
printf("** rounding up initial (to make it power of 2): old: %zu / new: %zu\n", initial, initial_pow2);
initial = initial_pow2;
}
if (range < initial)
{
range = 2 * initial;
}
printf("## Initial: %zu / Range: %zu / ", initial, range);
printf("OPTIK algorithm\n");
double kb = initial * sizeof(DS_NODE) / 1024.0;
double mb = kb / 1024.0;
printf("Sizeof initial: %.2f KB = %.2f MB\n", kb, mb);
if (!is_power_of_two(range))
{
size_t range_pow2 = pow2roundup(range);
printf("** rounding up range (to make it power of 2): old: %zu / new: %zu\n", range, range_pow2);
range = range_pow2;
}
if (put > update)
{
put = update;
}
update_rate = update / 100.0;
if (put_explicit)
{
put_rate = put / 100.0;
}
else
{
put_rate = update_rate / 2;
}
get_rate = 1 - update_rate;
/* printf("num_threads = %u\n", num_threads); */
/* printf("cap: = %u\n", num_buckets); */
/* printf("num elem = %u\n", num_elements); */
/* printf("filing rate= %f\n", filling_rate); */
/* printf("update = %f (putting = %f)\n", update_rate, put_rate); */
rand_max = range - 1;
struct timeval start, end;
struct timespec timeout;
timeout.tv_sec = duration / 1000;
timeout.tv_nsec = (duration % 1000) * 1000000;
stop = 0;
DS_TYPE* set = DS_NEW();
assert(set != NULL);
/* Initializes the local data */
putting_succ = (ticks *) calloc(num_threads , sizeof(ticks));
putting_fail = (ticks *) calloc(num_threads , sizeof(ticks));
getting_succ = (ticks *) calloc(num_threads , sizeof(ticks));
getting_fail = (ticks *) calloc(num_threads , sizeof(ticks));
removing_succ = (ticks *) calloc(num_threads , sizeof(ticks));
removing_fail = (ticks *) calloc(num_threads , sizeof(ticks));
putting_count = (ticks *) calloc(num_threads , sizeof(ticks));
putting_count_succ = (ticks *) calloc(num_threads , sizeof(ticks));
getting_count = (ticks *) calloc(num_threads , sizeof(ticks));
getting_count_succ = (ticks *) calloc(num_threads , sizeof(ticks));
removing_count = (ticks *) calloc(num_threads , sizeof(ticks));
removing_count_succ = (ticks *) calloc(num_threads , sizeof(ticks));
pthread_t threads[num_threads];
pthread_attr_t attr;
int rc;
void *status;
barrier_init(&barrier_global, num_threads + 1);
barrier_init(&barrier, num_threads);
/* Initialize and set thread detached attribute */
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
thread_data_t* tds = (thread_data_t*) malloc(num_threads * sizeof(thread_data_t));
long t;
for(t = 0; t < num_threads; t++)
{
tds[t].id = t;
tds[t].set = set;
rc = pthread_create(&threads[t], &attr, test, tds + t);
if (rc)
{
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
/* Free attribute and wait for the other threads */
pthread_attr_destroy(&attr);
barrier_cross(&barrier_global);
gettimeofday(&start, NULL);
nanosleep(&timeout, NULL);
stop = 1;
gettimeofday(&end, NULL);
duration = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000);
for(t = 0; t < num_threads; t++)
{
rc = pthread_join(threads[t], &status);
if (rc)
{
printf("ERROR; return code from pthread_join() is %d\n", rc);
exit(-1);
}
}
free(tds);
volatile ticks putting_suc_total = 0;
volatile ticks putting_fal_total = 0;
volatile ticks getting_suc_total = 0;
volatile ticks getting_fal_total = 0;
volatile ticks removing_suc_total = 0;
volatile ticks removing_fal_total = 0;
volatile uint64_t putting_count_total = 0;
volatile uint64_t putting_count_total_succ = 0;
volatile uint64_t getting_count_total = 0;
volatile uint64_t getting_count_total_succ = 0;
volatile uint64_t removing_count_total = 0;
volatile uint64_t removing_count_total_succ = 0;
for(t=0; t < num_threads; t++)
{
PRINT_OPS_PER_THREAD();
putting_suc_total += putting_succ[t];
putting_fal_total += putting_fail[t];
getting_suc_total += getting_succ[t];
getting_fal_total += getting_fail[t];
removing_suc_total += removing_succ[t];
removing_fal_total += removing_fail[t];
putting_count_total += putting_count[t];
putting_count_total_succ += putting_count_succ[t];
getting_count_total += getting_count[t];
getting_count_total_succ += getting_count_succ[t];
removing_count_total += removing_count[t];
removing_count_total_succ += removing_count_succ[t];
}
#if defined(COMPUTE_LATENCY)
printf("#thread srch_suc srch_fal insr_suc insr_fal remv_suc remv_fal ## latency (in cycles) \n"); fflush(stdout);
long unsigned get_suc = (getting_count_total_succ) ? getting_suc_total / getting_count_total_succ : 0;
long unsigned get_fal = (getting_count_total - getting_count_total_succ) ? getting_fal_total / (getting_count_total - getting_count_total_succ) : 0;
long unsigned put_suc = putting_count_total_succ ? putting_suc_total / putting_count_total_succ : 0;
long unsigned put_fal = (putting_count_total - putting_count_total_succ) ? putting_fal_total / (putting_count_total - putting_count_total_succ) : 0;
long unsigned rem_suc = removing_count_total_succ ? removing_suc_total / removing_count_total_succ : 0;
long unsigned rem_fal = (removing_count_total - removing_count_total_succ) ? removing_fal_total / (removing_count_total - removing_count_total_succ) : 0;
printf("%-7zu %-8lu %-8lu %-8lu %-8lu %-8lu %-8lu\n", num_threads, get_suc, get_fal, put_suc, put_fal, rem_suc, rem_fal);
#endif
#define LLU long long unsigned int
int UNUSED pr = (int) (putting_count_total_succ - removing_count_total_succ);
if (size_after != (initial + pr))
{
printf("// WRONG size. %zu + %d != %zu\n", initial, pr, size_after);
assert(size_after == (initial + pr));
}
printf(" : %-10s | %-10s | %-11s | %-11s | %s\n", "total", "success", "succ %", "total %", "effective %");
uint64_t total = putting_count_total + getting_count_total + removing_count_total;
double putting_perc = 100.0 * (1 - ((double)(total - putting_count_total) / total));
double putting_perc_succ = (1 - (double) (putting_count_total - putting_count_total_succ) / putting_count_total) * 100;
double getting_perc = 100.0 * (1 - ((double)(total - getting_count_total) / total));
double getting_perc_succ = (1 - (double) (getting_count_total - getting_count_total_succ) / getting_count_total) * 100;
double removing_perc = 100.0 * (1 - ((double)(total - removing_count_total) / total));
double removing_perc_succ = (1 - (double) (removing_count_total - removing_count_total_succ) / removing_count_total) * 100;
printf("srch: %-10llu | %-10llu | %10.1f%% | %10.1f%% | \n", (LLU) getting_count_total,
(LLU) getting_count_total_succ, getting_perc_succ, getting_perc);
printf("insr: %-10llu | %-10llu | %10.1f%% | %10.1f%% | %10.1f%%\n", (LLU) putting_count_total,
(LLU) putting_count_total_succ, putting_perc_succ, putting_perc, (putting_perc * putting_perc_succ) / 100);
printf("rems: %-10llu | %-10llu | %10.1f%% | %10.1f%% | %10.1f%%\n", (LLU) removing_count_total,
(LLU) removing_count_total_succ, removing_perc_succ, removing_perc, (removing_perc * removing_perc_succ) / 100);
double throughput = (putting_count_total + getting_count_total + removing_count_total) * 1000.0 / duration;
printf("#txs %zu\t(%-10.0f\n", num_threads, throughput);
printf("#Mops %.3f\n", throughput / 1e6);
OPTIK_STATS_PRINT();
RR_PRINT_UNPROTECTED(RAPL_PRINT_POW);
RR_PRINT_CORRECTED();
RETRY_STATS_PRINT(total, putting_count_total, removing_count_total, putting_count_total_succ + removing_count_total_succ);
LATENCY_DISTRIBUTION_PRINT();
pthread_exit(NULL);
return 0;
}