28
28
#define MAX_ENTRIES 1000000
29
29
#define TEST_INSERT_FAIL INT_MAX
30
30
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)" );
34
34
35
35
static int runs = 4 ;
36
36
module_param (runs , int , 0 );
@@ -67,6 +67,7 @@ struct test_obj {
67
67
};
68
68
69
69
struct thread_data {
70
+ unsigned int entries ;
70
71
int id ;
71
72
struct task_struct * task ;
72
73
struct test_obj * objs ;
@@ -105,11 +106,12 @@ static int insert_retry(struct rhashtable *ht, struct test_obj *obj,
105
106
return err ? : retries ;
106
107
}
107
108
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 )
109
111
{
110
112
unsigned int i ;
111
113
112
- for (i = 0 ; i < entries * 2 ; i ++ ) {
114
+ for (i = 0 ; i < entries ; i ++ ) {
113
115
struct test_obj * obj ;
114
116
bool expected = !(i % 2 );
115
117
struct test_obj_val key = {
@@ -142,7 +144,7 @@ static int __init test_rht_lookup(struct rhashtable *ht, struct test_obj *array)
142
144
return 0 ;
143
145
}
144
146
145
- static void test_bucket_stats (struct rhashtable * ht )
147
+ static void test_bucket_stats (struct rhashtable * ht , unsigned int entries )
146
148
{
147
149
unsigned int err , total = 0 , chain_len = 0 ;
148
150
struct rhashtable_iter hti ;
@@ -184,7 +186,8 @@ static void test_bucket_stats(struct rhashtable *ht)
184
186
pr_warn ("Test failed: Total count mismatch ^^^" );
185
187
}
186
188
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 )
188
191
{
189
192
struct test_obj * obj ;
190
193
int err ;
@@ -212,12 +215,12 @@ static s64 __init test_rhashtable(struct rhashtable *ht, struct test_obj *array)
212
215
pr_info (" %u insertions retried due to memory pressure\n" ,
213
216
insert_retries );
214
217
215
- test_bucket_stats (ht );
218
+ test_bucket_stats (ht , entries );
216
219
rcu_read_lock ();
217
- test_rht_lookup (ht , array );
220
+ test_rht_lookup (ht , array , entries );
218
221
rcu_read_unlock ();
219
222
220
- test_bucket_stats (ht );
223
+ test_bucket_stats (ht , entries );
221
224
222
225
pr_info (" Deleting %d keys\n" , entries );
223
226
for (i = 0 ; i < entries ; i ++ ) {
@@ -245,6 +248,7 @@ static struct rhashtable ht;
245
248
246
249
static int thread_lookup_test (struct thread_data * tdata )
247
250
{
251
+ unsigned int entries = tdata -> entries ;
248
252
int i , err = 0 ;
249
253
250
254
for (i = 0 ; i < entries ; i ++ ) {
@@ -281,7 +285,7 @@ static int threadfunc(void *data)
281
285
if (down_interruptible (& startup_sem ))
282
286
pr_err (" thread[%d]: down_interruptible failed\n" , tdata -> id );
283
287
284
- for (i = 0 ; i < entries ; i ++ ) {
288
+ for (i = 0 ; i < tdata -> entries ; i ++ ) {
285
289
tdata -> objs [i ].value .id = i ;
286
290
tdata -> objs [i ].value .tid = tdata -> id ;
287
291
err = insert_retry (& ht , & tdata -> objs [i ], test_rht_params );
@@ -305,7 +309,7 @@ static int threadfunc(void *data)
305
309
}
306
310
307
311
for (step = 10 ; step > 0 ; step -- ) {
308
- for (i = 0 ; i < entries ; i += step ) {
312
+ for (i = 0 ; i < tdata -> entries ; i += step ) {
309
313
if (tdata -> objs [i ].value .id == TEST_INSERT_FAIL )
310
314
continue ;
311
315
err = rhashtable_remove_fast (& ht , & tdata -> objs [i ].node ,
@@ -336,12 +340,16 @@ static int threadfunc(void *data)
336
340
337
341
static int __init test_rht_init (void )
338
342
{
343
+ unsigned int entries ;
339
344
int i , err , started_threads = 0 , failed_threads = 0 ;
340
345
u64 total_time = 0 ;
341
346
struct thread_data * tdata ;
342
347
struct test_obj * objs ;
343
348
344
- entries = min (entries , MAX_ENTRIES );
349
+ if (parm_entries < 0 )
350
+ parm_entries = 1 ;
351
+
352
+ entries = min (parm_entries , MAX_ENTRIES );
345
353
346
354
test_rht_params .automatic_shrinking = shrinking ;
347
355
test_rht_params .max_size = max_size ? : roundup_pow_of_two (entries );
@@ -367,7 +375,7 @@ static int __init test_rht_init(void)
367
375
continue ;
368
376
}
369
377
370
- time = test_rhashtable (& ht , objs );
378
+ time = test_rhashtable (& ht , objs , entries );
371
379
rhashtable_destroy (& ht );
372
380
if (time < 0 ) {
373
381
vfree (objs );
@@ -409,6 +417,7 @@ static int __init test_rht_init(void)
409
417
}
410
418
for (i = 0 ; i < tcount ; i ++ ) {
411
419
tdata [i ].id = i ;
420
+ tdata [i ].entries = entries ;
412
421
tdata [i ].objs = objs + i * entries ;
413
422
tdata [i ].task = kthread_run (threadfunc , & tdata [i ],
414
423
"rhashtable_thrad[%d]" , i );
0 commit comments