Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

locking/ww_mutex/test: Use prng instead of rng to avoid hangs at bootup

Booting w/ qemu without kvm, and with 64 cpus, I noticed we'd
sometimes hung task watchdog splats in get_random_u32_below()
when using the test-ww_mutex stress test.

While entropy exhaustion is no longer an issue, the RNG may be
slower early in boot. The test-ww_mutex code will spawn off
128 threads (2x cpus) and each thread will call
get_random_u32_below() a number of times to generate a random
order of the 16 locks.

This intense use takes time and without kvm, qemu can be slow
enough that we trip the hung task watchdogs.

For this test, we don't need true randomness, just mixed up
orders for testing ww_mutex lock acquisitions, so it changes
the logic to use the prng instead, which takes less time
and avoids the watchdgos.

Feedback would be appreciated!

Signed-off-by: John Stultz <jstultz@google.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230922043616.19282-2-jstultz@google.com

authored by

John Stultz and committed by
Ingo Molnar
4812c54d 0f4b5f97

+17 -2
+17 -2
kernel/locking/test-ww_mutex.c
··· 9 9 #include <linux/delay.h> 10 10 #include <linux/kthread.h> 11 11 #include <linux/module.h> 12 - #include <linux/random.h> 12 + #include <linux/prandom.h> 13 13 #include <linux/slab.h> 14 14 #include <linux/ww_mutex.h> 15 15 ··· 386 386 int nlocks; 387 387 }; 388 388 389 + struct rnd_state rng; 390 + DEFINE_SPINLOCK(rng_lock); 391 + 392 + static inline u32 prandom_u32_below(u32 ceil) 393 + { 394 + u32 ret; 395 + 396 + spin_lock(&rng_lock); 397 + ret = prandom_u32_state(&rng) % ceil; 398 + spin_unlock(&rng_lock); 399 + return ret; 400 + } 401 + 389 402 static int *get_random_order(int count) 390 403 { 391 404 int *order; ··· 412 399 order[n] = n; 413 400 414 401 for (n = count - 1; n > 1; n--) { 415 - r = get_random_u32_below(n + 1); 402 + r = prandom_u32_below(n + 1); 416 403 if (r != n) { 417 404 tmp = order[n]; 418 405 order[n] = order[r]; ··· 637 624 int ret, i; 638 625 639 626 printk(KERN_INFO "Beginning ww mutex selftests\n"); 627 + 628 + prandom_seed_state(&rng, get_random_u64()); 640 629 641 630 wq = alloc_workqueue("test-ww_mutex", WQ_UNBOUND, 0); 642 631 if (!wq)