public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: kan.liang@linux.intel.com
To: tglx@linutronix.de, jstultz@google.com, peterz@infradead.org,
	mingo@redhat.com, linux-kernel@vger.kernel.org
Cc: sboyd@kernel.org, eranian@google.com, namhyung@kernel.org,
	ak@linux.intel.com, adrian.hunter@intel.com,
	Kan Liang <kan.liang@linux.intel.com>
Subject: [RFC PATCH V2 9/9] perf evsel: Enable post-processing monotonic raw conversion by default
Date: Mon, 13 Feb 2023 11:07:54 -0800	[thread overview]
Message-ID: <20230213190754.1836051-10-kan.liang@linux.intel.com> (raw)
In-Reply-To: <20230213190754.1836051-1-kan.liang@linux.intel.com>

From: Kan Liang <kan.liang@linux.intel.com>

The HW time is more accurate than the time recorded in the NMI handler.
Set the hw_time by default for the monotonic raw clock, and convert the
HW time to the monotonic raw clock in perf tool.

For the legacy kernel which doesn't support the attr, nothing is
changed. The monotonic raw clock is still from the time recorded in the
NMI handler.

Print the hw_time in perf_event_attr__fprintf

Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
---
 tools/perf/util/evsel.c                   | 11 ++++++++++-
 tools/perf/util/evsel.h                   |  1 +
 tools/perf/util/perf_event_attr_fprintf.c |  1 +
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 5e27ac2b9f9b..d182c12fd291 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1349,6 +1349,8 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts,
 	if (opts->use_clockid) {
 		attr->use_clockid = 1;
 		attr->clockid = opts->clockid;
+		if (opts->clockid == CLOCK_MONOTONIC_RAW)
+			attr->hw_time = 1;
 	}
 
 	if (evsel->precise_max)
@@ -1853,6 +1855,8 @@ static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus,
 
 static void evsel__disable_missing_features(struct evsel *evsel)
 {
+	if (perf_missing_features.hw_time)
+		evsel->core.attr.hw_time = 0;
 	if (perf_missing_features.read_lost)
 		evsel->core.attr.read_format &= ~PERF_FORMAT_LOST;
 	if (perf_missing_features.weight_struct) {
@@ -1906,7 +1910,12 @@ bool evsel__detect_missing_features(struct evsel *evsel)
 	 * Must probe features in the order they were added to the
 	 * perf_event_attr interface.
 	 */
-	if (!perf_missing_features.read_lost &&
+	if (!perf_missing_features.hw_time &&
+	    evsel->core.attr.hw_time) {
+		perf_missing_features.hw_time = true;
+		pr_debug2("switching off hw_time support\n");
+		return true;
+	} else if (!perf_missing_features.read_lost &&
 	    (evsel->core.attr.read_format & PERF_FORMAT_LOST)) {
 		perf_missing_features.read_lost = true;
 		pr_debug2("switching off PERF_FORMAT_LOST support\n");
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index d1ef67852bda..c1d6fd40ea39 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -189,6 +189,7 @@ struct perf_missing_features {
 	bool code_page_size;
 	bool weight_struct;
 	bool read_lost;
+	bool hw_time;
 };
 
 extern struct perf_missing_features perf_missing_features;
diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/perf_event_attr_fprintf.c
index 7e5e7b30510d..7b3669430b87 100644
--- a/tools/perf/util/perf_event_attr_fprintf.c
+++ b/tools/perf/util/perf_event_attr_fprintf.c
@@ -154,6 +154,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
 	PRINT_ATTRf(sample_max_stack, p_unsigned);
 	PRINT_ATTRf(aux_sample_size, p_unsigned);
 	PRINT_ATTRf(sig_data, p_unsigned);
+	PRINT_ATTRf(hw_time, p_unsigned);
 
 	return ret;
 }
-- 
2.35.1


      parent reply	other threads:[~2023-02-13 19:08 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-13 19:07 [RFC PATCH V2 0/9] Convert TSC to monotonic raw clock for PEBS kan.liang
2023-02-13 19:07 ` [RFC PATCH V2 1/9] timekeeping: Expose the conversion information of monotonic raw kan.liang
2023-02-13 19:28   ` John Stultz
2023-02-13 19:07 ` [RFC PATCH V2 2/9] perf: Extend ABI to support post-processing monotonic raw conversion kan.liang
2023-02-13 19:37   ` John Stultz
2023-02-13 21:40     ` Liang, Kan
2023-02-13 22:22       ` John Stultz
2023-02-14 10:43         ` Peter Zijlstra
2023-02-14 17:46           ` Liang, Kan
2023-02-14 19:37             ` John Stultz
2023-02-14 20:09               ` Liang, Kan
2023-02-14 20:21                 ` John Stultz
2023-03-12 20:50                   ` Andi Kleen
2023-02-14 19:34           ` John Stultz
2023-02-14 14:51         ` Liang, Kan
2023-02-14 17:00           ` Liang, Kan
2023-02-14 20:11             ` John Stultz
2023-02-14 20:38               ` Liang, Kan
2023-02-17 23:11                 ` John Stultz
2023-03-08 18:44                   ` Liang, Kan
2023-03-09  1:17                     ` John Stultz
2023-03-09 16:56                       ` Liang, Kan
2023-03-11  5:55                         ` John Stultz
2023-03-13 21:19                           ` Liang, Kan
2023-03-18  6:02                             ` John Stultz
2023-03-21 15:26                               ` Liang, Kan
2023-02-14 19:52           ` John Stultz
2023-02-13 19:07 ` [RFC PATCH V2 3/9] perf/x86: Factor out x86_pmu_sample_preload() kan.liang
2023-02-13 19:07 ` [RFC PATCH V2 4/9] perf/x86: Enable post-processing monotonic raw conversion kan.liang
2023-02-14 20:02   ` Thomas Gleixner
2023-02-14 20:21     ` Liang, Kan
2023-02-14 20:55       ` Thomas Gleixner
2023-03-21 15:38         ` Liang, Kan
2023-02-13 19:07 ` [RFC PATCH V2 5/9] perf/x86/intel: Enable large PEBS for monotonic raw kan.liang
2023-02-13 19:07 ` [RFC PATCH V2 6/9] tools headers UAPI: Sync linux/perf_event.h with the kernel sources kan.liang
2023-02-13 19:07 ` [RFC PATCH V2 7/9] perf session: Support the monotonic raw clock conversion information kan.liang
2023-02-13 19:07 ` [RFC PATCH V2 8/9] perf evsel, tsc: Support the monotonic raw clock conversion kan.liang
2023-02-13 19:07 ` kan.liang [this message]

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=20230213190754.1836051-10-kan.liang@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    /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