Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753592Ab1BUVDW (ORCPT ); Mon, 21 Feb 2011 16:03:22 -0500 Received: from sj-iport-2.cisco.com ([171.71.176.71]:55507 "EHLO sj-iport-2.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752695Ab1BUVCg (ORCPT ); Mon, 21 Feb 2011 16:02:36 -0500 X-IronPort-AV: E=Sophos;i="4.62,202,1297036800"; d="scan'208";a="313370330" From: David Ahern To: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: acme@ghostprotocols.net, mingo@elte.hu, peterz@infradead.org, fweisbec@gmail.com, paulus@samba.org, tglx@linutronix.de, David Ahern Subject: [PATCH 1/4] perf events: Introduce realtime clock event Date: Mon, 21 Feb 2011 14:02:27 -0700 Message-Id: <1298322150-15505-2-git-send-email-daahern@cisco.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1298322150-15505-1-git-send-email-daahern@cisco.com> References: <1298322150-15505-1-git-send-email-daahern@cisco.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4262 Lines: 145 The motivation for this event is to convert perf_clock() time stamps to wall-clock (gettimeofday()) equivalents for comparing perf events to other log files. This patch is based on the monotonic patch by Arnaldo Carvalho de Melo . Signed-off-by: David Ahern --- include/linux/perf_event.h | 1 + kernel/perf_event.c | 66 ++++++++++++++++++++++++++++++++++++++++ tools/perf/util/parse-events.c | 2 + 3 files changed, 69 insertions(+), 0 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 8ceb5a6..51a2f34 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -105,6 +105,7 @@ enum perf_sw_ids { PERF_COUNT_SW_PAGE_FAULTS_MAJ = 6, PERF_COUNT_SW_ALIGNMENT_FAULTS = 7, PERF_COUNT_SW_EMULATION_FAULTS = 8, + PERF_COUNT_SW_REALTIME_CLOCK = 9, PERF_COUNT_SW_MAX, /* non-ABI */ }; diff --git a/kernel/perf_event.c b/kernel/perf_event.c index a0a6987..85f60c0 100644 --- a/kernel/perf_event.c +++ b/kernel/perf_event.c @@ -5413,6 +5413,7 @@ static int perf_swevent_init(struct perf_event *event) switch (event_id) { case PERF_COUNT_SW_CPU_CLOCK: case PERF_COUNT_SW_TASK_CLOCK: + case PERF_COUNT_SW_REALTIME_CLOCK: return -ENOENT; default: @@ -5751,6 +5752,70 @@ static struct pmu perf_cpu_clock = { }; /* + * Software event: realtime wall time clock + */ + +static void realtime_clock_event_update(struct perf_event *event) +{ + u64 now = ktime_to_ns(ktime_get_real()); + local64_set(&event->count, now); +} + +static void realtime_clock_event_start(struct perf_event *event, int flags) +{ + realtime_clock_event_update(event); + perf_swevent_start_hrtimer(event); +} + +static void realtime_clock_event_stop(struct perf_event *event, int flags) +{ + perf_swevent_cancel_hrtimer(event); + realtime_clock_event_update(event); +} + +static int realtime_clock_event_add(struct perf_event *event, int flags) +{ + if (flags & PERF_EF_START) + realtime_clock_event_start(event, flags); + + return 0; +} + +static void realtime_clock_event_del(struct perf_event *event, int flags) +{ + realtime_clock_event_stop(event, flags); +} + +static void realtime_clock_event_read(struct perf_event *event) +{ + realtime_clock_event_update(event); +} + +static int realtime_clock_event_init(struct perf_event *event) +{ + if (event->attr.type != PERF_TYPE_SOFTWARE) + return -ENOENT; + + if (event->attr.config != PERF_COUNT_SW_REALTIME_CLOCK) + return -ENOENT; + + perf_swevent_init_hrtimer(event); + + return 0; +} + +static struct pmu perf_realtime_clock = { + .task_ctx_nr = perf_sw_context, + + .event_init = realtime_clock_event_init, + .add = realtime_clock_event_add, + .del = realtime_clock_event_del, + .start = realtime_clock_event_start, + .stop = realtime_clock_event_stop, + .read = realtime_clock_event_read, +}; + +/* * Software event: task time clock */ @@ -7285,6 +7350,7 @@ void __init perf_event_init(void) init_srcu_struct(&pmus_srcu); perf_pmu_register(&perf_swevent, "software", PERF_TYPE_SOFTWARE); perf_pmu_register(&perf_cpu_clock, NULL, -1); + perf_pmu_register(&perf_realtime_clock, NULL, -1); perf_pmu_register(&perf_task_clock, NULL, -1); perf_tp_register(); perf_cpu_notifier(perf_cpu_notify); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 54a7e26..c40bfef 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -41,6 +41,7 @@ static struct event_symbol event_symbols[] = { { CSW(CPU_CLOCK), "cpu-clock", "" }, { CSW(TASK_CLOCK), "task-clock", "" }, + { CSW(REALTIME_CLOCK), "clock-realtime", "clkr" }, { CSW(PAGE_FAULTS), "page-faults", "faults" }, { CSW(PAGE_FAULTS_MIN), "minor-faults", "" }, { CSW(PAGE_FAULTS_MAJ), "major-faults", "" }, @@ -78,6 +79,7 @@ static const char *sw_event_names[] = { "major-faults", "alignment-faults", "emulation-faults", + "realtime-clock-msecs", }; #define MAX_ALIASES 8 -- 1.7.3.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/