From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796365419; b=A2LfXYcnaDaARacGxGBD8yClXgKdBpV9itWkjp8VicCwLAqgvBa6IGRwqj7ekotgLA/e 0p4TcvvrHX7NvhZQAbgnXZcRhT3zNIasVnBIkipKneN7V5E+qZgNmpZzHsBSmvduRCeSx tG5/tAiicv0sAnaHS+6H5Hs4hRNcTY9PKehutAddL116lgVrXxed7rrizaqKjYPBWnTWE ImS0A2Ulvu1ojatWL2W9h9/H1yuB2g2G0jd75mK9Rmi6sfHMl3Bj+drbmRPLTHB1Yl2Qs sKwrgy/aO1hS2ir1q6+6PenDV3bH/thxkGzzFJHeSa9p+n1SuYG5ilCcS1V6wCUNamg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796365419; 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=Fp6Bgv7e/IJG+Fhnr1M7fhZgNbJmwWtqB1l2IJhzpGsXz7aDhp7mNgG0tds92H09Ubht iekNDAFGOPG6+qrc9YSMVUX8UcqJL/YCceP/dXaRMeYSsBfQGtmcsinq5a5sj4SENE+O1 xuzgwg1IPU2uMkp1YDKJhKXML7Jjki91qKE3GsdcCorPgTNBxrbbVUC9cKfwUOT3hzrjL Ck8vIjAetQTllQf8BzYBZHOadLncQDEBBncVr8x5gfAgfHfGiobBjhFc3MqppS8xOeEi5 PYfurnO/vv1pwOwfcoiz3TZU4D8C/WFg/xS0g075K49+EPGJUWk7aJcwGeNhREsC4VA== 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=gnt4PYmF; arc=none smtp.remote-ip=74.125.82.197 Received: from mail-dy1-f197.google.com (mail-dy1-f197.google.com [74.125.82.197]) (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 B2C1F606A33C for ; Fri, 4 Dec 2026 06:23:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B2C1F606A33C 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=gnt4PYmF Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-38751f8cc15so1360932eec.1 for ; Thu, 03 Dec 2026 22:23:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796365418; x=1796970218; 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=gnt4PYmFHI3rLagT6/KSbkFymdJifuvaLfhypOd6cmygRsxSh6zKQpeJcXdyNwy1gV 1jjeUTtSECEzaGsYHQtiNWCl/cUX2u04OU6DCqeHnX5VFR7KT8NWZvHUG+pROJLYvmPe encXSyaPDh3JSaZHHRUdt5r9lALcZHk4Q0LeXITFXgXUYA+JRg1IP1kmlUzc7I/mBOiJ y/DlPibDOaIJymD2d2wgpYZUByjAY6YLF7jEfmhs5/4QA2LFyi36Z2dJA8Brty+hG/jt fY01hAn81XmDmMnLZp+FD/6Hqbi7nJ/E2UnICH58JD7Ce6NhwO+TJf+ZB6yWKc0p7prL f6EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796365418; x=1796970218; 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=NlzHSYdJRRJT9i6Xc+vSE4DBRLSbwUBBiDNwYS0mVY+9+5bjCSCniaKQZFnDn3BWT2 Y9S51/Ek5o6/quB0Jw6BJw6oHBVZ42ENJZP/KX+48r7BxS9kgfirIuylT+KjeoI0sivZ MoLOEWrgMKnTg36P22C8A4+J5zohgo/jdJsGhGIELKNIbJ3fLhbgwlMjdCPMmoxNLAsg IYPMOAxXxq6Ay278+filvwLVu2ynhxwsSa4et1WEIlCGOPLDM/Vbs8jBbRrA/zONBR+u JgZgVC7CJuGOVJ/SllBdeU0YG5n3k1ujocx+U1S+X9WC2MzYx6GOPQTNpRczraFbWPgD tyKA== X-Gm-Message-State: APuU4Z9xOX6nBtdPM/ZwtlGYi4c6gmmFYcP/q7+pct59qDHE2VdiKBwN p/f5L20mTroaI1McCnl3NGNEn/+VSW4jEZPECeq0RJFhNgkiVJsOQu9GauJwYXwxoZlOEY9b0AG WkOwE5jH77APW1j5IzeF964JAE9GHec7/WQDXm2R92a4uUlPtKL7jxRedWeOiV6gFqFdKTfkqT+ iPpEv4p03wy9bgJyDOpaRiyZzmRp69PQJM/QZVThZGyeCs/dy26EkUp1U= X-Received: from dycpp2.prod.google.com ([2002:a05:7301:dd82:b0:381:6d21:2e90]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:430b:b0:384:988d:6ec2 with SMTP id 5a478bee46e88-387521f68dfmr1746538eec.33.1796365417395; Thu, 03 Dec 2026 22:23:37 -0800 (PST) Date: Thu, 3 Dec 2026 22:23:24 -0800 In-Reply-To: <20261204062328.2508164-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: <20261204062328.2508164-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204062328.2508164-4-irogers@google.com> Subject: [PATCH v3 3/7] perf bench synthesize: Initialize symbols so build IDs can be read From: Ian Rogers To: linux-perf-users@vger.kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, 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