]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add maint set/show worker-threads
authorTom Tromey <tom@tromey.com>
Sat, 16 Mar 2019 20:36:57 +0000 (14:36 -0600)
committerTom Tromey <tom@tromey.com>
Sun, 10 Nov 2019 17:44:50 +0000 (10:44 -0700)
This adds maint commands to control the number of worker threads that
gdb can use.

2019-10-19  Tom Tromey  <tom@tromey.com>

* NEWS: Add entry.
* maint.c (_initialize_maint_cmds): Add "worker-threads" maint
commands.  Call update_thread_pool_size.
(update_thread_pool_size, maintenance_set_worker_threads): New
functions.
(n_worker_threads): New global.

gdb/doc/ChangeLog
2019-10-19  Tom Tromey  <tom@tromey.com>

* gdb.texinfo (Maintenance Commands): Document new maint
commands.

Change-Id: I4fb514faa05879d8afe62c77036a4469d57dca2a

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/maint.c

index 49f38c7531ca5c5b031b779de17705d3f68c7c3d..23ff4502b78b779b5e2cce13b107f520d31de927 100644 (file)
@@ -1,3 +1,12 @@
+2019-10-19  Tom Tromey  <tom@tromey.com>
+
+       * NEWS: Add entry.
+       * maint.c (_initialize_maint_cmds): Add "worker-threads" maint
+       commands.  Call update_thread_pool_size.
+       (update_thread_pool_size, maintenance_set_worker_threads): New
+       functions.
+       (n_worker_threads): New global.
+
 2019-10-19  Christian Biesinger  <cbiesinger@google.com>
            Tom Tromey  <tom@tromey.com>
 
index dc631794c093b7bfb5a10d4c58426a099e69c4ae..3c6e43caa4c0d2de87ef0eaa5ecc46bd9dd5ff7f 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -146,6 +146,13 @@ set style highlight background COLOR
 set style highlight intensity VALUE
   Control the styling of highlightings.
 
+maint set worker-threads
+maint show worker-threads
+  Control the number of worker threads that can be used by GDB.  The
+  default is "unlimited", which lets GDB choose a number that is
+  reasonable.  Currently worker threads are only used when demangling
+  the names of linker symbols.
+
 maint set test-settings KIND
 maint show test-settings KIND
   A set of commands used by the testsuite for exercising the settings
index ce89ee444ea157d800a525487d559b4d0c11cb2d..c614fc1d60a18b69d5c3fc2de5c73a94b82121e1 100644 (file)
@@ -1,3 +1,8 @@
+2019-10-19  Tom Tromey  <tom@tromey.com>
+
+       * gdb.texinfo (Maintenance Commands): Document new maint
+       commands.
+
 2019-10-31  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.texinfo (Symbols): Document new 'info module variables' and
index 70e4be1524402a02a82cadce92fdae2076fb9bce..79749810b6e2aa1497b3c8a05dc500d26b5b7fa4 100644 (file)
@@ -37841,6 +37841,21 @@ with the DWARF frame unwinders enabled.
 
 If DWARF frame unwinders are not supported for a particular target
 architecture, then enabling this flag does not cause them to be used.
+
+@kindex maint set worker-threads
+@kindex maint show worker-threads
+@item maint set worker-threads
+@item maint show worker-threads
+Control the number of worker threads that may be used by @value{GDBN}.
+On capable hosts, @value{GDBN} may use multiple threads to speed up
+certain CPU-intensive operations, such as demangling symbol names.
+While the number of threads used by @value{GDBN} may vary, this
+command can be used to set an upper bound on this number.  The default
+is @code{unlimited}, which lets @value{GDBN} choose a reasonable
+number.  Note that this only controls worker threads started by
+@value{GDBN} itself; libraries used by @value{GDBN} may start threads
+of their own.
+
 @kindex maint set profile
 @kindex maint show profile
 @cindex profiling GDB
index ec9f4abb26466936c76fc9bc0cef8a1091e616c9..fce1a1cdafc0917c3eed86c4ddc9285b85317290 100644 (file)
 #include "cli/cli-setshow.h"
 #include "cli/cli-cmds.h"
 
+#if CXX_STD_THREAD
+#include "gdbsupport/thread-pool.h"
+#endif
+
 static void maintenance_do_deprecate (const char *, int);
 
 /* Access the maintenance subcommands.  */
@@ -840,6 +844,37 @@ maintenance_set_profile_cmd (const char *args, int from_tty,
   error (_("Profiling support is not available on this system."));
 }
 #endif
+
+static int n_worker_threads = -1;
+
+/* Update the thread pool for the desired number of threads.  */
+static void
+update_thread_pool_size ()
+{
+#if CXX_STD_THREAD
+  int n_threads = n_worker_threads;
+
+  if (n_threads < 0)
+    {
+      n_threads = std::thread::hardware_concurrency ();
+      if (n_threads == 0)
+       {
+         /* Meh.  */
+         n_threads = 2;
+       }
+    }
+
+  gdb::thread_pool::g_thread_pool->set_thread_count (n_threads);
+#endif
+}
+
+static void
+maintenance_set_worker_threads (const char *args, int from_tty,
+                               struct cmd_list_element *c)
+{
+  update_thread_pool_size ();
+}
+
 \f
 /* If true, display time usage both at startup and for each command.  */
 
@@ -1312,4 +1347,17 @@ When enabled GDB is profiled."),
                           show_maintenance_profile_p,
                           &maintenance_set_cmdlist,
                           &maintenance_show_cmdlist);
+
+  add_setshow_zuinteger_unlimited_cmd ("worker-threads",
+                                      class_maintenance,
+                                      &n_worker_threads, _("\
+Set the number of worker threads GDB can use."), _("\
+Set the number of worker threads GDB can use."), _("\
+GDB may use multiple threads to speed up certain CPU-intensive operations,\n\
+such as demangling symbol names."),
+                                      maintenance_set_worker_threads, NULL,
+                                      &maintenance_set_cmdlist,
+                                      &maintenance_show_cmdlist);
+
+  update_thread_pool_size ();
 }