]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/blob - rt-patches/0220-cpu-hotplug-Document-why-PREEMPT_RT-uses-a-spinlock.patch
WAR:media:i2c:ov5693: add flip and mirror setting
[hercules2020/nv-tegra/linux-4.4.git] / rt-patches / 0220-cpu-hotplug-Document-why-PREEMPT_RT-uses-a-spinlock.patch
1 From de3de54b1610dfac21bf571fa03ccee3d94955df Mon Sep 17 00:00:00 2001
2 From: Steven Rostedt <rostedt@goodmis.org>
3 Date: Thu, 5 Dec 2013 09:16:52 -0500
4 Subject: [PATCH 220/365] cpu hotplug: Document why PREEMPT_RT uses a spinlock
5
6 The patch:
7
8     cpu: Make hotplug.lock a "sleeping" spinlock on RT
9
10     Tasks can block on hotplug.lock in pin_current_cpu(), but their
11     state might be != RUNNING. So the mutex wakeup will set the state
12     unconditionally to RUNNING. That might cause spurious unexpected
13     wakeups. We could provide a state preserving mutex_lock() function,
14     but this is semantically backwards. So instead we convert the
15     hotplug.lock() to a spinlock for RT, which has the state preserving
16     semantics already.
17
18 Fixed a bug where the hotplug lock on PREEMPT_RT can be called after a
19 task set its state to TASK_UNINTERRUPTIBLE and before it called
20 schedule. If the hotplug_lock used a mutex, and there was contention,
21 the current task's state would be turned to TASK_RUNNABLE and the
22 schedule call will not sleep. This caused unexpected results.
23
24 Although the patch had a description of the change, the code had no
25 comments about it. This causes confusion to those that review the code,
26 and as PREEMPT_RT is held in a quilt queue and not git, it's not as easy
27 to see why a change was made. Even if it was in git, the code should
28 still have a comment for something as subtle as this.
29
30 Document the rational for using a spinlock on PREEMPT_RT in the hotplug
31 lock code.
32
33 Reported-by: Nicholas Mc Guire <der.herr@hofr.at>
34 Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
35 Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
36 ---
37  kernel/cpu.c | 8 ++++++++
38  1 file changed, 8 insertions(+)
39
40 diff --git a/kernel/cpu.c b/kernel/cpu.c
41 index d3e2928..4522046 100644
42 --- a/kernel/cpu.c
43 +++ b/kernel/cpu.c
44 @@ -112,6 +112,14 @@ struct hotplug_pcp {
45         int grab_lock;
46         struct completion synced;
47  #ifdef CONFIG_PREEMPT_RT_FULL
48 +       /*
49 +        * Note, on PREEMPT_RT, the hotplug lock must save the state of
50 +        * the task, otherwise the mutex will cause the task to fail
51 +        * to sleep when required. (Because it's called from migrate_disable())
52 +        *
53 +        * The spinlock_t on PREEMPT_RT is a mutex that saves the task's
54 +        * state.
55 +        */
56         spinlock_t lock;
57  #else
58         struct mutex mutex;
59 -- 
60 2.7.4
61