public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Jiri Olsa <jolsa@redhat.com>,
	linux-kernel@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, kvm@vger.kernel.org,
	H Peter Anvin <hpa@zytor.com>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Leo Yan <leo.yan@linaro.org>
Subject: [PATCH V3 04/10] perf tools: Add new perf clock IDs
Date: Mon,  7 Mar 2022 10:53:06 +0200	[thread overview]
Message-ID: <20220307085312.1814506-5-adrian.hunter@intel.com> (raw)
In-Reply-To: <20220307085312.1814506-1-adrian.hunter@intel.com>

Add support for new clock IDs CLOCK_PERF_HW_CLOCK and
CLOCK_PERF_HW_CLOCK_NS.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/Documentation/perf-record.txt | 11 ++++++++++-
 tools/perf/builtin-record.c              |  2 +-
 tools/perf/util/clockid.c                |  5 +++++
 tools/perf/util/clockid.h                |  8 ++++++++
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 465be4e62a17..d7e609a5f824 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -444,7 +444,16 @@ Record running and enabled time for read events (:S)
 Sets the clock id to use for the various time fields in the perf_event_type
 records. See clock_gettime(). In particular CLOCK_MONOTONIC and
 CLOCK_MONOTONIC_RAW are supported, some events might also allow
-CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI.
+CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI. In addition, the kernel might
+support CLOCK_PERF_HW_CLOCK to select an architecture dependent hardware
+clock, for which the unit of time is ticks not nanoseconds. On x86,
+CLOCK_PERF_HW_CLOCK is provided by the rdtsc instruction, and is not
+paravirtualized. There is also CLOCK_PERF_HW_CLOCK_NS which is the same as
+CLOCK_PERF_HW_CLOCK, but converted to nanoseconds. Note support of
+CLOCK_PERF_HW_CLOCK_NS does not necessarily imply support of
+CLOCK_PERF_HW_CLOCK or vice versa. Be warned, CLOCK_PERF_HW_CLOCK and
+CLOCK_PERF_HW_CLOCK_NS may not be stable or well-behaved in any way,
+including varying across different CPUs. That warning can also apply to TSC.
 
 -S::
 --snapshot::
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 0b4abed555d8..c17b13528469 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1973,7 +1973,7 @@ static int record__init_clock(struct record *rec)
 	struct timeval ref_tod;
 	u64 ref;
 
-	if (!rec->opts.use_clockid)
+	if (!rec->opts.use_clockid || rec->opts.clockid >= CLOCK_PERF_HW_CLOCK)
 		return 0;
 
 	if (rec->opts.use_clockid && rec->opts.clockid_res_ns)
diff --git a/tools/perf/util/clockid.c b/tools/perf/util/clockid.c
index 74365a5d99c1..380429725df1 100644
--- a/tools/perf/util/clockid.c
+++ b/tools/perf/util/clockid.c
@@ -49,6 +49,9 @@ static const struct clockid_map clockids[] = {
 	CLOCKID_MAP("real", CLOCK_REALTIME),
 	CLOCKID_MAP("boot", CLOCK_BOOTTIME),
 
+	CLOCKID_MAP("perf_hw_clock", CLOCK_PERF_HW_CLOCK),
+	CLOCKID_MAP("perf_hw_clock_ns", CLOCK_PERF_HW_CLOCK_NS),
+
 	CLOCKID_END,
 };
 
@@ -57,6 +60,8 @@ static int get_clockid_res(clockid_t clk_id, u64 *res_ns)
 	struct timespec res;
 
 	*res_ns = 0;
+	if (clk_id >= CLOCK_PERF_HW_CLOCK)
+		return 0;
 	if (!clock_getres(clk_id, &res))
 		*res_ns = res.tv_nsec + res.tv_sec * NSEC_PER_SEC;
 	else
diff --git a/tools/perf/util/clockid.h b/tools/perf/util/clockid.h
index 9b49b4711c76..af396b14ae8b 100644
--- a/tools/perf/util/clockid.h
+++ b/tools/perf/util/clockid.h
@@ -8,4 +8,12 @@ int parse_clockid(const struct option *opt, const char *str, int unset);
 
 const char *clockid_name(clockid_t clk_id);
 
+#ifndef CLOCK_PERF_HW_CLOCK
+#define CLOCK_PERF_HW_CLOCK		0x10000000
+#endif
+
+#ifndef CLOCK_PERF_HW_CLOCK_NS
+#define CLOCK_PERF_HW_CLOCK_NS		0x10000001
+#endif
+
 #endif
-- 
2.25.1


  parent reply	other threads:[~2022-03-07  8:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-07  8:53 [PATCH V3 00/10] perf intel-pt: Add perf event clocks to better support VM tracing Adrian Hunter
2022-03-07  8:53 ` [PATCH V3 01/10] perf/x86: Fix native_perf_sched_clock_from_tsc() with __sched_clock_offset Adrian Hunter
2022-03-07  8:53 ` [PATCH V3 02/10] perf/x86: Add support for TSC as a perf event clock Adrian Hunter
2022-03-07  8:53 ` [PATCH V3 03/10] perf/x86: Add support for TSC in nanoseconds " Adrian Hunter
2022-03-07  8:53 ` Adrian Hunter [this message]
2022-03-07  8:53 ` [PATCH V3 05/10] perf tools: Add API probes for new clock IDs Adrian Hunter
2022-03-07  8:53 ` [PATCH V3 06/10] perf tools: Add new clock IDs to "perf time to TSC" test Adrian Hunter
2022-03-07  8:53 ` [PATCH V3 07/10] perf tools: Add perf_read_tsc_conv_for_clockid() Adrian Hunter
2022-03-07  8:53 ` [PATCH V3 08/10] perf intel-pt: Add support for new clock IDs Adrian Hunter
2022-03-07  8:53 ` [PATCH V3 09/10] perf intel-pt: Add config variables for timing parameters Adrian Hunter
2022-03-07  8:53 ` [PATCH V3 10/10] perf intel-pt: Add documentation for new clock IDs Adrian Hunter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220307085312.1814506-5-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=suzuki.poulose@arm.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox