Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp165896pxa; Fri, 31 Jul 2020 08:55:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZNoDhKqjDxAqHaDsX/ZHLbof+2wTlSd7BIoIt1EOUEAbl3tavGayBB9RLaiotiC4gJoDn X-Received: by 2002:a17:906:1bb1:: with SMTP id r17mr4648266ejg.268.1596210928984; Fri, 31 Jul 2020 08:55:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596210928; cv=none; d=google.com; s=arc-20160816; b=n70xHOMMjjG3ze4HXhImjQtgYs664Ghn+/GfGSHRkxls0QqA7VbkTmEClH6XTVygCf gr9qyNsMB2rzxKbn2Ps465lZxF68M7nC0xDz7vDwxKOOdf494M5t3FoO0m8ZQaefJ0yd DeEXkAE5kTPVWjTX8JUWki7p5xSfYs2rJOibmpQaOkt49kJNo76QQmhV0eLZ032qkfCr iVMBr2oJnoeyyv5nURbATNT7FRK5VqDWvn5B03Wx1h3odJJG7g5j0ivbd6wSxxHQSq1e PVW+OzCNu8Y9D1lV0UDDmwG3dDQI1eNVEIb1C3Npinmp0x/fSoeIYIIsi9nh0Q/+05fI 2sYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject:ironport-sdr :ironport-sdr; bh=remWMOwv/1KCMcWPqky5hrAdNjtRARTy+MJkFtPJxCQ=; b=PEwaeFyU7Cs2cVNM5Seywz9Tpids03pjiVRo2v2tYTEnWfqDO7w8dk8XJGIlu+q6Gg OqfPzCWucE8bWaRNcWf7+eyY1saJqHJmm6z3p/kNXip4kospdpKSlosJ1ca/SaNtmoCT PMEKHpGb67yc/r5cAtMwrQBGs02A7LjM4uN/bTcPziglxVHRSLGljzldvi8PL7qQ/pyE FC5opWKMzjK2dtDgd+EpgN+QDqqayTmZqYj/qwM3Aojotj+TemGXIOEA9HGKyK1l6usH OIHMf7/JC3tAu9yTGZaoANKUD6PUzjY87t5BeuC9KZ6vZ4MPfq/DMhc8queeFDekaxuq 398A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf25si5490869ejb.419.2020.07.31.08.55.06; Fri, 31 Jul 2020 08:55:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387468AbgGaPwr (ORCPT + 99 others); Fri, 31 Jul 2020 11:52:47 -0400 Received: from mga06.intel.com ([134.134.136.31]:33113 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726841AbgGaPwq (ORCPT ); Fri, 31 Jul 2020 11:52:46 -0400 IronPort-SDR: lY21kxDcyeZzg3vgHAEQ9PS6o4k4XMCSNuedkHk2eXi67rI7Uat55xJIWMYxDP4Ld/y85s4wSq sxLFHnG1KMKA== X-IronPort-AV: E=McAfee;i="6000,8403,9698"; a="213340569" X-IronPort-AV: E=Sophos;i="5.75,418,1589266800"; d="scan'208";a="213340569" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2020 08:52:46 -0700 IronPort-SDR: 05n9puqT+sY/Yo04hZWBossnIHYOR+L51iUMPgSxPRM5MBl8zIGdNy56xOT3mEqQCKAKDO94qk ufI62yuFdVqQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,418,1589266800"; d="scan'208";a="321429958" Received: from linux.intel.com ([10.54.29.200]) by orsmga008.jf.intel.com with ESMTP; 31 Jul 2020 08:52:46 -0700 Received: from [10.249.228.225] (abudanko-mobl.ccr.corp.intel.com [10.249.228.225]) by linux.intel.com (Postfix) with ESMTP id 01CF2580699; Fri, 31 Jul 2020 08:52:38 -0700 (PDT) Subject: Re: [PATCH 2/6] perf tools: Store clock references for -k/--clockid option To: Jiri Olsa , Arnaldo Carvalho de Melo Cc: David Ahern , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Ian Rogers , Andi Kleen , =?UTF-8?Q?Genevi=c3=a8ve_Bastien?= , Wang Nan , Jeremie Galarneau References: <20200730213950.1503773-1-jolsa@kernel.org> <20200730213950.1503773-3-jolsa@kernel.org> From: Alexey Budankov Organization: Intel Corp. Message-ID: <9be7eb7b-4f73-84cc-95e9-e65101b30819@linux.intel.com> Date: Fri, 31 Jul 2020 18:52:36 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200730213950.1503773-3-jolsa@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 31.07.2020 0:39, Jiri Olsa wrote: > Adding new CLOCK_DATA feature that stores reference times > when -k/--clockid option is specified. > > It contains clock id and its reference time together with > wall clock time taken at the 'same time', both values are > in nanoseconds. > > The format of data is as below: > > struct { > u32 version; /* version = 1 */ > u32 clockid; > u64 clockid_time_ns; > u64 wall_clock_ns; > }; > > This clock reference times will be used in following changes > to display wall clock for perf events. > > It's available only for recording with clockid specified, > because it's the only case where we can get reference time > to wallclock time. It's can't do that with perf clock yet. > > Original-patch-by: David Ahern > Signed-off-by: Jiri Olsa > --- > .../Documentation/perf.data-file-format.txt | 13 ++ > tools/perf/builtin-record.c | 41 +++++++ > tools/perf/util/env.h | 12 ++ > tools/perf/util/header.c | 112 ++++++++++++++++++ > tools/perf/util/header.h | 1 + > 5 files changed, 179 insertions(+) > > diff --git a/tools/perf/Documentation/perf.data-file-format.txt b/tools/perf/Documentation/perf.data-file-format.txt > index b6472e463284..c484e81987c7 100644 > --- a/tools/perf/Documentation/perf.data-file-format.txt > +++ b/tools/perf/Documentation/perf.data-file-format.txt > @@ -389,6 +389,19 @@ struct { > Example: > cpu pmu capabilities: branches=32, max_precise=3, pmu_name=icelake > > + HEADER_CLOCK_DATA = 29, > + > + Contains clock id and its reference time together with wall clock > + time taken at the 'same time', both values are in nanoseconds. > + The format of data is as below. > + > +struct { > + u32 version; /* version = 1 */ > + u32 clockid; > + u64 clockid_time_ns; > + u64 wall_clock_ns; > +}; > + > other bits are reserved and should ignored for now > HEADER_FEAT_BITS = 256, > > diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c > index 468c669519a6..f8280e721e1a 100644 > --- a/tools/perf/builtin-record.c > +++ b/tools/perf/builtin-record.c > @@ -70,6 +70,7 @@ > #include > #include > #include > +#include > > struct switch_output { > bool enabled; > @@ -1203,6 +1204,9 @@ static void record__init_features(struct record *rec) > if (!(rec->opts.use_clockid && rec->opts.clockid_res_ns)) > perf_header__clear_feat(&session->header, HEADER_CLOCKID); > > + if (!rec->opts.use_clockid) > + perf_header__clear_feat(&session->header, HEADER_CLOCK_DATA); > + > perf_header__clear_feat(&session->header, HEADER_DIR_FORMAT); > if (!record__comp_enabled(rec)) > perf_header__clear_feat(&session->header, HEADER_COMPRESSED); > @@ -1551,6 +1555,40 @@ static int record__setup_sb_evlist(struct record *rec) > return 0; > } > > +static int record__init_clock(struct record *rec) > +{ > + struct perf_session *session = rec->session; > + struct timespec ref_clockid; > + struct timeval ref_tod; > + u64 ref; > + > + if (!rec->opts.use_clockid) > + return 0; > + > + session->header.env.clock.clockid = rec->opts.clockid; > + > + if (gettimeofday(&ref_tod, NULL) != 0) { > + pr_err("gettimeofday failed, cannot set reference time.\n"); > + return -1; > + } > + > + if (clock_gettime(rec->opts.clockid, &ref_clockid)) { > + pr_err("clock_gettime failed, cannot set reference time.\n"); > + return -1; > + } It might also want to be implemented in a loop and iteration with minimal time delta is chosen to improve synchronization accuracy and also mitigate possible context switches between gettimeofday() and clock_gettime() calls. Alexei