-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_list.c
77 lines (64 loc) · 1.75 KB
/
test_list.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
#include "test.h"
#include "list.h"
#include "mr.h"
#include "random.h"
#include "allocator.h"
#include <stdio.h>
void testloop_body()
{
uint8_t n_search = 100 - n_update;
const int n = 100;
/* Get all our randomness out of r and split it up.
* Should have enough bits
*/
unsigned long r;
unsigned long action;
unsigned long ins_del;
unsigned long arange = 101;
unsigned long amask = (1 << 10) - 1;
long key;
struct list *l = (struct list*)global_ds;
for (int i = 0; i < n; ++i) {
r = Random();
ins_del = r & 1;
r >>= 1;
action = ((r & amask) % arange);
r >>= 10;
key = r % n_keys;
if (action <= n_search) {
search(l, key);
} else if (ins_del == 0) {
delete(l, key);
} else {
insert(l, key);
}
}
/* Record another n operations. */
threads[thread_id].ops += n;
}
void setup_test(int argc, char **argv)
{
if (argc != 5) {
fprintf(stderr, "Usage: %s: nmilli update_percent nelements nthreads\n",
argv[0]);
exit(-1);
}
n_ms = (uint32_t)atoi(argv[1]);
n_update = (uint8_t)atoi(argv[2]);
n_elements = (uint32_t)atoi(argv[3]);
n_threads = (uint32_t)atoi(argv[4]);
n_keys = n_elements * 2;
/* Initialize the random number generator. */
init_Random();
/* Initialize exponential backoff system. */
backoff_init();
/* Initialize the allocator. */
init_allocator();
/* Initialize the memory reclamation scheme. */
mr_init();
/* Initialize data_structure. */
list_init((struct list**)&global_ds);
for (uint32_t i = 0, j = 0; i < n_elements; i++, j += 2) {
insert((struct list*)global_ds, j);
}
}