aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/locking
diff options
context:
space:
mode:
authorDavidlohr Bueso <dave@stgolabs.net>2014-09-11 23:40:18 -0400
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2014-09-16 16:40:59 -0400
commit42ddc75ddd478edac6ad9dc8c63abb4441541af2 (patch)
tree4fe354b785d0d575bcd47af7dc8d9edb299f78f7 /kernel/locking
parentcdf26bb10bcb50161d452b16eb3cf2901645d625 (diff)
locktorture: Support mutexes
Add a "mutex_lock" torture test. The main difference with the already existing spinlock tests is that the latency of the critical region is much larger. We randomly delay for (arbitrarily) either 500 ms or, otherwise, 25 ms. While this can considerably reduce the amount of writes compared to non blocking locks, if run long enough it can have the same torturous effect. Furthermore it is more representative of mutex hold times and can stress better things like thrashing. 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.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index 8c770b2c6e2a..414ba45d580f 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -27,6 +27,7 @@
27#include <linux/kthread.h> 27#include <linux/kthread.h>
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/spinlock.h> 29#include <linux/spinlock.h>
30#include <linux/mutex.h>
30#include <linux/smp.h> 31#include <linux/smp.h>
31#include <linux/interrupt.h> 32#include <linux/interrupt.h>
32#include <linux/sched.h> 33#include <linux/sched.h>
@@ -66,7 +67,7 @@ torture_param(bool, verbose, true,
66static char *torture_type = "spin_lock"; 67static char *torture_type = "spin_lock";
67module_param(torture_type, charp, 0444); 68module_param(torture_type, charp, 0444);
68MODULE_PARM_DESC(torture_type, 69MODULE_PARM_DESC(torture_type,
69 "Type of lock to torture (spin_lock, spin_lock_irq, ...)"); 70 "Type of lock to torture (spin_lock, spin_lock_irq, mutex_lock, ...)");
70 71
71static atomic_t n_lock_torture_errors; 72static atomic_t n_lock_torture_errors;
72 73
@@ -206,6 +207,42 @@ static struct lock_torture_ops spin_lock_irq_ops = {
206 .name = "spin_lock_irq" 207 .name = "spin_lock_irq"
207}; 208};
208 209
210static DEFINE_MUTEX(torture_mutex);
211
212static int torture_mutex_lock(void) __acquires(torture_mutex)
213{
214 mutex_lock(&torture_mutex);
215 return 0;
216}
217
218static void torture_mutex_delay(struct torture_random_state *trsp)
219{
220 const unsigned long longdelay_ms = 100;
221
222 /* We want a long delay occasionally to force massive contention. */
223 if (!(torture_random(trsp) %
224 (nrealwriters_stress * 2000 * longdelay_ms)))
225 mdelay(longdelay_ms * 5);
226 else
227 mdelay(longdelay_ms / 5);
228#ifdef CONFIG_PREEMPT
229 if (!(torture_random(trsp) % (nrealwriters_stress * 20000)))
230 preempt_schedule(); /* Allow test to be preempted. */
231#endif
232}
233
234static void torture_mutex_unlock(void) __releases(torture_mutex)
235{
236 mutex_unlock(&torture_mutex);
237}
238
239static struct lock_torture_ops mutex_lock_ops = {
240 .writelock = torture_mutex_lock,
241 .write_delay = torture_mutex_delay,
242 .writeunlock = torture_mutex_unlock,
243 .name = "mutex_lock"
244};
245
209/* 246/*
210 * Lock torture writer kthread. Repeatedly acquires and releases 247 * Lock torture writer kthread. Repeatedly acquires and releases
211 * the lock, checking for duplicate acquisitions. 248 * the lock, checking for duplicate acquisitions.
@@ -352,7 +389,7 @@ static int __init lock_torture_init(void)
352 int i; 389 int i;
353 int firsterr = 0; 390 int firsterr = 0;
354 static struct lock_torture_ops *torture_ops[] = { 391 static struct lock_torture_ops *torture_ops[] = {
355 &lock_busted_ops, &spin_lock_ops, &spin_lock_irq_ops, 392 &lock_busted_ops, &spin_lock_ops, &spin_lock_irq_ops, &mutex_lock_ops,
356 }; 393 };
357 394
358 if (!torture_init_begin(torture_type, verbose, &torture_runnable)) 395 if (!torture_init_begin(torture_type, verbose, &torture_runnable))