From patchwork Sat Jan 10 00:34:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 42934 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1B4C526CF1 for ; Sat, 10 Jan 2015 00:34:58 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf9643554eek.1 for ; Fri, 09 Jan 2015 16:34:57 -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=4yg3EbwVT7eSB3UKWB46GJ9kdWpA3/SaH7Fu33MkJJI=; b=PMD/7h2FaT0AS9gu1pwJSonFjtuWkdQJ3sYk1hh0OzNbYKsbOSHzAYLrra6r7Sc8yq UW5H3tm8D+2eI7aOK+JzL8DWnN5oI7pnLl3g8TaaUUhmuycUblxApXbL8ePA9LbrijB9 jrAu75Ezh6DeObdrAVGyNqfazxOFZFAcK+KAkXAGH1lSt5tqHYLvxe8QggAgxBO01SnN ihPujVSoM4kdrsUsTecHc3GU9ODnKTXp9rYoLC/m6LWfdnKr5zh2pvCVooKTONh4nsMN 0UZq2Fl4hPygf2HlwBPcHgUHw3g/nmGFZ/aTEWUPSBU1IRdr1xQqRzaq3+F16Hbfetrw 1hJw== X-Gm-Message-State: ALoCoQkdBM9K+MWX+Mx/xJxM8kqKfIUmSHXS+AD/y04MjmUrOv0mO8qiT6EX9qOgf1VKYXiJmOmb X-Received: by 10.180.105.97 with SMTP id gl1mr760177wib.7.1420850097211; Fri, 09 Jan 2015 16:34:57 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.1 with SMTP id ku1ls489205lac.80.gmail; Fri, 09 Jan 2015 16:34:56 -0800 (PST) X-Received: by 10.152.5.7 with SMTP id o7mr24449655lao.26.1420850096892; Fri, 09 Jan 2015 16:34:56 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id qf1si14574627lbb.132.2015.01.09.16.34.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 09 Jan 2015 16:34:56 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id q1so17174954lam.5 for ; Fri, 09 Jan 2015 16:34:56 -0800 (PST) X-Received: by 10.152.87.100 with SMTP id w4mr24516231laz.71.1420850096804; Fri, 09 Jan 2015 16:34:56 -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.9.200 with SMTP id c8csp484840lbb; Fri, 9 Jan 2015 16:34:55 -0800 (PST) X-Received: by 10.68.65.108 with SMTP id w12mr27520069pbs.96.1420850083995; Fri, 09 Jan 2015 16:34:43 -0800 (PST) Received: from mail-pd0-f182.google.com (mail-pd0-f182.google.com. [209.85.192.182]) by mx.google.com with ESMTPS id mt1si15319546pbb.128.2015.01.09.16.34.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 09 Jan 2015 16:34:43 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.182 as permitted sender) client-ip=209.85.192.182; Received: by mail-pd0-f182.google.com with SMTP id p10so20167887pdj.13 for ; Fri, 09 Jan 2015 16:34:43 -0800 (PST) X-Received: by 10.70.32.133 with SMTP id j5mr16875196pdi.5.1420850083118; Fri, 09 Jan 2015 16:34:43 -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 hc10sm8046439pbd.78.2015.01.09.16.34.41 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Jan 2015 16:34:42 -0800 (PST) From: John Stultz To: Linux Kernel Mailing List Cc: John Stultz , Dave Jones , Linus Torvalds , Thomas Gleixner , Richard Cochran , Prarit Bhargava , Stephen Boyd , Ingo Molnar , Peter Zijlstra Subject: [PATCH 07/10] time: Try to catch clocksource delta underflows Date: Fri, 9 Jan 2015 16:34:25 -0800 Message-Id: <1420850068-27828-8-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1420850068-27828-1-git-send-email-john.stultz@linaro.org> References: <1420850068-27828-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.46 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 9740fd8..4acfc7f 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -224,6 +224,13 @@ static inline s64 timekeeping_get_ns_raw(struct timekeeper *tk) /* calculate the delta since the last update_wall_time: */ delta = clocksource_delta(cycle_now, tk->tkr.cycle_last, tk->tkr.mask); + /* + * Try to catch underflows by checking if we are seeing small + * mask-relative negative values. + */ + if (((~delta+1) & tk->tkr.mask) < (tk->tkr.mask >> 3)) + delta = 0; + /* Cap delta value to the max_cycles values to avoid mult overflows */ delta = min(delta, tk->tkr.clock->max_cycles);