From patchwork Tue Apr 2 19:39:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 13614536 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A868D15B96C; Tue, 2 Apr 2024 19:39:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086797; cv=none; b=P99CmhQ5K/9pPAD+U4d+safa5mRxWIk+fq3KHMSMONqwRRwb8cP6q/upoG8OQJr8kqPoH5m5i3T0cZqY/PpnkIJBvrCCRJSarNYoxvh+O/YoFvMWe6InfTivBnEAnIQpx8dE1AyGqGom70DJJ40m+tQ2S9Qy+B0d2G2nOUVCWeI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086797; c=relaxed/simple; bh=ST7KWbTW5vEgaJZoKatfLIs/wAQGXKcwIytfLAFU1Jc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Wc7fM/4G4FIm5YgwFPYYo1OmLs8uZQFzULHSV45FBJxJ0KqjcUpyxei/k38RMdsCd4J4u+64ijYie/bgG8fyxG2aVSkRvW+BW7S3X3b6Tu/tK6EbYmHP9zBssAJ63eW5AHDDbp4TwxHop/Q/nGQgIq9tk22nDaHfzaXlbjYYha0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TtvCejYp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TtvCejYp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 593FAC433F1; Tue, 2 Apr 2024 19:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712086797; bh=ST7KWbTW5vEgaJZoKatfLIs/wAQGXKcwIytfLAFU1Jc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TtvCejYpI1Y+rUbjKpCNbN0/PHt6K+fzdzm9aqrxsnY3obXACPgGX9q+WqpZ8GjhR Bq8/nKSE4ZNzUlnMgMtJru6USKDxYkpph7UAYaRT+BQjT17W/CR5Zj6oRPlrpQMg+2 R1g2vkmA/UKWrn39Ul2e9YwkZ8Fc57xaF+3/nqALzfIf4gBS2uERuTqKetGRcxlDWS 4h10K0e7p7yFl/TBjpyCPAEdsFNQkxrkp3JJTzZjOZiEtT0AzWrr7X1IXprhlzJrvj 27OocBXE7Md6+UnTfrPiBsgEMDN3Oomrilb77lMDVS3oUtEmji9Enf/AFFyjCjiQcr vZTG9zhfamsJQ== From: Arnaldo Carvalho de Melo To: dwarves@vger.kernel.org Cc: Jiri Olsa , Clark Williams , Kate Carcia , bpf@vger.kernel.org, Arnaldo Carvalho de Melo , Alan Maguire , Kui-Feng Lee , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH 01/12] core: Allow asking for a reproducible build Date: Tue, 2 Apr 2024 16:39:34 -0300 Message-ID: <20240402193945.17327-2-acme@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402193945.17327-1-acme@kernel.org> References: <20240402193945.17327-1-acme@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnaldo Carvalho de Melo This is initially about BTF encoding, we want to load DWARF and encode BTF from it in a way that is reproducible, i.e. no matter how many threads we use for the loading/encoding process, the output will be the same, i.e. the BTF ids produced will be the same for all builds. This first path just adds the conf_load field and allows it to be asked for with the '--reproducible_build' option in pahole. At some point we'll use with --btf_features=+reproducible_build or '--btf_features=default --btf_features=reproducible_build' to keep the default set of BTF features and be able to use this in the Linux kernel build system without doing an extra pahole version check for the availability of --reproducible_build with pahole versions that already support --btf_features and thus would ignore "reproducible_build". Cc: Alan Maguire Cc: Kui-Feng Lee Cc: Thomas Weißschuh Signed-off-by: Arnaldo Carvalho de Melo --- dwarves.h | 1 + pahole.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/dwarves.h b/dwarves.h index 2393a6c3dc836f39..4dfaa01a00f782d9 100644 --- a/dwarves.h +++ b/dwarves.h @@ -87,6 +87,7 @@ struct conf_load { bool skip_encoding_btf_vars; bool btf_gen_floats; bool btf_encode_force; + bool reproducible_build; uint8_t hashtable_bits; uint8_t max_hashtable_bits; uint16_t kabi_prefix_len; diff --git a/pahole.c b/pahole.c index 0b9c2de74f146a4d..96e153432fa212a5 100644 --- a/pahole.c +++ b/pahole.c @@ -1235,6 +1235,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version; #define ARGP_supported_btf_features 342 #define ARGP_btf_features_strict 343 #define ARGP_contains_enumerator 344 +#define ARGP_reproducible_build 345 /* --btf_features=feature1[,feature2,..] allows us to specify * a list of requested BTF features or "all" to enable all features. @@ -1819,6 +1820,11 @@ static const struct argp_option pahole__options[] = { .arg = "FEATURE_LIST_STRICT", .doc = "Specify supported BTF features in FEATURE_LIST_STRICT or 'all' for all supported features. Unlike --btf_features, unrecognized features will trigger an error." }, + { + .name = "reproducible_build", + .key = ARGP_reproducible_build, + .doc = "Generate reproducile BTF output" + }, { .name = NULL, } @@ -1997,6 +2003,8 @@ static error_t pahole__options_parser(int key, char *arg, conf_load.btf_gen_optimized = true; break; case ARGP_skip_encoding_btf_inconsistent_proto: conf_load.skip_encoding_btf_inconsistent_proto = true; break; + case ARGP_reproducible_build: + conf_load.reproducible_build = true; break; case ARGP_btf_features: parse_btf_features(arg, false); break; case ARGP_supported_btf_features: From patchwork Tue Apr 2 19:39:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 13614537 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 808B015B962; Tue, 2 Apr 2024 19:40:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086800; cv=none; b=BygbBwbnx+KkIoysa4d5II3Shht0+OrZys8kHo7t+h63SCdMqO66hOnb0qyVwGZXYR9CwSTwoMrV8z5l7ye6XcEydbnYrH0Cyy6N0YZLPcqec14Y7S4iIimmosl+jArVeHSzQnWXDvqw/wEo4y39ZihM9a+7AnOaKl5a77xsYqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086800; c=relaxed/simple; bh=yaRjQzEABL8hzuUckBbpGPbH5cBdTm25T5g2Axc+dyE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Gyqg0dYr/Pldgjvu+tIp6dt28NM6mNDkrrVJ9XJ420G/1wLU6eC34Gc6zX7KVXl8vXDRZqsNywlrYJeojhPe8kipwq1O2Wvy4bZq7xN0FPTa4SCwx+PPfXNcmttXna/2ugS1MPe9+mJNztcVasvPFgVCWRv+gEfLd3F29kFPHHg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iriRV2RE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iriRV2RE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED003C43399; Tue, 2 Apr 2024 19:39:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712086800; bh=yaRjQzEABL8hzuUckBbpGPbH5cBdTm25T5g2Axc+dyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iriRV2REB+Ewiu6YsLc/ph0ktZQEc0XCXCqjYZrplsC4UyPFOlZqYbo1RDyYNcgPC DiWPk/aBrPN5Cqns+XGCh+YL2g202pLIUE3diHyylME1kUAkXeCf8D/0Epd01G0AlI /NREQWnSLZb6Qh+z5pFk/LEFy5ShM3BpP9lKkt4psoVyWvjhSXUQibSDRACdbRfzEK uMN9EZ42ifu64ggyvP3gGs3czzJUqQk0hh8+EToaafX31ttdMSkyeUoMREEHHJ8jfX Y65AiswvnVNKV3LxtR/YAVwkbN9EDn9+qzy1VVM+QmUY5CvLK/DQbzg5QW8QWnk4ft s2qr4BisMH+lg== From: Arnaldo Carvalho de Melo To: dwarves@vger.kernel.org Cc: Jiri Olsa , Clark Williams , Kate Carcia , bpf@vger.kernel.org, Arnaldo Carvalho de Melo , Alan Maguire , Kui-Feng Lee , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH 02/12] pahole: Disable BTF multithreaded encoded when doing reproducible builds Date: Tue, 2 Apr 2024 16:39:35 -0300 Message-ID: <20240402193945.17327-3-acme@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402193945.17327-1-acme@kernel.org> References: <20240402193945.17327-1-acme@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnaldo Carvalho de Melo Reproducible builds need to produce BTF that have the same ids, which is not possible at the moment to do in parallel with libbpf, so serialize the encoding. The next patches will also make sure that DWARF while being read in parallel into internal representation for later BTF encoding has its CU (Compile Units) fed to the BTF encoder in the same order as it is in the DWARF file, this way we'll produce the same BTF output no matter how many threads are used to read BTF. Then we'll make sure we have tests in place that compare the output of parallel BTF encoding (well, just the DWARF loading part, maybe the BTF in the future), i.e. when using 'pahole -j' with the one obtained when doing single threaded encoding. Testing it on a: # grep -m1 "model name" /proc/cpuinfo model name : 13th Gen Intel(R) Core(TM) i7-1365U ~# I.e. 2 performance cores (4 threads) + 8 efficiency cores. From: $ perf stat -r5 pahole -j --btf_encode_detached=vmlinux.btf.parallel vmlinux Performance counter stats for 'pahole -j --btf_encode_detached=vmlinux.btf.parallel vmlinux' (5 runs): 17,187.27 msec task-clock:u # 6.153 CPUs utilized ( +- 0.34% ) 2.7931 +- 0.0336 seconds time elapsed ( +- 1.20% ) $ To: $ perf stat -r5 pahole -j --reproducible_build --btf_encode_detached=vmlinux.btf.parallel.reproducible_build vmlinux Performance counter stats for 'pahole -j --reproducible_build --btf_encode_detached=vmlinux.btf.parallel.reproducible_build vmlinux' (5 runs): 14,654.06 msec task-clock:u # 3.507 CPUs utilized ( +- 0.45% ) 4.1787 +- 0.0344 seconds time elapsed ( +- 0.82% ) $ Which is still a nice improvement over doing it completely serially: $ perf stat -r5 pahole --btf_encode_detached=vmlinux.btf.serial vmlinux Performance counter stats for 'pahole --btf_encode_detached=vmlinux.btf.serial vmlinux' (5 runs): 7,506.93 msec task-clock:u # 1.000 CPUs utilized ( +- 0.13% ) 7.5106 +- 0.0115 seconds time elapsed ( +- 0.15% ) $ $ pahole vmlinux.btf.parallel > /tmp/parallel $ pahole vmlinux.btf.parallel.reproducible_build > /tmp/parallel.reproducible_build $ diff -u /tmp/parallel /tmp/parallel.reproducible_build | wc -l 269920 $ pahole --sort vmlinux.btf.parallel > /tmp/parallel.sorted $ pahole --sort vmlinux.btf.parallel.reproducible_build > /tmp/parallel.reproducible_build.sorted $ diff -u /tmp/parallel.sorted /tmp/parallel.reproducible_build.sorted | wc -l 0 $ The BTF ids continue to be undeterministic, as we need to process the CUs (compile unites) in the same order that they are on vmlinux: $ bpftool btf dump file vmlinux.btf.serial > btfdump.serial $ bpftool btf dump file vmlinux.btf.parallel.reproducible_build > btfdump.parallel.reproducible_build $ bpftool btf dump file vmlinux.btf.parallel > btfdump.parallel $ diff -u btfdump.serial btfdump.parallel | wc -l 624144 $ diff -u btfdump.serial btfdump.parallel.reproducible_build | wc -l 594622 $ diff -u btfdump.parallel.reproducible_build btfdump.parallel | wc -l 623355 $ The BTF ids don't match, we'll get them to match at the end of this patch series: $ tail -5 btfdump.serial type_id=127124 offset=219200 size=40 (VAR 'rt6_uncached_list') type_id=11760 offset=221184 size=64 (VAR 'vmw_steal_time') type_id=13533 offset=221248 size=8 (VAR 'kvm_apic_eoi') type_id=13532 offset=221312 size=64 (VAR 'steal_time') type_id=13531 offset=221376 size=68 (VAR 'apf_reason') $ tail -5 btfdump.parallel.reproducible_build type_id=113812 offset=219200 size=40 (VAR 'rt6_uncached_list') type_id=87979 offset=221184 size=64 (VAR 'vmw_steal_time') type_id=127391 offset=221248 size=8 (VAR 'kvm_apic_eoi') type_id=127390 offset=221312 size=64 (VAR 'steal_time') type_id=127389 offset=221376 size=68 (VAR 'apf_reason') $ Now to make it process the CUs in order, that should get everything straight without hopefully not degrading it further too much. Cc: Alan Maguire Cc: Kui-Feng Lee Cc: Thomas Weißschuh Signed-off-by: Arnaldo Carvalho de Melo --- pahole.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pahole.c b/pahole.c index 96e153432fa212a5..fcb4360f11debeb9 100644 --- a/pahole.c +++ b/pahole.c @@ -3173,6 +3173,14 @@ struct thread_data { struct btf_encoder *encoder; }; +static int pahole_threads_prepare_reproducible_build(struct conf_load *conf, int nr_threads, void **thr_data) +{ + for (int i = 0; i < nr_threads; i++) + thr_data[i] = NULL; + + return 0; +} + static int pahole_threads_prepare(struct conf_load *conf, int nr_threads, void **thr_data) { int i; @@ -3283,7 +3291,10 @@ static enum load_steal_kind pahole_stealer(struct cu *cu, thread->btf = btf_encoder__btf(btf_encoder); } } - pthread_mutex_unlock(&btf_lock); + + // Reproducible builds don't have multiple btf_encoders, so we need to keep the lock until we encode BTF for this CU. + if (thr_data) + pthread_mutex_unlock(&btf_lock); if (!btf_encoder) { ret = LSK__STOP_LOADING; @@ -3319,6 +3330,8 @@ static enum load_steal_kind pahole_stealer(struct cu *cu, exit(1); } out_btf: + if (!thr_data) // See comment about reproducibe_build above + pthread_mutex_unlock(&btf_lock); return ret; } #if 0 @@ -3689,8 +3702,14 @@ int main(int argc, char *argv[]) conf_load.steal = pahole_stealer; conf_load.thread_exit = pahole_thread_exit; - conf_load.threads_prepare = pahole_threads_prepare; - conf_load.threads_collect = pahole_threads_collect; + + if (conf_load.reproducible_build) { + conf_load.threads_prepare = pahole_threads_prepare_reproducible_build; + conf_load.threads_collect = NULL; + } else { + conf_load.threads_prepare = pahole_threads_prepare; + conf_load.threads_collect = pahole_threads_collect; + } // Make 'pahole --header type < file' a shorter form of 'pahole -C type --count 1 < file' if (conf.header_type && !class_name && prettify_input) { From patchwork Tue Apr 2 19:39:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 13614538 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C0D315CD43; Tue, 2 Apr 2024 19:40:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086803; cv=none; b=rdEszzdQHaTGbwEyXKJgHsJB0pex2OoecQ6pyCSHXQO2IqoSQDHSJvHrpNTYzETcyBIyUeVB/GDmbNGO/ABYO5cr7D6oMoIKLiA+WdhzTnEHaEom80u359sE7F0hZJfXn6EkhZxl9k93sQXsKv2+0o/E6O1JJvFsUN2S9DlTNyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086803; c=relaxed/simple; bh=q+NUCdJP4mSxrZnr1exlGkXjhSC5UscKjBVbqiYsyl8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rIsSuWi4jd2FFJ/oyvejxp43OwnntUDfKjl4cXFsLMqfiTeNKtDazNAzmwG7itmKDcjZgzpCPFunlx4+/D52hVHFO2o94Yqienrcw4KEbaQwD+9H81shgAyMoothE0qVMlsd1gcbAp9BIUuSTdUmHkeSL32TAGV85HcVZkhs7lQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XvFq5hmE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XvFq5hmE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C051C433F1; Tue, 2 Apr 2024 19:40:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712086802; bh=q+NUCdJP4mSxrZnr1exlGkXjhSC5UscKjBVbqiYsyl8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XvFq5hmE59YgDgI35s2xIuFQw67EnlIW5BwxblGpIOxcWyZuA08VQD64j47+zWXfW vj3+ze4YyKTH0P+rF7dF/PjxNs/7PpGm2laojrHYkyxnrSu1FxW88GHrlN42PRp3NN v8gIX31cyX6S6eUROzsvajRwHhWmRx8/guX42gDsZSF9DPPMjbZAWkki2hZ78Hf/YZ bLxJhxwF9rJWjBd0Hde0u4U/h7C/kWeyHFdP4Z1V6dK0SaOQ6AGudiBcqFeS/XErAi Cc1Pw91oCStE84p2AG1GznCIQMMps+yXzFm/ATAbyA/OuXgNq7EslkeDeuThtZh9Qt au477FS3p93Sg== From: Arnaldo Carvalho de Melo To: dwarves@vger.kernel.org Cc: Jiri Olsa , Clark Williams , Kate Carcia , bpf@vger.kernel.org, Arnaldo Carvalho de Melo , Alan Maguire , Kui-Feng Lee , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH 03/12] dwarf_loader: Separate creating the cu/dcu pair from processing it Date: Tue, 2 Apr 2024 16:39:36 -0300 Message-ID: <20240402193945.17327-4-acme@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402193945.17327-1-acme@kernel.org> References: <20240402193945.17327-1-acme@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnaldo Carvalho de Melo We will need it so that we add the dcu to a list in the same order as the CUs are in the DWARF file (vmlinux mostly). Cc: Alan Maguire Cc: Kui-Feng Lee Cc: Thomas Weißschuh Signed-off-by: Arnaldo Carvalho de Melo --- dwarf_loader.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index 1dffb3f433cb7c8e..125e361ef2bf3f7b 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -3207,8 +3207,7 @@ struct dwarf_thread { void *data; }; -static int dwarf_cus__create_and_process_cu(struct dwarf_cus *dcus, Dwarf_Die *cu_die, - uint8_t pointer_size, void *thr_data) +static struct dwarf_cu *dwarf_cus__create_cu(struct dwarf_cus *dcus, Dwarf_Die *cu_die, uint8_t pointer_size) { /* * DW_AT_name in DW_TAG_compile_unit can be NULL, first seen in: @@ -3218,17 +3217,32 @@ static int dwarf_cus__create_and_process_cu(struct dwarf_cus *dcus, Dwarf_Die *c const char *name = attr_string(cu_die, DW_AT_name, dcus->conf); struct cu *cu = cu__new(name ?: "", pointer_size, dcus->build_id, dcus->build_id_len, dcus->filename, dcus->conf->use_obstack); if (cu == NULL || cu__set_common(cu, dcus->conf, dcus->mod, dcus->elf) != 0) - return DWARF_CB_ABORT; + return NULL; struct dwarf_cu *dcu = dwarf_cu__new(cu); - if (dcu == NULL) - return DWARF_CB_ABORT; + if (dcu == NULL) { + cu__delete(cu); + return NULL; + } dcu->type_unit = dcus->type_dcu; cu->priv = dcu; cu->dfops = &dwarf__ops; + return dcu; +} + +static int dwarf_cus__create_and_process_cu(struct dwarf_cus *dcus, Dwarf_Die *cu_die, + uint8_t pointer_size, void *thr_data) +{ + struct dwarf_cu *dcu = dwarf_cus__create_cu(dcus, cu_die, pointer_size); + + if (dcu == NULL) + return DWARF_CB_ABORT; + + struct cu *cu = dcu->cu; + if (die__process_and_recode(cu_die, cu, dcus->conf) != 0 || cus__finalize(dcus->cus, cu, dcus->conf, thr_data) == LSK__STOP_LOADING) return DWARF_CB_ABORT; From patchwork Tue Apr 2 19:39:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 13614539 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBB3F15B962; Tue, 2 Apr 2024 19:40:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086805; cv=none; b=R9jh9dRcoMt5OdRvIOWqmNt+vNa4emb5DS8cKTbE7Ktz8TzOURJRGY4Z57Wadws1DnS9pdv9Cx8nit3VBCeACE957ItlScZZlD/bG6sjo0oD73BGHLQGzDEwbWGmHKNX68vQiYkupbKgn2NlE6cTGhX9PYZaos9aKKpnkgKVeUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086805; c=relaxed/simple; bh=kOiNeJGVcoAa111TeF9EUHg4UgiYzaQpUB2MIZ6+pgI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BgAGq2t09UYbPKUSNMCNMcWuYG5IRs1mdOIPr3DkAI8c2zd8E3nukEv7s1sZ1+c0uJK+qZRNJ51y5JK/tOQZ+cOoYJRkwdogoI9NrkglbfjB3dbBq6IVdHV5nBFsXGoEO5cSJE51Ijc/vqlPm1o5iBy0V1OwjFGJvK2WQGmZ/L0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=flnBI7bv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="flnBI7bv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B1D9C43394; Tue, 2 Apr 2024 19:40:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712086805; bh=kOiNeJGVcoAa111TeF9EUHg4UgiYzaQpUB2MIZ6+pgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=flnBI7bvgMGdQCbpNB8dC8Yz/Fp3VYQcjVLjpj6PHAuRkuR1u6tCfDYxOPxVFh8XA mOrA/kvLD2HiQdOAfxENnwlcE3EhnjngJtKwGw3iGo6dobQ8SB3VgRtwq1PZkFXdmL uO8mBkULZLD6FXgFU1l6cy0o2TitCJ2w37LlMcmM5rP8BhiNeYdjt0kg8dZ7CvFCJY RAARUgKkYVtH3fQ1lcIClS7oRfm5tY+KGnkN2ikl7/IUgFuPbLdvTw2DdCDaO6Mpqi 4cTQL4y6GfJp4T+HMU4VviHorps6cb2JcBQerSDzuklm/dwR2NXCjeHkOkBxcl9snh wFYG0cIbaa43A== From: Arnaldo Carvalho de Melo To: dwarves@vger.kernel.org Cc: Jiri Olsa , Clark Williams , Kate Carcia , bpf@vger.kernel.org, Arnaldo Carvalho de Melo , Alan Maguire , Kui-Feng Lee , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH 04/12] dwarf_loader: Introduce dwarf_cus__process_cu() Date: Tue, 2 Apr 2024 16:39:37 -0300 Message-ID: <20240402193945.17327-5-acme@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402193945.17327-1-acme@kernel.org> References: <20240402193945.17327-1-acme@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnaldo Carvalho de Melo Finishing the separation of creating a dcu/cu pair from processing it, as we'll need to add the new dcu/cu pair to the list under cus__lock(), so that we process it in order to keep a reproducible BTF encoding. Cc: Alan Maguire Cc: Kui-Feng Lee Cc: Thomas Weißschuh Signed-off-by: Arnaldo Carvalho de Melo --- dwarf_loader.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index 125e361ef2bf3f7b..5090509309446890 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -3233,6 +3233,16 @@ static struct dwarf_cu *dwarf_cus__create_cu(struct dwarf_cus *dcus, Dwarf_Die * return dcu; } +static int dwarf_cus__process_cu(struct dwarf_cus *dcus, Dwarf_Die *cu_die, + struct cu *cu, void *thr_data) +{ + if (die__process_and_recode(cu_die, cu, dcus->conf) != 0 || + cus__finalize(dcus->cus, cu, dcus->conf, thr_data) == LSK__STOP_LOADING) + return DWARF_CB_ABORT; + + return DWARF_CB_OK; +} + static int dwarf_cus__create_and_process_cu(struct dwarf_cus *dcus, Dwarf_Die *cu_die, uint8_t pointer_size, void *thr_data) { @@ -3241,13 +3251,7 @@ static int dwarf_cus__create_and_process_cu(struct dwarf_cus *dcus, Dwarf_Die *c if (dcu == NULL) return DWARF_CB_ABORT; - struct cu *cu = dcu->cu; - - if (die__process_and_recode(cu_die, cu, dcus->conf) != 0 || - cus__finalize(dcus->cus, cu, dcus->conf, thr_data) == LSK__STOP_LOADING) - return DWARF_CB_ABORT; - - return DWARF_CB_OK; + return dwarf_cus__process_cu(dcus, cu_die, dcu->cu, thr_data); } static int dwarf_cus__nextcu(struct dwarf_cus *dcus, Dwarf_Die *die_mem, Dwarf_Die **cu_die, uint8_t *pointer_size, uint8_t *offset_size) From patchwork Tue Apr 2 19:39:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 13614540 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D9FA15CD52; Tue, 2 Apr 2024 19:40:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086808; cv=none; b=TJBXxj6sxMg2WwmNtSXqzJnLeYltx/EKq4iac8djgqLMj5u3X3lKCRagUJMIqEJiBA/PWeckTxzbu8eGFbnRcUwAz8Ocabs4nWHHLNNW0FZMdnn/MzQw3k7rAaCxgpKxZOw5/HLDhszCJvuCh2q1j88D8sAdd0Pp8TbCgt3H/hQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086808; c=relaxed/simple; bh=lZh+YT5icSodMOONQ1qbwDnaEbwSwsYdN6TXHDg3f48=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fqrtdc9KLW9Rod0m2+Vq+iOJfVbJo+KQh5XFzTqjwm0OWB5DWNMN/U85TaQqhFKYdf2fvYvSjhVp/bpaVpNpPkXlJrb5zc0e5DrHagvAlPJP6PRPi/S8fOUjFfH0+CLbUah3syPo63MBFRzOzTgqm2ZnBVr7+xPatC640s4FMw0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IaDuOm+D; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IaDuOm+D" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCEFAC433F1; Tue, 2 Apr 2024 19:40:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712086807; bh=lZh+YT5icSodMOONQ1qbwDnaEbwSwsYdN6TXHDg3f48=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IaDuOm+DIey+v0ijVDwiCx48UOiVpKb3YT42D26ukW5mekbTLjqy3ltF4KLVUVrH1 u/4LmRaY44vKJYh+ryc6jYErpL88Swzf3wdeR1rUJOc2nQ80ptoMGnhEfi+E/Les6R 9jVo3kZDb3WfJQr9DeLrYb3F5eWTX6YxjuszNV+l3POfiV1SbscLk4MFOApG9rO7va ZNyk8jMdlzpqM/uSo6P4OwEHeC0HvkI8yyKUIHiXR9RXYGHt0uF/1gf59tKZk2XzMb /2kleNUoBhwfEeETM5noyrn1aJjx17ecBYMSY1r3bSBgguIwlVlvd/oNIrWTqD3eI5 r3c4l8WR3A0JA== From: Arnaldo Carvalho de Melo To: dwarves@vger.kernel.org Cc: Jiri Olsa , Clark Williams , Kate Carcia , bpf@vger.kernel.org, Arnaldo Carvalho de Melo , Alan Maguire , Kui-Feng Lee , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH 05/12] dwarf_loader: Create the cu/dcu pair in dwarf_cus__nextcu() Date: Tue, 2 Apr 2024 16:39:38 -0300 Message-ID: <20240402193945.17327-6-acme@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402193945.17327-1-acme@kernel.org> References: <20240402193945.17327-1-acme@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnaldo Carvalho de Melo dwarf_cus__nextcu() is only used in parallel DWARF loading, and we want to make sure that we preserve the order of the CUs in the DWARF file being loaded, so move creating the cu/dcu to under that lock. Cc: Alan Maguire Cc: Kui-Feng Lee Cc: Thomas Weißschuh Signed-off-by: Arnaldo Carvalho de Melo --- dwarf_loader.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index 5090509309446890..a7a8b2bea112ba75 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -3254,7 +3254,9 @@ static int dwarf_cus__create_and_process_cu(struct dwarf_cus *dcus, Dwarf_Die *c return dwarf_cus__process_cu(dcus, cu_die, dcu->cu, thr_data); } -static int dwarf_cus__nextcu(struct dwarf_cus *dcus, Dwarf_Die *die_mem, Dwarf_Die **cu_die, uint8_t *pointer_size, uint8_t *offset_size) +static int dwarf_cus__nextcu(struct dwarf_cus *dcus, struct dwarf_cu **dcu, + Dwarf_Die *die_mem, Dwarf_Die **cu_die, + uint8_t *pointer_size, uint8_t *offset_size) { Dwarf_Off noff; size_t cuhl; @@ -3274,6 +3276,15 @@ static int dwarf_cus__nextcu(struct dwarf_cus *dcus, Dwarf_Die *die_mem, Dwarf_D dcus->off = noff; } + if (ret == 0 && *cu_die != NULL) { + *dcu = dwarf_cus__create_cu(dcus, *cu_die, *pointer_size); + if (*dcu == NULL) { + dcus->error = ENOMEM; + ret = -1; + goto out_unlock; + } + } + out_unlock: cus__unlock(dcus->cus); @@ -3286,13 +3297,13 @@ static void *dwarf_cus__process_cu_thread(void *arg) struct dwarf_cus *dcus = dthr->dcus; uint8_t pointer_size, offset_size; Dwarf_Die die_mem, *cu_die; + struct dwarf_cu *dcu; - while (dwarf_cus__nextcu(dcus, &die_mem, &cu_die, &pointer_size, &offset_size) == 0) { + while (dwarf_cus__nextcu(dcus, &dcu, &die_mem, &cu_die, &pointer_size, &offset_size) == 0) { if (cu_die == NULL) break; - if (dwarf_cus__create_and_process_cu(dcus, cu_die, - pointer_size, dthr->data) == DWARF_CB_ABORT) + if (dwarf_cus__process_cu(dcus, cu_die, dcu->cu, dthr->data) == DWARF_CB_ABORT) goto out_abort; } From patchwork Tue Apr 2 19:39:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 13614541 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECE3D15CD5C; Tue, 2 Apr 2024 19:40:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086811; cv=none; b=HsmIZUYYE2r+KYfN2U9qj3gF6qATx0VBmGKDeZnzvlxEjWowGo9rwQyj8Vc2AjJfwUcZgheZ2BArsjv9jq8GYiGdSgt1OtXGa1rYpx8ZyChN03uenj6J9Xlwdw9MR90vxmqWlxj2yM/gqtrrAXj8R2k7WXNHf47LlmrTOXqq60k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086811; c=relaxed/simple; bh=hf3RkDjDLj8EiGw9zjPmBSt3sYnB/bc1kdIdDMLEDn0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CIqYnBorGTT/vwrmkBL3Fp3gbEKyOQvB5QFENCxUhAjUpc71BlxoYZKJ6ohNYrwMiwZe4Vi+R3YgxJLZBNQHG1JxmU4VoNZOHR93wgz/5CpBAug02WETKRoQZUk0XKZp1A82otR+sOQcb0g3rnOHHaCNc5A9zeydg2W9FhFS6Ls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M10ZWBr1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="M10ZWBr1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C672C433A6; Tue, 2 Apr 2024 19:40:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712086810; bh=hf3RkDjDLj8EiGw9zjPmBSt3sYnB/bc1kdIdDMLEDn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M10ZWBr1Qi5s3T0NA04Q2WXSjqxYHYNSo+xQP5E3F64YrTKVIwv6pKBNLgH2QPQP3 BpusbUzPiMBymgrKaVYBJ3Ih4Rr0tNGuE6UXTIXgfN/O5h1ZkcESNI/7vC7NC/tZzK v26ODkL94KG8+4GGsZ9F6jvQnKaGhsf00MgrK0Wj+6ExiL9LQI9RU738e206XzHmqV rBp8JGMyJMTg8Oz2mYZXdNwrAj9bXvPfF46jlSK82mQMcydFj85hwS8N7Ym5332Nd5 OTjghP1+pU9W8VlnreyJE5qPi5H96LOA+6j2004OSQbQetJaenuhOZZeNwRtWJOvzl ym3r16DKKVfgQ== From: Arnaldo Carvalho de Melo To: dwarves@vger.kernel.org Cc: Jiri Olsa , Clark Williams , Kate Carcia , bpf@vger.kernel.org, Arnaldo Carvalho de Melo , Alan Maguire , Kui-Feng Lee , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH 06/12] dwarf_loader: Remove unused 'thr_data' arg from dwarf_cus__create_and_process_cu() Date: Tue, 2 Apr 2024 16:39:39 -0300 Message-ID: <20240402193945.17327-7-acme@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402193945.17327-1-acme@kernel.org> References: <20240402193945.17327-1-acme@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnaldo Carvalho de Melo The only caller for dwarf_cus__create_and_process_cu() now is serial loading of DWARF, so no point in passing the perf thread data, that is always NULL, so remove that parameter. Cc: Alan Maguire Cc: Kui-Feng Lee Cc: Thomas Weißschuh Signed-off-by: Arnaldo Carvalho de Melo --- dwarf_loader.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index a7a8b2bea112ba75..a097b67a2d123b55 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -3243,15 +3243,14 @@ static int dwarf_cus__process_cu(struct dwarf_cus *dcus, Dwarf_Die *cu_die, return DWARF_CB_OK; } -static int dwarf_cus__create_and_process_cu(struct dwarf_cus *dcus, Dwarf_Die *cu_die, - uint8_t pointer_size, void *thr_data) +static int dwarf_cus__create_and_process_cu(struct dwarf_cus *dcus, Dwarf_Die *cu_die, uint8_t pointer_size) { struct dwarf_cu *dcu = dwarf_cus__create_cu(dcus, cu_die, pointer_size); if (dcu == NULL) return DWARF_CB_ABORT; - return dwarf_cus__process_cu(dcus, cu_die, dcu->cu, thr_data); + return dwarf_cus__process_cu(dcus, cu_die, dcu->cu, NULL); } static int dwarf_cus__nextcu(struct dwarf_cus *dcus, struct dwarf_cu **dcu, @@ -3377,8 +3376,7 @@ static int __dwarf_cus__process_cus(struct dwarf_cus *dcus) if (cu_die == NULL) break; - if (dwarf_cus__create_and_process_cu(dcus, cu_die, - pointer_size, NULL) == DWARF_CB_ABORT) + if (dwarf_cus__create_and_process_cu(dcus, cu_die, pointer_size) == DWARF_CB_ABORT) return DWARF_CB_ABORT; dcus->off = noff; From patchwork Tue Apr 2 19:39:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 13614542 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82B8815B98A; Tue, 2 Apr 2024 19:40:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086813; cv=none; b=kg3L2j9rtSTglYIj/ZxkQZSsn/WH5vYLbRaK7l0z9SZDrBkOqzxiKSwJ5v8yeZzl1WQYShX2TLU3BPSsgUPdwXw+3KXT8ZHCk4Jm8jiX8hnvbjtnWQmLgCYqw0JPs5jtb2jjCorJW6qQ6dkkiiv4i8BBn+KOcIvajRps8BFl9cI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086813; c=relaxed/simple; bh=QPCVECCkNP/mRX6k0IN6gRC2BYWoQ9twP/v6i1a73s8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BB4K16tDcKbRyS//iXE2iGDkH3VPqhPQcB6+N4tnI2Hwil6bjpqdM0bLqIKnzo2AEfvn7CMm8CkyafUQ5NWJytO9IE16osKYcvzETPQ9xnq5iKFvzbpAMnSz1oXei6B2ddSh3iUE1LBcwe9PJ49HCK7gnI70MCGAqeanwpsh03o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p4FWt2N7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p4FWt2N7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEF65C433C7; Tue, 2 Apr 2024 19:40:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712086813; bh=QPCVECCkNP/mRX6k0IN6gRC2BYWoQ9twP/v6i1a73s8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p4FWt2N7OBQHYmRH1VgAmm3hSqyNia6Qi8YAyFVBsnp5/08BbqDMtCC6FG6xQX5TB IAD3oL0esloOKLs2SC/etLkIfml3KgqoL+CqXSrZIa1P3R5a1dwD75YhGhA+kUEa3l wONMMUFXHmGuXNH9M15GQt+I5hacRZKIcCHz8NcIuxJrDii2nKJv0cowfElz0lqU5z IimTjUUE0TW2Uopri7ypJW9DI2yV9roAwcsqCW8SrDIUEOMmUeHB1XoeeV62Ufln6X mXkbg5w6HAuZdxj24I9ggtyxOzAgQ90+jDMBN+ryQIGMZWAZpQm7+qAIVT/hvc53lO wcFKJzi3IoKiA== From: Arnaldo Carvalho de Melo To: dwarves@vger.kernel.org Cc: Jiri Olsa , Clark Williams , Kate Carcia , bpf@vger.kernel.org, Arnaldo Carvalho de Melo , Alan Maguire , Kui-Feng Lee , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH 07/12] core: Add unlocked cus__add() variant Date: Tue, 2 Apr 2024 16:39:40 -0300 Message-ID: <20240402193945.17327-8-acme@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402193945.17327-1-acme@kernel.org> References: <20240402193945.17327-1-acme@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnaldo Carvalho de Melo As we'll use with the cus lock already held when getting the next CU from vmlinux to keep the order in the original DWARF file. Cc: Alan Maguire Cc: Kui-Feng Lee Cc: Thomas Weißschuh Signed-off-by: Arnaldo Carvalho de Melo --- dwarves.c | 9 ++++++--- dwarves.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/dwarves.c b/dwarves.c index 3b4be595aa59a856..654a8085e9252a21 100644 --- a/dwarves.c +++ b/dwarves.c @@ -479,13 +479,16 @@ uint32_t cus__nr_entries(const struct cus *cus) return cus->nr_entries; } -void cus__add(struct cus *cus, struct cu *cu) +void __cus__add(struct cus *cus, struct cu *cu) { - cus__lock(cus); - cus->nr_entries++; list_add_tail(&cu->node, &cus->cus); +} +void cus__add(struct cus *cus, struct cu *cu) +{ + cus__lock(cus); + __cus__add(cus, cu); cus__unlock(cus); cu__find_class_holes(cu); diff --git a/dwarves.h b/dwarves.h index 4dfaa01a00f782d9..42b00bc1341e66cb 100644 --- a/dwarves.h +++ b/dwarves.h @@ -171,6 +171,7 @@ int cus__fprintf_load_files_err(struct cus *cus, const char *tool, int cus__load_dir(struct cus *cus, struct conf_load *conf, const char *dirname, const char *filename_mask, const int recursive); +void __cus__add(struct cus *cus, struct cu *cu); void cus__add(struct cus *cus, struct cu *cu); void cus__print_error_msg(const char *progname, const struct cus *cus, const char *filename, const int err); From patchwork Tue Apr 2 19:39:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 13614543 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0944D15CD52; Tue, 2 Apr 2024 19:40:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086816; cv=none; b=I0PALZguF7X6JvZ4eWdg9UGU0oUR/t6YoD8Cf8dcyKn3ynRZgnpoqEbH75DWSsbgw9/F9CLWLfvVUWktSjDikdMpyz131wMwJewzxxbGo6qlVF+82uoR3aISKElPtRpmbr7Eh/FtvIo9MFmUq4TIxcjNUVxCGhyzm5tMrf7JvUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086816; c=relaxed/simple; bh=JXjQeIPnvToaq4XBL3VYo8qBVMZF3R3DIiw5BmWaoJU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UggUwWcUExpo+aenr8s6VqufR/MuOrPVXRxmjTnUqNeSFHozKHS7llVgFsh0OQx2WXXy3BqwYv8xZA1QE1M1PQenqV4mb2C3dFv/uzo7WyDsPU9RxgqJfnw2eg99yYne7h4FB4NHbGvYzj6fDQ8Tq/WVu+CG7Tb/I+LEPVYW8IY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KZFk6HQw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KZFk6HQw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DB65C433F1; Tue, 2 Apr 2024 19:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712086815; bh=JXjQeIPnvToaq4XBL3VYo8qBVMZF3R3DIiw5BmWaoJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KZFk6HQwTTiYWg4u9C7EvDz7Mh24MvDr6xwrSR6R+J02EEylJ+bEsgETeb3znN6AT MpH/i363JWN9Sn1vJMeFJcI9mpVc9CoOz3CYsiKOKfKOAn4A/6debEyBSXoevrKim9 RvElIgcq9Le38UmKzVPOubqdlCn/hU9A6d5XIuk8nsd+H0+G3GLskqB3WyRgpzK3Fv Ugtxfo9MftH1HRBK+IIEgVlIzCY3D1YWt6V62jMOeXQkhLz2SC1E/BUQhuCyAREm0e I88O3lhUpFMlpUuUO4w+705QJs6J3guCj7nl2FF4kzeN5pvbxeB3JBTQSuF1+vNJh6 440U6IOOUYqVQ== From: Arnaldo Carvalho de Melo To: dwarves@vger.kernel.org Cc: Jiri Olsa , Clark Williams , Kate Carcia , bpf@vger.kernel.org, Arnaldo Carvalho de Melo , Alan Maguire , Kui-Feng Lee , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH 08/12] core: Add cus__remove(), counterpart of cus__add() Date: Tue, 2 Apr 2024 16:39:41 -0300 Message-ID: <20240402193945.17327-9-acme@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402193945.17327-1-acme@kernel.org> References: <20240402193945.17327-1-acme@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnaldo Carvalho de Melo We'll switch to adding the 'struct cu' instance to the 'struct cus' list early, under the lock, to keep the order from the original DWARF file and then LSK_KEEPIT will just leave it there while LSK_DELETE will first remove it from the cus list, under cus lock, to then call cu__delete(). Cc: Alan Maguire Cc: Kui-Feng Lee Cc: Thomas Weißschuh Signed-off-by: Arnaldo Carvalho de Melo --- dwarves.c | 13 +++++++++++++ dwarves.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/dwarves.c b/dwarves.c index 654a8085e9252a21..3cd300db97973ce4 100644 --- a/dwarves.c +++ b/dwarves.c @@ -479,6 +479,19 @@ uint32_t cus__nr_entries(const struct cus *cus) return cus->nr_entries; } +void __cus__remove(struct cus *cus, struct cu *cu) +{ + cus->nr_entries--; + list_del_init(&cu->node); +} + +void cus__remove(struct cus *cus, struct cu *cu) +{ + cus__lock(cus); + __cus__remove(cus, cu); + cus__unlock(cus); +} + void __cus__add(struct cus *cus, struct cu *cu) { cus->nr_entries++; diff --git a/dwarves.h b/dwarves.h index 42b00bc1341e66cb..9dc9cb4b074b5d33 100644 --- a/dwarves.h +++ b/dwarves.h @@ -173,6 +173,10 @@ int cus__load_dir(struct cus *cus, struct conf_load *conf, const int recursive); void __cus__add(struct cus *cus, struct cu *cu); void cus__add(struct cus *cus, struct cu *cu); + +void __cus__remove(struct cus *cus, struct cu *cu); +void cus__remove(struct cus *cus, struct cu *cu); + void cus__print_error_msg(const char *progname, const struct cus *cus, const char *filename, const int err); struct cu *cus__find_pair(struct cus *cus, const char *name); From patchwork Tue Apr 2 19:39:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 13614544 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F9F215B98E; Tue, 2 Apr 2024 19:40:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086818; cv=none; b=j7WmcoseKpeT8sSglW6SvHBI+q98YSnSZmLT/o5JZfpb8yuJ6SgQDP0K7wqKQ9l0Tv2g92/EBJMk6TooB4W23Nowj+Lx5B/lObNCrEMOERh9nd1Gkm1coVWlkl3pRXCe56laf4I8DuznBkHsiMoEQfxp0UMdRtM8Rz0A4mueMbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086818; c=relaxed/simple; bh=z7+fhvSYnE+bw/Mf0nRnQV50P8GFALuiKdWStWfrOt8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sn5VkgrXoTED5MDnZDS+9Y6GJMyscT6BJPgKf268d0NNCriQkKdcRC/LprpmV4NSm0EXy/z4DK+KyU8ETvUm/nrxLtf4PmbYyrNIfauugUB+VN7cUdnH6LCwSkPy3i3odcbIqfw22CGHtiC0L+sJe0dXb+vQWmJuXXqnRLklWBg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IMOACjLL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IMOACjLL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CC49C43394; Tue, 2 Apr 2024 19:40:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712086818; bh=z7+fhvSYnE+bw/Mf0nRnQV50P8GFALuiKdWStWfrOt8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IMOACjLLyzHouP6k3kd2qZwCQyfm3IicM25x6jJ1DxcMen0kaY7ejCz0Z70Zec33A RbtcX+yRE+mGtnGhX4P7zOynwiGf4dTlJOUx0FmLV0ZTX/sYxlBQaRfMPj8eoiYkpn py0uW3HOQaRcnzecSdwO5HN2YgZKXcGubjnThia/tG89XXOWm0hGVjgf2L6Rw4rCd0 UjZSN3fPWK8PwUc9IkE5nNePFSUKheoHmGHUofLuDCvHtWqvkG4rcHk5XLh2eAreSt Pwo9wl94pZ1j9v+EsN/zkcGhafZdgnEkpwiTJ5JvwsipUYTJO1KNstSIgPL4u6NCef SKU/sQDBsp7dQ== From: Arnaldo Carvalho de Melo To: dwarves@vger.kernel.org Cc: Jiri Olsa , Clark Williams , Kate Carcia , bpf@vger.kernel.org, Arnaldo Carvalho de Melo , Alan Maguire , Kui-Feng Lee , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH 09/12] dwarf_loader: Add the cu to the cus list early, remove on LSK_DELETE Date: Tue, 2 Apr 2024 16:39:42 -0300 Message-ID: <20240402193945.17327-10-acme@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402193945.17327-1-acme@kernel.org> References: <20240402193945.17327-1-acme@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnaldo Carvalho de Melo We want to keep it in the same order as in the original DWARF file we're loading (e.g. vmlinux), we'll only remove it after we load and process (e.g. convert to BTF). Cc: Alan Maguire Cc: Kui-Feng Lee Cc: Thomas Weißschuh Signed-off-by: Arnaldo Carvalho de Melo --- dwarf_loader.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index a097b67a2d123b55..3ef22aada6f46f13 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -3034,12 +3034,12 @@ static int cus__finalize(struct cus *cus, struct cu *cu, struct conf_load *conf, int lsk = cu__finalize(cu, conf, thr_data); switch (lsk) { case LSK__DELETE: + cus__remove(cus, cu); cu__delete(cu); break; case LSK__STOP_LOADING: break; case LSK__KEEPIT: - cus__add(cus, cu); break; } return lsk; @@ -3064,7 +3064,7 @@ static int cu__set_common(struct cu *cu, struct conf_load *conf, return 0; } -static int __cus__load_debug_types(struct conf_load *conf, Dwfl_Module *mod, Dwarf *dw, Elf *elf, +static int __cus__load_debug_types(struct cus *cus, struct conf_load *conf, Dwfl_Module *mod, Dwarf *dw, Elf *elf, const char *filename, const unsigned char *build_id, int build_id_len, struct cu **cup, struct dwarf_cu *dcup) { @@ -3098,6 +3098,7 @@ static int __cus__load_debug_types(struct conf_load *conf, Dwfl_Module *mod, Dwa cu->dfops = &dwarf__ops; *cup = cu; + cus__add(cus, cu); } Dwarf_Die die_mem; @@ -3250,6 +3251,8 @@ static int dwarf_cus__create_and_process_cu(struct dwarf_cus *dcus, Dwarf_Die *c if (dcu == NULL) return DWARF_CB_ABORT; + cus__add(dcus->cus, dcu->cu); + return dwarf_cus__process_cu(dcus, cu_die, dcu->cu, NULL); } @@ -3282,6 +3285,9 @@ static int dwarf_cus__nextcu(struct dwarf_cus *dcus, struct dwarf_cu **dcu, ret = -1; goto out_unlock; } + // Do it here to keep all CUs in cus->cus in the same + // order as in the DWARF file being loaded (e.g. vmlinux) + __cus__add(dcus->cus, (*dcu)->cu); } out_unlock: @@ -3496,15 +3502,15 @@ static int cus__load_module(struct cus *cus, struct conf_load *conf, struct dwarf_cu type_dcu; int type_lsk = LSK__KEEPIT; - int res = __cus__load_debug_types(conf, mod, dw, elf, filename, build_id, build_id_len, &type_cu, &type_dcu); + int res = __cus__load_debug_types(cus, conf, mod, dw, elf, filename, build_id, build_id_len, &type_cu, &type_dcu); if (res != 0) { return res; } if (type_cu != NULL) { type_lsk = cu__finalize(type_cu, conf, NULL); - if (type_lsk == LSK__KEEPIT) { - cus__add(cus, type_cu); + if (type_lsk == LSK__DELETE) { + cus__remove(cus, type_cu); } } From patchwork Tue Apr 2 19:39:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 13614545 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AE3815B98A; Tue, 2 Apr 2024 19:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086821; cv=none; b=B8itTuVhgbf7jbQIKK/UjHjAqCLdsakLLH4obibnZWK/4swbXbATFFZc1bX4ALyzUAbsNCANlJeCZXkKKLgqREPQDvWSUEAdB+/dkZopWCVKu9o+2mroK62bSoOZ/52gDg4LI6i5/MpSPfg4dGmGxDRSjv+WifHcH+4AUARgTFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086821; c=relaxed/simple; bh=2fRaByBcu71Pu+J3uKplrEOFOlvvPf69p5YcpYqYZlo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NI94a5faey5Eml3x1PuNl4vpgfJXxunhx27y35f1i4GnZK+XQ/PzKpS18czXM0tEX5l66InVHcHQaNQLhkXHBJ39DWJwwnJp0BGMrk+PjDI87ziDm5jKm1Nc6O0BXPQ1ONri3YPSyeZ14pQ9/Vud5WgGB9XLdoOsa7M4JwbjHXU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FXNubaU8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FXNubaU8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDE19C43390; Tue, 2 Apr 2024 19:40:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712086820; bh=2fRaByBcu71Pu+J3uKplrEOFOlvvPf69p5YcpYqYZlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FXNubaU8tIHL3xwocWZKcPiRI0FM1k8DnxPbenW29pQ95EcDX3VYX/PiQUWTaQmf7 xRKnoj7NONa5WPELsUPLn2t8tl26cA0tooGOEcbrE6DUBCYnT9d/SaADxH0eJPldcw NQ2gBupvsfMJcjUySiGI8cFS+FUM3GgvgXn9k7Fi5vjAQsosDIQYwBktwTugnHkSIP Eh9OTKq1PRZEhXRNath6/cxY3G2umsO5jzjESO5S2OFAZ0SNsvVjianjkEvljHZ50K rJv/Z67YBou7ywU9qwCEffLoWIdRKfE4jS5PNcLLBcYBV83S2nZOBf3VCD5MoqFnrE /2JVGWedotDAw== From: Arnaldo Carvalho de Melo To: dwarves@vger.kernel.org Cc: Jiri Olsa , Clark Williams , Kate Carcia , bpf@vger.kernel.org, Arnaldo Carvalho de Melo , Alan Maguire , Kui-Feng Lee , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH 10/12] core/dwarf_loader: Add functions to set state of CU processing Date: Tue, 2 Apr 2024 16:39:43 -0300 Message-ID: <20240402193945.17327-11-acme@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402193945.17327-1-acme@kernel.org> References: <20240402193945.17327-1-acme@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnaldo Carvalho de Melo When doing reproducible builds we'll process loaded CUs in pahole_stealer in the same order as the CUs are in the DWARF file (vmlinux), so sometimes when we may finish loading a CU out of order and thus will have to either busy loop (to use a hot cache?) to way for its turn or simply leave it in the ordered queue waiting its turn (may use too much memory with a pile of CUs waiting to be processed (converted to BTF)?), so we need to mark its state: unprocessed, loaded, processing So when pahole has pahole_stealer called, it will not use necessarily the handed cu, because it may be out of order, say if the first CU that pahole gets in one of its threads is a big one and takes longer to process than one of the other handed to the otherd DWARF loading threads, then it will have to wait for the first one to be processed by the, so far, non reproducible BTF encoder. We will instead allow tools such as pahole to ask for the next CU do be processed, i.e. in order, if the first one is still not loaded, then it'll just return NULL and the encoder will return so that its DWARF loading thread can go load one more CU and then ask pahole to encode one more CU, rinse repeat. We'll see if this ends up using too much memory due to unconstrained loading of CUs that pile up waiting for BTF encoding. At the end the tool will need to flush the queue. When a CU is processed it gets deleted, which goes on freeing memory. Cc: Alan Maguire Cc: Kui-Feng Lee Cc: Thomas Weißschuh Signed-off-by: Arnaldo Carvalho de Melo --- dwarf_loader.c | 8 +++++--- dwarves.c | 40 ++++++++++++++++++++++++++++++++++++++++ dwarves.h | 11 +++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index 3ef22aada6f46f13..b15cf543fa9d7471 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -3016,13 +3016,15 @@ static void cu__sort_types_by_offset(struct cu *cu, struct conf_load *conf) cu__for_all_tags(cu, type__sort_by_offset, conf); } -static int cu__finalize(struct cu *cu, struct conf_load *conf, void *thr_data) +static int cu__finalize(struct cu *cu, struct cus *cus, struct conf_load *conf, void *thr_data) { cu__for_all_tags(cu, class_member__cache_byte_size, conf); if (cu__language_reorders_offsets(cu)) cu__sort_types_by_offset(cu, conf); + cus__set_cu_state(cus, cu, CU__LOADED); + if (conf && conf->steal) { return conf->steal(cu, conf, thr_data); } @@ -3031,7 +3033,7 @@ static int cu__finalize(struct cu *cu, struct conf_load *conf, void *thr_data) static int cus__finalize(struct cus *cus, struct cu *cu, struct conf_load *conf, void *thr_data) { - int lsk = cu__finalize(cu, conf, thr_data); + int lsk = cu__finalize(cu, cus, conf, thr_data); switch (lsk) { case LSK__DELETE: cus__remove(cus, cu); @@ -3508,7 +3510,7 @@ static int cus__load_module(struct cus *cus, struct conf_load *conf, } if (type_cu != NULL) { - type_lsk = cu__finalize(type_cu, conf, NULL); + type_lsk = cu__finalize(type_cu, cus, conf, NULL); if (type_lsk == LSK__DELETE) { cus__remove(cus, type_cu); } diff --git a/dwarves.c b/dwarves.c index 3cd300db97973ce4..fbc8d8aa0060b7d0 100644 --- a/dwarves.c +++ b/dwarves.c @@ -469,6 +469,44 @@ void cus__unlock(struct cus *cus) pthread_mutex_unlock(&cus->mutex); } +void cus__set_cu_state(struct cus *cus, struct cu *cu, enum cu_state state) +{ + cus__lock(cus); + cu->state = state; + cus__unlock(cus); +} + +// Used only when reproducible builds are desired +struct cu *cus__get_next_processable_cu(struct cus *cus) +{ + struct cu *cu; + + cus__lock(cus); + + list_for_each_entry(cu, &cus->cus, node) { + switch (cu->state) { + case CU__LOADED: + cu->state = CU__PROCESSING; + goto found; + case CU__PROCESSING: + // This will only happen when we get to parallel + // reproducible BTF encoding, libbpf dedup work needed here. + continue; + case CU__UNPROCESSED: + // The first entry isn't loaded, signal the + // caller to return and try another day, as we + // need to respect the original DWARF CU ordering. + goto out; + } + } +out: + cu = NULL; +found: + cus__unlock(cus); + + return cu; +} + bool cus__empty(const struct cus *cus) { return list_empty(&cus->cus); @@ -701,6 +739,8 @@ struct cu *cu__new(const char *name, uint8_t addr_size, cu->addr_size = addr_size; cu->extra_dbg_info = 0; + cu->state = CU__UNPROCESSED; + cu->nr_inline_expansions = 0; cu->size_inline_expansions = 0; cu->nr_structures_changed = 0; diff --git a/dwarves.h b/dwarves.h index 9dc9cb4b074b5d33..dd35a4efd6e5decb 100644 --- a/dwarves.h +++ b/dwarves.h @@ -43,6 +43,12 @@ enum load_steal_kind { LSK__STOP_LOADING, }; +enum cu_state { + CU__UNPROCESSED, + CU__LOADED, + CU__PROCESSING, +}; + /* * BTF combines all the types into one big CU using btf_dedup(), so for something * like a allyesconfig vmlinux kernel we can get over 65535 types. @@ -177,6 +183,10 @@ void cus__add(struct cus *cus, struct cu *cu); void __cus__remove(struct cus *cus, struct cu *cu); void cus__remove(struct cus *cus, struct cu *cu); +struct cu *cus__get_next_processable_cu(struct cus *cus); + +void cus__set_cu_state(struct cus *cus, struct cu *cu, enum cu_state state); + void cus__print_error_msg(const char *progname, const struct cus *cus, const char *filename, const int err); struct cu *cus__find_pair(struct cus *cus, const char *name); @@ -287,6 +297,7 @@ struct cu { uint8_t little_endian:1; uint8_t nr_register_params; int register_params[ARCH_MAX_REGISTER_PARAMS]; + enum cu_state state; uint16_t language; unsigned long nr_inline_expansions; size_t size_inline_expansions; From patchwork Tue Apr 2 19:39:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 13614546 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E8EE15B98E; Tue, 2 Apr 2024 19:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086823; cv=none; b=nhQMf+Ag3ahPPABNCMyjdaxjtyviVEAbSee01gScUr1cfkaILopgmdoZZyxnBBL0ll/28ff+SMBD2+xlp5xX/uBkyXNG1vFko550VDcL4Evt3CE+wXWv9fgJccHGhLs1EuwvPoXTiov+pxhut8M/BgeeU4VPATt0vwTE3i0plOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086823; c=relaxed/simple; bh=iIj9NPKKmIV9Tf8oLFA45D5NzZabIyrWNxvk3SoSwNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mwdWXV/+MWJR0K04YRPTIq4wX4Vdr2Lu9IYpohITljkpan74iyKvAYX0k0Oh7InaT1U1f83wGkDQZAHaybtXWFIlFJ64h2E+H5bKNcuY03giKNfH+FSrwU7RotVywktXn6aLFrLeGXRFKA1NPDfhYyJFmW2apgNQqvGO9UckUiA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FKjS965U; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FKjS965U" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B97FC433B2; Tue, 2 Apr 2024 19:40:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712086823; bh=iIj9NPKKmIV9Tf8oLFA45D5NzZabIyrWNxvk3SoSwNg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FKjS965U0mnVNi029HQdRri+aCWSOWl38NZVzY9XUzQKRYsxoI/nbHl8+ieXAXAOZ wFbm0YOt69BG8kXhWu4AZ2MPniDz1TqINeoPzKs7y80mhQ71QgUihKUx3yw4rlad1q Bcmq3l56pC+KI1ANhV8siFjpAh0VXVpaxmNUUpyoVT2g6STu5cBb607urMQ6QHmHjY Giqfl/BZi2u/mYCfgxqjYsoMhrIIm75p0f37ExMztKAwjdUZ3fS2Dt12+CB3sV1js/ zOecP1rKb4jBjxOUX002yfP80VAoe8msg8nWtCyOBDCsniBrj85/s0Q8HrtO8+gY0t a6lRwKvQ1iiLw== From: Arnaldo Carvalho de Melo To: dwarves@vger.kernel.org Cc: Jiri Olsa , Clark Williams , Kate Carcia , bpf@vger.kernel.org, Arnaldo Carvalho de Melo , Alan Maguire , Kui-Feng Lee , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH 11/12] pahole: Encode BTF serially in a reproducible build Date: Tue, 2 Apr 2024 16:39:44 -0300 Message-ID: <20240402193945.17327-12-acme@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402193945.17327-1-acme@kernel.org> References: <20240402193945.17327-1-acme@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnaldo Carvalho de Melo Now we will ask the cus instance for the next processable CU, i.e. one that is loaded and is in the same CU order as in the original DWARF file, under the BTF lock. With this we can go on loading the DWARF file in parallel and only serialize the BTF encoding, keeping that order, with this the BTF ids end up the same both for a serial encoding: And here are some numbers with a Release build: $ cat buildcmd.sh mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release .. cd .. make -j $(getconf _NPROCESSORS_ONLN) -C build $ rm -rf build $ ./buildcmd.sh Its an Intel Hybrid system, and migrates to/from efficiency/perfomance cores: $ getconf _NPROCESSORS_ONLN 28 $ grep -m1 'model name' /proc/cpuinfo model name : Intel(R) Core(TM) i7-14700K $ 8 performance cores (16 threads), 12 efficiency cores. Serial encoding: $ time perf stat -e cycles -r5 pahole --btf_encode_detached=vmlinux.btf.serial vmlinux Performance counter stats for 'pahole --btf_encode_detached=vmlinux.btf.serial vmlinux' (5 runs): 13,313,169,305 cpu_atom/cycles:u/ ( +- 30.61% ) (0.00%) 27,985,776,096 cpu_core/cycles:u/ ( +- 0.17% ) (100.00%) 5.18276 +- 0.00952 seconds time elapsed ( +- 0.18% ) real 0m25.937s user 0m25.337s sys 0m0.533s $ Parallel, but non-reproducible: $ time perf stat -e cycles -r5 pahole -j --btf_encode_detached=vmlinux.btf.parallel vmlinux Performance counter stats for 'pahole -j --btf_encode_detached=vmlinux.btf.parallel vmlinux' (5 runs): 65,781,092,442 cpu_atom/cycles:u/ ( +- 0.99% ) (42.99%) 88,578,827,055 cpu_core/cycles:u/ ( +- 0.90% ) (60.93%) 1.8529 +- 0.0159 seconds time elapsed ( +- 0.86% ) real 0m9.293s user 1m21.599s sys 0m11.348s $ Now what we want, a reproducible build done using parallel DWARF loading + CUs-ordered-as-in-vmlinux serial BTF encoding: $ time perf stat -e cycles -r5 pahole -j --reproducible_build --btf_encode_detached=vmlinux.btf.parallel.reproducible_build vmlinux Performance counter stats for 'pahole -j --reproducible_build --btf_encode_detached=vmlinux.btf.parallel.reproducible_build vmlinux' (5 runs): 21,255,687,225 cpu_atom/cycles:u/ ( +- 0.76% ) (35.06%) 33,852,263,760 cpu_core/cycles:u/ ( +- 0.24% ) (72.70%) 2.3632 +- 0.0164 seconds time elapsed ( +- 0.69% ) real 0m11.840s user 0m35.952s sys 0m1.534s $ Fastest is off course the unreproducible, fully parallel DWARF loading/ BTF encoding at 1.8529 +- 0.0159 seconds, but doing a reproducible build in 2.3632 +- 0.0164 seconds is better than completely disabling -j/full serial at 5.18276 +- 0.00952 seconds. Comparing the BTF generated: $ bpftool btf dump file vmlinux.btf.serial > output.vmlinux.btf.serial $ bpftool btf dump file vmlinux.btf.parallel > output.vmlinux.btf.parallel $ bpftool btf dump file vmlinux.btf.parallel.reproducible > output.vmlinux.btf.parallel.reproducible $ wc -l output.vmlinux.btf.serial output.vmlinux.btf.parallel output.vmlinux.btf.parallel.reproducible 313404 output.vmlinux.btf.serial 314345 output.vmlinux.btf.parallel 313404 output.vmlinux.btf.parallel.reproducible 941153 total $ Non reproducible parallel BTF encoding: $ diff -u output.vmlinux.btf.serial output.vmlinux.btf.parallel | head --- output.vmlinux.btf.serial 2024-04-02 11:11:56.665027947 -0300 +++ output.vmlinux.btf.parallel 2024-04-02 11:12:38.490895460 -0300 @@ -1,1708 +1,2553 @@ [1] INT 'long unsigned int' size=8 bits_offset=0 nr_bits=64 encoding=(none) -[2] CONST '(anon)' type_id=1 -[3] VOLATILE '(anon)' type_id=2 -[4] ARRAY '(anon)' type_id=1 index_type_id=21 nr_elems=2 -[5] PTR '(anon)' type_id=8 -[6] CONST '(anon)' type_id=5 -[7] INT 'char' size=1 bits_offset=0 nr_bits=8 encoding=(none) $ Reproducible: $ diff -u output.vmlinux.btf.serial output.vmlinux.btf.parallel.reproducible $ And using a test script that I'll add to a nascent repository of regression tests: $ time tests/reproducible_build.sh vmlinux Parallel reproducible DWARF Loading/Serial BTF encoding: Ok real 1m13.844s user 3m3.601s sys 0m9.049s $ If the number of threads started by pahole is different than what was requests via its -j command line option, it will fail as well as if the output of 'bpftool btf dump' differs from the BTF encoded totally serially to one of the detached BTF encoded using reproducible DWARF loading/BTF encoding. In verbose mode: $ time VERBOSE=1 tests/reproducible_build.sh vmlinux Parallel reproducible DWARF Loading/Serial BTF encoding: serial encoding... 1 threads encoding 1 threads started diff from serial encoding: ----------------------------- 2 threads encoding 2 threads started diff from serial encoding: ----------------------------- 3 threads encoding 3 threads started diff from serial encoding: ----------------------------- 4 threads encoding 4 threads started diff from serial encoding: ----------------------------- 5 threads encoding 5 threads started diff from serial encoding: ----------------------------- 6 threads encoding 6 threads started diff from serial encoding: ----------------------------- 7 threads encoding 7 threads started diff from serial encoding: ----------------------------- 8 threads encoding 8 threads started diff from serial encoding: ----------------------------- 9 threads encoding 9 threads started diff from serial encoding: ----------------------------- 10 threads encoding 10 threads started diff from serial encoding: ----------------------------- 11 threads encoding 11 threads started diff from serial encoding: ----------------------------- 12 threads encoding 12 threads started diff from serial encoding: ----------------------------- 13 threads encoding 13 threads started diff from serial encoding: ----------------------------- 14 threads encoding 14 threads started diff from serial encoding: ----------------------------- 15 threads encoding 15 threads started diff from serial encoding: ----------------------------- 16 threads encoding 16 threads started diff from serial encoding: ----------------------------- 17 threads encoding 17 threads started diff from serial encoding: ----------------------------- 18 threads encoding 18 threads started diff from serial encoding: ----------------------------- 19 threads encoding 19 threads started diff from serial encoding: ----------------------------- 20 threads encoding 20 threads started diff from serial encoding: ----------------------------- 21 threads encoding 21 threads started diff from serial encoding: ----------------------------- 22 threads encoding 22 threads started diff from serial encoding: ----------------------------- 23 threads encoding 23 threads started diff from serial encoding: ----------------------------- 24 threads encoding 24 threads started diff from serial encoding: ----------------------------- 25 threads encoding 25 threads started diff from serial encoding: ----------------------------- 26 threads encoding 26 threads started diff from serial encoding: ----------------------------- 27 threads encoding 27 threads started diff from serial encoding: ----------------------------- 28 threads encoding 28 threads started diff from serial encoding: ----------------------------- Ok real 1m14.800s user 3m4.315s sys 0m8.977s $ Cc: Alan Maguire Cc: Kui-Feng Lee Cc: Thomas Weißschuh Signed-off-by: Arnaldo Carvalho de Melo --- pahole.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/pahole.c b/pahole.c index fcb4360f11debeb9..6c7e73835b3e9139 100644 --- a/pahole.c +++ b/pahole.c @@ -31,6 +31,7 @@ static struct btf_encoder *btf_encoder; static char *detached_btf_filename; +struct cus *cus; static bool btf_encode; static bool ctf_encode; static bool sort_output; @@ -3324,11 +3325,32 @@ static enum load_steal_kind pahole_stealer(struct cu *cu, encoder = btf_encoder; } + // Since we don't have yet a way to parallelize the BTF encoding, we + // need to ask the loader for the next CU that we can process, one + // that is loaded and is in order, if the next one isn't yet loaded, + // then return to let the DWARF loader thread to load the next one, + // eventually all will get processed, even if when all DWARF loading + // threads finish. + if (conf_load->reproducible_build) { + ret = LSK__KEEPIT; // we're not processing the cu passed to this + // function, so keep it. + cu = cus__get_next_processable_cu(cus); + if (cu == NULL) + goto out_btf; + } + ret = btf_encoder__encode_cu(encoder, cu, conf_load); if (ret < 0) { fprintf(stderr, "Encountered error while encoding BTF.\n"); exit(1); } + + if (conf_load->reproducible_build) { + ret = LSK__KEEPIT; // we're not processing the cu passed to this function, so keep it. + // Equivalent to LSK__DELETE since we processed this + cus__remove(cus, cu); + cu__delete(cu); + } out_btf: if (!thr_data) // See comment about reproducibe_build above pthread_mutex_unlock(&btf_lock); @@ -3632,6 +3654,27 @@ out_free: return ret; } +static int cus__flush_reproducible_build(struct cus *cus, struct btf_encoder *encoder, struct conf_load *conf_load) +{ + int err = 0; + + while (true) { + struct cu *cu = cus__get_next_processable_cu(cus); + + if (cu == NULL) + break; + + err = btf_encoder__encode_cu(encoder, cu, conf_load); + if (err < 0) + break; + + cus__remove(cus, cu); + cu__delete(cu); + } + + return err; +} + int main(int argc, char *argv[]) { int err, remaining, rc = EXIT_FAILURE; @@ -3692,7 +3735,7 @@ int main(int argc, char *argv[]) } } - struct cus *cus = cus__new(); + cus = cus__new(); if (cus == NULL) { fputs("pahole: insufficient memory\n", stderr); goto out_dwarves_exit; @@ -3797,6 +3840,12 @@ try_sole_arg_as_class_names: header = NULL; if (btf_encode && btf_encoder) { // maybe all CUs were filtered out and thus we don't have an encoder? + if (conf_load.reproducible_build && + cus__flush_reproducible_build(cus, btf_encoder, &conf_load) < 0) { + fprintf(stderr, "Encountered error while encoding BTF.\n"); + exit(1); + } + err = btf_encoder__encode(btf_encoder); if (err) { fputs("Failed to encode BTF\n", stderr); From patchwork Tue Apr 2 19:39:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 13614547 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CB9A15B962; Tue, 2 Apr 2024 19:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086826; cv=none; b=NTUw8Jf3MiC4/XQ8gmGmKDcam9AdebKMA99ij/L6nRqZFzVS4JACRm4Z70auQYMAb3T8RoJJKcF78oIaJO1bMy6xriKpx1teJf+SeRxHEDxK3d7AJRD5CTnb+6bvW0a25UE3qDG6K8Ei1at7c+tI38l4styMIJfaOwq9Gww3x/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086826; c=relaxed/simple; bh=w7hwgkzrUbZqiWKsRGTQDtzfq+Myzi8KNFzNsNgtgO0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W/Qy8f3vuGblxPdqqBuU/m53GpB4YLeCpm2+qhJ+ikujPS6hVmj5p1uXPJqJQiO1aWjc9+iTBLARKZmgU7uVWNxToAusOTjg3SeM94AO82NXsMLE3HScxkGxo1qrRdgnEuxLtz0DP4Xw+y9BmU5IaCK+uvtANujp49wMD57bfOE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G+KpeLBV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="G+KpeLBV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED66BC433A6; Tue, 2 Apr 2024 19:40:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712086826; bh=w7hwgkzrUbZqiWKsRGTQDtzfq+Myzi8KNFzNsNgtgO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G+KpeLBVUYfQfZp1yvN1Nk7P0uOif6M+IEaHUXR+MgdUi/0XEjC3UaEnVLQyOtdsy TIhXW690ZIl6y6emAjzg2LX69dXD27umnzTAF1PMFsjlgR4VgSRdhCWDCUKFYgR1te 7XEpVWMWnBqaBJ37CIxfz3nuSEPAQ/NnGrqRiQ5keCx7sP+ROozwtFIuqKf2FWZ3y5 XePv0iUKfzQ3qONEEEi8jXD1G4HR45oi84r3t7ecTPdTUj7+6ie8MIht/yRSqtrwGY O3IHZSQPjucBJgLfUA44OlJNrNkfD5x0Q0ahM3RcyPTjygwT6Y0lhVA3p2ILIgsRAl Ih4O7R9qK09tA== From: Arnaldo Carvalho de Melo To: dwarves@vger.kernel.org Cc: Jiri Olsa , Clark Williams , Kate Carcia , bpf@vger.kernel.org, Arnaldo Carvalho de Melo , Alan Maguire , Kui-Feng Lee , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH 12/12] tests: Add a BTF reproducible generation test Date: Tue, 2 Apr 2024 16:39:45 -0300 Message-ID: <20240402193945.17327-13-acme@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402193945.17327-1-acme@kernel.org> References: <20240402193945.17327-1-acme@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnaldo Carvalho de Melo $ time tests/reproducible_build.sh vmlinux Parallel reproducible DWARF Loading/Serial BTF encoding: Ok real 1m13.844s user 3m3.601s sys 0m9.049s $ If the number of threads started by pahole is different than what was requests via its -j command line option, it will fail as well as if the output of 'bpftool btf dump' differs from the BTF encoded totally serially to one of the detached BTF encoded using reproducible DWARF loading/BTF encoding. Cc: Alan Maguire Cc: Kui-Feng Lee Cc: Thomas Weißschuh Signed-off-by: Arnaldo Carvalho de Melo --- tests/reproducible_build.sh | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 tests/reproducible_build.sh diff --git a/tests/reproducible_build.sh b/tests/reproducible_build.sh new file mode 100755 index 0000000000000000..9c72d548c2a21136 --- /dev/null +++ b/tests/reproducible_build.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# +# Test if BTF generated serially matches reproducible parallel DWARF loading + serial BTF encoding +# Arnaldo Carvalho de Melo (C) 2024- + +vmlinux=$1 +outdir=$(mktemp -d /tmp/reproducible_build.sh.XXXXXX) + +echo -n "Parallel reproducible DWARF Loading/Serial BTF encoding: " + +test -n "$VERBOSE" && printf "\nserial encoding...\n" + +pahole --btf_encode_detached=$outdir/vmlinux.btf.serial $vmlinux +bpftool btf dump file $outdir/vmlinux.btf.serial > $outdir/bpftool.output.vmlinux.btf.serial + +nr_proc=$(getconf _NPROCESSORS_ONLN) + +for threads in $(seq $nr_proc) ; do + test -n "$VERBOSE" && echo $threads threads encoding + pahole -j$threads --reproducible_build --btf_encode_detached=$outdir/vmlinux.btf.parallel.reproducible $vmlinux & + pahole=$! + # HACK: Wait a bit for pahole to start its threads + sleep 0.3s + # PID part to remove ps output headers + nr_threads_started=$(ps -L -C pahole | grep -v PID | wc -l) + + if [ $threads -gt 1 ] ; then + ((nr_threads_started -= 1)) + fi + + if [ $threads != $nr_threads_started ] ; then + echo "ERROR: pahole asked to start $threads encoding threads, started $nr_threads_started" + exit 1; + fi + + # ps -L -C pahole | grep -v PID | nl + test -n "$VERBOSE" && echo $nr_threads_started threads started + wait $pahole + rm -f $outdir/bpftool.output.vmlinux.btf.parallel.reproducible + bpftool btf dump file $outdir/vmlinux.btf.parallel.reproducible > $outdir/bpftool.output.vmlinux.btf.parallel.reproducible + test -n "$VERBOSE" && echo "diff from serial encoding:" + diff -u $outdir/bpftool.output.vmlinux.btf.serial $outdir/bpftool.output.vmlinux.btf.parallel.reproducible > $outdir/diff + if [ -s $outdir/diff ] ; then + echo "ERROR: BTF generated from DWARF in parallel is different from the one generated in serial!" + exit 1 + fi + test -n "$VERBOSE" && echo ----------------------------- +done + +rm $outdir/* +rmdir $outdir + +echo "Ok" + +exit 0