public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org
Subject: [committed] Calculate workset before serial/parallel code in dwz_files_1
Date: Sat, 27 Mar 2021 20:14:23 +0100	[thread overview]
Message-ID: <20210327191422.GA22316@delia> (raw)

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  <tdevries@suse.de>

	* 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]);

                 reply	other threads:[~2021-03-27 19:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210327191422.GA22316@delia \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    --cc=mark@klomp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).