[Linux] Avoid refetching core-of-thread if thread hasn't run
authorPedro Alves <palves@redhat.com>
Tue, 24 May 2016 13:47:57 +0000 (14:47 +0100)
committerPedro Alves <palves@redhat.com>
Tue, 24 May 2016 13:48:57 +0000 (14:48 +0100)
commit1ad3de988d2f41c72de66613c68ed78507a3abbd
tree15bbafba25939c164b8f05e4407dd57df129d187
parent95e94c3f18aaf34fadcd9a2a882ffe6147b9acc3
[Linux] Avoid refetching core-of-thread if thread hasn't run

Hacking the gdb.threads/attach-many-short-lived-threads.exp test to
spawn thousands of threads instead of dozens, I saw GDB having trouble
keeping up with threads being spawned too fast, when it tried to stop
them all.  This was because while gdb is doing that, it updates the
thread list to make sure no new thread has sneaked in that might need
to be paused.  It does this a few times until it sees no-new-threads
twice in a row.  The thread listing update itself is not that
expensive, however, in the Linux backend, updating the threads list
calls linux_common_core_of_thread for each LWP to record on which core
each LWP was last seen running, which opens/reads/closes a /proc file
for each LWP which becomes expensive when you need to do it for
thousands of LWPs.

perf shows gdb in linux_common_core_of_thread 44% of the time, in the
stop_all_threads -> update_thread_list path in this use case.

This patch simply makes linux_common_core_of_thread avoid updating the
core the thread is bound to if the thread hasn't run since the last
time we updated that info.  This makes linux_common_core_of_thread
disappear into the noise in the perf report.

gdb/ChangeLog:
2016-05-24  Pedro Alves  <palves@redhat.com>

PR gdb/19828
* linux-nat.c (linux_resume_one_lwp_throw): Clear the LWP's core
field.
(linux_nat_update_thread_list): Don't fetch the core if already
known.
gdb/ChangeLog
gdb/linux-nat.c
This page took 0.063539 seconds and 4 git commands to generate.