From patchwork Fri Jan 23 00:09:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 43550 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 053E5218DB for ; Fri, 23 Jan 2015 00:09:58 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id ge10sf234500lab.1 for ; Thu, 22 Jan 2015 16:09: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=Uppn9xmH0lk9i0qu6zTJ7H16Ih1paWpol7eoGfnkbJU=; b=ghCxHTRhWTyNSIQN+teeQMcMStBjijBLV4Y1bmfTBkMYht6TpNSc6wfggf4WnhTzfH 4BFb/RMBvzCMINKPowz5Ec3nCYBTIMN4cJgPo6lQwaIlXcQDm3UaV0TbkhgYaVunGfjT 1aEMmRC64viXWHFz1EBXTAxpWKmxEgUjT0QwsZSVFj0rIV5li6HX2T6/gYyRlpD2htzZ peA0sLOK8NEBvEbKXS/+d6nhp9h6EKNvJ5zBGBvtKgjwdc7YkXX4aLwl1MF0QwPDIo3k q3XUsajPLdmP6eGP0uxsfXgMXpp8uecg+voZLp+WlTIcT5L4dIr1tBPZQeEc8jZsqNvN wkMw== X-Gm-Message-State: ALoCoQntx3nMN5h3M96DGfq91IM4nkkjY2LhrEJTgWd/UXjnLWzbvzE77qAWs+aqnuIajjN8U+vX X-Received: by 10.152.3.234 with SMTP id f10mr582140laf.1.1421971797009; Thu, 22 Jan 2015 16:09:57 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.207.3 with SMTP id ls3ls219531lac.46.gmail; Thu, 22 Jan 2015 16:09:56 -0800 (PST) X-Received: by 10.112.156.132 with SMTP id we4mr4426248lbb.59.1421971796866; Thu, 22 Jan 2015 16:09:56 -0800 (PST) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id we6si14776300lbb.1.2015.01.22.16.09.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Jan 2015 16:09:56 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id pv20so4632869lab.7 for ; Thu, 22 Jan 2015 16:09:56 -0800 (PST) X-Received: by 10.152.18.135 with SMTP id w7mr4349055lad.47.1421971796786; Thu, 22 Jan 2015 16:09: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 c8csp63950lbb; Thu, 22 Jan 2015 16:09:55 -0800 (PST) X-Received: by 10.70.131.78 with SMTP id ok14mr6656834pdb.112.1421971782345; Thu, 22 Jan 2015 16:09:42 -0800 (PST) Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com. [209.85.220.44]) by mx.google.com with ESMTPS id jd10si14069021pbd.81.2015.01.22.16.09.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Jan 2015 16:09:42 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.44 as permitted sender) client-ip=209.85.220.44; Received: by mail-pa0-f44.google.com with SMTP id rd3so3985755pab.3 for ; Thu, 22 Jan 2015 16:09:41 -0800 (PST) X-Received: by 10.70.135.165 with SMTP id pt5mr6446075pdb.37.1421971781392; Thu, 22 Jan 2015 16:09:41 -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 am14sm10405657pac.35.2015.01.22.16.09.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Jan 2015 16:09:40 -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/12] time: Try to catch clocksource delta underflows Date: Thu, 22 Jan 2015 16:09:22 -0800 Message-Id: <1421971767-17707-8-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1421971767-17707-1-git-send-email-john.stultz@linaro.org> References: <1421971767-17707-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.48 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 ae3945d..568186c 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;