public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [committed] Calculate workset before serial/parallel code in dwz_files_1
@ 2021-03-27 19:14 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2021-03-27 19:14 UTC (permalink / raw)
  To: dwz, jakub, mark

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-27 19:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-27 19:14 [committed] Calculate workset before serial/parallel code in dwz_files_1 Tom de Vries

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).