Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752128AbcDVKkZ (ORCPT ); Fri, 22 Apr 2016 06:40:25 -0400 Received: from mailapp01.imgtec.com ([195.59.15.196]:22783 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751614AbcDVKkY (ORCPT ); Fri, 22 Apr 2016 06:40:24 -0400 From: James Hogan To: Thomas Gleixner CC: , James Hogan , Martin Schwidefsky Subject: [PATCH] clockevents: Retry programming min delta up to 10 times Date: Fri, 22 Apr 2016 11:40:11 +0100 Message-ID: <1461321611-6159-1-git-send-email-james.hogan@imgtec.com> X-Mailer: git-send-email 2.4.10 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.168.154.110] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2200 Lines: 66 Under virtualisation it is possible to get unexpected latency during a clockevent device's set_next_event() callback which can make it return -ETIME even for a delta based on min_delta_ns. The clockevents_program_min_delta() implementation for CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST=n doesn't handle retries when this happens, nor does clockevents_program_event() or its callers when force is true (for example hrtimer_reprogram()). This can result in hangs until the clock event device does a full period. It isn't appropriate to use MIN_ADJUST in this case as occasional hypervisor induced high latency will cause min_delta_ns to quickly increase to the maximum. Instead, borrow the retry pattern from the MIN_ADJUST case, but without making adjustments. We retry up to 10 times before giving up. Signed-off-by: James Hogan Cc: Thomas Gleixner Cc: Martin Schwidefsky --- kernel/time/clockevents.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c index a9b76a40319e..35f445f1bf39 100644 --- a/kernel/time/clockevents.c +++ b/kernel/time/clockevents.c @@ -281,16 +281,28 @@ static int clockevents_program_min_delta(struct clock_event_device *dev) { unsigned long long clc; int64_t delta; + int i; - delta = dev->min_delta_ns; - dev->next_event = ktime_add_ns(ktime_get(), delta); + for (i = 0;;) { + delta = dev->min_delta_ns; + dev->next_event = ktime_add_ns(ktime_get(), delta); - if (clockevent_state_shutdown(dev)) - return 0; + if (clockevent_state_shutdown(dev)) + return 0; - dev->retries++; - clc = ((unsigned long long) delta * dev->mult) >> dev->shift; - return dev->set_next_event((unsigned long) clc, dev); + dev->retries++; + clc = ((unsigned long long) delta * dev->mult) >> dev->shift; + if (dev->set_next_event((unsigned long) clc, dev) == 0) + return 0; + + if (++i > 9) { + /* + * We tried 10 times to program the device with the + * given min_delta_ns. Get out of here. + */ + return -ETIME; + } + } } #endif /* CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST */ -- 2.4.10