From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933740AbeAXLzf (ORCPT ); Wed, 24 Jan 2018 06:55:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38434 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933625AbeAXLwI (ORCPT ); Wed, 24 Jan 2018 06:52:08 -0500 From: Jiri Olsa To: Peter Zijlstra , Ingo Molnar Cc: lkml , Namhyung Kim , David Ahern , Andi Kleen , Alexander Shishkin , Andy Lutomirski , Arnaldo Carvalho de Melo Subject: [PATCH 09/21] perf: Export running sample length values through debugfs Date: Wed, 24 Jan 2018 12:51:31 +0100 Message-Id: <20180124115143.14322-10-jolsa@kernel.org> In-Reply-To: <20180124115143.14322-1-jolsa@kernel.org> References: <20180124115143.14322-1-jolsa@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Exporting running_sample_length value through the debugfs, via per cpu files: /sys/kernel/debug/irq/cpuX/sample_length and reset file to zero it: /sys/kernel/debug/irq/reset to allow some basic meassurements of the NMI time length. Link: http://lkml.kernel.org/n/tip-uodlhfk3zc55fyajtlczr5wd@git.kernel.org Signed-off-by: Jiri Olsa --- kernel/events/core.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/kernel/events/core.c b/kernel/events/core.c index 4676fbf681c7..582913b7aba9 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -51,6 +51,7 @@ #include #include #include +#include #include "internal.h" @@ -554,6 +555,72 @@ void perf_sample_event_took(u64 sample_len_ns) } } +static int get_sample_length(void *data, u64 *val) +{ + unsigned long cpu = (unsigned long) data; + + *val = per_cpu(running_sample_length, cpu); + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(sample_length_fops, get_sample_length, NULL, "%llu\n"); + + +static int reset_sample_length(void *data, u64 val) +{ + int cpu; + + for_each_possible_cpu(cpu) { + per_cpu(running_sample_length, cpu) = val; + } + + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(reset_fops, NULL, reset_sample_length, "%llu\n"); + +static __init int init_perf_debugfs(void) +{ + struct dentry *root, *irq, *icpu, *file; + int cpu, ret = 0; + + root = debugfs_create_dir("perf", NULL); + if (!root) + return -1; + + irq = debugfs_create_dir("irq", root); + if (!irq) + return -1; + + for_each_possible_cpu(cpu) { + char buf[50]; + + snprintf(buf, sizeof(buf), "cpu%d", cpu); + + icpu = debugfs_create_dir(buf, irq); + if (!icpu) + return -1; + + file = debugfs_create_file("sample_length", 0444, icpu, + (void *)(unsigned long) cpu, + &sample_length_fops); + if (!file) { + ret = -1; + break; + } + } + + if (!ret) { + file = debugfs_create_file("reset", S_IWUSR, irq, NULL, &reset_fops); + if (!file) + ret = -1; + } + + return ret; +} + +late_initcall(init_perf_debugfs); + static atomic64_t perf_event_id; static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx, -- 2.13.6