diff options
author | Tom Tromey <tom@tromey.com> | 2019-03-03 10:15:30 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2019-11-26 14:02:58 -0700 |
commit | d55c9a68473d4378e484a870d3ca4222a68078ca (patch) | |
tree | 481619709ee6a4382df2f8b48d6d9835d942a31a /gdb/minsyms.c | |
parent | a0b57563b1317e0000a67a7bed4c1712403682f3 (diff) | |
download | gdb-d55c9a68473d4378e484a870d3ca4222a68078ca.zip gdb-d55c9a68473d4378e484a870d3ca4222a68078ca.tar.gz gdb-d55c9a68473d4378e484a870d3ca4222a68078ca.tar.bz2 |
Demangle minsyms in parallel
This patch introduces a simple parallel for_each and changes the
minimal symbol reader to use it when computing the demangled name for
a minimal symbol. This yields a speedup when reading minimal symbols.
2019-11-26 Christian Biesinger <cbiesinger@google.com>
Tom Tromey <tom@tromey.com>
* minsyms.c (minimal_symbol_reader::install): Use
parallel_for_each.
* gdbsupport/parallel-for.h: New file.
* Makefile.in (HFILES_NO_SRCDIR): Add gdbsupport/parallel-for.h.
Change-Id: I220341f70e94dd02df5dd424272c50a5afb64978
Diffstat (limited to 'gdb/minsyms.c')
-rw-r--r-- | gdb/minsyms.c | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 6e7021a..03a1932 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -53,6 +53,11 @@ #include "gdbsupport/symbol.h" #include <algorithm> #include "safe-ctype.h" +#include "gdbsupport/parallel-for.h" + +#if CXX_STD_THREAD +#include <mutex> +#endif /* See minsyms.h. */ @@ -1359,16 +1364,43 @@ minimal_symbol_reader::install () m_objfile->per_bfd->minimal_symbol_count = mcount; m_objfile->per_bfd->msymbols = std::move (msym_holder); +#if CXX_STD_THREAD + /* Mutex that is used when modifying or accessing the demangled + hash table. */ + std::mutex demangled_mutex; +#endif + msymbols = m_objfile->per_bfd->msymbols.get (); - for (int i = 0; i < mcount; ++i) - { - if (!msymbols[i].name_set) - { - symbol_set_names (&msymbols[i], msymbols[i].name, - false, m_objfile->per_bfd); - msymbols[i].name_set = 1; - } - } + gdb::parallel_for_each + (&msymbols[0], &msymbols[mcount], + [&] (minimal_symbol *start, minimal_symbol *end) + { + for (minimal_symbol *msym = start; msym < end; ++msym) + { + if (!msym->name_set) + { + /* This will be freed later, by symbol_set_names. */ + char *demangled_name + = symbol_find_demangled_name (msym, msym->name); + symbol_set_demangled_name + (msym, demangled_name, + &m_objfile->per_bfd->storage_obstack); + msym->name_set = 1; + } + } + { + /* To limit how long we hold the lock, we only acquire it here + and not while we demangle the names above. */ +#if CXX_STD_THREAD + std::lock_guard<std::mutex> guard (demangled_mutex); +#endif + for (minimal_symbol *msym = start; msym < end; ++msym) + { + symbol_set_names (msym, msym->name, false, + m_objfile->per_bfd); + } + } + }); build_minimal_symbol_hash_tables (m_objfile); } |