From patchwork Sat Mar 7 02:49:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 45507 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 82933214A0 for ; Sat, 7 Mar 2015 02:50:32 +0000 (UTC) Received: by lams18 with SMTP id s18sf460423lam.2 for ; Fri, 06 Mar 2015 18:50:31 -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=RInq/cnmTzMulme+6Xxd/019k+Rm3BjJnPKxCUIFScs=; b=fOhl2VO/vGbe/6upC87tCyKGvMAcHIvgeXDhIN0MfyOOSxYog4XyURNsY90zt8Guc4 AySX+g7V4NCXw0XRO6h0cO5bvK9LskRbNfasWSEWYAVY0JHNmAdfFfqr83tKgGEWUCfb NHleVeFeaX1gsvVjufUa2JTOBo8fW2Ar+hzmKOTDaifjUANolNobfi83ehZX8APvAs17 Lfg6ptuG6IybjdxRu+3p4lPo15Tw5YmM/UKyAlWJG2rjYrzTk/aUvWONcuPwO5/3schX 9CdIfDNRKDT4ny/bdhhsUAyrhxTQmn+p2gXTcXn4oBFfh+wRQS8wNCMNPAfR1tZjdpQQ 3KVw== X-Gm-Message-State: ALoCoQlvsWpf3l41rhn59CH1cWdqOkd4ICKBh+nKpNi9phE/Jley05CNhoLMe4M8cSKiEQ2sWN4K X-Received: by 10.112.41.131 with SMTP id f3mr2779783lbl.20.1425696631468; Fri, 06 Mar 2015 18:50:31 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.72 with SMTP id lm8ls143576lac.3.gmail; Fri, 06 Mar 2015 18:50:31 -0800 (PST) X-Received: by 10.112.16.1 with SMTP id b1mr1724863lbd.39.1425696631321; Fri, 06 Mar 2015 18:50:31 -0800 (PST) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id ry4si8532522lbc.90.2015.03.06.18.50.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Mar 2015 18:50:30 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by lbiz12 with SMTP id z12so38452326lbi.5 for ; Fri, 06 Mar 2015 18:50:30 -0800 (PST) X-Received: by 10.112.130.195 with SMTP id og3mr15369826lbb.112.1425696630868; Fri, 06 Mar 2015 18:50:30 -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 h5csp256445lbj; Fri, 6 Mar 2015 18:50:30 -0800 (PST) X-Received: by 10.70.129.72 with SMTP id nu8mr11164469pdb.72.1425696623249; Fri, 06 Mar 2015 18:50:23 -0800 (PST) Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com. [209.85.220.49]) by mx.google.com with ESMTPS id eq9si17668110pbd.31.2015.03.06.18.50.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Mar 2015 18:50:23 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.49 as permitted sender) client-ip=209.85.220.49; Received: by paceu11 with SMTP id eu11so42303818pac.4 for ; Fri, 06 Mar 2015 18:50:22 -0800 (PST) X-Received: by 10.66.65.169 with SMTP id y9mr30922692pas.60.1425696622362; Fri, 06 Mar 2015 18:50:22 -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.20 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Mar 2015 18:50:21 -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 05/12] time: Add debugging checks to warn if we see delays Date: Fri, 6 Mar 2015 18:49:56 -0800 Message-Id: <1425696603-16878-6-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.175 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: , Recently there's been some request for better sanity checking in the time code, so that its more clear when something is going wrong since timekeeping issues could manifest in a large number of strange ways with various subsystems. Thus, this patch adds some extra infrastructure to add a check update_wall_time to print warnings if we see the call delayed beyond the max_cycles overflow point, or beyond the clocksource max_idle_ns value which is currently 50% of the overflow point. This extra infrastructure is conditionalized behind a new CONFIG_DEBUG_TIMEKEEPING option also added in this patch. Tested this a bit by halting qemu for specified lengths of time to trigger the warnings. 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/jiffies.c | 1 + kernel/time/timekeeping.c | 26 ++++++++++++++++++++++++++ lib/Kconfig.debug | 12 ++++++++++++ 3 files changed, 39 insertions(+) diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c index a6a5bf5..7e41390 100644 --- a/kernel/time/jiffies.c +++ b/kernel/time/jiffies.c @@ -71,6 +71,7 @@ static struct clocksource clocksource_jiffies = { .mask = 0xffffffff, /*32bits*/ .mult = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */ .shift = JIFFIES_SHIFT, + .max_cycles = 10, }; __cacheline_aligned_in_smp DEFINE_SEQLOCK(jiffies_lock); diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 91db941..7e9d433 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -118,6 +118,29 @@ static inline void tk_update_sleep_time(struct timekeeper *tk, ktime_t delta) tk->offs_boot = ktime_add(tk->offs_boot, delta); } +#ifdef CONFIG_DEBUG_TIMEKEEPING +static void timekeeping_check_update(struct timekeeper *tk, cycle_t offset) +{ + + cycle_t max_cycles = tk->tkr.clock->max_cycles; + const char *name = tk->tkr.clock->name; + + if (offset > max_cycles) + printk_deferred("ERROR: cycle offset (%lld) is larger then" + " allowed %s max_cycles (%lld)\n", + offset, name, max_cycles); + else if (offset > (max_cycles >> 1)) + printk_deferred("WARNING: cycle offset (%lld) is past" + " the %s 50%% safety margin (%lld)\n", + offset, name, max_cycles>>1); +} +#else +static inline +void timekeeping_check_update(struct timekeeper *tk, cycle_t offset) +{ +} +#endif + /** * tk_setup_internals - Set up internals to use clocksource clock. * @@ -1630,6 +1653,9 @@ void update_wall_time(void) if (offset < real_tk->cycle_interval) goto out; + /* Do some additional sanity checking */ + timekeeping_check_update(real_tk, offset); + /* * With NO_HZ we may have to accumulate many cycle_intervals * (think "ticks") worth of time at once. To do this efficiently, diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index c5cefb3..32065f6 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -865,6 +865,18 @@ config SCHED_STACK_END_CHECK data corruption or a sporadic crash at a later stage once the region is examined. The runtime overhead introduced is minimal. +config DEBUG_TIMEKEEPING + bool "Enable extra timekeeping sanity checking" + help + This option will enable additional timekeeping sanity checks + which may be helpful when diagnoising issues where timekeeping + problems are suspected. + + This may include checks in the timekeeping hotpaths, so this + option may have a performance impact to some workloads. + + If unsure, say N. + config TIMER_STATS bool "Collect kernel timers statistics" depends on DEBUG_KERNEL && PROC_FS