1 From b46f8c74afdd30cd52bfdcc2231470a0bab04416 Mon Sep 17 00:00:00 2001
2 From: James Hogan <james.hogan@imgtec.com>
3 Date: Fri, 22 Apr 2016 18:22:45 +0100
4 Subject: clockevents: Retry programming min delta up to 10 times
6 Under virtualisation it is possible to get unexpected latency during a
7 clockevent device's set_next_event() callback which can make it return
8 -ETIME even for a delta based on min_delta_ns.
10 The clockevents_program_min_delta() implementation for
11 CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST=n doesn't handle retries when this
12 happens, nor does clockevents_program_event() or its callers when force
13 is true (for example hrtimer_reprogram()). This can result in hangs
14 until the clock event device does a full period.
16 It isn't appropriate to use MIN_ADJUST in this case as occasional
17 hypervisor induced high latency will cause min_delta_ns to quickly
18 increase to the maximum.
19 Instead, borrow the retry pattern from the MIN_ADJUST case, but without
20 making adjustments. We retry up to 10 times before giving up.
22 (picked https://patchwork.kernel.org/patch/8909491/)
24 Signed-off-by: James Hogan <james.hogan@imgtec.com>
26 kernel/time/clockevents.c | 26 +++++++++++++++++++-------
27 1 file changed, 19 insertions(+), 7 deletions(-)
29 diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c
30 index 2c5bc77..ddd7e82 100644
31 --- a/kernel/time/clockevents.c
32 +++ b/kernel/time/clockevents.c
33 @@ -281,16 +281,28 @@ static int clockevents_program_min_delta(struct clock_event_device *dev)
35 unsigned long long clc;
39 - delta = dev->min_delta_ns;
40 - dev->next_event = ktime_add_ns(ktime_get(), delta);
42 + delta = dev->min_delta_ns;
43 + dev->next_event = ktime_add_ns(ktime_get(), delta);
45 - if (clockevent_state_shutdown(dev))
47 + if (clockevent_state_shutdown(dev))
51 - clc = ((unsigned long long) delta * dev->mult) >> dev->shift;
52 - return dev->set_next_event((unsigned long) clc, dev);
54 + clc = ((unsigned long long) delta * dev->mult) >> dev->shift;
55 + if (dev->set_next_event((unsigned long) clc, dev) == 0)
60 + * We tried 10 times to program the device with the
61 + * given min_delta_ns. Get out of here.
68 #endif /* CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST */