Linux Perf Users
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ian Rogers <irogers@google.com>, Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-perf-users@vger.kernel.org
Subject: [PATCH v2 02/11] perf tools: Add perf_env__is_same_boot()
Date: Sun, 15 Nov 2026 21:57:22 -0800	[thread overview]
Message-ID: <20261116055731.707164-3-namhyung@kernel.org> (raw)
In-Reply-To: <20261116055731.707164-1-namhyung@kernel.org>

Add perf_env__is_same_boot() to compare the recorded boot_id in struct
perf_env against the running host's /proc/sys/kernel/random/boot_id.
For live sessions where no offline header was populated, it falls back
to reading the host boot_id and returns true.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/env.c | 25 +++++++++++++++++++++++++
 tools/perf/util/env.h |  1 +
 2 files changed, 26 insertions(+)

diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 24de685486af9bd5..91ab4ccaf5a9475c 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -444,6 +444,31 @@ const char *perf_env__boot_id(struct perf_env *env)
 	return boot_id;
 }
 
+static char *host_boot_id;
+
+static void init_host_boot_id(void)
+{
+	host_boot_id = read_host_boot_id();
+}
+
+bool perf_env__is_same_boot(struct perf_env *env)
+{
+	const char *env_boot_id;
+
+	DO_ONCE(init_host_boot_id);
+	if (!host_boot_id)
+		return false;
+
+	if (!env)
+		return true;
+
+	env_boot_id = perf_env__boot_id(env);
+	if (!env_boot_id)
+		return false;
+
+	return !strcmp(env_boot_id, host_boot_id);
+}
+
 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
 {
 	int i;
diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h
index aafd213c7523c018..856385624cee6adf 100644
--- a/tools/perf/util/env.h
+++ b/tools/perf/util/env.h
@@ -190,6 +190,7 @@ int perf_env__kernel_is_64_bit(struct perf_env *env);
 bool perf_arch_is_big_endian(const char *arch);
 const char *perf_env__os_release(struct perf_env *env);
 const char *perf_env__boot_id(struct perf_env *env);
+bool perf_env__is_same_boot(struct perf_env *env);
 
 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]);
 
-- 
2.56.0.611.g1030f0b940-goog


  parent reply	other threads:[~2026-11-16  5:57 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  5:57 [PATCH v2 00/11] perf tools: Enhance namespace and chroot handling Namhyung Kim
2026-11-16  5:57 ` [PATCH v2 01/11] perf tools: Add HEADER_BOOT_ID feature Namhyung Kim
2026-11-16  6:09   ` sashiko-bot
2026-11-16  5:57 ` Namhyung Kim [this message]
2026-11-16  6:02   ` [PATCH v2 02/11] perf tools: Add perf_env__is_same_boot() sashiko-bot
2026-11-16  5:57 ` [PATCH v2 03/11] perf tools: Add nsinfo__new_thread() to track tid Namhyung Kim
2026-11-16  6:16   ` sashiko-bot
2026-11-16  5:57 ` [PATCH v2 04/11] perf tools: Add lock to struct nsinfo Namhyung Kim
2026-11-16  6:17   ` sashiko-bot
2026-11-16  5:57 ` [PATCH v2 05/11] perf tools: Defer /proc lookup until nsinfo is used Namhyung Kim
2026-11-16  6:11   ` sashiko-bot
2026-11-16  5:57 ` [PATCH v2 06/11] perf tools: Verify thread status and mount namespace inode Namhyung Kim
2026-11-16  6:14   ` sashiko-bot
2026-11-16  5:57 ` [PATCH v2 07/11] perf tools: Check thread liveness when accessing /proc Namhyung Kim
2026-11-16  5:57 ` [PATCH v2 08/11] perf tools: Export filename__read_build_id_ns() Namhyung Kim
2026-11-16  6:16   ` sashiko-bot
2026-11-16  5:57 ` [PATCH v2 09/11] perf tools: Only enter mount namespace if necessary Namhyung Kim
2026-11-16  5:57 ` [PATCH v2 10/11] perf tools: Scope mount namespace entry in dso__load() Namhyung Kim
2026-11-16  6:16   ` sashiko-bot
2026-11-16  5:57 ` [PATCH v2 11/11] perf tests: Add namespace, nsinfo, and boot ID tests Namhyung Kim

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=20261116055731.707164-3-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.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