Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
To: Tom de Vries <tdevries@suse.de>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] [gdb] Exclude unavailable hardware threads in default worker-threads
Date: Mon, 07 Sep 2026 04:44:44 +0000	[thread overview]
Message-ID: <87tso1n003.fsf@linaro.org> (raw)
In-Reply-To: <20260906154838.139837-2-tdevries@suse.de> (Tom de Vries's message of "Sun, 6 Sep 2026 17:48:38 +0200")

Tom de Vries <tdevries@suse.de> writes:

> The default worker-threads is set to the number of hardware threads:
> ...
> $ gdb -q -batch -ex "maint show worker-thread"
> The number of worker threads GDB can use is the default (currently 8).
> ...
> but does not take into account how many of those are actually available.
>
> If we reduce the amount of available threads to 1, we get the same answer:
> ...
> $ taskset -c 0 gdb -q -batch -ex "maint show worker-thread"
> The number of worker threads GDB can use is the default (currently 8).
> ...
>
> Fix this on linux using sched_getaffinity:
> ...
> $ taskset -c 0 gdb -q -batch -ex "maint show worker-thread"
> The number of worker threads GDB can use is the default (currently 1).
> $ gdb -q -batch -ex "maint show worker-thread"
> The number of worker threads GDB can use is the default (currently 8).
> ...
> ---
>  gdb/maint.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)

This is a nice improvement. At least some good came out of my red
herring. Thanks!

One comment, but:

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>

> diff --git a/gdb/maint.c b/gdb/maint.c
> index 1daa6ce1d2e..fbddfe15591 100644
> --- a/gdb/maint.c
> +++ b/gdb/maint.c
> @@ -47,6 +47,10 @@
>  #include "cli/cli-style.h"
>  #include "cli/cli-cmds.h"
>  
> +#ifdef __linux__
> +#include <sched.h>

The sched_getaffinity(2) man page mentions that one should define
_GNU_SOURCE before including <sched.h>

> +#endif
> +
>  static void maintenance_do_deprecate (const char *, int);
>  
>  #ifndef _WIN32
> @@ -882,6 +886,20 @@ update_thread_pool_size ()
>  	 systems.  */
>        const int max_thread_count = 8;
>        n_threads = std::min (hardware_threads, max_thread_count);
> +
> +      if (n_threads > 1)
> +	{
> +	  /* Exclude unavailable hardware threads (for instance made
> +	     unavailable using taskset).  */
> +#ifdef __linux__
> +	  cpu_set_t cpus;
> +	  int res = sched_getaffinity (getpid (), sizeof (cpu_set_t), &cpus);
> +	  if (res == 0)
> +	    n_threads = std::min (n_threads, CPU_COUNT (&cpus));
> +#else
> +	  /* Todo: handle other platforms.  */
> +#endif
> +	}
>      }
>  
>    gdb::thread_pool::g_thread_pool->set_thread_count (n_threads);

-- 
Thiago
(he/him)

  reply	other threads:[~2026-09-07  4:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-06 15:48 [PATCH 1/2] [gdb/testsuite] Fix timeout in do_self_tests Tom de Vries
2026-09-06 15:48 ` [PATCH 2/2] [gdb] Exclude unavailable hardware threads in default worker-threads Tom de Vries
2026-09-07  4:44   ` Thiago Jung Bauermann [this message]
2026-09-07  6:52     ` Tom de Vries
2026-09-09 12:02     ` Tom de Vries
2026-09-07  4:36 ` [PATCH 1/2] [gdb/testsuite] Fix timeout in do_self_tests Thiago Jung Bauermann
2026-09-09 11:57   ` Tom de Vries
2026-09-09 20:28     ` Thiago Jung Bauermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tso1n003.fsf@linaro.org \
    --to=thiago.bauermann@linaro.org \
    --cc=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox