From patchwork Sat Mar 7 02:49:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 45509 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f197.google.com (mail-we0-f197.google.com [74.125.82.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 73E87214A0 for ; Sat, 7 Mar 2015 02:50:37 +0000 (UTC) Received: by wevk48 with SMTP id k48sf12327963wev.0 for ; Fri, 06 Mar 2015 18:50:36 -0800 (PST) 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=egutl0+KU2+D7xgdezaD/K8NmvyTGkjvKVLO/aL8gkY=; b=mZ0v8+IA3wYv52iaxkz0fjhDTFzgh1ho761/tgfat+JpGcn0D0NfNqqMnZH5IPb8IQ H4BEMozb6jqUr9Ih3KfWRegiFar6uakb8G8IVt5HG5mipb33F0pDZrdWu2ZJwH4RTE0m 63QpYtffWSQ0hGNh2BxCWYfaG0XAm13N7e4GAtXEuN/Hm6UyVgdwoH7X9SOqceRF3GGA TpezYDwxc6Sdr5CueMvZXZQwBASM5trESH+Ya2Jl9zYivNgTAsalBjxrvY8LbrckMlOV EkICTAX/nLluJwQ/03Ul6wt9Y2JxlBCMIN+11P3SOBaQiYYXmV8Sb/4cd1p1YCn9lqBr SA8A== X-Gm-Message-State: ALoCoQksYhsD0i0GzdkQwE5/jsNUg21oIiA+Cn5utQKcuwVwLFD+WVNhd2R/p7kXBaNw4dcX5m1D X-Received: by 10.112.147.35 with SMTP id th3mr2662642lbb.15.1425696636666; Fri, 06 Mar 2015 18:50:36 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.70 with SMTP id h6ls130514laa.78.gmail; Fri, 06 Mar 2015 18:50:36 -0800 (PST) X-Received: by 10.112.98.201 with SMTP id ek9mr15743712lbb.68.1425696636353; Fri, 06 Mar 2015 18:50:36 -0800 (PST) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id t9si8538097lal.77.2015.03.06.18.50.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Mar 2015 18:50:36 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbiw7 with SMTP id w7so21936812lbi.7 for ; Fri, 06 Mar 2015 18:50:36 -0800 (PST) X-Received: by 10.152.30.103 with SMTP id r7mr12996894lah.76.1425696636087; Fri, 06 Mar 2015 18:50:36 -0800 (PST) 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 h5csp256468lbj; Fri, 6 Mar 2015 18:50:35 -0800 (PST) X-Received: by 10.66.151.5 with SMTP id um5mr30553402pab.43.1425696626322; Fri, 06 Mar 2015 18:50:26 -0800 (PST) Received: from mail-pd0-f176.google.com (mail-pd0-f176.google.com. [209.85.192.176]) by mx.google.com with ESMTPS id q3si17388537pdj.219.2015.03.06.18.50.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Mar 2015 18:50:26 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.176 as permitted sender) client-ip=209.85.192.176; Received: by pdbfl12 with SMTP id fl12so48467187pdb.5 for ; Fri, 06 Mar 2015 18:50:25 -0800 (PST) X-Received: by 10.68.190.101 with SMTP id gp5mr30773552pbc.30.1425696625421; Fri, 06 Mar 2015 18:50:25 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id a2sm8381456pbu.27.2015.03.06.18.50.23 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Mar 2015 18:50:24 -0800 (PST) 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 07/12] time: Try to catch clocksource delta underflows Date: Fri, 6 Mar 2015 18:49:58 -0800 Message-Id: <1425696603-16878-8-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1425696603-16878-1-git-send-email-john.stultz@linaro.org> References: <1425696603-16878-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.217.173 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 8b9e328..4e8ccde 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -145,6 +145,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;