151
151
static void deinit_cht(const bench_info_t *b, void *p);
152
152
static size_t rcu_upd_cht(bench_loop_input_t *in);
154
static size_t s_lookup_ht(bench_loop_input_t *in);
155
static size_t bkt_s_lookup_ht(bench_loop_input_t *in);
156
static size_t rcu_lookup_cht(bench_loop_input_t *in);
155
159
static size_t shift_loop(bench_loop_input_t *input);
156
160
static size_t div_127_loop(bench_loop_input_t *input);
251
255
.desc = "Updates a hash table protected by a spinlock/bucket."
261
.name = "cht-lookup-rcu",
262
.desc = "Looks up keys in a CHT protected by rcu."
268
.name = "ht-lookup-s-lock",
269
.desc = "Looks up keys in a hash table protected by a spinlock."
272
.f = bkt_s_lookup_ht,
275
.name = "ht-upd-bkt-lock",
276
.desc = "Looks up keys in a hash table protected by a spinlock/bucket."
255
280
.ctor = init_nop_bench,
256
281
.dtor = deinit_nop_bench,
1449
1474
/*-------------------------------------------------------------------*/
1476
static inline size_t s_lookup_ht_kernel(ht_upd_t *data, size_t id, size_t k,
1479
link_t *item = hash_table_find(&data->ht, &key);
1482
ASSERT(data->inserted_bitmap[id][k]);
1483
ht_elem_t *e = member_to_inst(item, ht_elem_t, ht_link);
1484
ASSERT(e->key == key);
1487
ASSERT(!data->inserted_bitmap[id][k]);
1492
static size_t s_lookup_ht(bench_loop_input_t *in)
1494
ht_upd_t *data = (ht_upd_t*)in->data;
1496
/* Sum keys in the hash table a store the result in dummy. */
1499
for (size_t loops = 0; loops < default_loop_cnt ; ++loops) {
1500
in->seed = next_rand(in->seed);
1501
size_t k = in->seed % data->key_cnt_per_thr;
1502
size_t key = (k << 8) + in->id;
1504
spinlock_lock(&data->bktlock[0]);
1506
dummy += s_lookup_ht_kernel(data, in->id, k, key);
1508
spinlock_unlock(&data->bktlock[0]);
1510
/* Use the dummy total to prevent the compiler from removing the loop. */
1512
return default_loop_cnt;
1515
static size_t bkt_s_lookup_ht(bench_loop_input_t *in)
1517
ht_upd_t *data = (ht_upd_t*)in->data;
1519
/* Sum keys in the hash table a store the result in dummy. */
1522
for (size_t loops = 0; loops < default_loop_cnt ; ++loops) {
1523
in->seed = next_rand(in->seed);
1524
size_t k = in->seed % data->key_cnt_per_thr;
1525
size_t key = (k << 8) + in->id;
1526
size_t bkt = key % ht_bucket_cnt;
1528
spinlock_lock(&data->bktlock[bkt]);
1530
dummy += s_lookup_ht_kernel(data, in->id, k, key);
1532
spinlock_unlock(&data->bktlock[bkt]);
1534
/* Use the dummy total to prevent the compiler from removing the loop. */
1536
return default_loop_cnt;
1540
static size_t rcu_lookup_cht(bench_loop_input_t *in)
1542
ht_upd_t *data = (ht_upd_t*)in->data;
1544
/* Sum keys in the hash table a store the result in dummy. */
1547
for (size_t loops = 0; loops < default_loop_cnt ; ++loops) {
1548
in->seed = next_rand(in->seed);
1549
size_t k = in->seed % data->key_cnt_per_thr;
1550
size_t key = (k << 8) + in->id;
1552
/* Update the table - add *or* remove one item. */
1554
//spinlock_lock(&data->slock);
1556
cht_link_t *item = cht_find_lazy(&data->cht, &key);
1557
//cht_link_t *item = cht_find(&data->cht, &key);
1560
ASSERT(data->inserted_bitmap[in->id][k]);
1561
ht_elem_t *e = member_to_inst(item, ht_elem_t, cht_link);
1562
ASSERT(e->key == key);
1565
ASSERT(!data->inserted_bitmap[in->id][k]);
1568
//spinlock_unlock(&data->slock);
1571
/* Use the dummy total to prevent the compiler from removing the loop. */
1573
return default_loop_cnt;
1450
1576
/*-------------------------------------------------------------------*/
1451
1577
/*-------------------------------------------------------------------*/