From patchwork Thu Nov 6 16:51:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 40359 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8A42D24687 for ; Thu, 6 Nov 2014 16:53:45 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id h11sf926122wiw.3 for ; Thu, 06 Nov 2014 08:53:44 -0800 (PST) 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=//4i/sYTbKAu1iTv6h27EegCEWvyAOQcF9XBSBC2ahg=; b=T6B8CuO7+dVDx5kBGEliUXgymdUqtSxHkTlKmvBd+0BVjvpV4qcy496FcU7GU86BAX Ad6Q4FjZ6HlQONQB1ctxA2paiSxMBqQ0jb2MkQgo1bp8bE7mt5z1LJOLMzAKc9Pk4nfq npNStC/E1f/mEq0ElM6zp5cKIL5gXS2MeUw7wKcR5TlBpI9H091zv1lk8ucaYg7Xx8dS 8NSEbfqwy9psr1i2lGmFZfSvASJ8T18ZmEoNxnOJ1At9Gdl7c0kpfKH67fgSaR184y0x 8jbp7Mcezfy2iPD0rCufvfUx+6UmeTW+P6cxqSzbWOFy2kjUoVdoyANGHtQFJqfjsF/g 8OrA== X-Gm-Message-State: ALoCoQmtJaWsv4V9p07a/Hb8GAFqFs3QU/hbP72RcW0Wz+QWWpvjcQz5zLATcn9yfxBeMhaU291/ X-Received: by 10.112.180.71 with SMTP id dm7mr183046lbc.18.1415292824815; Thu, 06 Nov 2014 08:53:44 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.205 with SMTP id ba13ls115696lab.33.gmail; Thu, 06 Nov 2014 08:53:44 -0800 (PST) X-Received: by 10.152.120.133 with SMTP id lc5mr6248898lab.62.1415292824502; Thu, 06 Nov 2014 08:53:44 -0800 (PST) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id l10si12162133lbd.29.2014.11.06.08.53.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Nov 2014 08:53:44 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id 10so1264436lbg.28 for ; Thu, 06 Nov 2014 08:53:44 -0800 (PST) X-Received: by 10.112.14.69 with SMTP id n5mr6232737lbc.34.1415292824398; Thu, 06 Nov 2014 08:53:44 -0800 (PST) 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.184.201 with SMTP id ew9csp74646lbc; Thu, 6 Nov 2014 08:53:43 -0800 (PST) X-Received: by 10.70.61.68 with SMTP id n4mr5762520pdr.60.1415292822717; Thu, 06 Nov 2014 08:53:42 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fr3si6462237pbd.34.2014.11.06.08.53.41 for ; Thu, 06 Nov 2014 08:53:42 -0800 (PST) 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 S1752926AbaKFQxj (ORCPT + 25 others); Thu, 6 Nov 2014 11:53:39 -0500 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]:54050 "EHLO foss-mx-na.foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751435AbaKFQwM (ORCPT ); Thu, 6 Nov 2014 11:52:12 -0500 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 A79EC222; Thu, 6 Nov 2014 10:52:07 -0600 (CST) 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 885285FAD7; Thu, 6 Nov 2014 10:52:05 -0600 (CST) Received: from hornet.Cambridge.Arm.com (hornet.cambridge.arm.com [10.2.201.42]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 398C013F697; Thu, 6 Nov 2014 10:52:03 -0600 (CST) From: Pawel Moll To: Richard Cochran , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Paul Mackerras , Arnaldo Carvalho de Melo , John Stultz , Masami Hiramatsu , Christopher Covington , Namhyung Kim , David Ahern , Thomas Gleixner , Tomeu Vizoso Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Pawel Moll Subject: [PATCH v4 1/3] perf: Use monotonic clock as a source for timestamps Date: Thu, 6 Nov 2014 16:51:56 +0000 Message-Id: <1415292718-19785-2-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1415292718-19785-1-git-send-email-pawel.moll@arm.com> References: <1415292718-19785-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.169 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: , Until now, perf framework never defined the meaning of the timestamps captured as PERF_SAMPLE_TIME sample type. The values were obtaining from local (sched) clock, which is unavailable in userspace. This made it impossible to correlate perf data with any other events. Other tracing solutions have the source configurable (ftrace) or just share a common time domain between kernel and userspace (LTTng). Follow the trend by using monotonic clock, which is readily available as POSIX CLOCK_MONOTONIC. Also add a sysctl "perf_sample_time_clk_id" attribute which can be used by the user to obtain the clk_id to be used with POSIX clock API (eg. clock_gettime()) to obtain a time value comparable with perf samples. Old behaviour can be restored by using "perf_use_local_clock" kernel parameter. Signed-off-by: Pawel Moll --- Ingo, I remember your comments about this approach in the past, but during discussions at LPC Thomas was convinced that it's the right thing to do - see cover letter for the series... Changes since v3: - Added "perf_use_lock_clock" parameter... - ... and creating the sysctl value only when it's not defined (turned out that negative clk_ids are not invalid - they are used to describe dynamic clocks) - Had to keep sysctl_perf_sample_time_clk_id non-const, because struct ctl_table.data is non-const Documentation/kernel-parameters.txt | 9 +++++++++ kernel/events/core.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 4c81a86..8ead8d8 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -91,6 +91,7 @@ parameter is applicable: NUMA NUMA support is enabled. NFS Appropriate NFS support is enabled. OSS OSS sound support is enabled. + PERF Performance events and counters support is enabled. PV_OPS A paravirtualized kernel is enabled. PARIDE The ParIDE (parallel port IDE) subsystem is enabled. PARISC The PA-RISC architecture is enabled. @@ -2763,6 +2764,14 @@ bytes respectively. Such letter suffixes can also be entirely omitted. allocator. This parameter is primarily for debugging and performance comparison. + perf_use_local_clock + [PERF] + Use local_clock() as a source for perf timestamps + generation. This was be the default behaviour and + this parameter can be used to maintain backward + compatibility or on older hardware with expensive + monotonic clock source. + pf. [PARIDE] See Documentation/blockdev/paride.txt. diff --git a/kernel/events/core.c b/kernel/events/core.c index 2b02c9f..5d0aa03 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "internal.h" @@ -322,8 +323,41 @@ extern __weak const char *perf_pmu_name(void) return "pmu"; } +static bool perf_use_local_clock; +static int __init perf_use_local_clock_setup(char *__unused) +{ + perf_use_local_clock = true; + return 1; +} +__setup("perf_use_local_clock", perf_use_local_clock_setup); + +static int sysctl_perf_sample_time_clk_id = CLOCK_MONOTONIC; + +static struct ctl_table perf_sample_time_kern_table[] = { + { + .procname = "perf_sample_time_clk_id", + .data = &sysctl_perf_sample_time_clk_id, + .maxlen = sizeof(int), + .mode = 0444, + .proc_handler = proc_dointvec, + }, + {} +}; + +static struct ctl_table perf_sample_time_root_table[] = { + { + .procname = "kernel", + .mode = 0555, + .child = perf_sample_time_kern_table, + }, + {} +}; + static inline u64 perf_clock(void) { + if (likely(!perf_use_local_clock)) + return ktime_get_mono_fast_ns(); + return local_clock(); } @@ -8230,6 +8264,9 @@ void __init perf_event_init(void) */ BUILD_BUG_ON((offsetof(struct perf_event_mmap_page, data_head)) != 1024); + + if (!perf_use_local_clock) + register_sysctl_table(perf_sample_time_root_table); } static int __init perf_event_sysfs_init(void)