aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMichael Bohan <mbohan@codeaurora.org>2013-04-12 13:40:55 -0500
committerMister Oyster <oysterized@gmail.com>2017-09-11 11:31:31 +0200
commit644ea5676b133a06c34332fff4a22dc7280c7bb4 (patch)
tree69368bb08f7e144fbd499c35ea4578c995831dcb /kernel
parent0425711d7e7c58a232e5a421028cf8ea8d1b48b4 (diff)
hrtimer: Consider preemption when migrating hrtimer cpu_bases
Date Wed, 10 Apr 2013 14:07:47 -0700 When switching to a new cpu_base in switch_hrtimer_base(), we briefly enable preemption by unlocking the cpu_base lock in two places. During this interval it's possible for the running thread to be swapped to a different CPU. Consider the following example: CPU #0 CPU #1 ---- ---- hrtimer_start() ... lock_hrtimer_base() switch_hrtimer_base() this_cpu = 0; target_cpu_base = 0; raw_spin_unlock(&cpu_base->lock) <migrate to CPU 1> ... this_cpu == 0 cpu == this_cpu timer->base = CPU #0 timer->base != LOCAL_CPU Since the cached this_cpu is no longer accurate, we'll skip the hrtimer_check_target() check. Once we eventually go to program the hardware, we'll decide not to do so since it knows the real CPU that we're running on is not the same as the chosen base. As a consequence, we may end up missing the hrtimer's deadline. Fix this by updating the local CPU number each time we retake a cpu_base lock in switch_hrtimer_base(). Another possibility is to disable preemption across the whole of switch_hrtimer_base. This looks suboptimal since preemption would be disabled while waiting for lock(s). Change-Id: I46be5cf3069f8e6683ad8fff0841949bdb801684 Signed-off-by: Michael Bohan <mbohan@codeaurora.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/hrtimer.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index a6195617a..7832f70f4 100644
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -241,10 +241,12 @@ again:
raw_spin_unlock(&base->cpu_base->lock);
raw_spin_lock(&new_base->cpu_base->lock);
+ this_cpu = smp_processor_id();
+
if (cpu != this_cpu && hrtimer_check_target(timer, new_base)) {
- cpu = this_cpu;
raw_spin_unlock(&new_base->cpu_base->lock);
raw_spin_lock(&base->cpu_base->lock);
+ cpu = smp_processor_id();
timer->base = base;
goto again;
}