Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1711793

[RFC][PATCHv5 05/13] printk: enable printk offloading

From Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Newsgroups linux.kernel
Subject [RFC][PATCHv5 05/13] printk: enable printk offloading
Date 2017-08-15 05:10 +0200
Message-ID <ueAoW-4hM-17@gated-at.bofh.it> (permalink)
References <ueAff-3Y4-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Initialize kernel printing thread and make printk offloading
possible. By default `atomic_print_limit' is set to 0, so no
offloading will take place, unless requested by user.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
 kernel/printk/printk.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 3a0e78812818..05165f008bc8 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2913,6 +2913,65 @@ static DEFINE_PER_CPU(struct irq_work, wake_up_klogd_work) = {
 	.flags = IRQ_WORK_LAZY,
 };
 
+static int printk_kthread_func(void *data)
+{
+	while (1) {
+		set_current_state(TASK_INTERRUPTIBLE);
+		/*
+		 * We must check `printk_emergency' as well, to let
+		 * printk_emergency_begin() stop active `printk_kthread' at
+		 * some point. Otherwise we can end up in a loop:
+		 *   - we bail out of console_unlock() because of
+		 *     printk_kthread_should_stop()
+		 * and
+		 *   - don't schedule() and attempt to return back
+		 *     immediately to console_unlock() because we
+		 *     see PRINTK_PENDING_OUTPUT bit set.
+		 */
+		if (!test_bit(PRINTK_PENDING_OUTPUT, &printk_pending) ||
+				atomic_read(&printk_emergency) != 0)
+			schedule();
+
+		__set_current_state(TASK_RUNNING);
+
+		/* We might have been woken for stop */
+		if (kthread_should_park())
+			kthread_parkme();
+
+		console_lock();
+		console_unlock();
+
+		/* We might have been blocked on console_sem */
+		if (kthread_should_park())
+			kthread_parkme();
+	}
+
+	return 0;
+}
+
+/*
+ * Init printk kthread at late_initcall stage, after core/arch/device/etc.
+ * initialization.
+ */
+static int __init init_printk_kthread(void)
+{
+	struct task_struct *thread;
+
+	if (!alloc_cpumask_var(&printk_offload_cpus, GFP_KERNEL))
+		return -ENOMEM;
+
+	thread = kthread_run(printk_kthread_func, NULL, "printk");
+	if (IS_ERR(thread)) {
+		pr_err("printk: unable to create printing thread\n");
+		free_cpumask_var(printk_offload_cpus);
+		return PTR_ERR(thread);
+	}
+
+	printk_kthread = thread;
+	return 0;
+}
+late_initcall(init_printk_kthread);
+
 void wake_up_klogd(void)
 {
 	preempt_disable();
-- 
2.14.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC][PATCHv5 00/13] printk: introduce printing kernel thread Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:00 +0200
  [RFC][PATCHv5 12/13] printk: do not cond_resched() when we can offload Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:10 +0200
  [RFC][PATCHv5 10/13] printk: force printk_kthread to offload printing Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:10 +0200
  [RFC][PATCHv5 04/13] printk: add enforce_emergency parameter Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:10 +0200
  [RFC][PATCHv5 07/13] printk: register syscore notifier Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:10 +0200
    Re: [RFC][PATCHv5 07/13] printk: register syscore notifier "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2017-08-15 14:10 +0200
      Re: [RFC][PATCHv5 07/13] printk: register syscore notifier Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-08-16 09:00 +0200
        Re: [RFC][PATCHv5 07/13] printk: register syscore notifier "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2017-08-16 15:10 +0200
  [RFC][PATCHv5 11/13] printk: always offload printing from user-space processes Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:10 +0200
  [RFC][PATCHv5 05/13] printk: enable printk offloading Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:10 +0200
  [RFC][PATCHv5 01/13] printk: move printk_pending out of per-cpu Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:10 +0200
  [RFC][PATCHv5 02/13] printk: introduce printing kernel thread Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:10 +0200
  [RFC][PATCHv5 08/13] printk: set watchdog_thresh as maximum value for atomic_print_limit Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:10 +0200
  [RFC][PATCHv5 03/13] printk: add sync printk_emergency API Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:10 +0200
  [RFC][PATCHv5 09/13] printk: add auto-emergency enforcement mechanism Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:10 +0200
  [RFC][PATCHv5 13/13] printk: move offloading logic to per-cpu Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:10 +0200
  [RFC][PATCHv5 06/13] printk: register PM notifier Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-08-15 05:10 +0200
    Re: [RFC][PATCHv5 06/13] printk: register PM notifier "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2017-08-15 14:00 +0200
      Re: [RFC][PATCHv5 06/13] printk: register PM notifier Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-08-16 09:40 +0200
        Re: [RFC][PATCHv5 06/13] printk: register PM notifier "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2017-08-16 15:10 +0200
          Re: [RFC][PATCHv5 06/13] printk: register PM notifier Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-08-17 08:00 +0200
            Re: [RFC][PATCHv5 06/13] printk: register PM notifier "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2017-08-17 18:00 +0200
              Re: [RFC][PATCHv5 06/13] printk: register PM notifier Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-08-18 01:20 +0200
  Re: [RFC][PATCHv5 00/13] printk: introduce printing kernel thread Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-08-23 10:40 +0200

csiph-web