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


Groups > linux.kernel > #1311153

Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of console_trylock callers

From Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Newsgroups linux.kernel
Subject Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of console_trylock callers
Date 2016-01-17 15:30 +0100
Message-ID <qRWv8-3B6-5@gated-at.bofh.it> (permalink)
References <qQIaS-1Pl-1@gated-at.bofh.it> <qQIaT-1Pl-19@gated-at.bofh.it> <qRWls-3wI-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On (01/17/16 23:11), Sergey Senozhatsky wrote:
[..]
>  	console_locked = 1;
> -	console_may_schedule = 0;
> +	console_may_schedule = !(oops_in_progress ||
> +			irqs_disabled() ||
> +			in_atomic(),
				^^^^ fat fingers, obviously. ||
> +			rcu_preempt_depth());

sorry.

===8<===8<===

 console_unlock() allows to cond_resched() if its caller has
set `console_may_schedule' to 1 (this functionality present
since commit 'printk: do cond_resched() between lines while
outputting to consoles').

The rules are:
-- console_lock() always sets `console_may_schedule' to 1
-- console_trylock() always sets `console_may_schedule' to 0

However, console_trylock() callers (among them is printk()) are
not necessarily executing in atomic contexts, and some of them
can cond_resched() in console_unlock(). So console_trylock()
can set `console_may_schedule' to 0 only if cond_resched() is
invalid in the current context, and set it to 1 otherwise.

The patch also drops explicit preempt_disable()/preempt_enable()
calls in vprintk_emit().

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
V2: rcu_preempt_depth() on preempt RCU kernels

 kernel/printk/printk.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index ae641d7..9ac05e0 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1777,20 +1777,12 @@ asmlinkage int vprintk_emit(int facility, int level,
 	if (!in_sched) {
 		lockdep_off();
 		/*
-		 * Disable preemption to avoid being preempted while holding
-		 * console_sem which would prevent anyone from printing to
-		 * console
-		 */
-		preempt_disable();
-
-		/*
 		 * Try to acquire and then immediately release the console
 		 * semaphore.  The release will print out buffers and wake up
 		 * /dev/kmsg and syslog() users.
 		 */
 		if (console_trylock_for_printk())
 			console_unlock();
-		preempt_enable();
 		lockdep_on();
 	}
 
@@ -2123,7 +2115,10 @@ int console_trylock(void)
 		return 0;
 	}
 	console_locked = 1;
-	console_may_schedule = 0;
+	console_may_schedule = !(oops_in_progress ||
+			irqs_disabled() ||
+			in_atomic() ||
+			rcu_preempt_depth());
 	return 1;
 }
 EXPORT_SYMBOL(console_trylock);
-- 
2.7.0

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


Thread

Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of  console_trylock callers Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-01-17 15:20 +0100
  Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of  console_trylock callers Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-01-17 15:30 +0100
    Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of  console_trylock callers Petr Mladek <pmladek@suse.com> - 2016-01-18 17:20 +0100
      Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of  console_trylock callers Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-01-19 02:20 +0100
        Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of  console_trylock callers Petr Mladek <pmladek@suse.com> - 2016-01-19 16:20 +0100
          Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of  console_trylock callers Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-01-20 05:00 +0100
            Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of  console_trylock callers Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-01-20 13:00 +0100
              Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of  console_trylock callers Petr Mladek <pmladek@suse.com> - 2016-01-20 13:40 +0100
            Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of  console_trylock callers Petr Mladek <pmladek@suse.com> - 2016-01-20 13:40 +0100
              Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of  console_trylock callers Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-01-21 02:30 +0100
                Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of  console_trylock callers Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-01-21 07:00 +0100
                Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of  console_trylock callers Petr Mladek <pmladek@suse.com> - 2016-01-22 10:50 +0100
                Re: [RFC][PATCH -next 2/2] printk: set may_schedule for some of  console_trylock callers Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-01-23 05:50 +0100

csiph-web