[RFC PATCH 14/18] ring_buffer: Allow to cleanly freeze the ring buffer benchmark kthreads

Petr Mladek pmladek at suse.cz
Fri Jun 5 08:01:13 PDT 2015


One target of the switch to the kthread iterant API is to make
most kthreads cleanly freezable.

This patch adds try_to_freeze() where appropriate and enables
freezing.

Signed-off-by: Petr Mladek <pmladek at suse.cz>
---
 kernel/trace/ring_buffer_benchmark.c | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c
index 164f3762cc82..2d276b892aea 100644
--- a/kernel/trace/ring_buffer_benchmark.c
+++ b/kernel/trace/ring_buffer_benchmark.c
@@ -6,6 +6,7 @@
 #include <linux/ring_buffer.h>
 #include <linux/completion.h>
 #include <linux/kthread.h>
+#include <linux/freezer.h>
 #include <linux/module.h>
 #include <linux/ktime.h>
 #include <asm/local.h>
@@ -207,6 +208,7 @@ static void ring_buffer_consumer(void)
 			break;
 
 		schedule();
+		try_to_freeze();
 	}
 	reader_finish = 0;
 	complete(&read_done);
@@ -252,19 +254,21 @@ static void ring_buffer_producer(void)
 		if (consumer && !(cnt % wakeup_interval))
 			wake_up_process(consumer);
 
+		if (cnt % wakeup_interval) {
 #ifndef CONFIG_PREEMPT
-		/*
-		 * If we are a non preempt kernel, the 10 second run will
-		 * stop everything while it runs. Instead, we will call
-		 * cond_resched and also add any time that was lost by a
-		 * rescedule.
-		 *
-		 * Do a cond resched at the same frequency we would wake up
-		 * the reader.
-		 */
-		if (cnt % wakeup_interval)
+			/*
+			 * If we are a non preempt kernel, the 10 second run
+			 * will stop everything while it runs. Instead, we will
+			 * call cond_resched and also add any time that was
+			 * lost by a rescedule.
+			 *
+			 * Do a cond resched at the same frequency we would
+			 * wake up the reader.
+			 */
 			cond_resched();
 #endif
+			try_to_freeze();
+		}
 
 	} while (ktime_before(end_time, timeout) && !kill_test);
 	trace_printk("End ring buffer hammer\n");
@@ -356,12 +360,6 @@ static void ring_buffer_producer(void)
 	}
 }
 
-static void ring_buffer_consumer_thread_init(void *arg)
-{
-	/* it does not matter where we freeze */
-	current->flags |= PF_NOFREEZE;
-}
-
 static void ring_buffer_consumer_thread_func(void *arg)
 {
 	if (kill_test)
@@ -375,9 +373,6 @@ static void ring_buffer_consumer_thread_func(void *arg)
 static void ring_buffer_producer_thread_init(void *arg)
 {
 	init_completion(&read_start);
-
-	/* it does not matter where we freeze */
-	current->flags |= PF_NOFREEZE;
 }
 
 static void ring_buffer_producer_thread_func(void *arg)
@@ -413,7 +408,6 @@ static int __init ring_buffer_benchmark_init(void)
 		return -ENOMEM;
 
 	consumer_kti.type = KTI_INT_SLEEP;
-	consumer_kti.func = ring_buffer_consumer_thread_init;
 	consumer_kti.func = ring_buffer_consumer_thread_func;
 
 	if (!disable_reader) {
-- 
1.8.5.6




More information about the linux-mtd mailing list