-
Notifications
You must be signed in to change notification settings - Fork 0
/
silotpcc.cc
146 lines (120 loc) · 3.51 KB
/
silotpcc.cc
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
#define CONFIG_H "config/config-perf.h"
#define NDB_MASSTREE 1
#define NO_MYSQL 1
#define USE_JEMALLOC 1
#include <masstree/config.h>
#include <map>
#include <vector>
#include <benchmarks/bench.h>
#include <benchmarks/ndb_wrapper.h>
#include <benchmarks/ndb_wrapper_impl.h>
#include "silotpcc.h"
using namespace std;
// These are hacks to access protected members of classes defined in silo
class tpcc_bench_runner : public bench_runner
{
public:
tpcc_bench_runner(abstract_db *db);
vector<bench_loader*> make_loaders(void);
vector<bench_worker*> make_workers(void);
map<string, vector<abstract_ordered_index *>> partitions;
};
class my_bench_runner : public tpcc_bench_runner
{
public:
my_bench_runner(abstract_db *db) : tpcc_bench_runner(db) { }
vector<bench_loader*> call_make_loaders(void)
{
return make_loaders();
}
vector<bench_worker*> call_make_workers(void)
{
return make_workers();
}
};
class my_bench_worker : public bench_worker
{
public:
unsigned int get_worker_id(void)
{
return worker_id;
}
util::fast_random *get_r(void)
{
return &r;
}
void call_on_run_setup(void)
{
on_run_setup();
}
};
static abstract_db *db;
static my_bench_runner *runner;
static vector<my_bench_worker *> workers;
extern "C" {
int silotpcc_exec_one(int thread_id)
{
auto worker = workers[thread_id];
auto workload = worker->get_workload();
double d = worker->get_r()->next_uniform();
for (size_t i = 0; i < workload.size(); i++) {
if ((i + 1) == workload.size() || d < workload[i].frequency) {
workload[i].fn(worker);
break;
}
d -= workload[i].frequency;
}
return 1;
}
int silotpcc_init(int number_threads, long numa_memory_)
{
nthreads = number_threads;
scale_factor = number_threads;
pin_cpus = 1;
verbose = 1;
long numa_memory = numa_memory_;
size_t maxpercpu = util::iceil(numa_memory / nthreads, ::allocator::GetHugepageSize());
::allocator::Initialize(nthreads, maxpercpu);
vector<string> logfiles;
vector<vector<unsigned>> assignments;
int nofsync = 0;
int do_compress = 0;
int fake_writes = 0;
db = new ndb_wrapper<transaction_proto2>(logfiles, assignments, !nofsync, do_compress, fake_writes);
ALWAYS_ASSERT(!transaction_proto2_static::get_hack_status());
runner = new my_bench_runner(db);
// Copy-paste from benchmarks/bench.cc:168
const vector<bench_loader *> loaders = runner->call_make_loaders();
spin_barrier b(loaders.size());
for (vector<bench_loader *>::const_iterator it = loaders.begin(); it != loaders.end(); ++it) {
(*it)->set_barrier(b);
(*it)->start();
}
for (vector<bench_loader *>::const_iterator it = loaders.begin(); it != loaders.end(); ++it)
(*it)->join();
db->do_txn_epoch_sync();
auto persisted_info = db->get_ntxn_persisted();
assert(get<0>(persisted_info) == get<1>(persisted_info));
db->reset_ntxn_persisted();
persisted_info = db->get_ntxn_persisted();
ALWAYS_ASSERT(get<0>(persisted_info) == 0 && get<1>(persisted_info) == 0 && get<2>(persisted_info) == 0.0);
// This is a hack to access protected members of classes defined in silo
for (auto w: runner->call_make_workers())
workers.push_back((my_bench_worker *) w);
return 0;
}
// Hack to access private field coreid::tl_core_id
extern __thread int _ZN6coreid10tl_core_idE;
void silotpcc_init_thread(int thread_id)
{
auto worker = workers[thread_id];
// Hack because the first thread of the program becomes a worker
_ZN6coreid10tl_core_idE = -1;
// Copy-paste from benchmarks/bench.cc:112
coreid::set_core_id(worker->get_worker_id());
{
scoped_rcu_region r;
}
worker->call_on_run_setup();
}
}