From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796524484; b=oxWxBp5lwhawhYasUSQVoPha8pZsJtg+oVZtITTk7Ihlt85TOsR06NUiSVmBbdN2Ifdd YHqonB/H7itTYdSYKaJo/7fcvxGP+mJ/ybfWCIru00VIgX0uskXuPNj33cx0mx56JiYZQ u6ISCkpdyiBMeP0Wm5n+i4IlUJNTxV8G6ATOD9eQPSZAiCMqFEML1t+itPjwIpGI3a+1e oi+ZZrQ+sVoq3pRuN0oy5WE4eYQbQZwQrXMSnD25szwvjbaqp8Vsl6c0sjfL1UDfREF5l YhdblOwPQ3qizFMfs3o/mqVMahBvCurMnX89YvAbWKnm4K/M/MD1efl5GUAuITUxgYA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796524484; 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=ZOLtoiHggcvV4u4vTb01VKaZhFnkX14aVHB/4arYn4Y=; b=WjkbFugguViGpR7c3+48UzaVKPY0eqNmMLjX6g74tBXSyW1Ij3Z0e0fciabvyW4hLDr9 DjZWckq8Rdl0xos4NIZ84Qp0Yzu7eSJuK0rxHWtirPWbzQSKJaEgyLWN6fHevc0GllanI 97+O//IUFmidIsR1c66339T6COTNIWc1mbqTjG2HneMSlMtLUM7qUFWF4b8LgXxHQe34W uXy0B0GGvm3UbM79v9a+UJzEYLNSbh5PAYvsAv0LPTRIgjBdJYp42IzFmwJCKjDHLbwR5 0uIqwOPYwkwBFjahdy8yw07HoK6/bOUQh1ReW1pTdQqfaWT4fUsZ+wjjBJoTOUf/72A== 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=kSlZEia8; arc=none smtp.remote-ip=209.85.216.70 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (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 854B6606A322 for ; Sun, 6 Dec 2026 02:34:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 854B6606A322 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=kSlZEia8 Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-3b427e5a37dso2044591a91.2 for ; Sat, 05 Dec 2026 18:34:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796524484; x=1797129284; 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=ZOLtoiHggcvV4u4vTb01VKaZhFnkX14aVHB/4arYn4Y=; b=kSlZEia8vpy8uVfnVMMpndAwKZoc9Rd+UPg8FNwVFlML6ETQ+lv0QNX8Ma3iLBUNry 7AmbzwzzrMxH5n7YJAPwLr6P6NW4jBadwDv7GYvwZ7vS0xtr0t/SyMp+SRX+TSTNz9el 7uG0OvelxxyHWVN9EjRmkTIKH0J8RF3qxIJRScKfaVCLbXm5DOj2K9CQVfvYFafb/0c6 61hhJ2baREoc3cBWMsZ1HyEpUH8O4FkmuZqWZGekXWDOYhH8WIzSLaCBUfC8l61TLVcr ySvFxi2Jlpde0qk+89J9+fDPcLF7coSBostcZ8XrezOoHKlY0zeIv97sf2piTy+VU2bC uJbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796524484; x=1797129284; 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=ZOLtoiHggcvV4u4vTb01VKaZhFnkX14aVHB/4arYn4Y=; b=R9f7FLpVVf8kTxVcg3ftGvfPi5zNHMJKm7K7CMFPDcLauaY0f9GVIeBANwVd7Z6m/o SvKY2NA1PgyXiQGLYFNJU6cijRHf/etgpKbvHVfQI3RId2oHmvluVqPuW5qOZVpp0SK3 rFlnSQTdUsAbLyBQgvbiHd/Q3bzt4roIJKk4G5BLTzw9/3Lhfb1oDypXNcmy/byVF9w/ uGXfjWEOp9GknYO+iM0NwmiBhcAvY04Undi3eQNZwf7EPCPeiIYjIpuy6lbMqd0qSNV7 8A2SAQP2SawcL6dpPlZikCFv+uSNDOW4yVDM0QVY5SS5kPD08AbWi87jlPQbiPKVRmu+ IfBA== X-Gm-Message-State: AB4q+uGWG93K9S9rqENrJoW6Xz6ba5wswxkSmkqPAYKShiAAA9VUKfP7 JtWbc5euMJe1xEidNW5FTySa+zp6So6VCejwidZnF5vxG9RLEJ1GIQkzAbb4HIz3zGnYgtrhsMj BTGOeQqbY1AA5bZOUmIEbkFwFMqOrzvNhgTZX27vXQzfL6CR/BzICH3fIqS6mWYRN5rmVU255o5 bCCjFpk9kkCpCYhda88i3zs7AurRYsXrGgu0raPp6C6cQAgGyjAUqIpxA= X-Received: from pjot17.prod.google.com ([2002:a17:90a:9511:b0:3a8:8d0:61eb]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3ccf:b0:3b0:a511:fb75 with SMTP id 98e67ed59e1d1-3b5e0697bf8mr5823586a91.40.1796524483447; Sat, 05 Dec 2026 18:34:43 -0800 (PST) Date: Sat, 5 Dec 2026 18:34:09 -0800 In-Reply-To: <20261206023413.3078292-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: <20261206023413.3078292-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261206023413.3078292-4-irogers@google.com> Subject: [PATCH v5 3/7] 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 --- 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