Skip to content

Commit f651616

Browse files
Florian Westphaldavem330
authored andcommitted
test_rhashtable: don't use global entries variable
pass the entries to test as an argument instead. Followup patch will add an rhlist test case; rhlist delete opererations are slow so we need to use a smaller number to test it. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7e936bd commit f651616

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

lib/test_rhashtable.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
#define MAX_ENTRIES 1000000
2929
#define TEST_INSERT_FAIL INT_MAX
3030

31-
static int entries = 50000;
32-
module_param(entries, int, 0);
33-
MODULE_PARM_DESC(entries, "Number of entries to add (default: 50000)");
31+
static int parm_entries = 50000;
32+
module_param(parm_entries, int, 0);
33+
MODULE_PARM_DESC(parm_entries, "Number of entries to add (default: 50000)");
3434

3535
static int runs = 4;
3636
module_param(runs, int, 0);
@@ -67,6 +67,7 @@ struct test_obj {
6767
};
6868

6969
struct thread_data {
70+
unsigned int entries;
7071
int id;
7172
struct task_struct *task;
7273
struct test_obj *objs;
@@ -105,11 +106,12 @@ static int insert_retry(struct rhashtable *ht, struct test_obj *obj,
105106
return err ? : retries;
106107
}
107108

108-
static int __init test_rht_lookup(struct rhashtable *ht, struct test_obj *array)
109+
static int __init test_rht_lookup(struct rhashtable *ht, struct test_obj *array,
110+
unsigned int entries)
109111
{
110112
unsigned int i;
111113

112-
for (i = 0; i < entries * 2; i++) {
114+
for (i = 0; i < entries; i++) {
113115
struct test_obj *obj;
114116
bool expected = !(i % 2);
115117
struct test_obj_val key = {
@@ -142,7 +144,7 @@ static int __init test_rht_lookup(struct rhashtable *ht, struct test_obj *array)
142144
return 0;
143145
}
144146

145-
static void test_bucket_stats(struct rhashtable *ht)
147+
static void test_bucket_stats(struct rhashtable *ht, unsigned int entries)
146148
{
147149
unsigned int err, total = 0, chain_len = 0;
148150
struct rhashtable_iter hti;
@@ -184,7 +186,8 @@ static void test_bucket_stats(struct rhashtable *ht)
184186
pr_warn("Test failed: Total count mismatch ^^^");
185187
}
186188

187-
static s64 __init test_rhashtable(struct rhashtable *ht, struct test_obj *array)
189+
static s64 __init test_rhashtable(struct rhashtable *ht, struct test_obj *array,
190+
unsigned int entries)
188191
{
189192
struct test_obj *obj;
190193
int err;
@@ -212,12 +215,12 @@ static s64 __init test_rhashtable(struct rhashtable *ht, struct test_obj *array)
212215
pr_info(" %u insertions retried due to memory pressure\n",
213216
insert_retries);
214217

215-
test_bucket_stats(ht);
218+
test_bucket_stats(ht, entries);
216219
rcu_read_lock();
217-
test_rht_lookup(ht, array);
220+
test_rht_lookup(ht, array, entries);
218221
rcu_read_unlock();
219222

220-
test_bucket_stats(ht);
223+
test_bucket_stats(ht, entries);
221224

222225
pr_info(" Deleting %d keys\n", entries);
223226
for (i = 0; i < entries; i++) {
@@ -245,6 +248,7 @@ static struct rhashtable ht;
245248

246249
static int thread_lookup_test(struct thread_data *tdata)
247250
{
251+
unsigned int entries = tdata->entries;
248252
int i, err = 0;
249253

250254
for (i = 0; i < entries; i++) {
@@ -281,7 +285,7 @@ static int threadfunc(void *data)
281285
if (down_interruptible(&startup_sem))
282286
pr_err(" thread[%d]: down_interruptible failed\n", tdata->id);
283287

284-
for (i = 0; i < entries; i++) {
288+
for (i = 0; i < tdata->entries; i++) {
285289
tdata->objs[i].value.id = i;
286290
tdata->objs[i].value.tid = tdata->id;
287291
err = insert_retry(&ht, &tdata->objs[i], test_rht_params);
@@ -305,7 +309,7 @@ static int threadfunc(void *data)
305309
}
306310

307311
for (step = 10; step > 0; step--) {
308-
for (i = 0; i < entries; i += step) {
312+
for (i = 0; i < tdata->entries; i += step) {
309313
if (tdata->objs[i].value.id == TEST_INSERT_FAIL)
310314
continue;
311315
err = rhashtable_remove_fast(&ht, &tdata->objs[i].node,
@@ -336,12 +340,16 @@ static int threadfunc(void *data)
336340

337341
static int __init test_rht_init(void)
338342
{
343+
unsigned int entries;
339344
int i, err, started_threads = 0, failed_threads = 0;
340345
u64 total_time = 0;
341346
struct thread_data *tdata;
342347
struct test_obj *objs;
343348

344-
entries = min(entries, MAX_ENTRIES);
349+
if (parm_entries < 0)
350+
parm_entries = 1;
351+
352+
entries = min(parm_entries, MAX_ENTRIES);
345353

346354
test_rht_params.automatic_shrinking = shrinking;
347355
test_rht_params.max_size = max_size ? : roundup_pow_of_two(entries);
@@ -367,7 +375,7 @@ static int __init test_rht_init(void)
367375
continue;
368376
}
369377

370-
time = test_rhashtable(&ht, objs);
378+
time = test_rhashtable(&ht, objs, entries);
371379
rhashtable_destroy(&ht);
372380
if (time < 0) {
373381
vfree(objs);
@@ -409,6 +417,7 @@ static int __init test_rht_init(void)
409417
}
410418
for (i = 0; i < tcount; i++) {
411419
tdata[i].id = i;
420+
tdata[i].entries = entries;
412421
tdata[i].objs = objs + i * entries;
413422
tdata[i].task = kthread_run(threadfunc, &tdata[i],
414423
"rhashtable_thrad[%d]", i);

0 commit comments

Comments
 (0)