From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796346313; b=U32/p6EcoEgGi+io3uRVkeVuMf70rkLz5PIyfgfAsiu4twRT3q3BqFGIKC7J9SE8j/sh f+fhTrKcJoedeUc5RLQWU77VtZira2hI6pQ53Ukm1kf0c7Rnc7X8GrztvP5SY5Qi2cYAJ B8xmmOWaEmE3jTuW6b+n1ELy063aCmiUvUhw8QqlNaXmHxyCTP+c6bQtyIZ/LIl79UKzt E7Y6qnk7OtM9RAUHuRdPY3ErkpGyTTSDi5PGfLdxIAnRDKHt7Oe11t38ZPM/o47GwZrye 3GcjbF3M3A9bEzyBqT6M++yolcTHNp4ShS57Jkpky286laAaMbbEI1CNM+0DzJx0V/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796346313; 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=QvOL4KeDzPj/OY0lviNq8EuQOtaKHu7b5CMfnW49TwV2CW1qboC3RYYZ6+updnCfAoaj f1TTpofnwnOKV4sLtq+E2kcN00/kVXWUTxKnSTgak2KffNNFCO+kGB0wWE8Et5aws4mAb BrfsUdSQFqXISVSXD7XQ8SAb2xx0HBl4DPcZH17O/yHr5GwYxUqOLk8ie3hbICr6OYrsW DqRcdbSG1c2+Sjj7qOhlRb7neDAdRa0PKYGrAeXS8dSH02CcWBrd4M609iR7r6+u94R6C Zb/qayFN/GiqfafNXlXdOmmd/vEySCeIFC4i4PlvqxEhxWoVwvGSZ9uVYOImit9BKEQ== 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=o66UMrDV; arc=none smtp.remote-ip=74.125.82.200 Received: from mail-dy1-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) (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 A12F0606A691 for ; Fri, 4 Dec 2026 01:05:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A12F0606A691 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=o66UMrDV Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-386a0f79047so637012eec.1 for ; Thu, 03 Dec 2026 17:05:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796346312; x=1796951112; 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=o66UMrDVQBC0i+hAO9nlMuL7AriN9num+6bqZ6JKiyzgeFuDfL23qlU82zyZuWEn9q UV69Mf5SSvqW4RWVPnZo6HGK1JGrVh7WrSyMhQTcIjhAKFRiC6k6K6HbLpXCy3jA0OcG QoS15HL5ZaRd3KmRAA7SIUgMWtKP7dDfTgKwpXT0Fb658KLCpJjfOXAGI+k/6NSaKy4T QPwcKfoPZHpB5daB2xQBPfWshboa2jxZjtG0c6bSDC0xc84IHPwNZwPyWj8ltNVC+UKp mRy6UoxdJ3Tu47IFc1nMUpivlotTxPI3vX/wXuKn9LHtk1dWYFn9F6WfSZfeH6tBAAUC kJSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796346312; x=1796951112; 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=FQpXVzWHb8/JqaDMt7U4lNAGAZlZRovsQff6Fesa2E3mIYphP1YMtMLAhz19vnVbnO EyW/vKiRB/CGI2d1SX6+uJkQPBPT9Ie3wWRlfqwlAJntajMy4K9Cq1GA4jUvOKigy84Q 38Wvh+mAHfs/XDd+OKJKVcuGnqXurcsKEkz1evilXqzDmuNo12/0TlaDa/ogP88gUXi5 q04qTwkv1JMU8Kb1rIsdFTNuAzrQhhxl3WTg+n3gDwLexDaMPOyj67npoWSerwEPtYh1 wiKoLd2rN2TYGjWFi9WGXkok9tFJJwNzuT7Zvzc+5BTgANXvM6NKdpQiMBF6wsARef9I JZPA== X-Gm-Message-State: APuU4Z/yvAZF87SnJlvOMFs3+9SYi2Sj82rUNP2m0sz/2PcC/EvRTj4R LsvEZ5O7MmYzQh9JfQPg0pqFZtGS7CUim/Kb9gRyaTEPshKIItlt4wUueC8dmaXjFIPD8wwmI+v gHzOWG+ZyUbQO3jhM2OZrzWnxjbPLoNAiKX0t3uGRVkd0NEcZaKn+yXrmEDMw6UtPK572lk3XOI RZhHza+w73FPlT8nPhb2UptJvXlLoZCtUjfBTMN9YkWzkwmoLRzG2SlNc= X-Received: from dyctb1.prod.google.com ([2002:a05:693c:39c1:b0:386:cb77:8766]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:d10a:b0:386:b896:319c with SMTP id 5a478bee46e88-387522101a7mr456990eec.35.1796346311206; Thu, 03 Dec 2026 17:05:11 -0800 (PST) Date: Thu, 3 Dec 2026 17:04:48 -0800 In-Reply-To: <20261204010452.1937224-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: <20261204010452.1937224-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204010452.1937224-4-irogers@google.com> Subject: [PATCH 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