From: Jan Kara <jack@suse.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
pmladek@suse.com, KY Srinivasan <kys@microsoft.com>,
rostedt@goodmis.org, Jan Kara <jack@suse.cz>
Subject: [PATCH 2/7] printk: Start printing handover kthreads on demand
Date: Mon, 26 Oct 2015 05:52:45 +0100 [thread overview]
Message-ID: <1445835169-8203-3-git-send-email-jack@suse.com> (raw)
In-Reply-To: <1445835169-8203-1-git-send-email-jack@suse.com>
From: Jan Kara <jack@suse.cz>
Start kthreads for handing over printing only when printk.offload_chars
is set to value > 0 (i.e., when print offloading gets enabled).
Signed-off-by: Jan Kara <jack@suse.cz>
---
kernel/printk/printk.c | 78 +++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 64 insertions(+), 14 deletions(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 1b26263edfa7..b9bb4a7a6dff 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -98,6 +98,10 @@ static atomic_t printing_tasks_spinning = ATOMIC_INIT(0);
* CPUs.
*/
#define PRINTING_TASKS 2
+/* Pointers to printing kthreads */
+static struct task_struct *printing_kthread[PRINTING_TASKS];
+/* Serialization of changes to printk_offload_chars and kthread creation */
+static DEFINE_MUTEX(printk_kthread_mutex);
/* Wait queue printing kthreads sleep on when idle */
static DECLARE_WAIT_QUEUE_HEAD(print_queue);
@@ -303,6 +307,13 @@ static u32 clear_idx;
static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN);
static char *log_buf = __log_buf;
static u32 log_buf_len = __LOG_BUF_LEN;
+
+static int offload_chars_set(const char *val, const struct kernel_param *kp);
+static struct kernel_param_ops offload_chars_ops = {
+ .set = offload_chars_set,
+ .get = param_get_uint,
+};
+
/*
* How many characters can we print in one call of printk before asking
* other cpus to continue printing. 0 means infinity. Tunable via
@@ -311,7 +322,7 @@ static u32 log_buf_len = __LOG_BUF_LEN;
*/
static unsigned int __read_mostly printk_offload_chars = 1000;
-module_param_named(offload_chars, printk_offload_chars, uint,
+module_param_cb(offload_chars, &offload_chars_ops, &printk_offload_chars,
S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(offload_chars, "offload printing to console to a different"
" cpu after this number of characters");
@@ -2778,12 +2789,61 @@ static int printing_task(void *arg)
return 0;
}
-static int __init printk_late_init(void)
+static int printk_start_offload_kthreads(void)
{
- struct console *con;
int i;
struct task_struct *task;
+ /* Does handover of printing make any sense? */
+ if (printk_offload_chars == 0 || num_possible_cpus() <= 1)
+ return 0;
+ for (i = 0; i < PRINTING_TASKS; i++) {
+ if (printing_kthread[i])
+ continue;
+ task = kthread_run(printing_task, NULL, "print/%d", i);
+ if (IS_ERR(task))
+ goto out_err;
+ printing_kthread[i] = task;
+ }
+ return 0;
+out_err:
+ pr_err("printk: Cannot create printing thread: %ld\n", PTR_ERR(task));
+ /* Disable offloading if creating kthreads failed */
+ printk_offload_chars = 0;
+ return PTR_ERR(task);
+}
+
+static int offload_chars_set(const char *val, const struct kernel_param *kp)
+{
+ int ret;
+
+ /* Protect against parallel change of printk_offload_chars */
+ mutex_lock(&printk_kthread_mutex);
+ ret = param_set_uint(val, kp);
+ if (ret) {
+ mutex_unlock(&printk_kthread_mutex);
+ return ret;
+ }
+ ret = printk_start_offload_kthreads();
+ mutex_unlock(&printk_kthread_mutex);
+ return ret;
+}
+
+static void printk_offload_init(void)
+{
+ mutex_lock(&printk_kthread_mutex);
+ if (num_possible_cpus() <= 1) {
+ /* Offloading doesn't make sense. Disable print offloading. */
+ printk_offload_chars = 0;
+ } else
+ printk_start_offload_kthreads();
+ mutex_unlock(&printk_kthread_mutex);
+}
+
+static int __init printk_late_init(void)
+{
+ struct console *con;
+
for_each_console(con) {
if (!keep_bootcon && con->flags & CON_BOOT) {
unregister_console(con);
@@ -2791,17 +2851,7 @@ static int __init printk_late_init(void)
}
hotcpu_notifier(console_cpu_notify, 0);
- /* Does any handover of printing have any sence? */
- if (num_possible_cpus() <= 1)
- return 0;
-
- for (i = 0; i < PRINTING_TASKS; i++) {
- task = kthread_run(printing_task, NULL, "print/%d", i);
- if (IS_ERR(task)) {
- pr_err("printk: Cannot create printing thread: %ld\n",
- PTR_ERR(task));
- }
- }
+ printk_offload_init();
return 0;
}
--
2.1.4
next prev parent reply other threads:[~2015-10-26 4:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-26 4:52 [PATCH 0/6 v2] printk: Softlockup avoidance Jan Kara
2015-10-26 4:52 ` [PATCH 1/7] printk: Hand over printing to console if printing too long Jan Kara
2016-03-01 17:22 ` Denys Vlasenko
2016-03-02 9:30 ` Jan Kara
2015-10-26 4:52 ` Jan Kara [this message]
2015-10-26 4:52 ` [PATCH 3/7] kernel: Avoid softlockups in stop_machine() during heavy printing Jan Kara
2015-10-26 4:56 ` Jan Kara
2015-10-26 4:52 ` [PATCH 4/7] panic: Always flush printk buffer before panic Jan Kara
2015-10-26 4:52 ` [PATCH 5/7] printk: Add config option for disabling printk offloading Jan Kara
2015-10-26 4:52 ` [PATCH 6/7] printk: Avoid scheduling printing threads on the same CPU Jan Kara
-- strict thread matches above, loose matches on Subject: below --
2015-12-10 14:56 [PATCH 2/7] printk: Start printing handover kthreads on demand Sergey Senozhatsky
2015-12-10 15:06 ` Sergey Senozhatsky
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=1445835169-8203-3-git-send-email-jack@suse.com \
--to=jack@suse.com \
--cc=akpm@linux-foundation.org \
--cc=jack@suse.cz \
--cc=kys@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.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;
as well as URLs for NNTP newsgroup(s).