public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Add maint set/show worker-threads
@ 2019-11-26 21:12 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2019-11-26 21:12 UTC (permalink / raw)
  To: gdb-cvs

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

commit 22138db609721897c213e5a08ccaca206c0fb1f6
Author: Tom Tromey <tom@tromey.com>
Date:   Sat Mar 16 14:36:57 2019 -0600

    Add maint set/show worker-threads
    
    This adds maint commands to control the number of worker threads that
    gdb can use.
    
    2019-11-26  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-11-26  Tom Tromey  <tom@tromey.com>
    
    	* gdb.texinfo (Maintenance Commands): Document new maint
    	commands.
    
    Change-Id: I4fb514faa05879d8afe62c77036a4469d57dca2a

Diff:
---
 gdb/ChangeLog       |  9 +++++++++
 gdb/NEWS            |  7 +++++++
 gdb/doc/ChangeLog   |  5 +++++
 gdb/doc/gdb.texinfo | 15 +++++++++++++++
 gdb/maint.c         | 41 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 77 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b73ae8d..289cbce 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2019-11-26  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-11-26  Christian Biesinger  <cbiesinger@google.com>
 	    Tom Tromey  <tom@tromey.com>
 
diff --git a/gdb/NEWS b/gdb/NEWS
index 01b38cf..5fd0f41 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -149,6 +149,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
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index c6fa5f5..06d7a6d 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2019-11-26  Tom Tromey  <tom@tromey.com>
+
+	* gdb.texinfo (Maintenance Commands): Document new maint
+	commands.
+
 2019-11-25  Luis Machado  <luis.machado@linaro.org>
 
 	* gdb.texinfo (Debugging Output): Document set debug
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 18bb18b..e3be0cd 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -37876,6 +37876,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
diff --git a/gdb/maint.c b/gdb/maint.c
index ce59ef6..7ab3fdb 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -46,6 +46,10 @@
 #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,30 @@ 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 ();
+
+  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.  */
 
@@ -1313,4 +1341,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."), _("\
+Show 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 ();
 }


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

only message in thread, other threads:[~2019-11-26 21:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-26 21:12 [binutils-gdb] Add maint set/show worker-threads 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).