From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 4257E383542B for ; Fri, 22 Jul 2022 17:03:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4257E383542B Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 38E0E20458 for ; Fri, 22 Jul 2022 17:03:46 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 25A7F13ABC for ; Fri, 22 Jul 2022 17:03:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CN0hCHLY2mKvMAAAMHmgww (envelope-from ) for ; Fri, 22 Jul 2022 17:03:46 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 3/4] [gdb/symtab] Use task size in parallel_for_each in dwarf2_build_psymtabs_hard Date: Fri, 22 Jul 2022 19:03:44 +0200 Message-Id: <20220722170345.24713-3-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220722170345.24713-1-tdevries@suse.de> References: <20220722170345.24713-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jul 2022 17:03:48 -0000 In dwarf2_build_psymtabs_hard, we use a parallel_for_each to distribute CUs over threads. Ensuring a fair distribution over the worker threads and main thread in terms of number of CUs might not be the most efficient way, given that CUs can vary in size. Fix this by using per_cu->get_length () as the task size. I've used this experiment to verify the performance impact: ... $ for n in $(seq 1 10); do \ time gdb -q -batch ~/firefox/libxul.so-93.0-1.1.x86_64.debug \ 2>&1 \ | grep "real:"; \ done ... and without the patch got: ... real: 4.71 real: 4.88 real: 4.29 real: 4.30 real: 4.65 real: 4.27 real: 4.27 real: 4.27 real: 4.75 real: 4.41 ... and with the patch: ... real: 3.68 real: 3.81 real: 3.80 real: 3.68 real: 3.75 real: 3.69 real: 3.69 real: 3.74 real: 3.67 real: 3.74 ... so that seems a reasonable improvement. With parallel_for_each_debug set to true, we get some more detail about the difference in behaviour. Without the patch we have: ... Parallel for: n_elements: 2818 Parallel for: minimum elements per thread: 1 Parallel for: elts_per_thread: 704 Parallel for: elements on worker thread 0 : 705 Parallel for: elements on worker thread 1 : 705 Parallel for: elements on worker thread 2 : 704 Parallel for: elements on worker thread 3 : 0 Parallel for: elements on main thread : 704 ... and with the patch: ... Parallel for: n_elements: 2818 Parallel for: total_size: 1483674865 Parallel for: size_per_thread: 370918716 Parallel for: elements on worker thread 0 : 752 (size: 371811790) Parallel for: elements on worker thread 1 : 360 (size: 371509370) Parallel for: elements on worker thread 2 : 1130 (size: 372681710) Parallel for: elements on worker thread 3 : 0 (size: 0) Parallel for: elements on main thread : 576 (size: 367671995) ... Tested on x86_64-linux. --- gdb/dwarf2/read.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 42230607fe0..6cf61214b40 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -7067,6 +7067,13 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile) using iter_type = decltype (per_bfd->all_comp_units.begin ()); + auto task_size_ = [] (iter_type iter) + { + dwarf2_per_cu_data *per_cu = iter->get (); + return (size_t)per_cu->length (); + }; + auto task_size = gdb::make_function_view (task_size_); + /* Each thread returns a pair holding a cooked index, and a vector of errors that should be printed. The latter is done because GDB's I/O system is not thread-safe. run_on_main_thread could be @@ -7095,7 +7102,7 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile) } } return result_type (thread_storage.release (), std::move (errors)); - }); + }, task_size); /* Only show a given exception a single time. */ std::unordered_set seen_exceptions; -- 2.35.3