From patchwork Thu Mar 12 04:16:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 45719 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f200.google.com (mail-we0-f200.google.com [74.125.82.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 96E04214BF for ; Thu, 12 Mar 2015 04:17:03 +0000 (UTC) Received: by wesp10 with SMTP id p10sf9698284wes.3 for ; Wed, 11 Mar 2015 21:17:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=sTnDGqjyglKsHOoJxxQhkXu0Tq46qBesAt04dxXVMKM=; b=QawejI+5+bgJsi9u6K3mtp29rx6vhlGUjRHsPMgUPlarN6HQ2EZOV/Ojb3nFcimY1h PP1U+MALADA3vVFJjx7m4WdashnY6bHHZGGovdEK24zZdW3WYAgQ7n+z31jFCKFkiJwk pNa0gqGS6UoKcF7Emzb5dQAe5UcZvNmZviLj5aWE75bLJFs1YXLtt99mb1Jwd4gyWHgz SkWOQGjaPbyKKq5y/J4dZnrkdjzftyipSIOiG6AAuzpvf9JdNPPF5HF+TNkBv4B6gqh+ lmHJ8VRUnCavO+m+qCCB6AnPIVfJBn4pqtkajpsTvTfNqML12aHtVf2uKoN0oHEf0W+Q JSlw== X-Gm-Message-State: ALoCoQlBmTkB6t8r/3vwP1hTK5t1qgKfq/CnVq2IE4o5WC9jfPchlAzXwYjgXVzf+cNEhRm8EWBQ X-Received: by 10.180.81.134 with SMTP id a6mr99549wiy.1.1426133822922; Wed, 11 Mar 2015 21:17:02 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.38 with SMTP id x6ls241842lax.63.gmail; Wed, 11 Mar 2015 21:17:02 -0700 (PDT) X-Received: by 10.152.28.5 with SMTP id x5mr36706553lag.112.1426133822506; Wed, 11 Mar 2015 21:17:02 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id a4si3581424lbs.98.2015.03.11.21.17.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 21:17:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by labmn12 with SMTP id mn12so13278507lab.0 for ; Wed, 11 Mar 2015 21:17:02 -0700 (PDT) X-Received: by 10.112.147.229 with SMTP id tn5mr3705147lbb.106.1426133822233; Wed, 11 Mar 2015 21:17:02 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.35.133 with SMTP id h5csp3173253lbj; Wed, 11 Mar 2015 21:17:01 -0700 (PDT) X-Received: by 10.66.136.17 with SMTP id pw17mr86409643pab.33.1426133812529; Wed, 11 Mar 2015 21:16:52 -0700 (PDT) Received: from mail-pa0-f50.google.com (mail-pa0-f50.google.com. [209.85.220.50]) by mx.google.com with ESMTPS id ks10si10474007pdb.234.2015.03.11.21.16.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 21:16:52 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.50 as permitted sender) client-ip=209.85.220.50; Received: by padet14 with SMTP id et14so17009413pad.11 for ; Wed, 11 Mar 2015 21:16:51 -0700 (PDT) X-Received: by 10.66.237.35 with SMTP id uz3mr86309490pac.46.1426133811177; Wed, 11 Mar 2015 21:16:51 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id x1sm3070268pdp.1.2015.03.11.21.16.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Mar 2015 21:16:50 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Dave Jones , Linus Torvalds , Thomas Gleixner , Richard Cochran , Prarit Bhargava , Stephen Boyd , Ingo Molnar , Peter Zijlstra Subject: [PATCH 06/12] time: Try to catch clocksource delta underflows Date: Wed, 11 Mar 2015 21:16:34 -0700 Message-Id: <1426133800-29329-7-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426133800-29329-1-git-send-email-john.stultz@linaro.org> References: <1426133800-29329-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , In the case where there is a broken clocksource where there are multiple actual clocks that aren't perfectly aligned, we may see small "negative" deltas when we subtract 'now' from 'cycle_last'. The values are actually negative with respect to the clocksource mask value, not necessarily negative if cast to a s64, but we can check by checking the delta see if it is a small (relative to the mask) negative value (again negative relative to the mask). If so, we assume we jumped backwards somehow and instead use zero for our delta. Cc: Dave Jones Cc: Linus Torvalds Cc: Thomas Gleixner Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Cc: Ingo Molnar Cc: Peter Zijlstra Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index c06fe6e..2ba62fe 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -146,6 +146,13 @@ static inline cycle_t timekeeping_get_delta(struct tk_read_base *tkr) /* calculate the delta since the last update_wall_time */ delta = clocksource_delta(cycle_now, tkr->cycle_last, tkr->mask); + /* + * Try to catch underflows by checking if we are seeing small + * mask-relative negative values. + */ + if (unlikely((~delta & tkr->mask) < (tkr->mask >> 3))) + delta = 0; + /* Cap delta value to the max_cycles values to avoid mult overflows */ if (unlikely(delta > tkr->clock->max_cycles)) delta = tkr->clock->max_cycles;