From patchwork Tue Nov 4 00:28:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 40084 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 61ABB21894 for ; Tue, 4 Nov 2014 00:29:19 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id ex7sf3355449wid.8 for ; Mon, 03 Nov 2014 16:29:18 -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=LiPdTO4fXc6cxrdF9aU7+T9uvB29YnOjW0svKxz0Fz0=; b=lkA+IiS+bmxIakhBmIuSyi6uMQiIBP+6BtTSLevLWu0ZvuSdcVDfqCst1byWRKr8eL ilb5HfqeKEAmYeBP2CawwLumat1aI51X+g5+kaosVX8YlQLBExihPJxPvKhdT3Nu0uJd cxPY1mFORgHISl1+cMwPsEKTY1YV53pjQRRNT/icXedU/wA6SqRq/peOJS8S59fp7Wy1 qxVGdVkdDHrgKAkPm1MKdZWB92zEMSlzRS9tasCvglOAjFpl62NjbNwTdzo6H72osSH5 Lk/EA5M+5jV814CnRVE2KtwI78ZbvWE2G2yO1znLwA9K4m7YVMSJgpFa16jADXxjTfDY yGcw== X-Gm-Message-State: ALoCoQkRVldbIzE5Q9rh8vG0n7+pbvEV1BSgOgmbTdIoh1ks3ift3uEVODOcdClsOmpjs2evNnie X-Received: by 10.181.27.135 with SMTP id jg7mr3465287wid.5.1415060958617; Mon, 03 Nov 2014 16:29:18 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.6 with SMTP id r6ls656249lae.5.gmail; Mon, 03 Nov 2014 16:29:18 -0800 (PST) X-Received: by 10.152.206.68 with SMTP id lm4mr54896214lac.2.1415060958307; Mon, 03 Nov 2014 16:29:18 -0800 (PST) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id w8si16353781lbb.16.2014.11.03.16.29.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Nov 2014 16:29:18 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by mail-lb0-f172.google.com with SMTP id w7so3094886lbi.31 for ; Mon, 03 Nov 2014 16:29:18 -0800 (PST) X-Received: by 10.152.120.199 with SMTP id le7mr32079692lab.67.1415060958066; Mon, 03 Nov 2014 16:29:18 -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 ew9csp45109lbc; Mon, 3 Nov 2014 16:29:16 -0800 (PST) X-Received: by 10.68.69.107 with SMTP id d11mr46295864pbu.57.1415060955597; Mon, 03 Nov 2014 16:29:15 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bb10si16490062pbd.144.2014.11.03.16.29.14 for ; Mon, 03 Nov 2014 16:29:15 -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 S1751687AbaKDA3I (ORCPT + 25 others); Mon, 3 Nov 2014 19:29:08 -0500 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]:52449 "EHLO foss-mx-na.foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751016AbaKDA3C (ORCPT ); Mon, 3 Nov 2014 19:29:02 -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 E96144E0; Mon, 3 Nov 2014 18:28:58 -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 B4E1A5FAD7; Mon, 3 Nov 2014 18:28:51 -0600 (CST) Received: from rojo.cambridge.arm.com (unknown [10.37.23.91]) by collaborate-mta1.arm.com (Postfix) with ESMTP id D976013F91E; Mon, 3 Nov 2014 18:28:47 -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 v3 1/3] perf: Use monotonic clock as a source for timestamps Date: Tue, 4 Nov 2014 00:28:36 +0000 Message-Id: <1415060918-19954-2-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1415060918-19954-1-git-send-email-pawel.moll@arm.com> References: <1415060918-19954-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.172 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 timestampt 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. 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... include/linux/perf_event.h | 1 + kernel/events/core.c | 4 +++- kernel/sysctl.c | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 893a0d0..ba490d5 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -738,6 +738,7 @@ extern int sysctl_perf_event_paranoid; extern int sysctl_perf_event_mlock; extern int sysctl_perf_event_sample_rate; extern int sysctl_perf_cpu_time_max_percent; +extern int sysctl_perf_sample_time_clk_id; extern void perf_sample_event_took(u64 sample_len_ns); diff --git a/kernel/events/core.c b/kernel/events/core.c index 2b02c9f..ea3d6d3 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -234,6 +234,8 @@ int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write, return 0; } +int sysctl_perf_sample_time_clk_id = CLOCK_MONOTONIC; + /* * perf samples are done in some very critical code paths (NMIs). * If they take too much CPU time, the system can lock up and not @@ -324,7 +326,7 @@ extern __weak const char *perf_pmu_name(void) static inline u64 perf_clock(void) { - return local_clock(); + return ktime_get_mono_fast_ns(); } static inline struct perf_cpu_context * diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 15f2511..cb75f5b 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1094,6 +1094,13 @@ static struct ctl_table kern_table[] = { .extra1 = &zero, .extra2 = &one_hundred, }, + { + .procname = "perf_sample_time_clk_id", + .data = &sysctl_perf_sample_time_clk_id, + .maxlen = sizeof(unsigned int), + .mode = 0444, + .proc_handler = proc_dointvec, + }, #endif #ifdef CONFIG_KMEMCHECK {