From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796417948; b=gc8R8v+lP7vuIrHNkjLhsmlYICaWRn8JGznkdYQQj14qy5WpZdywNh2pkFJw8zu584py Xpoj7h/dG7Bu1n+3CxPnpjvOwOi95y9VJSzmX2m05NdCTsdNYB1YxIz/tMj/bkvgVbIuq T5AwPFRFrCry0wu85WKYTjhG6ynJynmJ/Vgr09Aj75a1nyW00/uxY4qOWJW1OE+26xW+W 8M2mYbir9WDnKOoIcV/mJqf9jB0gxyMyl8b1Uto60Nh1hmRLbpxrxUkzAA7tkEBydCnvk 09nS1WbhnhfyFSjKMMo6DBT2xn8jFwR4UDKceJlMvONbCY+3KbKUTi1GerfAKoQAmKQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796417948; 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=EJMaMLHLwSewXPjV0pHF8NXDb4cUhGFkmmezkSUUPbpbEVQo3beqoicy9h4ishJphagy UYWOtJBxmRKXyOm1R36G/z3nNliuorqfog+d8HwIFn2sVHGxn/+BBIdfh65m0Xj+zcVxp oEHtK/snIBNFtow0z90Ie+D9zrL2NpRxUgR+o6uEHQ+MDoj/6aExhDGJyjXrhPgaGE4LR OL8S9spXS7I/wKPqbiIximIR4sAlOtLffyp1BXMN09b7HR7V7L1pTJFLXuxUWj3MYNJKi oiZZwYGi+IfXMHQQuF/Iz64nmyVYzN++LB2IlFR8cZrZbv8134HbYWn2vVy3wZD1Olg== 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=lrjHLmwl; arc=none smtp.remote-ip=209.85.210.70 Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.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 6F2B7606A32D for ; Fri, 4 Dec 2026 20:59:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6F2B7606A32D 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=lrjHLmwl Received: by mail-ot1-f70.google.com with SMTP id 46e09a7af769-83edc5c5ae9so1723851a34.1 for ; Fri, 04 Dec 2026 12:59:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796417947; x=1797022747; 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=lrjHLmwlOhcSpdGkAEoAdxtIrkQEVmhq6jkQ6PpGa3snY+d9++RpsEttIX2OU+ZWfq SVGVwslr35482d8bkmCQZBr9MEUnCGCHD1LIp/Duo1WuPWJJ2GIytCsaQJUnbh35HJFR O0UsacJUe1BX1yBVY+7xuH7Pg71D6mwOT/rm4fCmrSDOKZN3zThahClgYUG6SfWBW6xk lpK61LXZjWqWVV2VPIashdBwH+WJyccrpQF8PuvjRy7zncwIq3nAhBwhZq2VK1PG7T58 U7+gX+xQQKzMk6LV5gXQHuFo/emB5wVeg3R/c51W0Vo/z2B6CipD8mvBTxl62AQ1Wyxc CV+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796417947; x=1797022747; 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=rV45VqjDiXhyDMVZgaydZvagyamj9aQWOx2JpSSJGipssrgAuFJFdO/+xqNh//si/y Dc9CxQloFA9BQ6al/ToGA1hHMgOgLFiy8ZYs3mSJfVldiun3UUyS6I7jzZGPv2cSC4+L BYt6F3dCHxPEZasOdwCfXcSpQyUGLn3XzZFgZLKrjBp89/ONKXnxTYKHe/WVFJ7BSqyT 7RIRAJGv3Xzz2rngyu8a5JTZC12s97QLvZ93XXTIeX0jyAvKmOvkJdJnsZNfNljlB7mH Wiu6WwCgm6pheyjG/iTnnxm8b7EY5eBciVlAkZFw3VqmE73yK2TJo5ORn5Fxq0ZMuzKC FhBg== X-Gm-Message-State: APuU4Z+kCnfHzk3MNydDvwx8avq11rjvCix2Kvzyr+KvzrMSwzJ4LFbi TmDpHatwZLMMORmZIkzLH6Dhwzcmx3RP0m3B5eYy82Rz0HUTA1lZ7Hvhg1NUDpr4sOggC8mn0bU ZF0LsC2+/Nfdge05QEyIlTO+BeOhcMb96iGvq4DxYJz0dp+3IGaS32EZy5D+Gi+RpAg6FQYdzWr FbiB3cH+cLdl4F9el17N/zWidgDcrl7oeUSysVXZvBmWhYaoS1X5fmK+U= X-Received: from otez34.prod.google.com ([2002:a05:6830:84a2:b0:863:4140:fac4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6830:640d:b0:7fa:ab72:9e04 with SMTP id 46e09a7af769-863f8a2c487mr3779835a34.28.1796417947238; Fri, 04 Dec 2026 12:59:07 -0800 (PST) Date: Fri, 4 Dec 2026 12:58:49 -0800 In-Reply-To: <20261204205854.3973609-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: <20261204205854.3973609-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204205854.3973609-4-irogers@google.com> Subject: [PATCH v4 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 --- 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