From patchwork Fri Sep 12 11:48:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 37294 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id ECB97203EE for ; Fri, 12 Sep 2014 11:58:23 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id n12sf406483wgh.9 for ; Fri, 12 Sep 2014 04:58:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=LKTyEeWlvqoZH8UHrgp8uQ66NuMb+0wtja6y/q1Ftiw=; b=fwhDh/EjGWA0e8QlmqBveXKL24pLW/AZjSp8T398eVpAGe1cxakbdcPpC0d4WvmKta OK0SnrMfHXtJuf6Ve0wuyboabKg9CFUEbbS1C295oYN3k2Z/Jlb+M+B+OfV3Cl5oB546 rb6vKCz8Yw4jiAj5sqBAyda2Svcgz2ZeN6G/9VUAen8lrwV3fWxViVx4WDT4aF3eoWmG SLniaTx7ixWYGHq57u2qdPdc6wXVp9yQjZDuUSUe1pyeB8gmYXfr7qGHK6MJ093tXSZc 09Qj8oQgEvuoE7KS56yT+VcH431middbqeE4PVY2wnin4lvXSaYuIhlamKBSdWn4RfNH 5b+g== X-Gm-Message-State: ALoCoQlWyr8G0x8T+Yaq6Uf1jVSkSDC0gmp0nYauex6GYiQQZ+YUgK2V/Df/NaYrnBCCxk2eq+S5 X-Received: by 10.180.74.137 with SMTP id t9mr502105wiv.1.1410523100879; Fri, 12 Sep 2014 04:58:20 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.102 with SMTP id p6ls141107laj.28.gmail; Fri, 12 Sep 2014 04:58:20 -0700 (PDT) X-Received: by 10.152.25.170 with SMTP id d10mr8218004lag.37.1410523100596; Fri, 12 Sep 2014 04:58:20 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) by mx.google.com with ESMTPS id x8si6126041lbf.91.2014.09.12.04.58.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 12 Sep 2014 04:58:19 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id z11so728737lbi.26 for ; Fri, 12 Sep 2014 04:58:19 -0700 (PDT) X-Received: by 10.112.62.200 with SMTP id a8mr7975041lbs.34.1410523099334; Fri, 12 Sep 2014 04:58:19 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.141.42 with SMTP id rl10csp716793lbb; Fri, 12 Sep 2014 04:58:18 -0700 (PDT) X-Received: by 10.66.65.202 with SMTP id z10mr7297520pas.20.1410523097769; Fri, 12 Sep 2014 04:58:17 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id co6si7539300pac.57.2014.09.12.04.58.17 for ; Fri, 12 Sep 2014 04:58:17 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754452AbaILL6N (ORCPT + 27 others); Fri, 12 Sep 2014 07:58:13 -0400 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]:32874 "EHLO foss-mx-na.foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753736AbaILL6I (ORCPT ); Fri, 12 Sep 2014 07:58:08 -0400 Received: from foss-smtp-na-1.foss.arm.com (unknown [10.80.61.8]) by foss-mx-na.foss.arm.com (Postfix) with ESMTP id 649E544B; Fri, 12 Sep 2014 06:48:49 -0500 (CDT) Received: from collaborate-mta1.arm.com (highbank-bc01-b06.austin.arm.com [10.112.81.134]) by foss-smtp-na-1.foss.arm.com (Postfix) with ESMTP id 13D4A5FAD1; Fri, 12 Sep 2014 06:48:47 -0500 (CDT) Received: from hornet.Cambridge.Arm.com (hornet.cambridge.arm.com [10.2.201.42]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 9710F13F626; Fri, 12 Sep 2014 06:48:45 -0500 (CDT) From: Pawel Moll To: Richard Cochran , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Paul Mackerras , Arnaldo Carvalho de Melo , John Stultz Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Pawel Moll Subject: [RFC 1/2] perf: Add sampling of the raw monotonic clock Date: Fri, 12 Sep 2014 12:48:32 +0100 Message-Id: <1410522513-1045-2-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1410522513-1045-1-git-send-email-pawel.moll@arm.com> References: <1410522513-1045-1-git-send-email-pawel.moll@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pawel.moll@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch adds an option to sample raw monotonic clock value with any perf event, with the the aim of allowing time correlation between data coming from perf and additional performance-related information generated in userspace. In order to correlate timestamps in perf data stream with events happening in userspace (be it JITed debug symbols or hwmon-originating environment data), user requests a more or less periodic event (sched_switch trace event of a hrtimer-based cpu-clock being the most obvious examples) with PERF_SAMPLE_TIME *and* PERF_SAMPLE_CLOCK_RAW_MONOTONIC and stamps user-originating data with values obtained from clock_gettime(CLOCK_MONOTONIC_RAW). Then, during analysis, one looks at the perf events immediately preceding and following (in terms of the clock_raw_monotonic sample) the userspace event and does simple linear approximation to get the equivalent perf time. perf event user event -----O--------------+-------------O------> t_mono : | : : V : -----O----------------------------O------> t_perf Signed-off-by: Pawel Moll --- include/linux/perf_event.h | 2 ++ include/uapi/linux/perf_event.h | 4 +++- kernel/events/core.c | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 707617a..28b73b2 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -602,6 +602,8 @@ struct perf_sample_data { * Transaction flags for abort events: */ u64 txn; + /* Raw monotonic timestamp, for userspace time correlation */ + u64 clock_raw_monotonic; }; static inline void perf_sample_data_init(struct perf_sample_data *data, diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h index 9269de2..e5a75c5 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -137,8 +137,9 @@ enum perf_event_sample_format { PERF_SAMPLE_DATA_SRC = 1U << 15, PERF_SAMPLE_IDENTIFIER = 1U << 16, PERF_SAMPLE_TRANSACTION = 1U << 17, + PERF_SAMPLE_CLOCK_RAW_MONOTONIC = 1U << 18, - PERF_SAMPLE_MAX = 1U << 18, /* non-ABI */ + PERF_SAMPLE_MAX = 1U << 19, /* non-ABI */ }; /* @@ -686,6 +687,7 @@ enum perf_event_type { * { u64 weight; } && PERF_SAMPLE_WEIGHT * { u64 data_src; } && PERF_SAMPLE_DATA_SRC * { u64 transaction; } && PERF_SAMPLE_TRANSACTION + * { u64 clock_raw_monotonic; } && PERF_SAMPLE_CLOCK_RAW_MONOTONIC * }; */ PERF_RECORD_SAMPLE = 9, diff --git a/kernel/events/core.c b/kernel/events/core.c index f9c1ed0..df093e3 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -1216,6 +1216,9 @@ static void perf_event__header_size(struct perf_event *event) if (sample_type & PERF_SAMPLE_TRANSACTION) size += sizeof(data->txn); + if (sample_type & PERF_SAMPLE_CLOCK_RAW_MONOTONIC) + size += sizeof(data->clock_raw_monotonic); + event->header_size = size; } @@ -4456,6 +4459,12 @@ static void __perf_event_header__init_id(struct perf_event_header *header, data->cpu_entry.cpu = raw_smp_processor_id(); data->cpu_entry.reserved = 0; } + + if (sample_type & PERF_SAMPLE_CLOCK_RAW_MONOTONIC) { + struct timespec now; + getrawmonotonic(&now); + data->clock_raw_monotonic = timespec_to_ns(&now); + } } void perf_event_header__init_id(struct perf_event_header *header, @@ -4714,6 +4723,9 @@ void perf_output_sample(struct perf_output_handle *handle, if (sample_type & PERF_SAMPLE_TRANSACTION) perf_output_put(handle, data->txn); + if (sample_type & PERF_SAMPLE_CLOCK_RAW_MONOTONIC) + perf_output_put(handle, data->clock_raw_monotonic); + if (!event->attr.watermark) { int wakeup_events = event->attr.wakeup_events;