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.

lib/test_vmalloc.c: replace RWSEM to SRCU for setup

The test has the initialization step during which threads are created. To
prevent the workers from starting prematurely a write lock was previously
used by the main setup thread, while each worker would block on a read
lock.

Replace this RWSEM based synchronization with a simpler SRCU based
approach. Which does two basic steps:

- Main thread wraps the setup phase in an SRCU read-side critical
section. Pair of srcu_read_lock()/srcu_read_unlock().
- Each worker calls synchronize_srcu() on entry, ensuring it waits for
the initialization phase to be completed.

This patch eliminates the need for down_read()/up_read() and
down_write()/up_write() pairs thus simplifying the logic and improving
clarity.

[urezki@gmail.com: fix compile error with CONFIG_TINY_RCU]
Link: https://lkml.kernel.org/r/20250420142029.103169-1-urezki@gmail.com
Link: https://lkml.kernel.org/r/20250417161216.88318-1-urezki@gmail.com
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Reviewed-by: Adrian Huang <ahuang12@lenovo.com>
Tested-by: Adrian Huang <ahuang12@lenovo.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Christop Hellwig <hch@infradead.org>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Uladzislau Rezki (Sony) and committed by
Andrew Morton
7a73348e b05f8d7e

+7 -10
+7 -10
lib/test_vmalloc.c
··· 13 13 #include <linux/moduleparam.h> 14 14 #include <linux/completion.h> 15 15 #include <linux/delay.h> 16 - #include <linux/rwsem.h> 17 16 #include <linux/mm.h> 18 17 #include <linux/rcupdate.h> 18 + #include <linux/srcu.h> 19 19 #include <linux/slab.h> 20 20 21 21 #define __param(type, name, init, msg) \ ··· 58 58 ); 59 59 60 60 /* 61 - * Read write semaphore for synchronization of setup 62 - * phase that is done in main thread and workers. 61 + * This is for synchronization of setup phase. 63 62 */ 64 - static DECLARE_RWSEM(prepare_for_test_rwsem); 63 + DEFINE_STATIC_SRCU(prepare_for_test_srcu); 65 64 66 65 /* 67 66 * Completion tracking for worker threads. ··· 457 458 /* 458 459 * Block until initialization is done. 459 460 */ 460 - down_read(&prepare_for_test_rwsem); 461 + synchronize_srcu(&prepare_for_test_srcu); 461 462 462 463 t->start = get_cycles(); 463 464 for (i = 0; i < ARRAY_SIZE(test_case_array); i++) { ··· 486 487 t->data[index].time = delta; 487 488 } 488 489 t->stop = get_cycles(); 489 - 490 - up_read(&prepare_for_test_rwsem); 491 490 test_report_one_done(); 492 491 493 492 /* ··· 523 526 524 527 static void do_concurrent_test(void) 525 528 { 526 - int i, ret; 529 + int i, ret, idx; 527 530 528 531 /* 529 532 * Set some basic configurations plus sanity check. ··· 535 538 /* 536 539 * Put on hold all workers. 537 540 */ 538 - down_write(&prepare_for_test_rwsem); 541 + idx = srcu_read_lock(&prepare_for_test_srcu); 539 542 540 543 for (i = 0; i < nr_threads; i++) { 541 544 struct test_driver *t = &tdriver[i]; ··· 552 555 /* 553 556 * Now let the workers do their job. 554 557 */ 555 - up_write(&prepare_for_test_rwsem); 558 + srcu_read_unlock(&prepare_for_test_srcu, idx); 556 559 557 560 /* 558 561 * Sleep quiet until all workers are done with 1 second