From patchwork Mon Aug 29 06:55:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 74880 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1483255qga; Mon, 29 Aug 2016 00:04:55 -0700 (PDT) X-Received: by 10.66.72.106 with SMTP id c10mr29903746pav.18.1472454295778; Mon, 29 Aug 2016 00:04:55 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gw1si37587039pac.108.2016.08.29.00.04.55; Mon, 29 Aug 2016 00:04:55 -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 S932594AbcH2HDR (ORCPT + 27 others); Mon, 29 Aug 2016 03:03:17 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:36277 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752889AbcH2HCF (ORCPT ); Mon, 29 Aug 2016 03:02:05 -0400 Received: by mail-pa0-f44.google.com with SMTP id ci2so6142792pad.3 for ; Mon, 29 Aug 2016 00:02:04 -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=JnfHiVWFXN2+P+fg0l38v0rb8Z18meGU0KyZvgn/uIY=; b=anrWymwMT/qt4FUznhrfB8B1TkBN3iUE5y40UJmmltzmKnv8YwjVc1CQrBG66Q6eX5 O/K0caihsNc/NViD7AAtL4wqOKgZTrmHsIRKECQY2SYI44t3bwV+lr8Qj+L7hj6Ne34H QgOkyIIaxj40GIrl502W+QOAURvk2daV1MCVc= 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=JnfHiVWFXN2+P+fg0l38v0rb8Z18meGU0KyZvgn/uIY=; b=KJuH1UjjXwHjAX88Hf6B6psWdBbEQ3dxdFhhkXoBMrbmOeZRdLSuAOqXjO0+BsRN4Y lu3Dss11rgs7wmlKnDFVz/ijI7+Zqz2KVZibzm2HUXQQ6srZ8V7fk7SQ7wMEkc2j6A/V /BE3pd7L9dHO4XorBWSm7WWCkw5QVODCaNqJDjbkMD3YmAfPn4/wHIEp2bp7OOYhiNK0 Qtkt7s+1wx+uJGQAiKTHcT02QOm0Vl9sE7KbnOeXmnjQgdX8/W0xdDKEmctdt5g3A0s3 nQn2fpHtMUNrS5im10EQcysTzm+J+B+8cHOelGb1Ec2kP9hV62PdrlSf3t26rzSiV3rp Qr7Q== X-Gm-Message-State: AE9vXwNr7XO0P+zOtV5tVQLfIZa/0Au0FLXKI0LQkRgYWlpksYfDF8dlwYmT6HFRejUllZVb X-Received: by 10.66.76.38 with SMTP id h6mr29746276paw.79.1472453749578; Sun, 28 Aug 2016 23:55:49 -0700 (PDT) Received: from blr-ubuntu-59.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id l128sm46184359pfl.21.2016.08.28.23.55.46 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 28 Aug 2016 23:55:49 -0700 (PDT) From: Binoy Jayan To: "Steven Rostedt (Red Hat)" Cc: Ingo Molnar , Daniel Wagner , Arnd Bergmann , linaro-kernel@lists.linaro.org, Carsten Emde , linux-kernel@vger.kernel.org, Masami , Binoy Jayan Subject: [PATCH v3 3/3] tracing: Histogram for missed timer offsets Date: Mon, 29 Aug 2016 12:25:28 +0530 Message-Id: <1472453728-577-4-git-send-email-binoy.jayan@linaro.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1472453728-577-1-git-send-email-binoy.jayan@linaro.org> References: <1472453728-577-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 Latencies of missed timer offsets. Generate a histogram of missed timer offsets in microseconds. This will be a based along with irq and preemption latencies to calculate the effective process wakeup latencies. The following filter(s) may be used 'hist:key=common_pid.execname' 'hist:key=common_pid.execname,cpu:val=toffset,hitcount' Signed-off-by: Binoy Jayan --- include/linux/hrtimer.h | 3 +++ include/trace/events/latency.h | 31 +++++++++++++++++++++++++++++++ kernel/time/hrtimer.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 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 1c34536..746f035 100644 --- a/include/trace/events/latency.h +++ b/include/trace/events/latency.h @@ -31,6 +31,37 @@ DEFINE_EVENT(latency_template, latency_preempt, TP_PROTO(int ltype, int cpu, cycles_t latency), TP_ARGS(ltype, cpu, latency)); +TRACE_EVENT(latency_hrtimer_interrupt, + + TP_PROTO(int cpu, long long toffset, struct task_struct *curr, + struct task_struct *task), + + TP_ARGS(cpu, toffset, curr, task), + + TP_STRUCT__entry( + __field(int, cpu) + __field(long long, toffset) + __array(char, ccomm, TASK_COMM_LEN) + __field(int, cprio) + __array(char, tcomm, TASK_COMM_LEN) + __field(int, tprio) + ), + + TP_fast_assign( + __entry->cpu = cpu; + __entry->toffset = toffset; + memcpy(__entry->ccomm, curr->comm, TASK_COMM_LEN); + __entry->cprio = curr->prio; + memcpy(__entry->tcomm, task != NULL ? task->comm : "", + task != NULL ? TASK_COMM_LEN : 7); + __entry->tprio = task != NULL ? task->prio : -1; + ), + + TP_printk("cpu=%d toffset=%lld curr=%s[%d] thread=%s[%d]", + __entry->cpu, __entry->toffset, __entry->ccomm, + __entry->cprio, __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..1a96e34 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,38 @@ static inline ktime_t hrtimer_update_lowres(struct hrtimer *timer, ktime_t tim, return tim; } +static inline void trace_latency_mark_ts(struct hrtimer *timer, + struct hrtimer_clock_base *new_base, + ktime_t tim) +{ +#if defined(CONFIG_PREEMPT_TRACER) || defined(CONFIG_IRQSOFF_TRACER) + if (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 trace_missed_hrtimer(struct hrtimer *timer, ktime_t basenow) +{ +#if defined(CONFIG_PREEMPT_TRACER) || defined(CONFIG_IRQSOFF_TRACER) + if (trace_latency_hrtimer_interrupt_enabled()) + trace_latency_hrtimer_interrupt(raw_smp_processor_id(), + ktime_to_ns(ktime_sub(ktime_to_ns(timer->praecox) ? + timer->praecox : hrtimer_get_expires(timer), + basenow)), + current, + timer->function == hrtimer_wakeup ? + container_of(timer, struct hrtimer_sleeper, + timer)->task : NULL); +#endif + +} + /** * hrtimer_start_range_ns - (re)start an hrtimer on the current CPU * @timer: the timer to be added @@ -992,6 +1027,8 @@ void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim, timer_stats_hrtimer_set_start_info(timer); + trace_latency_mark_ts(timer, new_base, tim); + leftmost = enqueue_hrtimer(timer, new_base); if (!leftmost) goto unlock; @@ -1284,6 +1321,8 @@ static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now) timer = container_of(node, struct hrtimer, node); + trace_missed_hrtimer(timer, basenow); + /* * The immediate goal for using the softexpires is * minimizing wakeups, not running timers at the