mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-06 12:09:26 +08:00
33ae45434d
This commit enables the early initialization commands (92e4e97a9f
) to modify the number of threads used by gdb's thread pool. The motivation here is to prevent gdb from spawning a detrimental number of threads on many-core systems under environments with restrictive ulimits. With gdb before this commit, the thread pool takes the following sizes: 1. Thread pool size is initialized to 0. 2. After the maintenance commands are defined, the thread pool size is set to the number of system cores (if it has not already been set). 3. Using early initialization commands, the thread pool size can be changed using "maint set worker-threads". 4. After the first prompt, the thread pool size can be changed as in the previous step. Therefore after step 2. gdb has potentially launched hundreds of threads on a many-core system. After this change, step 2 and 3 are reversed so there is an opportunity to set the required number of threads without needing to default to the number of system cores first. There does exist a configure option (added in261b07488b
) to disable multithreading, but this does not allow for an already deployed gdb to be configured. Additionally, the default number of worker threads is clamped at eight to control the number of worker threads spawned on many-core systems. This value was chosen as testing recorded on bugzilla issue 29959 indicates that parallel efficiency drops past this point. GDB built with GCC 13. No test suite regressions detected. Compilers: GCC, ACfL, Intel, Intel LLVM, NVHPC; Platforms: x86_64, aarch64. The scenario that interests me the most involves preventing GDB from spawning any worker threads at all. This was tested by counting the number of clones observed by strace: strace -e clone,clone3 gdb/gdb -q \ --early-init-eval-command="maint set worker-threads 0" \ -ex q ./gdb/gdb |& grep --count clone The new test relies on "gdb: install CLI uiout while processing early init files" developed by Andrew Burgess. This patch will need pushing prior to this change. The clamping was tested on machines with both 16 cores and a single core. "maint show worker-threads" correctly reported eight and one respectively. Approved-By: Tom Tromey <tom@tromey.com>
74 lines
2.3 KiB
C++
74 lines
2.3 KiB
C++
/* Support for GDB maintenance commands.
|
|
Copyright (C) 2013-2023 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef MAINT_H
|
|
#define MAINT_H
|
|
|
|
#include "gdbsupport/run-time-clock.h"
|
|
#include <chrono>
|
|
|
|
extern void set_per_command_time (int);
|
|
|
|
extern void set_per_command_space (int);
|
|
|
|
/* Update the thread pool for the desired number of threads. */
|
|
|
|
extern void update_thread_pool_size ();
|
|
|
|
/* Records a run time and space usage to be used as a base for
|
|
reporting elapsed time or change in space. */
|
|
|
|
class scoped_command_stats
|
|
{
|
|
public:
|
|
|
|
explicit scoped_command_stats (bool msg_type);
|
|
~scoped_command_stats ();
|
|
|
|
private:
|
|
|
|
DISABLE_COPY_AND_ASSIGN (scoped_command_stats);
|
|
|
|
/* Print the time, along with a string. */
|
|
void print_time (const char *msg);
|
|
|
|
/* Zero if the saved time is from the beginning of GDB execution.
|
|
One if from the beginning of an individual command execution. */
|
|
bool m_msg_type;
|
|
/* Track whether the stat was enabled at the start of the command
|
|
so that we can avoid printing anything if it gets turned on by
|
|
the current command. */
|
|
bool m_time_enabled : 1;
|
|
bool m_space_enabled : 1;
|
|
bool m_symtab_enabled : 1;
|
|
run_time_clock::time_point m_start_cpu_time;
|
|
std::chrono::steady_clock::time_point m_start_wall_time;
|
|
long m_start_space;
|
|
/* Total number of symtabs (over all objfiles). */
|
|
int m_start_nr_symtabs;
|
|
/* A count of the compunits. */
|
|
int m_start_nr_compunit_symtabs;
|
|
/* Total number of blocks. */
|
|
int m_start_nr_blocks;
|
|
};
|
|
|
|
extern obj_section *maint_obj_section_from_bfd_section (bfd *abfd,
|
|
asection *asection,
|
|
objfile *ofile);
|
|
#endif /* MAINT_H */
|