Skip to contentSkip to conversation

rcuperf: Remove useless while loops around wait_event

PATCH Applied Joel Fernandes (Google) 3 participants 4 messages May 25, 2020 – May 27, 2020 RCU

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 rcuperf: Remove useless while loops around wait_event

wait_event() already retries if the condition for the wake up is not satisifed after wake up. Remove them from the rcuperf test.

---
 kernel/rcu/rcuperf.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
kernel/rcu/rcuperf.c +4 -10
index 16dd1e6b7c09f..246da8fe199e8 100644
@@ -576,11 +576,8 @@ static int compute_real(int n)
 static int
 rcu_perf_shutdown(void *arg)
 {
-	do {
-		wait_event(shutdown_wq,
-			   atomic_read(&n_rcu_perf_writer_finished) >=
-			   nrealwriters);
-	} while (atomic_read(&n_rcu_perf_writer_finished) < nrealwriters);
+	wait_event(shutdown_wq,
+		   atomic_read(&n_rcu_perf_writer_finished) >= nrealwriters);
 	smp_mb(); /* Wake before output. */
 	rcu_perf_cleanup();
 	kernel_power_off();
@@ -693,11 +690,8 @@ kfree_perf_cleanup(void)
 static int
 kfree_perf_shutdown(void *arg)
 {
-	do {
-		wait_event(shutdown_wq,
-			   atomic_read(&n_kfree_perf_thread_ended) >=
-			   kfree_nrealthreads);
-	} while (atomic_read(&n_kfree_perf_thread_ended) < kfree_nrealthreads);
+	wait_event(shutdown_wq,
+		   atomic_read(&n_kfree_perf_thread_ended) >= kfree_nrealthreads);
 
 	smp_mb(); /* Wake before output. */
 
Signature · 1 line
2.27.0.rc0.183.gde8f92d652-goog
#1 lore raw

PATCH 2/2 refperf: Add a test to measure performance of read-side synchronization

Add a test for comparing the performance of RCU with various read-side synchronization mechanisms. The test has proved useful for collecting data and performing these comparisons.

Currently RCU, SRCU, reader-writer lock, reader-writer semaphore and reference counting can be measured using refperf.perf_type parameter. Each invocation of the test runs measures performance of a specific mechanism.

The maximum number of CPUs to concurrently run readers on is chosen by the test itself and is 75% of the total number of CPUs. So if you had 24 CPUs, the test runs with a maximum of 18 parallel readers.

A number of experiments are conducted, and in each experiment, the number of readers is increased by 1, upto the 75% of CPUs mark. During each experiment, all readers execute an empty loop with refperf.loops iterations and time the total loop duration. This is then averaged.

Example output:
Parameters "refperf.perf_type=srcu refperf.loops=2000000" looks like:

[    3.347133] srcu-ref-perf:
[    3.347133] Threads  Time(ns)
[    3.347133] 1        36
[    3.347133] 2        34
[    3.347133] 3        34
[    3.347133] 4        34
[    3.347133] 5        33
[    3.347133] 6        33
[    3.347133] 7        33
[    3.347133] 8        33
[    3.347133] 9        33
[    3.347133] 10       33
[    3.347133] 11       33
[    3.347133] 12       33
[    3.347133] 13       33
[    3.347133] 14       33
[    3.347133] 15       32
[    3.347133] 16       33
[    3.347133] 17       33
[    3.347133] 18       34
---
 kernel/rcu/Kconfig.debug |  19 ++
 kernel/rcu/Makefile      |   1 +
 kernel/rcu/refperf.c     | 558 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 578 insertions(+)
 create mode 100644 kernel/rcu/refperf.c
kernel/rcu/Kconfig.debug +19 -0
index a4db41d9a401e..04c35e1e3c3fa 100644
@@ -56,6 +56,25 @@ config RCU_TORTURE_TEST
 	  Say M if you want the RCU torture tests to build as a module.
 	  Say N if you are unsure.
 
+config RCU_REF_PERF_TEST
+	tristate "Performance tests for read-side synchronization (RCU and others)"
+	depends on DEBUG_KERNEL
+	select TORTURE_TEST
+	select SRCU
+	select TASKS_RCU
+	select TASKS_RUDE_RCU
+	select TASKS_TRACE_RCU
+	default n
+	help
+	  This option provides a kernel module that runs performance tests
+	  useful comparing RCU with various read-side synchronization mechanisms.
+	  The kernel module may be built after the fact on the running kernel to be
+	  tested, if desired.
+
+	  Say Y here if you want these performance tests built into the kernel.
+	  Say M if you want to build it as a module instead.
+	  Say N if you are unsure.
+
 config RCU_CPU_STALL_TIMEOUT
 	int "RCU CPU stall timeout in seconds"
 	depends on RCU_STALL_COMMON
kernel/rcu/Makefile +1 -0
index f91f2c2cf1382..ba7d82609cbe1 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_TREE_SRCU) += srcutree.o
 obj-$(CONFIG_TINY_SRCU) += srcutiny.o
 obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
 obj-$(CONFIG_RCU_PERF_TEST) += rcuperf.o
+obj-$(CONFIG_RCU_REF_PERF_TEST) += refperf.o
 obj-$(CONFIG_TREE_RCU) += tree.o
 obj-$(CONFIG_TINY_RCU) += tiny.o
 obj-$(CONFIG_RCU_NEED_SEGCBLIST) += rcu_segcblist.o
kernel/rcu/refperf.c new file +558 -0

558 lines not on this page · raw message

Signature · 1 line
2.27.0.rc0.183.gde8f92d652-goog
#2 lore raw

Re: [PATCH 2/2] refperf: Add a test to measure performance of read-side synchronization

Thank you for the patch! Perhaps something to improve:

Hi "Joel,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on rcu/dev]
[also build test WARNING on linus/master v5.7-rc7 next-20200526] [cannot apply to linux/master]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Joel-Fernandes-Google/rcuperf-Remove-useless-while-loops-around-wait_event/20200525-123825
base:   https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git dev
config: openrisc-randconfig-r011-20200527 (attached as .config)
compiler: or1k-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=openrisc

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> kernel/rcu/refperf.c:298:6: warning: no previous prototype for 'reset_readers' [-Wmissing-prototypes]
298 | void reset_readers(int n)
|      ^~~~~~~~~~~~~
>> kernel/rcu/refperf.c:311:5: warning: no previous prototype for 'process_durations' [-Wmissing-prototypes]

311 | u64 process_durations(int n)
| ^~~~~~~~~~~~~~~~~

vim +/reset_readers +298 kernel/rcu/refperf.c

297

 > 298	void reset_readers(int n)
   299	{
   300		int i;
   301		struct reader_task *rt;
   302	
   303		for (i = 0; i < n; i++) {
   304			rt = &(reader_tasks[i]);
   305	
   306			rt->last_duration_ns = 0;
   307		}
   308	}
   309	
   310	// Print the results of each reader and return the sum of all their durations.
 > 311	u64 process_durations(int n)

312 {
313 int i;
314 struct reader_task *rt;
315 char buf1[64];
316 char buf[512];
317 u64 sum = 0;
318
319 buf[0] = 0;
320 sprintf(buf, "Experiment #%d (Format: <THREAD-NUM>:<Total loop time in ns>)",
321 exp_idx);
322
323 for (i = 0; i <= n && !torture_must_stop(); i++) {
324 rt = &(reader_tasks[i]);
325 sprintf(buf1, "%d: %llu\t", i, rt->last_duration_ns);
326
327 if (i % 5 == 0)
328 strcat(buf, "\n");
329 strcat(buf, buf1);
330
331 sum += rt->last_duration_ns;
332 }
333 strcat(buf, "\n");
334
335 PERFOUT("%s\n", buf);
336
337 return sum;
338 }
339

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer Applied
#3 lore raw
In reply to Joel Fernandes (Google)
Quoted 4 lines · Joel Fernandes (Google)

wait_event() already retries if the condition for the wake up is not satisifed after wake up. Remove them from the rcuperf test.

Queued the series, thank you, Joel!

Thanx, Paul

Quoted 39 lines
---
 kernel/rcu/rcuperf.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
kernel/rcu/rcuperf.c +4 -10
index 16dd1e6b7c09f..246da8fe199e8 100644
@@ -576,11 +576,8 @@ static int compute_real(int n)
 static int
 rcu_perf_shutdown(void *arg)
 {
-	do {
-		wait_event(shutdown_wq,
-			   atomic_read(&n_rcu_perf_writer_finished) >=
-			   nrealwriters);
-	} while (atomic_read(&n_rcu_perf_writer_finished) < nrealwriters);
+	wait_event(shutdown_wq,
+		   atomic_read(&n_rcu_perf_writer_finished) >= nrealwriters);
 	smp_mb(); /* Wake before output. */
 	rcu_perf_cleanup();
 	kernel_power_off();
@@ -693,11 +690,8 @@ kfree_perf_cleanup(void)
 static int
 kfree_perf_shutdown(void *arg)
 {
-	do {
-		wait_event(shutdown_wq,
-			   atomic_read(&n_kfree_perf_thread_ended) >=
-			   kfree_nrealthreads);
-	} while (atomic_read(&n_kfree_perf_thread_ended) < kfree_nrealthreads);
+	wait_event(shutdown_wq,
+		   atomic_read(&n_kfree_perf_thread_ended) >= kfree_nrealthreads);
 
 	smp_mb(); /* Wake before output. */
 
Signature · 1 line
2.27.0.rc0.183.gde8f92d652-goog