diff options
| author | Davidlohr Bueso <dave@stgolabs.net> | 2014-09-12 00:42:25 -0400 |
|---|---|---|
| committer | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2014-09-16 16:41:40 -0400 |
| commit | 630952c22b04ada7e88ad93b87ad893cd818cc6b (patch) | |
| tree | 6510ea291334818a1cfe13272ff576d4f42df1c1 /kernel/locking | |
| parent | 4a3b427f0b27c7e15edfa607524ff012a155337a (diff) | |
locktorture: Introduce torture context
The amount of global variables is getting pretty ugly. Group variables
related to the execution (ie: not parameters) in a new context structure.
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Diffstat (limited to 'kernel/locking')
| -rw-r--r-- | kernel/locking/locktorture.c | 161 |
1 files changed, 82 insertions, 79 deletions
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index 8480118c0ca8..540d5dfe1112 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c | |||
| @@ -66,29 +66,22 @@ torture_param(int, stutter, 5, "Number of jiffies to run/halt test, 0=disable"); | |||
| 66 | torture_param(bool, verbose, true, | 66 | torture_param(bool, verbose, true, |
| 67 | "Enable verbose debugging printk()s"); | 67 | "Enable verbose debugging printk()s"); |
| 68 | 68 | ||
| 69 | static bool debug_lock = false; | ||
| 70 | static char *torture_type = "spin_lock"; | 69 | static char *torture_type = "spin_lock"; |
| 71 | module_param(torture_type, charp, 0444); | 70 | module_param(torture_type, charp, 0444); |
| 72 | MODULE_PARM_DESC(torture_type, | 71 | MODULE_PARM_DESC(torture_type, |
| 73 | "Type of lock to torture (spin_lock, spin_lock_irq, mutex_lock, ...)"); | 72 | "Type of lock to torture (spin_lock, spin_lock_irq, mutex_lock, ...)"); |
| 74 | 73 | ||
| 75 | static atomic_t n_lock_torture_errors; | ||
| 76 | |||
| 77 | static struct task_struct *stats_task; | 74 | static struct task_struct *stats_task; |
| 78 | static struct task_struct **writer_tasks; | 75 | static struct task_struct **writer_tasks; |
| 79 | static struct task_struct **reader_tasks; | 76 | static struct task_struct **reader_tasks; |
| 80 | 77 | ||
| 81 | static int nrealwriters_stress; | ||
| 82 | static bool lock_is_write_held; | 78 | static bool lock_is_write_held; |
| 83 | static int nrealreaders_stress; | ||
| 84 | static bool lock_is_read_held; | 79 | static bool lock_is_read_held; |
| 85 | 80 | ||
| 86 | struct lock_stress_stats { | 81 | struct lock_stress_stats { |
| 87 | long n_lock_fail; | 82 | long n_lock_fail; |
| 88 | long n_lock_acquired; | 83 | long n_lock_acquired; |
| 89 | }; | 84 | }; |
| 90 | static struct lock_stress_stats *lwsa; /* writer statistics */ | ||
| 91 | static struct lock_stress_stats *lrsa; /* reader statistics */ | ||
| 92 | 85 | ||
| 93 | #if defined(MODULE) | 86 | #if defined(MODULE) |
| 94 | #define LOCKTORTURE_RUNNABLE_INIT 1 | 87 | #define LOCKTORTURE_RUNNABLE_INIT 1 |
| @@ -117,8 +110,18 @@ struct lock_torture_ops { | |||
| 117 | const char *name; | 110 | const char *name; |
| 118 | }; | 111 | }; |
| 119 | 112 | ||
| 120 | static struct lock_torture_ops *cur_ops; | 113 | struct lock_torture_cxt { |
| 121 | 114 | int nrealwriters_stress; | |
| 115 | int nrealreaders_stress; | ||
| 116 | bool debug_lock; | ||
| 117 | atomic_t n_lock_torture_errors; | ||
| 118 | struct lock_torture_ops *cur_ops; | ||
| 119 | struct lock_stress_stats *lwsa; /* writer statistics */ | ||
| 120 | struct lock_stress_stats *lrsa; /* reader statistics */ | ||
| 121 | }; | ||
| 122 | static struct lock_torture_cxt cxt = { 0, 0, false, | ||
| 123 | ATOMIC_INIT(0), | ||
| 124 | NULL, NULL}; | ||
| 122 | /* | 125 | /* |
| 123 | * Definitions for lock torture testing. | 126 | * Definitions for lock torture testing. |
| 124 | */ | 127 | */ |
| @@ -134,10 +137,10 @@ static void torture_lock_busted_write_delay(struct torture_random_state *trsp) | |||
| 134 | 137 | ||
| 135 | /* We want a long delay occasionally to force massive contention. */ | 138 | /* We want a long delay occasionally to force massive contention. */ |
| 136 | if (!(torture_random(trsp) % | 139 | if (!(torture_random(trsp) % |
| 137 | (nrealwriters_stress * 2000 * longdelay_us))) | 140 | (cxt.nrealwriters_stress * 2000 * longdelay_us))) |
| 138 | mdelay(longdelay_us); | 141 | mdelay(longdelay_us); |
| 139 | #ifdef CONFIG_PREEMPT | 142 | #ifdef CONFIG_PREEMPT |
| 140 | if (!(torture_random(trsp) % (nrealwriters_stress * 20000))) | 143 | if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000))) |
| 141 | preempt_schedule(); /* Allow test to be preempted. */ | 144 | preempt_schedule(); /* Allow test to be preempted. */ |
| 142 | #endif | 145 | #endif |
| 143 | } | 146 | } |
| @@ -174,13 +177,13 @@ static void torture_spin_lock_write_delay(struct torture_random_state *trsp) | |||
| 174 | * we want a long delay occasionally to force massive contention. | 177 | * we want a long delay occasionally to force massive contention. |
| 175 | */ | 178 | */ |
| 176 | if (!(torture_random(trsp) % | 179 | if (!(torture_random(trsp) % |
| 177 | (nrealwriters_stress * 2000 * longdelay_us))) | 180 | (cxt.nrealwriters_stress * 2000 * longdelay_us))) |
| 178 | mdelay(longdelay_us); | 181 | mdelay(longdelay_us); |
| 179 | if (!(torture_random(trsp) % | 182 | if (!(torture_random(trsp) % |
| 180 | (nrealwriters_stress * 2 * shortdelay_us))) | 183 | (cxt.nrealwriters_stress * 2 * shortdelay_us))) |
| 181 | udelay(shortdelay_us); | 184 | udelay(shortdelay_us); |
| 182 | #ifdef CONFIG_PREEMPT | 185 | #ifdef CONFIG_PREEMPT |
| 183 | if (!(torture_random(trsp) % (nrealwriters_stress * 20000))) | 186 | if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000))) |
| 184 | preempt_schedule(); /* Allow test to be preempted. */ | 187 | preempt_schedule(); /* Allow test to be preempted. */ |
| 185 | #endif | 188 | #endif |
| 186 | } | 189 | } |
| @@ -206,14 +209,14 @@ __acquires(torture_spinlock_irq) | |||
| 206 | unsigned long flags; | 209 | unsigned long flags; |
| 207 | 210 | ||
| 208 | spin_lock_irqsave(&torture_spinlock, flags); | 211 | spin_lock_irqsave(&torture_spinlock, flags); |
| 209 | cur_ops->flags = flags; | 212 | cxt.cur_ops->flags = flags; |
| 210 | return 0; | 213 | return 0; |
| 211 | } | 214 | } |
| 212 | 215 | ||
| 213 | static void torture_lock_spin_write_unlock_irq(void) | 216 | static void torture_lock_spin_write_unlock_irq(void) |
| 214 | __releases(torture_spinlock) | 217 | __releases(torture_spinlock) |
| 215 | { | 218 | { |
| 216 | spin_unlock_irqrestore(&torture_spinlock, cur_ops->flags); | 219 | spin_unlock_irqrestore(&torture_spinlock, cxt.cur_ops->flags); |
| 217 | } | 220 | } |
| 218 | 221 | ||
| 219 | static struct lock_torture_ops spin_lock_irq_ops = { | 222 | static struct lock_torture_ops spin_lock_irq_ops = { |
| @@ -240,12 +243,12 @@ static void torture_mutex_delay(struct torture_random_state *trsp) | |||
| 240 | 243 | ||
| 241 | /* We want a long delay occasionally to force massive contention. */ | 244 | /* We want a long delay occasionally to force massive contention. */ |
| 242 | if (!(torture_random(trsp) % | 245 | if (!(torture_random(trsp) % |
| 243 | (nrealwriters_stress * 2000 * longdelay_ms))) | 246 | (cxt.nrealwriters_stress * 2000 * longdelay_ms))) |
| 244 | mdelay(longdelay_ms * 5); | 247 | mdelay(longdelay_ms * 5); |
| 245 | else | 248 | else |
| 246 | mdelay(longdelay_ms / 5); | 249 | mdelay(longdelay_ms / 5); |
| 247 | #ifdef CONFIG_PREEMPT | 250 | #ifdef CONFIG_PREEMPT |
| 248 | if (!(torture_random(trsp) % (nrealwriters_stress * 20000))) | 251 | if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000))) |
| 249 | preempt_schedule(); /* Allow test to be preempted. */ | 252 | preempt_schedule(); /* Allow test to be preempted. */ |
| 250 | #endif | 253 | #endif |
| 251 | } | 254 | } |
| @@ -278,12 +281,12 @@ static void torture_rwsem_write_delay(struct torture_random_state *trsp) | |||
| 278 | 281 | ||
| 279 | /* We want a long delay occasionally to force massive contention. */ | 282 | /* We want a long delay occasionally to force massive contention. */ |
| 280 | if (!(torture_random(trsp) % | 283 | if (!(torture_random(trsp) % |
| 281 | (nrealwriters_stress * 2000 * longdelay_ms))) | 284 | (cxt.nrealwriters_stress * 2000 * longdelay_ms))) |
| 282 | mdelay(longdelay_ms * 10); | 285 | mdelay(longdelay_ms * 10); |
| 283 | else | 286 | else |
| 284 | mdelay(longdelay_ms / 10); | 287 | mdelay(longdelay_ms / 10); |
| 285 | #ifdef CONFIG_PREEMPT | 288 | #ifdef CONFIG_PREEMPT |
| 286 | if (!(torture_random(trsp) % (nrealwriters_stress * 20000))) | 289 | if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000))) |
| 287 | preempt_schedule(); /* Allow test to be preempted. */ | 290 | preempt_schedule(); /* Allow test to be preempted. */ |
| 288 | #endif | 291 | #endif |
| 289 | } | 292 | } |
| @@ -305,12 +308,12 @@ static void torture_rwsem_read_delay(struct torture_random_state *trsp) | |||
| 305 | 308 | ||
| 306 | /* We want a long delay occasionally to force massive contention. */ | 309 | /* We want a long delay occasionally to force massive contention. */ |
| 307 | if (!(torture_random(trsp) % | 310 | if (!(torture_random(trsp) % |
| 308 | (nrealwriters_stress * 2000 * longdelay_ms))) | 311 | (cxt.nrealwriters_stress * 2000 * longdelay_ms))) |
| 309 | mdelay(longdelay_ms * 2); | 312 | mdelay(longdelay_ms * 2); |
| 310 | else | 313 | else |
| 311 | mdelay(longdelay_ms / 2); | 314 | mdelay(longdelay_ms / 2); |
| 312 | #ifdef CONFIG_PREEMPT | 315 | #ifdef CONFIG_PREEMPT |
| 313 | if (!(torture_random(trsp) % (nrealreaders_stress * 20000))) | 316 | if (!(torture_random(trsp) % (cxt.nrealreaders_stress * 20000))) |
| 314 | preempt_schedule(); /* Allow test to be preempted. */ | 317 | preempt_schedule(); /* Allow test to be preempted. */ |
| 315 | #endif | 318 | #endif |
| 316 | } | 319 | } |
| @@ -345,14 +348,14 @@ static int lock_torture_writer(void *arg) | |||
| 345 | do { | 348 | do { |
| 346 | if ((torture_random(&rand) & 0xfffff) == 0) | 349 | if ((torture_random(&rand) & 0xfffff) == 0) |
| 347 | schedule_timeout_uninterruptible(1); | 350 | schedule_timeout_uninterruptible(1); |
| 348 | cur_ops->writelock(); | 351 | cxt.cur_ops->writelock(); |
| 349 | if (WARN_ON_ONCE(lock_is_write_held)) | 352 | if (WARN_ON_ONCE(lock_is_write_held)) |
| 350 | lwsp->n_lock_fail++; | 353 | lwsp->n_lock_fail++; |
| 351 | lock_is_write_held = 1; | 354 | lock_is_write_held = 1; |
| 352 | lwsp->n_lock_acquired++; | 355 | lwsp->n_lock_acquired++; |
| 353 | cur_ops->write_delay(&rand); | 356 | cxt.cur_ops->write_delay(&rand); |
| 354 | lock_is_write_held = 0; | 357 | lock_is_write_held = 0; |
| 355 | cur_ops->writeunlock(); | 358 | cxt.cur_ops->writeunlock(); |
| 356 | stutter_wait("lock_torture_writer"); | 359 | stutter_wait("lock_torture_writer"); |
| 357 | } while (!torture_must_stop()); | 360 | } while (!torture_must_stop()); |
| 358 | torture_kthread_stopping("lock_torture_writer"); | 361 | torture_kthread_stopping("lock_torture_writer"); |
| @@ -374,12 +377,12 @@ static int lock_torture_reader(void *arg) | |||
| 374 | do { | 377 | do { |
| 375 | if ((torture_random(&rand) & 0xfffff) == 0) | 378 | if ((torture_random(&rand) & 0xfffff) == 0) |
| 376 | schedule_timeout_uninterruptible(1); | 379 | schedule_timeout_uninterruptible(1); |
| 377 | cur_ops->readlock(); | 380 | cxt.cur_ops->readlock(); |
| 378 | lock_is_read_held = 1; | 381 | lock_is_read_held = 1; |
| 379 | lrsp->n_lock_acquired++; | 382 | lrsp->n_lock_acquired++; |
| 380 | cur_ops->read_delay(&rand); | 383 | cxt.cur_ops->read_delay(&rand); |
| 381 | lock_is_read_held = 0; | 384 | lock_is_read_held = 0; |
| 382 | cur_ops->readunlock(); | 385 | cxt.cur_ops->readunlock(); |
| 383 | stutter_wait("lock_torture_reader"); | 386 | stutter_wait("lock_torture_reader"); |
| 384 | } while (!torture_must_stop()); | 387 | } while (!torture_must_stop()); |
| 385 | torture_kthread_stopping("lock_torture_reader"); | 388 | torture_kthread_stopping("lock_torture_reader"); |
| @@ -398,7 +401,7 @@ static void __torture_print_stats(char *page, | |||
| 398 | long min = statp[0].n_lock_acquired; | 401 | long min = statp[0].n_lock_acquired; |
| 399 | long long sum = 0; | 402 | long long sum = 0; |
| 400 | 403 | ||
| 401 | n_stress = write ? nrealwriters_stress : nrealreaders_stress; | 404 | n_stress = write ? cxt.nrealwriters_stress : cxt.nrealreaders_stress; |
| 402 | for (i = 0; i < n_stress; i++) { | 405 | for (i = 0; i < n_stress; i++) { |
| 403 | if (statp[i].n_lock_fail) | 406 | if (statp[i].n_lock_fail) |
| 404 | fail = true; | 407 | fail = true; |
| @@ -414,7 +417,7 @@ static void __torture_print_stats(char *page, | |||
| 414 | sum, max, min, max / 2 > min ? "???" : "", | 417 | sum, max, min, max / 2 > min ? "???" : "", |
| 415 | fail, fail ? "!!!" : ""); | 418 | fail, fail ? "!!!" : ""); |
| 416 | if (fail) | 419 | if (fail) |
| 417 | atomic_inc(&n_lock_torture_errors); | 420 | atomic_inc(&cxt.n_lock_torture_errors); |
| 418 | } | 421 | } |
| 419 | 422 | ||
| 420 | /* | 423 | /* |
| @@ -427,11 +430,11 @@ static void __torture_print_stats(char *page, | |||
| 427 | */ | 430 | */ |
| 428 | static void lock_torture_stats_print(void) | 431 | static void lock_torture_stats_print(void) |
| 429 | { | 432 | { |
| 430 | int size = nrealwriters_stress * 200 + 8192; | 433 | int size = cxt.nrealwriters_stress * 200 + 8192; |
| 431 | char *buf; | 434 | char *buf; |
| 432 | 435 | ||
| 433 | if (cur_ops->readlock) | 436 | if (cxt.cur_ops->readlock) |
| 434 | size += nrealreaders_stress * 200 + 8192; | 437 | size += cxt.nrealreaders_stress * 200 + 8192; |
| 435 | 438 | ||
| 436 | buf = kmalloc(size, GFP_KERNEL); | 439 | buf = kmalloc(size, GFP_KERNEL); |
| 437 | if (!buf) { | 440 | if (!buf) { |
| @@ -440,11 +443,11 @@ static void lock_torture_stats_print(void) | |||
| 440 | return; | 443 | return; |
| 441 | } | 444 | } |
| 442 | 445 | ||
| 443 | __torture_print_stats(buf, lwsa, true); | 446 | __torture_print_stats(buf, cxt.lwsa, true); |
| 444 | pr_alert("%s", buf); | 447 | pr_alert("%s", buf); |
| 445 | kfree(buf); | 448 | kfree(buf); |
| 446 | 449 | ||
| 447 | if (cur_ops->readlock) { | 450 | if (cxt.cur_ops->readlock) { |
| 448 | buf = kmalloc(size, GFP_KERNEL); | 451 | buf = kmalloc(size, GFP_KERNEL); |
| 449 | if (!buf) { | 452 | if (!buf) { |
| 450 | pr_err("lock_torture_stats_print: Out of memory, need: %d", | 453 | pr_err("lock_torture_stats_print: Out of memory, need: %d", |
| @@ -452,7 +455,7 @@ static void lock_torture_stats_print(void) | |||
| 452 | return; | 455 | return; |
| 453 | } | 456 | } |
| 454 | 457 | ||
| 455 | __torture_print_stats(buf, lrsa, false); | 458 | __torture_print_stats(buf, cxt.lrsa, false); |
| 456 | pr_alert("%s", buf); | 459 | pr_alert("%s", buf); |
| 457 | kfree(buf); | 460 | kfree(buf); |
| 458 | } | 461 | } |
| @@ -483,8 +486,8 @@ lock_torture_print_module_parms(struct lock_torture_ops *cur_ops, | |||
| 483 | { | 486 | { |
| 484 | pr_alert("%s" TORTURE_FLAG | 487 | pr_alert("%s" TORTURE_FLAG |
| 485 | "--- %s%s: nwriters_stress=%d nreaders_stress=%d stat_interval=%d verbose=%d shuffle_interval=%d stutter=%d shutdown_secs=%d onoff_interval=%d onoff_holdoff=%d\n", | 488 | "--- %s%s: nwriters_stress=%d nreaders_stress=%d stat_interval=%d verbose=%d shuffle_interval=%d stutter=%d shutdown_secs=%d onoff_interval=%d onoff_holdoff=%d\n", |
| 486 | torture_type, tag, debug_lock ? " [debug]": "", | 489 | torture_type, tag, cxt.debug_lock ? " [debug]": "", |
| 487 | nrealwriters_stress, nrealreaders_stress, stat_interval, | 490 | cxt.nrealwriters_stress, cxt.nrealreaders_stress, stat_interval, |
| 488 | verbose, shuffle_interval, stutter, shutdown_secs, | 491 | verbose, shuffle_interval, stutter, shutdown_secs, |
| 489 | onoff_interval, onoff_holdoff); | 492 | onoff_interval, onoff_holdoff); |
| 490 | } | 493 | } |
| @@ -497,7 +500,7 @@ static void lock_torture_cleanup(void) | |||
| 497 | return; | 500 | return; |
| 498 | 501 | ||
| 499 | if (writer_tasks) { | 502 | if (writer_tasks) { |
| 500 | for (i = 0; i < nrealwriters_stress; i++) | 503 | for (i = 0; i < cxt.nrealwriters_stress; i++) |
| 501 | torture_stop_kthread(lock_torture_writer, | 504 | torture_stop_kthread(lock_torture_writer, |
| 502 | writer_tasks[i]); | 505 | writer_tasks[i]); |
| 503 | kfree(writer_tasks); | 506 | kfree(writer_tasks); |
| @@ -505,7 +508,7 @@ static void lock_torture_cleanup(void) | |||
| 505 | } | 508 | } |
| 506 | 509 | ||
| 507 | if (reader_tasks) { | 510 | if (reader_tasks) { |
| 508 | for (i = 0; i < nrealreaders_stress; i++) | 511 | for (i = 0; i < cxt.nrealreaders_stress; i++) |
| 509 | torture_stop_kthread(lock_torture_reader, | 512 | torture_stop_kthread(lock_torture_reader, |
| 510 | reader_tasks[i]); | 513 | reader_tasks[i]); |
| 511 | kfree(reader_tasks); | 514 | kfree(reader_tasks); |
| @@ -515,14 +518,14 @@ static void lock_torture_cleanup(void) | |||
| 515 | torture_stop_kthread(lock_torture_stats, stats_task); | 518 | torture_stop_kthread(lock_torture_stats, stats_task); |
| 516 | lock_torture_stats_print(); /* -After- the stats thread is stopped! */ | 519 | lock_torture_stats_print(); /* -After- the stats thread is stopped! */ |
| 517 | 520 | ||
| 518 | if (atomic_read(&n_lock_torture_errors)) | 521 | if (atomic_read(&cxt.n_lock_torture_errors)) |
| 519 | lock_torture_print_module_parms(cur_ops, | 522 | lock_torture_print_module_parms(cxt.cur_ops, |
| 520 | "End of test: FAILURE"); | 523 | "End of test: FAILURE"); |
| 521 | else if (torture_onoff_failures()) | 524 | else if (torture_onoff_failures()) |
| 522 | lock_torture_print_module_parms(cur_ops, | 525 | lock_torture_print_module_parms(cxt.cur_ops, |
| 523 | "End of test: LOCK_HOTPLUG"); | 526 | "End of test: LOCK_HOTPLUG"); |
| 524 | else | 527 | else |
| 525 | lock_torture_print_module_parms(cur_ops, | 528 | lock_torture_print_module_parms(cxt.cur_ops, |
| 526 | "End of test: SUCCESS"); | 529 | "End of test: SUCCESS"); |
| 527 | torture_cleanup_end(); | 530 | torture_cleanup_end(); |
| 528 | } | 531 | } |
| @@ -541,8 +544,8 @@ static int __init lock_torture_init(void) | |||
| 541 | 544 | ||
| 542 | /* Process args and tell the world that the torturer is on the job. */ | 545 | /* Process args and tell the world that the torturer is on the job. */ |
| 543 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { | 546 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { |
| 544 | cur_ops = torture_ops[i]; | 547 | cxt.cur_ops = torture_ops[i]; |
| 545 | if (strcmp(torture_type, cur_ops->name) == 0) | 548 | if (strcmp(torture_type, cxt.cur_ops->name) == 0) |
| 546 | break; | 549 | break; |
| 547 | } | 550 | } |
| 548 | if (i == ARRAY_SIZE(torture_ops)) { | 551 | if (i == ARRAY_SIZE(torture_ops)) { |
| @@ -555,40 +558,40 @@ static int __init lock_torture_init(void) | |||
| 555 | torture_init_end(); | 558 | torture_init_end(); |
| 556 | return -EINVAL; | 559 | return -EINVAL; |
| 557 | } | 560 | } |
| 558 | if (cur_ops->init) | 561 | if (cxt.cur_ops->init) |
| 559 | cur_ops->init(); /* no "goto unwind" prior to this point!!! */ | 562 | cxt.cur_ops->init(); /* no "goto unwind" prior to this point!!! */ |
| 560 | 563 | ||
| 561 | if (nwriters_stress >= 0) | 564 | if (nwriters_stress >= 0) |
| 562 | nrealwriters_stress = nwriters_stress; | 565 | cxt.nrealwriters_stress = nwriters_stress; |
| 563 | else | 566 | else |
| 564 | nrealwriters_stress = 2 * num_online_cpus(); | 567 | cxt.nrealwriters_stress = 2 * num_online_cpus(); |
| 565 | 568 | ||
| 566 | #ifdef CONFIG_DEBUG_MUTEXES | 569 | #ifdef CONFIG_DEBUG_MUTEXES |
| 567 | if (strncmp(torture_type, "mutex", 5) == 0) | 570 | if (strncmp(torture_type, "mutex", 5) == 0) |
| 568 | debug_lock = true; | 571 | cxt.debug_lock = true; |
| 569 | #endif | 572 | #endif |
| 570 | #ifdef CONFIG_DEBUG_SPINLOCK | 573 | #ifdef CONFIG_DEBUG_SPINLOCK |
| 571 | if (strncmp(torture_type, "spin", 4) == 0) | 574 | if (strncmp(torture_type, "spin", 4) == 0) |
| 572 | debug_lock = true; | 575 | cxt.debug_lock = true; |
| 573 | #endif | 576 | #endif |
| 574 | 577 | ||
| 575 | /* Initialize the statistics so that each run gets its own numbers. */ | 578 | /* Initialize the statistics so that each run gets its own numbers. */ |
| 576 | 579 | ||
| 577 | lock_is_write_held = 0; | 580 | lock_is_write_held = 0; |
| 578 | lwsa = kmalloc(sizeof(*lwsa) * nrealwriters_stress, GFP_KERNEL); | 581 | cxt.lwsa = kmalloc(sizeof(*cxt.lwsa) * cxt.nrealwriters_stress, GFP_KERNEL); |
| 579 | if (lwsa == NULL) { | 582 | if (cxt.lwsa == NULL) { |
| 580 | VERBOSE_TOROUT_STRING("lwsa: Out of memory"); | 583 | VERBOSE_TOROUT_STRING("cxt.lwsa: Out of memory"); |
| 581 | firsterr = -ENOMEM; | 584 | firsterr = -ENOMEM; |
| 582 | goto unwind; | 585 | goto unwind; |
| 583 | } | 586 | } |
| 584 | for (i = 0; i < nrealwriters_stress; i++) { | 587 | for (i = 0; i < cxt.nrealwriters_stress; i++) { |
| 585 | lwsa[i].n_lock_fail = 0; | 588 | cxt.lwsa[i].n_lock_fail = 0; |
| 586 | lwsa[i].n_lock_acquired = 0; | 589 | cxt.lwsa[i].n_lock_acquired = 0; |
| 587 | } | 590 | } |
| 588 | 591 | ||
| 589 | if (cur_ops->readlock) { | 592 | if (cxt.cur_ops->readlock) { |
| 590 | if (nreaders_stress >= 0) | 593 | if (nreaders_stress >= 0) |
| 591 | nrealreaders_stress = nreaders_stress; | 594 | cxt.nrealreaders_stress = nreaders_stress; |
| 592 | else { | 595 | else { |
| 593 | /* | 596 | /* |
| 594 | * By default distribute evenly the number of | 597 | * By default distribute evenly the number of |
| @@ -596,25 +599,25 @@ static int __init lock_torture_init(void) | |||
| 596 | * of threads as the writer-only locks default. | 599 | * of threads as the writer-only locks default. |
| 597 | */ | 600 | */ |
| 598 | if (nwriters_stress < 0) /* user doesn't care */ | 601 | if (nwriters_stress < 0) /* user doesn't care */ |
| 599 | nrealwriters_stress = num_online_cpus(); | 602 | cxt.nrealwriters_stress = num_online_cpus(); |
| 600 | nrealreaders_stress = nrealwriters_stress; | 603 | cxt.nrealreaders_stress = cxt.nrealwriters_stress; |
| 601 | } | 604 | } |
| 602 | 605 | ||
| 603 | lock_is_read_held = 0; | 606 | lock_is_read_held = 0; |
| 604 | lrsa = kmalloc(sizeof(*lrsa) * nrealreaders_stress, GFP_KERNEL); | 607 | cxt.lrsa = kmalloc(sizeof(*cxt.lrsa) * cxt.nrealreaders_stress, GFP_KERNEL); |
| 605 | if (lrsa == NULL) { | 608 | if (cxt.lrsa == NULL) { |
| 606 | VERBOSE_TOROUT_STRING("lrsa: Out of memory"); | 609 | VERBOSE_TOROUT_STRING("cxt.lrsa: Out of memory"); |
| 607 | firsterr = -ENOMEM; | 610 | firsterr = -ENOMEM; |
| 608 | kfree(lwsa); | 611 | kfree(cxt.lwsa); |
| 609 | goto unwind; | 612 | goto unwind; |
| 610 | } | 613 | } |
| 611 | 614 | ||
| 612 | for (i = 0; i < nrealreaders_stress; i++) { | 615 | for (i = 0; i < cxt.nrealreaders_stress; i++) { |
| 613 | lrsa[i].n_lock_fail = 0; | 616 | cxt.lrsa[i].n_lock_fail = 0; |
| 614 | lrsa[i].n_lock_acquired = 0; | 617 | cxt.lrsa[i].n_lock_acquired = 0; |
| 615 | } | 618 | } |
| 616 | } | 619 | } |
| 617 | lock_torture_print_module_parms(cur_ops, "Start of test"); | 620 | lock_torture_print_module_parms(cxt.cur_ops, "Start of test"); |
| 618 | 621 | ||
| 619 | /* Prepare torture context. */ | 622 | /* Prepare torture context. */ |
| 620 | if (onoff_interval > 0) { | 623 | if (onoff_interval > 0) { |
| @@ -640,7 +643,7 @@ static int __init lock_torture_init(void) | |||
| 640 | goto unwind; | 643 | goto unwind; |
| 641 | } | 644 | } |
| 642 | 645 | ||
| 643 | writer_tasks = kzalloc(nrealwriters_stress * sizeof(writer_tasks[0]), | 646 | writer_tasks = kzalloc(cxt.nrealwriters_stress * sizeof(writer_tasks[0]), |
| 644 | GFP_KERNEL); | 647 | GFP_KERNEL); |
| 645 | if (writer_tasks == NULL) { | 648 | if (writer_tasks == NULL) { |
| 646 | VERBOSE_TOROUT_ERRSTRING("writer_tasks: Out of memory"); | 649 | VERBOSE_TOROUT_ERRSTRING("writer_tasks: Out of memory"); |
| @@ -648,8 +651,8 @@ static int __init lock_torture_init(void) | |||
| 648 | goto unwind; | 651 | goto unwind; |
| 649 | } | 652 | } |
| 650 | 653 | ||
| 651 | if (cur_ops->readlock) { | 654 | if (cxt.cur_ops->readlock) { |
| 652 | reader_tasks = kzalloc(nrealreaders_stress * sizeof(reader_tasks[0]), | 655 | reader_tasks = kzalloc(cxt.nrealreaders_stress * sizeof(reader_tasks[0]), |
| 653 | GFP_KERNEL); | 656 | GFP_KERNEL); |
| 654 | if (reader_tasks == NULL) { | 657 | if (reader_tasks == NULL) { |
| 655 | VERBOSE_TOROUT_ERRSTRING("reader_tasks: Out of memory"); | 658 | VERBOSE_TOROUT_ERRSTRING("reader_tasks: Out of memory"); |
| @@ -666,22 +669,22 @@ static int __init lock_torture_init(void) | |||
| 666 | * for very specific needs, or even let the user choose the policy, if | 669 | * for very specific needs, or even let the user choose the policy, if |
| 667 | * ever wanted. | 670 | * ever wanted. |
| 668 | */ | 671 | */ |
| 669 | for (i = 0, j = 0; i < nrealwriters_stress || | 672 | for (i = 0, j = 0; i < cxt.nrealwriters_stress || |
| 670 | j < nrealreaders_stress; i++, j++) { | 673 | j < cxt.nrealreaders_stress; i++, j++) { |
| 671 | if (i >= nrealwriters_stress) | 674 | if (i >= cxt.nrealwriters_stress) |
| 672 | goto create_reader; | 675 | goto create_reader; |
| 673 | 676 | ||
| 674 | /* Create writer. */ | 677 | /* Create writer. */ |
| 675 | firsterr = torture_create_kthread(lock_torture_writer, &lwsa[i], | 678 | firsterr = torture_create_kthread(lock_torture_writer, &cxt.lwsa[i], |
| 676 | writer_tasks[i]); | 679 | writer_tasks[i]); |
| 677 | if (firsterr) | 680 | if (firsterr) |
| 678 | goto unwind; | 681 | goto unwind; |
| 679 | 682 | ||
| 680 | create_reader: | 683 | create_reader: |
| 681 | if (cur_ops->readlock == NULL || (j >= nrealreaders_stress)) | 684 | if (cxt.cur_ops->readlock == NULL || (j >= cxt.nrealreaders_stress)) |
| 682 | continue; | 685 | continue; |
| 683 | /* Create reader. */ | 686 | /* Create reader. */ |
| 684 | firsterr = torture_create_kthread(lock_torture_reader, &lrsa[j], | 687 | firsterr = torture_create_kthread(lock_torture_reader, &cxt.lrsa[j], |
| 685 | reader_tasks[j]); | 688 | reader_tasks[j]); |
| 686 | if (firsterr) | 689 | if (firsterr) |
| 687 | goto unwind; | 690 | goto unwind; |
