Skip to content

Commit

Permalink
locking/ww_mutex: Replace cpu_relax with cond_resched for tests
Browse files Browse the repository at this point in the history
When busy-spinning on a ww_mutex_trylock(), we depend upon the other
thread advancing and releasing the lock. This can not happen on a single
CPU unless we relinquish it.

[   28.709171] NMI watchdog: BUG: soft lockup - CPU#0 stuck for 22s! [kworker/0:1:18]
[   28.710974] irq event stamp: 25570
[   28.711660] hardirqs last  enabled at (25569): [<8148b70e>] restore_all+0xf/0x31
[   28.713123] hardirqs last disabled at (25570): [<8148bef0>] apic_timer_interrupt+0x30/0x40
[   28.714896] softirqs last  enabled at (19288): [<8103372b>] __do_softirq+0x187/0x1d3
[   28.716673] softirqs last disabled at (19279): [<81011d9f>] do_softirq_own_stack+0x1c/0x22
[   28.740997] CPU: 0 PID: 18 Comm: kworker/0:1 Not tainted 4.10.0-rc3-00151-gf2a5fec torvalds#180
[   28.751629] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.9.3-20161025_171302-gandalf 04/01/2014
[   28.761621] Workqueue: events test_mutex_work
[   28.762938] task: 95110480 task.stack: 9517e000
[   28.764313] EIP: __mutex_trylock+0x4/0xa3
[   28.765531] EFLAGS: 00200282 CPU: 0
[   28.766660] EAX: 95035e10 EBX: 95035df0 ECX: 00000006 EDX: 00000007
[   28.773223] ESI: 95035e10 EDI: 00000000 EBP: 9517feec ESP: 9517fee8
[   28.783901]  DS: 007b ES: 007b FS: 0000 GS: 0000 SS: 0068
[   28.792941] CR0: 80050033 CR2: ffffffff CR3: 018cc000 CR4: 00000690
[   28.795138] Call Trace:
[   28.796037]  mutex_trylock+0xf/0x4c
[   28.797299]  test_mutex_work+0x31/0x56
[   28.798683]  process_one_work+0x1b4/0x2f9
[   28.803362]  ? process_one_work+0x131/0x2f9
[   28.813482]  worker_thread+0x1b0/0x27c
[   28.814741]  kthread+0xd1/0xd3
[   28.815825]  ? process_scheduled_works+0x24/0x24
[   28.825830]  ? __list_add+0x24/0x24
[   28.827000]  ret_from_fork+0x19/0x30
[   28.828106] Code: 5d c3 55 89 e5 5d c3 55 89 e5 50 9d 8d 74 26 00 5d c3 55 89 e5 9c 58 8d 74 26 00 89 c1 fa 90 8d 74 26 00 89 c8 5d c3 55 89 e5 57 <56> 89 c6 53 83 ec 18 8b 1e a1 8c 24 79 81 89 45 ec 89 45 f0 89

Fixes: f2a5fec ("locking/ww_mutex: Begin kselftests for ww_mutex")
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Fengguang Wu <fengguang.wu@intel.com>
  • Loading branch information
ickle authored and 0day robot committed Feb 28, 2017
1 parent 95cb64c commit 213c59a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kernel/locking/test-ww_mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void test_mutex_work(struct work_struct *work)

if (mtx->flags & TEST_MTX_TRY) {
while (!ww_mutex_trylock(&mtx->mutex))
cpu_relax();
cond_resched();
} else {
ww_mutex_lock(&mtx->mutex, NULL);
}
Expand Down Expand Up @@ -88,7 +88,7 @@ static int __test_mutex(unsigned int flags)
ret = -EINVAL;
break;
}
cpu_relax();
cond_resched();
} while (time_before(jiffies, timeout));
} else {
ret = wait_for_completion_timeout(&mtx.done, TIMEOUT);
Expand Down

0 comments on commit 213c59a

Please sign in to comment.