From patchwork Mon Aug 29 06:55:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 74879 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1481105qga; Sun, 28 Aug 2016 23:59:35 -0700 (PDT) X-Received: by 10.66.131.111 with SMTP id ol15mr27020833pab.105.1472453975106; Sun, 28 Aug 2016 23:59:35 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si37591391pfk.77.2016.08.28.23.59.34; Sun, 28 Aug 2016 23:59:35 -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 S1756558AbcH2G5Y (ORCPT + 27 others); Mon, 29 Aug 2016 02:57:24 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:35971 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756483AbcH2G47 (ORCPT ); Mon, 29 Aug 2016 02:56:59 -0400 Received: by mail-pa0-f42.google.com with SMTP id ci2so6083064pad.3 for ; Sun, 28 Aug 2016 23:55:46 -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=OQHgpJkQrAzIHKMxr8ReC8Jy8bCE1/QjeSxQZc8WueY=; b=P5zXonTS5iW9py4zY35yBr6XAcMX4nmH+WWmtdAsBgGu0yUSNyZYohNk2kFhaRdjjZ ypWRUPLD6e1bV+LdQOsgbEdvSZM8glpJZtZeMNXw2439Cokaph0+4wccJwlimmKrYCjj jdJvs1+tuFn9MJEYb/LHALqfngmfNdyAXBPOQ= 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=OQHgpJkQrAzIHKMxr8ReC8Jy8bCE1/QjeSxQZc8WueY=; b=fVbOE9RBbNrVn+8EOGy7MsiEKNPX0ct/Ug186VvqIGf3QsxDK8VzXGjFylJscBQBgY +pZlB+TV4BJjJqQjI+pvg+zC/75gn7T38y47jedT2Z8HEzCDXJMfnAf+JyUxnbs4agE6 oUgiMgoM5XaZj6vJRT1ggCSfn5K/pfDVCZY1bmwqg7InU5RxL6VdUqfBq7/8G7j7FYSO GoADCUDipw+2zsbds+yrMkhWJoMHgWKvtITiUqbgFXMPXXByt2Txt7ZZKxT4B5htbA7p +p5Co6CKb/ZMlXfGaCZ5bRqpJMkcRTdYgN5a0cGEO0jFFusbUd7g5ThWdwRK1GsomKd0 Ogmw== X-Gm-Message-State: AE9vXwMZoe7qqg8bzqU81wVKuJmIDGr+RbsJBMiRThhU8Anx5qSfdoa8dXMoKTItvlHKfSo5 X-Received: by 10.66.100.230 with SMTP id fb6mr29818874pab.107.1472453745746; Sun, 28 Aug 2016 23:55:45 -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.42 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 28 Aug 2016 23:55:45 -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 2/3] tracing: Add trace_irqsoff tracepoints Date: Mon, 29 Aug 2016 12:25:27 +0530 Message-Id: <1472453728-577-3-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 This work is based on work by Daniel Wagner. A few tracepoints are added at the end of the critical section. With the hist trigger in place, the hist trigger plots may be generated, with per-cpu breakdown of events captured. It is based on linux kernel's event infrastructure. The following filter(s) may be used 'hist:key=latency.log2:val=hitcount:sort=latency' 'hist:key=cpu,latency:val=hitcount:sort=latency if cpu==1' 'hist:key=ltype,cpu:val=latency:sort=ltype,cpu if ltype==0' Where ltype is 0: IRQSOFF latency 1: PREEMPTOFF Latency 2: Critical Timings This captures only the latencies introduced by disabled irqs and preemption. Additional per process data has to be captured to calculate the effective latencies introduced for individual processes. Initial work - latency.patch [1] https://git.kernel.org/cgit/linux/kernel/git/rt/linux-stable-rt.git/commit/?h=v3.14-rt-rebase&id=56d50cc34943bbba12b8c5942ee1ae3b29f73acb Signed-off-by: Binoy Jayan --- include/trace/events/latency.h | 37 ++++++++++++++++++++++++++++++++++ kernel/trace/trace_irqsoff.c | 45 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 include/trace/events/latency.h -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project diff --git a/include/trace/events/latency.h b/include/trace/events/latency.h new file mode 100644 index 0000000..1c34536 --- /dev/null +++ b/include/trace/events/latency.h @@ -0,0 +1,37 @@ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM latency + +#if !defined(_TRACE_HIST_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_HIST_H + +#include + +DECLARE_EVENT_CLASS(latency_template, + TP_PROTO(int ltype, int cpu, cycles_t latency), + + TP_ARGS(ltype, cpu, latency), + + TP_STRUCT__entry( + __field(int, ltype) + __field(int, cpu) + __field(cycles_t, latency) + ), + + TP_fast_assign( + __entry->ltype = ltype; + __entry->cpu = cpu; + __entry->latency = latency; + ), + + TP_printk("ltype=%d, cpu=%d, latency=%lu", + __entry->ltype, __entry->cpu, (unsigned long) __entry->latency) +); + +DEFINE_EVENT(latency_template, latency_preempt, + TP_PROTO(int ltype, int cpu, cycles_t latency), + TP_ARGS(ltype, cpu, latency)); + +#endif /* _TRACE_HIST_H */ + +/* This part must be outside protection */ +#include diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c index 03cdff8..d4f2b25 100644 --- a/kernel/trace/trace_irqsoff.c +++ b/kernel/trace/trace_irqsoff.c @@ -13,14 +13,27 @@ #include #include #include +#include + +#include #include "trace.h" +#define CREATE_TRACE_POINTS +#include + static struct trace_array *irqsoff_trace __read_mostly; static int tracer_enabled __read_mostly; -static DEFINE_PER_CPU(int, tracing_cpu); +enum latency_type { + TS_IRQ, + TS_PREEMPT, + TS_CRITTIME, + TS_MAX +}; +static DEFINE_PER_CPU(int, tracing_cpu); +static DEFINE_PER_CPU(cycle_t, lat_ts[TS_MAX]); static DEFINE_RAW_SPINLOCK(max_trace_lock); enum { @@ -419,9 +432,19 @@ stop_critical_timing(unsigned long ip, unsigned long parent_ip) atomic_dec(&data->disabled); } +static inline void latency_trace(enum latency_type type) +{ + trace_latency_preempt(type, raw_smp_processor_id(), + (cycle_t) trace_clock_local() - this_cpu_read(lat_ts[type])); + +} /* start and stop critical timings used to for stoppage (in idle) */ void start_critical_timings(void) { + if (trace_latency_preempt_enabled()) + this_cpu_write(lat_ts[TS_CRITTIME], + (cycle_t) trace_clock_local()); + if (preempt_trace() || irq_trace()) start_critical_timing(CALLER_ADDR0, CALLER_ADDR1); } @@ -431,6 +454,10 @@ void stop_critical_timings(void) { if (preempt_trace() || irq_trace()) stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1); + + if (trace_latency_preempt_enabled()) + latency_trace(TS_CRITTIME); + } EXPORT_SYMBOL_GPL(stop_critical_timings); @@ -438,6 +465,9 @@ EXPORT_SYMBOL_GPL(stop_critical_timings); #ifdef CONFIG_PROVE_LOCKING void time_hardirqs_on(unsigned long a0, unsigned long a1) { + if (trace_latency_preempt_enabled()) { + latency_trace(TS_IRQ); + } if (!preempt_trace() && irq_trace()) stop_critical_timing(a0, a1); } @@ -446,6 +476,11 @@ void time_hardirqs_off(unsigned long a0, unsigned long a1) { if (!preempt_trace() && irq_trace()) start_critical_timing(a0, a1); + + if (trace_latency_preempt_enabled()) { + this_cpu_write(lat_ts[TS_IRQ], + (cycle_t) trace_clock_local()); + } } #else /* !CONFIG_PROVE_LOCKING */ @@ -503,6 +538,9 @@ EXPORT_SYMBOL(trace_hardirqs_off_caller); #ifdef CONFIG_PREEMPT_TRACER void trace_preempt_on(unsigned long a0, unsigned long a1) { + if (trace_latency_preempt_enabled()) + latency_trace(TS_PREEMPT); + if (preempt_trace() && !irq_trace()) stop_critical_timing(a0, a1); } @@ -511,6 +549,11 @@ void trace_preempt_off(unsigned long a0, unsigned long a1) { if (preempt_trace() && !irq_trace()) start_critical_timing(a0, a1); + + if (trace_latency_preempt_enabled()) { + this_cpu_write(lat_ts[TS_PREEMPT], + (cycle_t) trace_clock_local()); + } } #endif /* CONFIG_PREEMPT_TRACER */