public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Add batching parameter to parallel_for_each
@ 2022-04-12 15:40 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-04-12 15:40 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=82d734f7a3b6f08813a9ad6272aa026779c88975

commit 82d734f7a3b6f08813a9ad6272aa026779c88975
Author: Tom Tromey <tom@tromey.com>
Date:   Sun May 23 09:04:27 2021 -0600

    Add batching parameter to parallel_for_each
    
    parallel_for_each currently requires each thread to process at least
    10 elements.  However, when indexing, it's fine for a thread to handle
    just a single CU.  This patch parameterizes this, and updates the one
    user.

Diff:
---
 gdb/minsyms.c                          |  4 ++--
 gdb/unittests/parallel-for-selftests.c |  2 +-
 gdbsupport/parallel-for.h              | 18 ++++++++++++------
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index f1c28907fa6..cbd0ad22392 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -1460,8 +1460,8 @@ minimal_symbol_reader::install ()
       std::vector<computed_hash_values> hash_values (mcount);
 
       msymbols = m_objfile->per_bfd->msymbols.get ();
-      gdb::parallel_for_each
-	(&msymbols[0], &msymbols[mcount],
+      /* Arbitrarily require at least 10 elements in a thread.  */
+      gdb::parallel_for_each (10, &msymbols[0], &msymbols[mcount],
 	 [&] (minimal_symbol *start, minimal_symbol *end)
 	 {
 	   for (minimal_symbol *msym = start; msym < end; ++msym)
diff --git a/gdb/unittests/parallel-for-selftests.c b/gdb/unittests/parallel-for-selftests.c
index adfc82f82bd..e0c07e55e03 100644
--- a/gdb/unittests/parallel-for-selftests.c
+++ b/gdb/unittests/parallel-for-selftests.c
@@ -52,7 +52,7 @@ test (int n_threads)
 #define NUMBER 10000
 
   std::atomic<int> counter (0);
-  gdb::parallel_for_each (0, NUMBER,
+  gdb::parallel_for_each (1, 0, NUMBER,
 			  [&] (int start, int end)
 			  {
 			    counter += end - start;
diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h
index 915814e485e..811ffd61bda 100644
--- a/gdbsupport/parallel-for.h
+++ b/gdbsupport/parallel-for.h
@@ -32,11 +32,16 @@ namespace gdb
 
    This approach was chosen over having the callback work on single
    items because it makes it simple for the caller to do
-   once-per-subrange initialization and destruction.  */
+   once-per-subrange initialization and destruction.
+
+   The parameter N says how batching ought to be done -- there will be
+   at least N elements processed per thread.  Setting N to 0 is not
+   allowed.  */
 
 template<class RandomIt, class RangeFunction>
 void
-parallel_for_each (RandomIt first, RandomIt last, RangeFunction callback)
+parallel_for_each (unsigned n, RandomIt first, RandomIt last,
+		   RangeFunction callback)
 {
   /* So we can use a local array below.  */
   const size_t local_max = 16;
@@ -48,10 +53,11 @@ parallel_for_each (RandomIt first, RandomIt last, RangeFunction callback)
   size_t n_elements = last - first;
   if (n_threads > 1)
     {
-      /* Arbitrarily require that there should be at least 10 elements
-	 in a thread.  */
-      if (n_elements / n_threads < 10)
-	n_threads = std::max (n_elements / 10, (size_t) 1);
+      /* Require that there should be at least N elements in a
+	 thread.  */
+      gdb_assert (n > 0);
+      if (n_elements / n_threads < n)
+	n_threads = std::max (n_elements / n, (size_t) 1);
       size_t elts_per_thread = n_elements / n_threads;
       n_actual_threads = n_threads - 1;
       for (int i = 0; i < n_actual_threads; ++i)


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

only message in thread, other threads:[~2022-04-12 15:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 15:40 [binutils-gdb] Add batching parameter to parallel_for_each Tom Tromey

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