From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796360402; b=qaBJfat5APy6LXKkN9JCqb50LzjTXSjTmwXEEIol7fD/vZdnMMEHxwluIXmTAW2ygGeM u9Z4yLE48imLRuahQ8D8U/FHDKUyp+URMTx8/WSEnnDP2Ms/nneetSdF9wv95B9OC6CXB IwAUwnKT+CiEv0ahwcYSxqiWIXCHsosA3f2j+XaAO/UcpkARKP8jetoSVKZjkQT6+l1op 0qmEvb2uYWRpTIHS4G0uTBzSgKsNBW2wjMeZPCjknhTCQzh0noqwU/0mTcEnag/d9S5GY /22x13Lr6aKfbkVwCSBb1hGhCxovfJSjPp+gytiJyMMuz/e/WR+JBWbjWuWCrq2upxQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796360402; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=UYUeC/k65jzJ4rwucKOgdLHJeJdlrs5c8Wi+nw+cP0U=; b=Tc5Y5r+Nw3tgrReOiGJZrgy6ETNghMvArMT9EhLOxp2cKliK+dAEYiXoOo7E3QmZWkl1 fc1epgXM9bkGwkVUsBRVNWcSUfXSm/YdUwBeku05gSaImXZv5UGJzf+COb+g0z3Cp92J2 EgHPwu20IRbJDG1+5nOqYTRI4fJOOCM3gORNK2LG+HSOTrz0k9SUTnQ0Ivn+0Xv9XO2+7 /mHWyqurLzGm6tSyhN12b7kpocBQup3TngxOaPuB7OYPm0UoUCFDdS4m/4KuU83HE7BwO SBcMxizWMN5QiUjMPuie/UjNXDc0C+eM/U2u5uiMH160sHDiZPqoFTLjlMbBWlYPRBQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=j+yYGCGv; arc=none smtp.remote-ip=74.125.82.199 Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8082606A6A6 for ; Fri, 4 Dec 2026 05:00:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D8082606A6A6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=j+yYGCGv Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-30bcb065bfdso635356eec.0 for ; Thu, 03 Dec 2026 21:00:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796360401; x=1796965201; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=UYUeC/k65jzJ4rwucKOgdLHJeJdlrs5c8Wi+nw+cP0U=; b=j+yYGCGvwbA8ZkosSyUdS+ObwG4qpRD5Q9GfEunKGMxwY/HYUr3itgojb5EeDdq/7W gH7Ty7c+lm2Hsx0HItZ/PYR3vArfXsSJvikpOiQrFbZ+DQssWoLmw1NNFKXz4yk6axNJ BpV7kXCgxRprw5xwXV/aJU0bKSW9aTBwcqjyUyOUR5S8G+NOnj3vwyyV5XS/T1rBwIOJ yabLomVyHxs8gcjJrfKWoJjWvhTmbl4rZ0EOyC7oPfwpzKHsnm20ik1k3kNJHVlqzxhc r7oA8QSXqB6KRtTCEIUkf/tKw6FyjkTNkeC4Z2IhzBDluZMrEtvxB+YKuJUouiFPRpgm fGvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796360401; x=1796965201; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=UYUeC/k65jzJ4rwucKOgdLHJeJdlrs5c8Wi+nw+cP0U=; b=04ZLEln6ZSRh7GqxCcDH3A6h0BiektXnDypTnveIDZmw5VQ2kUxIDgFA0gGqIQzRN+ rTCzVvynqIaCQ/YsXeKNtAiMTEXXEk9OPsVV/BwJsoLCCf0dsvMV2Omsp4q6jdGYp5yM bPl3nWYCfpo7Jw2Mlx/6UaHo7au3ZTAa6Y8+yHXxqZh762NS3ZmP4FElhUK7KjBuXDFJ 8dC/9ERIUfRLohwQtUbsguvbfy8sUKxMFxYeE35pv9+paq8t7N0mirclhUPJxP134ZD2 L3sbm3Ljn1uHbEOvcoI7OBnlGP9sWkibugG+ILVdJu3hsIf+A8Dji8K1Fzjk480VdSyc kfWQ== X-Gm-Message-State: APuU4Z+gxTuwkk7fWZOSpCcE+TZ9dl6kxfdKiGzOS1rk2uHYrlJCVN90 KBlgT1H4qeWm+t7mEUMqW2cW9uKHIxCBgD+oQpTlb+2RqFI1hV4WkrQUmj6aHF1uYK1B+0kDv+3 JJrEHbtNmPjJNWvAzYbIg1y0xX5f8fLX675xnFyxTGCRpBMWjvLpIblsUGrdKffPCDjzW8jh9gf 1W9zgMDbbdCRH9MOgBK9dxx7ium0HH2/irL3qUqkT5O2FKjNjLtNN0OpU= X-Received: from dleb8-n1.prod.google.com ([2002:a05:701b:4248:10b0:1b2:48fb:f4d0]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7023:e44:10b0:1b5:4aba:b087 with SMTP id a92af1059eb24-1b5d7061cb7mr960476c88.3.1796360400637; Thu, 03 Dec 2026 21:00:00 -0800 (PST) Date: Thu, 3 Dec 2026 20:59:45 -0800 In-Reply-To: <20261204045948.2254888-1-irogers@google.com> X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261204045948.2254888-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204045948.2254888-4-irogers@google.com> Subject: [PATCH v2 3/6] perf bench synthesize: Initialize symbols so build IDs can be read From: Ian Rogers To: linux-perf-users@vger.kernel.org, acme@kernel.org, namhyung@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, jolsa@kernel.org, adrian.hunter@intel.com, james.clark@linaro.org, dsahern@gmail.com, andrii@kernel.org, Ian Rogers Content-Type: text/plain; charset="UTF-8" Since build IDs became the default in synthesized MMAP2 events, the synthesize benchmark reads the build ID of every mapped file. The benchmark never called symbol__init(), so elf_version() was never called, elf_begin() fails and every build ID read fails. As no build ID is found the DSO build ID cache is never populated, and so every mapping re-opens its file and enters the mount namespace again on every iteration. This made the benchmark measure a failure path that doesn't occur in 'perf record', for example on an Intel Core i7-14700: Before: Average synthesis took: 3876.387 usec (+- 13.053 usec) Average data synthesis took: 24886.623 usec (+- 1238.682 usec) After (median of 10 runs): Average synthesis took: 258.8 usec Average data synthesis took: 1621.8 usec Create a single host perf_env in bench_synthesize(), pass it to symbol__init() so libelf is initialized and vmlinux paths match the host, and share it with the sessions the single and multi-threaded benchmarks create rather than each creating their own. Fixes: 53b00ff358dc ("perf record: Make --buildid-mmap the default") Signed-off-by: Ian Rogers --- Notes: This change was developed with the help of an AI coding assistant (Gemini in Jetski), which wrote the initial code, tests and changelog; it was reviewed, built and tested by the author. tools/perf/bench/synthesize.c | 52 +++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/tools/perf/bench/synthesize.c b/tools/perf/bench/synthesize.c index 265d49a913d9..fdc5465db3f0 100644 --- a/tools/perf/bench/synthesize.c +++ b/tools/perf/bench/synthesize.c @@ -12,6 +12,7 @@ #include "../util/debug.h" #include "../util/session.h" #include "../util/stat.h" +#include "../util/symbol.h" #include "../util/synthetic-events.h" #include "../util/target.h" #include "../util/thread_map.h" @@ -108,23 +109,20 @@ static int do_run_single_threaded(struct perf_session *session, return 0; } -static int run_single_threaded(void) +static int run_single_threaded(struct perf_env *host_env) { struct perf_session *session; struct target target = { .pid = "self", }; struct perf_thread_map *threads; - struct perf_env host_env; int err; perf_set_singlethreaded(); - perf_env__init(&host_env); session = __perf_session__new(/*data=*/NULL, /*tool=*/NULL, - /*trace_event_repipe=*/false, &host_env); + /*trace_event_repipe=*/false, host_env); if (IS_ERR(session)) { pr_err("Session creation failed.\n"); - perf_env__exit(&host_env); return PTR_ERR(session); } threads = thread_map__new_by_pid(getpid()); @@ -149,12 +147,12 @@ static int run_single_threaded(void) perf_thread_map__put(threads); perf_session__delete(session); - perf_env__exit(&host_env); return err; } -static int do_run_multi_threaded(struct target *target, - unsigned int nr_threads_synthesize) +static int do_run_multi_threaded(struct perf_env *host_env, + struct target *target, + unsigned int nr_threads_synthesize) { struct timeval start, end, diff; u64 runtime_us; @@ -163,18 +161,14 @@ static int do_run_multi_threaded(struct target *target, int err = 0; struct stats time_stats, event_stats; struct perf_session *session; - struct perf_env host_env; - perf_env__init(&host_env); init_stats(&time_stats); init_stats(&event_stats); for (i = 0; i < multi_iterations; i++) { session = __perf_session__new(/*data=*/NULL, /*tool=*/NULL, - /*trace_event_repipe=*/false, &host_env); - if (IS_ERR(session)) { - err = PTR_ERR(session); - goto err_out; - } + /*trace_event_repipe=*/false, host_env); + if (IS_ERR(session)) + return PTR_ERR(session); atomic_set(&event_count, 0); gettimeofday(&start, NULL); err = __machine__synthesize_threads(&session->machines.host, @@ -185,7 +179,7 @@ static int do_run_multi_threaded(struct target *target, nr_threads_synthesize); if (err) { perf_session__delete(session); - goto err_out; + return err; } gettimeofday(&end, NULL); @@ -208,12 +202,10 @@ static int do_run_multi_threaded(struct target *target, printf(" Average time per event %.3f usec\n", time_average / event_average); -err_out: - perf_env__exit(&host_env); - return err; + return 0; } -static int run_multi_threaded(void) +static int run_multi_threaded(struct perf_env *host_env) { struct target target = { .cpu_list = "0" @@ -239,7 +231,7 @@ static int run_multi_threaded(void) printf(" Number of synthesis threads: %u\n", nr_threads_synthesize); - err = do_run_multi_threaded(&target, nr_threads_synthesize); + err = do_run_multi_threaded(host_env, &target, nr_threads_synthesize); if (err) return err; } @@ -249,6 +241,7 @@ static int run_multi_threaded(void) int bench_synthesize(int argc, const char **argv) { + struct perf_env host_env; int err = 0; argc = parse_options(argc, argv, options, bench_usage, 0); @@ -264,11 +257,24 @@ int bench_synthesize(int argc, const char **argv) if (!run_st && !run_mt) run_st = true; + /* + * Initialize libelf, otherwise reading build IDs fails and the DSO + * build ID cache is never populated. + */ + perf_env__init(&host_env); + err = symbol__init(&host_env); + if (err < 0) { + perf_env__exit(&host_env); + return err; + } + if (run_st) - err = run_single_threaded(); + err = run_single_threaded(&host_env); if (!err && run_mt) - err = run_multi_threaded(); + err = run_multi_threaded(&host_env); + symbol__exit(); + perf_env__exit(&host_env); return err; } -- 2.56.1.915.g69d5ec7298-goog