From patchwork Sun Oct 20 20:54:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35188 Received: (qmail 19806 invoked by alias); 20 Oct 2019 20:54:54 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 19748 invoked by uid 89); 20 Oct 2019 20:54:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 20 Oct 2019 20:54:52 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id BA85E2041E; Sun, 20 Oct 2019 16:54:50 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [8.43.85.239]) by mx1.osci.io (Postfix) with ESMTP id B4EE02041E for ; Sun, 20 Oct 2019 16:54:46 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 8E9B721926 for ; Sun, 20 Oct 2019 16:54:46 -0400 (EDT) X-Gerrit-PatchSet: 2 Date: Sun, 20 Oct 2019 16:54:43 -0400 From: "Tom Tromey (Code Review)" To: gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [review v2] Add maint set/show worker-threads X-Gerrit-Change-Id: I4fb514faa05879d8afe62c77036a4469d57dca2a X-Gerrit-Change-Number: 174 X-Gerrit-ChangeURL: X-Gerrit-Commit: 847300a1a21ea5eee888c3c997a474924732fa5e In-Reply-To: References: Reply-To: tromey@sourceware.org, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3 Message-Id: <20191020205446.8E9B721926@gnutoolchain-gerrit.osci.io> Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/174 ...................................................................... Add maint set/show worker-threads This adds maint commands to control the number of worker threads that gdb can use. gdb/ChangeLog 2019-10-19 Tom Tromey * 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 * gdb.texinfo (Maintenance Commands): Document new maint commands. Change-Id: I4fb514faa05879d8afe62c77036a4469d57dca2a --- M gdb/ChangeLog M gdb/NEWS M gdb/doc/ChangeLog M gdb/doc/gdb.texinfo M gdb/maint.c 5 files changed, 84 insertions(+), 0 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 400ccc1..d7b40d7 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2019-10-19 Tom Tromey + + * 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 Tom Tromey diff --git a/gdb/NEWS b/gdb/NEWS index 25e67e4..7c98c14 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -134,6 +134,13 @@ 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 26f858f..175fc98 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,8 @@ +2019-10-19 Tom Tromey + + * gdb.texinfo (Maintenance Commands): Document new maint + commands. + 2019-10-07 Tom de Vries * gdb.texinfo: Fix typo. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 1208e4f..3219e68 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -37683,6 +37683,21 @@ 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 ec9f4ab..fce1a1c 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,37 @@ 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 (); +} + /* If true, display time usage both at startup and for each command. */ @@ -1312,4 +1347,17 @@ 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 (); }