Patchwork Compute msymbol hash codes in parallel

login
register
mail settings
Submitter Doug Evans via gdb-patches
Date Sept. 30, 2019, 10:29 p.m.
Message ID <20190930222953.136346-1-cbiesinger@google.com>
Download mbox | patch
Permalink /patch/34751/
State New
Headers show

Comments

Doug Evans via gdb-patches - Sept. 30, 2019, 10:29 p.m.
[This patch applies on top of
https://sourceware.org/ml/gdb-patches/2019-09/msg00620.html
for an additional 10-15% speedup]

This is for the msymbol_hash and msymbol_demangled_hash hashtables
in objfile_per_bfd_storage. This basically computes those hash
codes together with the demangled symbol name in the background,
before it inserts the symbols in the hash table.

gdb/ChangeLog:

2019-09-30  Christian Biesinger  <cbiesinger@google.com>

	* minsyms.c (add_minsym_to_hash_table): Use a previously computed
	hash code if possible.
	(add_minsym_to_demangled_hash_table): Likewise.
	(minimal_symbol_reader::install): Compute the hash codes for msymbol
	on the background thread.
	* symtab.h (struct minimal_symbol) <hash_value, demangled_hash_value>:
	Add these fields.
---
 gdb/minsyms.c | 19 +++++++++++++------
 gdb/symtab.h  |  3 +++
 2 files changed, 16 insertions(+), 6 deletions(-)

Patch

diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 4802b0bea0..ee80401b91 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -155,8 +155,9 @@  add_minsym_to_hash_table (struct minimal_symbol *sym,
 {
   if (sym->hash_next == NULL)
     {
-      unsigned int hash
-	= msymbol_hash (MSYMBOL_LINKAGE_NAME (sym)) % MINIMAL_SYMBOL_HASH_SIZE;
+      if (sym->hash_value == 0)
+	sym->hash_value = msymbol_hash (MSYMBOL_LINKAGE_NAME (sym));
+      unsigned int hash = sym->hash_value % MINIMAL_SYMBOL_HASH_SIZE;
 
       sym->hash_next = table[hash];
       table[hash] = sym;
@@ -171,14 +172,16 @@  add_minsym_to_demangled_hash_table (struct minimal_symbol *sym,
 {
   if (sym->demangled_hash_next == NULL)
     {
-      unsigned int hash = search_name_hash (MSYMBOL_LANGUAGE (sym),
-					    MSYMBOL_SEARCH_NAME (sym));
-
+      if (sym->demangled_hash_value == 0)
+	sym->demangled_hash_value
+	  = search_name_hash (MSYMBOL_LANGUAGE (sym),
+			      MSYMBOL_SEARCH_NAME (sym));
       objfile->per_bfd->demangled_hash_languages.set (MSYMBOL_LANGUAGE (sym));
 
       struct minimal_symbol **table
 	= objfile->per_bfd->msymbol_demangled_hash;
-      unsigned int hash_index = hash % MINIMAL_SYMBOL_HASH_SIZE;
+      unsigned int hash_index
+	= sym->demangled_hash_value % MINIMAL_SYMBOL_HASH_SIZE;
       sym->demangled_hash_next = table[hash_index];
       table[hash_index] = sym;
     }
@@ -1368,6 +1371,10 @@  minimal_symbol_reader::install ()
 		    msym.name_set = 1;
 		  }
 	      }
+	    msym.hash_value = msymbol_hash (MSYMBOL_LINKAGE_NAME (&msym));
+	    msym.demangled_hash_value
+	      = search_name_hash (MSYMBOL_LANGUAGE (&msym),
+				  MSYMBOL_SEARCH_NAME (&msym));
 	  },
 	  [&] (minimal_symbol *first, minimal_symbol* last) {
 	    std::lock_guard<std::mutex> guard (demangled_mutex);
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 17903df92d..27499eab6a 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -693,6 +693,9 @@  struct minimal_symbol : public general_symbol_info
 
   struct minimal_symbol *demangled_hash_next;
 
+  unsigned int hash_value;
+  unsigned int demangled_hash_value;
+
   /* True if this symbol is of some data type.  */
 
   bool data_p () const;