mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>, Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	linux-kernel@vger.kernel.org,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Subject: Re: [RFC][PATCH 0/4] printk: introduce printing kernel thread
Date: Fri, 24 Mar 2017 13:43:59 +0900	[thread overview]
Message-ID: <20170324044359.GA448@jagdpanzerIV.localdomain> (raw)
In-Reply-To: <20170324015936.GA366@jagdpanzerIV.localdomain>

On (03/24/17 10:59), Sergey Senozhatsky wrote:
[..]
> and we can jump between rescue-normal printk modes, so this should
> also return back the throttling of tasks which printk() a lot (item
> (2) in patch set cover letter) that we used to have.

ok, I obviously lied here "this should also return back the throttling".
throttling is a bit hard to implement properly.


automatic printk rescue mode on console output stall [when we can't
wake_up printk_kthread] is not so difficult. something like below.

may be it's too simple minded. // it does not handle throttling.


---
 kernel/printk/printk.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index e84b9fbb298f..005741486376 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -447,6 +447,12 @@ static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN);
 static char *log_buf = __log_buf;
 static u32 log_buf_len = __LOG_BUF_LEN;
 
+/*
+ * How many pending messages we can have in the logbuf before we
+ * switch to printk rescue mode (stop waking up printk_kthread).
+ */
+#define CONSOLE_STALL_MESSAGES_LIMIT	50
+
 static struct task_struct *printk_kthread __read_mostly;
 /*
  * We can't call into the scheduler (wake_up() printk kthread) during
@@ -1739,6 +1745,11 @@ static size_t log_output(int facility, int level, enum log_flags lflags, const c
 	return log_store(facility, level, lflags, 0, dict, dictlen, text, text_len);
 }
 
+static bool console_output_stall(void)
+{
+	return (log_next_seq - console_seq) > CONSOLE_STALL_MESSAGES_LIMIT;
+}
+
 asmlinkage int vprintk_emit(int facility, int level,
 			    const char *dict, size_t dictlen,
 			    const char *fmt, va_list args)
@@ -1750,6 +1761,7 @@ asmlinkage int vprintk_emit(int facility, int level,
 	unsigned long flags;
 	int printed_len = 0;
 	bool in_sched = false;
+	bool printk_stall;
 
 	if (level == LOGLEVEL_SCHED) {
 		level = LOGLEVEL_DEFAULT;
@@ -1811,6 +1823,7 @@ asmlinkage int vprintk_emit(int facility, int level,
 
 	printed_len += log_output(facility, level, lflags, dict, dictlen, text, text_len);
 
+	printk_stall = console_output_stall();
 	set_bit(PRINTK_PENDING_OUTPUT, &printk_pending);
 	logbuf_unlock_irqrestore(flags);
 
@@ -1824,7 +1837,7 @@ asmlinkage int vprintk_emit(int facility, int level,
 		 * from a dedicated printk_kthread, which always runs in
 		 * schedulable context.
 		 */
-		if (printk_kthread_enabled()) {
+		if (!printk_stall && printk_kthread_enabled()) {
 			printk_safe_enter_irqsave(flags);
 			wake_up_process(printk_kthread);
 			printk_safe_exit_irqrestore(flags);
-- 
2.12.1

  reply	other threads:[~2017-03-24  4:44 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-06 12:45 Sergey Senozhatsky
2017-03-06 12:45 ` [RFC][PATCH 1/4] " Sergey Senozhatsky
2017-03-22 16:40   ` Petr Mladek
2017-03-23  5:12     ` Sergey Senozhatsky
2017-03-23 10:40       ` Petr Mladek
2017-03-24  5:20         ` Sergey Senozhatsky
2017-03-06 12:45 ` [RFC][PATCH 2/4] printk: offload printing from wake_up_klogd_work_func() Sergey Senozhatsky
2017-03-17 12:19   ` Petr Mladek
2017-03-18  9:57     ` Sergey Senozhatsky
2017-03-20 16:09       ` Petr Mladek
2017-03-21  4:01         ` Sergey Senozhatsky
2017-03-23  9:00         ` Sergey Senozhatsky
2017-03-23 12:11           ` Petr Mladek
2017-03-06 12:45 ` [RFC][PATCH 3/4] kernel, power: disable printk_kthread in unsafe places Sergey Senozhatsky
2017-03-22 15:38   ` Petr Mladek
2017-03-06 12:45 ` [RFC][PATCH 4/4] printk: enable printk offloading Sergey Senozhatsky
2017-03-22 15:43   ` Petr Mladek
2017-03-22 16:40     ` Sergey Senozhatsky
2017-03-22 17:59 ` [RFC][PATCH 0/4] printk: introduce printing kernel thread Peter Zijlstra
2017-03-23  4:09   ` Sergey Senozhatsky
2017-03-23  8:51     ` Peter Zijlstra
2017-03-24  1:59       ` Sergey Senozhatsky
2017-03-24  4:43         ` Sergey Senozhatsky [this message]
2017-03-24 14:43         ` Petr Mladek
2017-03-25  0:18           ` Sergey Senozhatsky
2017-03-23 12:01   ` Petr Mladek
2017-04-03 11:53 ` Sergey Senozhatsky
2017-04-04 12:59   ` Petr Mladek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170324044359.GA448@jagdpanzerIV.localdomain \
    --to=sergey.senozhatsky.work@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rjw@rjwysocki.net \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®