From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id D47C9385801A for ; Sat, 27 Mar 2021 19:14:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D47C9385801A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id F3B21AA55; Sat, 27 Mar 2021 19:14:24 +0000 (UTC) Date: Sat, 27 Mar 2021 20:14:23 +0100 From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org Subject: [committed] Calculate workset before serial/parallel code in dwz_files_1 Message-ID: <20210327191422.GA22316@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Mar 2021 19:14:27 -0000 Hi, The function dwz_files_1 has code that can execute either serially or in parallel. Evidently, there's code duplication between the serial and parallel code, which creates the burden of keeping this in sync. The burden can be kept minimal by keeping the duplicate code minimal. Part of the duplicate code is the selection which files to handle. Move this selection out of the serial/parallel code, and use it to compute an array workset, which is then used in both the serial and parallel code. Committed to trunk. Thanks, - Tom Calculate workset before serial/parallel code in dwz_files_1 2021-03-27 Tom de Vries * dwz.c (dwz_files_1): Calculate workset before serial/parallel code. --- dwz.c | 55 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/dwz.c b/dwz.c index 40829ac..0ba04c5 100644 --- a/dwz.c +++ b/dwz.c @@ -16491,7 +16491,7 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink, struct file_result *resa) { int ret = 0; - int i; + int i, j; const char *file; int successcount = 0; @@ -16519,20 +16519,30 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink, if (hardlink) hardlink = detect_hardlinks (nr_files, files, resa); + int workset[nr_files]; + int workset_size = 0; + for (i = 0; i < nr_files; i++) + { + struct file_result *res = &resa[i]; + if (res->res == -2) + /* Skip hard links. */ + continue; + workset[workset_size] = i; + workset_size++; + } + if (max_forks > 1 && multifile == NULL) { pid_t pids[nr_files]; int nr_forks = 0; for (i = 0; i < nr_files; i++) pids[i] = 0; - for (i = 0; i < nr_files; i++) + for (j = 0; j < workset_size; j++) { + int i = workset[j]; int thisret; file = files[i]; struct file_result *res = &resa[i]; - if (res->res == -2) - /* Skip hard links. */ - continue; if (nr_forks == max_forks) { @@ -16564,14 +16574,12 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink, } else { - for (i = 0; i < nr_files; i++) + for (j = 0; j < workset_size; j++) { + int i = workset[j]; int thisret; file = files[i]; struct file_result *res = &resa[i]; - if (res->res == -2) - /* Skip hard links. */ - continue; if (stats_p) init_stats (file); thisret = dwz_with_low_mem (file, NULL, res); @@ -16614,22 +16622,31 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink, goto cleanup; } + workset_size = 0; + for (i = 0; i < nr_files; i++) + { + struct file_result *res = &resa[i]; + /* Don't process again files that couldn't + be processed successfully. Also skip hard links. */ + if (res->res == -1 || res->res == -2 + || res->skip_multifile) + continue; + workset[workset_size] = i; + workset_size++; + } + if (max_forks > 1) { pid_t pids[nr_files]; int nr_forks = 0; for (i = 0; i < nr_files; i++) pids[i] = 0; - for (i = 0; i < nr_files; i++) + for (j = 0; j < workset_size; j++) { + int i = workset[j]; file = files[i]; struct file_result *res = &resa[i]; multifile_mode = MULTIFILE_MODE_FI; - /* Don't process again files that couldn't - be processed successfully. Also skip hard links. */ - if (resa[i].res == -1 || resa[i].res == -2 - || resa[i].skip_multifile) - continue; if (nr_forks == max_forks) { @@ -16661,18 +16678,14 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink, } else { - for (i = 0; i < nr_files; i++) + for (j = 0; j < workset_size; j++) { + int i = workset[j]; dw_cu_ref cu; file = files[i]; if (stats_p) init_stats (file); multifile_mode = MULTIFILE_MODE_FI; - /* Don't process again files that couldn't - be processed successfully. Also skip hard links. */ - if (resa[i].res == -1 || resa[i].res == -2 - || resa[i].skip_multifile) - continue; for (cu = alt_first_cu; cu; cu = cu->cu_next) alt_clear_dups (cu->cu_die); ret |= dwz (file, NULL, &resa[i]);