linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RT] cpu hotplug: Document why PREEMPT_RT uses a spinlock
@ 2013-12-05 14:16 Steven Rostedt
  2014-01-24 12:41 ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 2+ messages in thread
From: Steven Rostedt @ 2013-12-05 14:16 UTC (permalink / raw)
  To: LKML, linux-rt-users
  Cc: Thomas Gleixner, Sebastian Andrzej Siewior, Nicholas Mc Guire

The patch:

    cpu: Make hotplug.lock a "sleeping" spinlock on RT
    
    Tasks can block on hotplug.lock in pin_current_cpu(), but their
    state might be != RUNNING. So the mutex wakeup will set the state
    unconditionally to RUNNING. That might cause spurious unexpected
    wakeups. We could provide a state preserving mutex_lock() function,
    but this is semantically backwards. So instead we convert the
    hotplug.lock() to a spinlock for RT, which has the state preserving
    semantics already.

Fixed a bug where the hotplug lock on PREEMPT_RT can be called after a
task set its state to TASK_UNINTERRUPTIBLE and before it called
schedule. If the hotplug_lock used a mutex, and there was contention,
the current task's state would be turned to TASK_RUNNABLE and the
schedule call will not sleep. This caused unexpected results.

Although the patch had a description of the change, the code had no
comments about it. This causes confusion to those that review the code,
and as PREEMPT_RT is held in a quilt queue and not git, it's not as easy
to see why a change was made. Even if it was in git, the code should
still have a comment for something as subtle as this.

Document the rational for using a spinlock on PREEMPT_RT in the hotplug
lock code.

Reported-by: Nicholas Mc Guire <der.herr@hofr.at>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

diff --git a/kernel/cpu.c b/kernel/cpu.c
index 063c2bb..c3014f1 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -80,6 +80,14 @@ struct hotplug_pcp {
 	struct completion synced;
 	struct completion unplug_wait;
 #ifdef CONFIG_PREEMPT_RT_FULL
+	/*
+	 * Note, on PREEMPT_RT, the hotplug lock must save the state of
+	 * the task, otherwise the mutex will cause the task to fail
+	 * to sleep when required. (Because it's called from migrate_disable())
+	 *
+	 * The spinlock_t on PREEMPT_RT is a mutex that saves the task's
+	 * state.
+	 */
 	spinlock_t lock;
 #else
 	struct mutex mutex;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH RT] cpu hotplug: Document why PREEMPT_RT uses a spinlock
  2013-12-05 14:16 [PATCH RT] cpu hotplug: Document why PREEMPT_RT uses a spinlock Steven Rostedt
@ 2014-01-24 12:41 ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Andrzej Siewior @ 2014-01-24 12:41 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, linux-rt-users, Thomas Gleixner, Nicholas Mc Guire

* Steven Rostedt | 2013-12-05 09:16:52 [-0500]:

>Document the rational for using a spinlock on PREEMPT_RT in the hotplug
>lock code.
applied.

>Reported-by: Nicholas Mc Guire <der.herr@hofr.at>
>Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
>

Sebastian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-01-24 12:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-05 14:16 [PATCH RT] cpu hotplug: Document why PREEMPT_RT uses a spinlock Steven Rostedt
2014-01-24 12:41 ` Sebastian Andrzej Siewior

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).