mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pan Xinhui <xinhui@linux.vnet.ibm.com>
To: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Jan Kara <jack@suse.com>, Petr Mladek <pmladek@suse.com>,
	Tejun Heo <tj@kernel.org>,
	Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	linux-kernel@vger.kernel.org,
	Byungchul Park <byungchul.park@lge.com>,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Subject: Re: [PATCH v11 3/3] printk: make printk.synchronous param rw
Date: Fri, 08 Apr 2016 12:04:55 +0800	[thread overview]
Message-ID: <57072DE7.50806@linux.vnet.ibm.com> (raw)
In-Reply-To: <1460050307-3718-4-git-send-email-sergey.senozhatsky@gmail.com>



On 2016年04月08日 01:31, Sergey Senozhatsky wrote:
> Change `synchronous' printk param to be RW, so user space
> can change printk mode back and forth to/from sync mode
> (which is considered to be more reliable).
> 
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> ---
>  kernel/printk/printk.c | 63 ++++++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 53 insertions(+), 10 deletions(-)
> 
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 89f5441..5ae6f73 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -288,9 +288,6 @@ static u32 log_buf_len = __LOG_BUF_LEN;
> 
>  /* Control whether printing to console must be synchronous. */
>  static bool __read_mostly printk_sync = true;
> -module_param_named(synchronous, printk_sync, bool, S_IRUGO);
> -MODULE_PARM_DESC(synchronous, "make printing to console synchronous");
> -
>  /* Printing kthread for async printk */
>  static struct task_struct *printk_kthread;
>  /* When `true' printing thread has messages to print */
> @@ -1785,7 +1782,7 @@ asmlinkage int vprintk_emit(int facility, int level,
>  		 * operate in sync mode once panic() occurred.
>  		 */
>  		if (console_loglevel != CONSOLE_LOGLEVEL_MOTORMOUTH &&
> -				printk_kthread) {
> +				!printk_sync && printk_kthread) {
>  			/* Offload printing to a schedulable context. */
>  			printk_kthread_need_flush_console = true;
>  			wake_up_process(printk_kthread);
> @@ -2757,6 +2754,16 @@ static int __init printk_late_init(void)
>  late_initcall(printk_late_init);
> 
>  #if defined CONFIG_PRINTK
> +/*
> + * kernel_param_ops.set is called from two places:
> + * - from parse_args()->printk_sync_set(), when we can't kthread_run(), so
> + *   we just set the param value. The actual initalization happens later,
> + *   from late_initcall().
> + *
> + * - from user space via sysfs knob; we can kthread_run() there (if needed).
> + */
> +static bool printk_initcall_done;
> +
>  static int printk_kthread_func(void *data)
>  {
>  	while (1) {
> @@ -2780,11 +2787,7 @@ static int printk_kthread_func(void *data)
>  	return 0;
>  }
> 
> -/*
> - * Init async printk via late_initcall, after core/arch/device/etc.
> - * initialization.
> - */
> -static int __init init_printk_kthread(void)
> +static int __init_printk_kthread(void)
>  {
>  	struct task_struct *thread;
>  	struct sched_param param = {
> @@ -2794,6 +2797,9 @@ static int __init init_printk_kthread(void)
>  	if (printk_sync)
>  		return 0;
> 
> +	if (printk_kthread)
> +		return 0;
> +
>  	thread = kthread_run(printk_kthread_func, NULL, "printk");
>  	if (IS_ERR(thread)) {
>  		pr_err("printk: unable to create printing thread\n");
> @@ -2805,6 +2811,43 @@ static int __init init_printk_kthread(void)
>  	printk_kthread = thread;
>  	return 0;
>  }
> +
> +static int printk_sync_set(const char *val, const struct kernel_param *kp)
> +{
> +	static DEFINE_MUTEX(printk_sync_lock);
> +	int ret;
> +
> +	mutex_lock(&printk_sync_lock);
> +	ret = param_set_bool(val, kp);
> +	if (ret) {
> +		mutex_unlock(&printk_sync_lock);
> +		return ret;
> +	}
> +
> +	if (printk_initcall_done)
> +		ret = __init_printk_kthread();
> +	mutex_unlock(&printk_sync_lock);
> +	return ret;
> +}
> +
> +static const struct kernel_param_ops param_ops_printk_sync = {
> +	.set = printk_sync_set,
> +	.get = param_get_bool,
> +};
> +
> +module_param_cb(synchronous, &param_ops_printk_sync, &printk_sync,
> +		S_IRUGO | S_IWUSR);
> +MODULE_PARM_DESC(synchronous, "make printing to console synchronous");
> +
> +/*
> + * Init async printk via late_initcall, after core/arch/device/etc.
> + * initialization.
> + */
> +static __init int init_printk_kthread(void)
> +{
> +	printk_initcall_done = true;
> +	return __init_printk_kthread();
hello, 

One confusion, Why not use a lock to protect __init_printk_kthread from parallel call? Otherwise I think there is a race.
But for simplicity, maybe you could write codes as below.

+	int ret  = __init_printk_kthread();
+	printk_initcall_done = true;
+	return ret;

In my opinion, using a lock is better.

thanks
xinhui
> +}
>  late_initcall(init_printk_kthread);
> 
>  /*
> @@ -2820,7 +2863,7 @@ static void wake_up_klogd_work_func(struct irq_work *irq_work)
>  	int pending = __this_cpu_xchg(printk_pending, 0);
> 
>  	if (pending & PRINTK_PENDING_OUTPUT) {
> -		if (printk_kthread) {
> +		if (!printk_sync && printk_kthread) {
>  			wake_up_process(printk_kthread);
>  		} else {
>  			/*
> 

  reply	other threads:[~2016-04-08  4:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-07 17:31 [PATCH v11 0/3] printk: Make printk() completely async Sergey Senozhatsky
2016-04-07 17:31 ` [PATCH v11 1/3] " Sergey Senozhatsky
2016-04-07 17:31 ` [PATCH v11 2/3] printk: Make wake_up_klogd_work_func() async Sergey Senozhatsky
2016-04-07 17:31 ` [PATCH v11 3/3] printk: make printk.synchronous param rw Sergey Senozhatsky
2016-04-08  4:04   ` Pan Xinhui [this message]
2016-04-08  5:29     ` Sergey Senozhatsky
2016-04-08  5:44       ` Pan Xinhui
2016-04-21 11:07       ` Petr Mladek
2016-04-22  1:28         ` Sergey Senozhatsky
2016-04-22  8:41           ` Petr Mladek
2016-04-22 13:12             ` Sergey Senozhatsky
2016-04-20 15:16   ` Jan Kara
2016-04-21  2:03     ` Sergey Senozhatsky
2016-04-16  2:55 ` [PATCH v11 0/3] printk: Make printk() completely async Sergey Senozhatsky
2016-04-16  5:44   ` Joe Perches
2016-04-21  2:14     ` Sergey Senozhatsky
2016-04-21  2:17       ` Joe Perches
2016-04-21 13:19         ` Jan Kara

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=57072DE7.50806@linux.vnet.ibm.com \
    --to=xinhui@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=byungchul.park@lge.com \
    --cc=jack@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=pmladek@suse.com \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=tj@kernel.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

Powered by JetHome