From patchwork Fri Sep 2 12:37:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 75300 Delivered-To: patch@linaro.org Received: by 10.140.29.8 with SMTP id a8csp848358qga; Fri, 2 Sep 2016 05:38:29 -0700 (PDT) X-Received: by 10.66.229.9 with SMTP id sm9mr35705807pac.138.1472819907609; Fri, 02 Sep 2016 05:38:27 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i67si11445861pfg.136.2016.09.02.05.38.27; Fri, 02 Sep 2016 05:38:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753428AbcIBMiO (ORCPT + 27 others); Fri, 2 Sep 2016 08:38:14 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:34190 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753350AbcIBMiK (ORCPT ); Fri, 2 Sep 2016 08:38:10 -0400 Received: by mail-pa0-f49.google.com with SMTP id to9so1843853pac.1 for ; Fri, 02 Sep 2016 05:38:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dA3B9Vfq8qYiQ4Ap5wuvPfSzoU9EWBK8PRnzzbNRVEs=; b=dPVjTQvhbjLTVudwNsgJky+79pM03evBkuTOEaAEvayTjF7c9lttbaylhRX/1SRu+K bS47B8GYCDkFLWMx8uz057sG8IRH0zWOwS1OhzQ9aH30uc+Ygu/nSv3e7e1NuRVCzzkT /Z71ZeJKHeoTqhpO+mUIRClW7DWdQkO9W2Kdk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dA3B9Vfq8qYiQ4Ap5wuvPfSzoU9EWBK8PRnzzbNRVEs=; b=Xg7Ph5k3l/uF98O5T+KTABeNFL32fKYArs8MKiE9Aq5gTqy9QHcuNjE0frtMsUwyIJ q7UkBgfCB5qiI/tVkrWJkPSvBtk7RJ7ao+QtoaeNj0pP+KyHay+MrzB3OmDrO/iH3gXc be47ULuRsQeuwrDY1LyeUPdcDh0ZSsneyicLzQBpuFmncPX83djjp3A5v3QYUE8H0SMP 58E9AaSEWviiLbxfXooCpWNJX1gqi8+Pwynkgsu+Ij1EH80YUb1d1e49r94Z2nJXSl1V E4J+5Ne5p6b/LPkS3+x6BlNo+Voxq9qsECEJtkQQeYrdSmPALI7JVpmWuLiBJgDbvidE /c3A== X-Gm-Message-State: AE9vXwO4jB/jFjYyoovCPbjGFpTkbXghjB+IUagN7e9MJ5/0/bQCmXdQNOZRLTZhyLX/ZDuj X-Received: by 10.66.145.73 with SMTP id ss9mr35812720pab.82.1472819888569; Fri, 02 Sep 2016 05:38:08 -0700 (PDT) Received: from blr-ubuntu-59.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id i7sm14796781paf.9.2016.09.02.05.38.05 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Sep 2016 05:38:08 -0700 (PDT) From: Binoy Jayan To: "Steven Rostedt (Red Hat)" Cc: Ingo Molnar , Daniel Wagner , Arnd Bergmann , linux-kernel@vger.kernel.org, Masami , Binoy Jayan Subject: [PATCH v5 4/4] tracing: Histogram for delayed hrtimer offsets Date: Fri, 2 Sep 2016 18:07:31 +0530 Message-Id: <1472819851-12857-5-git-send-email-binoy.jayan@linaro.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1472819851-12857-1-git-send-email-binoy.jayan@linaro.org> References: <1472819851-12857-1-git-send-email-binoy.jayan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Generate a histogram of the latencies of delayed timer offsets in nanoseconds. It shows the latency captured due to a delayed timer expire event. It happens for example when a timer misses its deadline due to disabled interrupts. A process if scheduled as a result of the timer expiration suffers this latency. The following filter(s) may be used 'hist:key=common_pid.execname:val=toffset,hitcount' 'hist:key=cpu,tcomm:val=toffset:sort=tcomm' 'hist:key=common_pid.execname,tcomm' Signed-off-by: Binoy Jayan --- include/linux/hrtimer.h | 3 +++ include/trace/events/latency.h | 23 +++++++++++++++++++++ kernel/time/hrtimer.c | 46 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h index 5e00f80..e09de14 100644 --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h @@ -104,6 +104,9 @@ struct hrtimer { struct hrtimer_clock_base *base; u8 state; u8 is_rel; +#if defined(CONFIG_PREEMPT_TRACER) || defined(CONFIG_IRQSOFF_TRACER) + ktime_t praecox; +#endif #ifdef CONFIG_TIMER_STATS int start_pid; void *start_site; diff --git a/include/trace/events/latency.h b/include/trace/events/latency.h index ca57f06..d616db5 100644 --- a/include/trace/events/latency.h +++ b/include/trace/events/latency.h @@ -44,6 +44,29 @@ DEFINE_EVENT(latency_template, latency_preempt, TP_PROTO(int ltype, cycles_t latency), TP_ARGS(ltype, latency)); +TRACE_EVENT(latency_hrtimer_interrupt, + + TP_PROTO(long long toffset, struct task_struct *task), + + TP_ARGS(toffset, task), + + TP_STRUCT__entry( + __field(long long, toffset) + __array(char, tcomm, TASK_COMM_LEN) + __field(int, tprio) + ), + + TP_fast_assign( + __entry->toffset = toffset; + memcpy(__entry->tcomm, task != NULL ? task->comm : "", + task != NULL ? TASK_COMM_LEN : 7); + __entry->tprio = task != NULL ? task->prio : -1; + ), + + TP_printk("toffset=%lld thread=%s[%d]", + __entry->toffset, __entry->tcomm, __entry->tprio) +); + #endif /* _TRACE_HIST_H */ /* This part must be outside protection */ diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 9ba7c82..04d936b 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -53,9 +53,12 @@ #include #include +#include #include "tick-internal.h" +static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer); + /* * The timer bases: * @@ -960,6 +963,45 @@ static inline ktime_t hrtimer_update_lowres(struct hrtimer *timer, ktime_t tim, return tim; } +static inline void latency_hrtimer_timing_start(struct hrtimer *timer, + struct hrtimer_clock_base *new_base, + ktime_t tim) +{ +#if defined(CONFIG_PREEMPT_TRACER) || defined(CONFIG_IRQSOFF_TRACER) + if (unlikely(trace_latency_hrtimer_interrupt_enabled())) { + ktime_t now = new_base->get_time(); + + if (ktime_to_ns(tim) < ktime_to_ns(now)) + timer->praecox = now; + else + timer->praecox = ktime_set(0, 0); + } +#endif +} + +static inline void latency_hrtimer_timing_stop(struct hrtimer *timer, + ktime_t basenow) +{ +#if defined(CONFIG_PREEMPT_TRACER) || defined(CONFIG_IRQSOFF_TRACER) + long latency; + + struct task_struct *task; + + if (likely(!trace_latency_hrtimer_interrupt_enabled())) + return; + + latency = ktime_to_ns(ktime_sub(basenow, + ktime_to_ns(timer->praecox) ? + timer->praecox : hrtimer_get_expires(timer))); + + task = timer->function == hrtimer_wakeup ? + container_of(timer, struct hrtimer_sleeper, + timer)->task : NULL; + if (latency > 0) + trace_latency_hrtimer_interrupt((u64) latency, task); +#endif +} + /** * hrtimer_start_range_ns - (re)start an hrtimer on the current CPU * @timer: the timer to be added @@ -992,6 +1034,8 @@ void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim, timer_stats_hrtimer_set_start_info(timer); + latency_hrtimer_timing_start(timer, new_base, tim); + leftmost = enqueue_hrtimer(timer, new_base); if (!leftmost) goto unlock; @@ -1284,6 +1328,8 @@ static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now) timer = container_of(node, struct hrtimer, node); + latency_hrtimer_timing_stop(timer, basenow); + /* * The immediate goal for using the softexpires is * minimizing wakeups, not running timers at the