Blame SOURCES/gdb-rhbz1103894-slow-gstack-performance.patch

2c2fa1
<https://sourceware.org/ml/gdb-patches/2014-10/msg00031.html>
2c2fa1
2c2fa1
Date: Thu, 2 Oct 2014 17:56:53 +0200
2c2fa1
From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
2c2fa1
To: Doug Evans <dje at google dot com>
2c2fa1
Cc: gdb-patches at sourceware dot org
2c2fa1
Subject: [patchv2] Fix 100x slowdown regression on DWZ files
2c2fa1
Message-ID: <20141002155653.GA9001@host2.jankratochvil.net>
2c2fa1
2c2fa1
2c2fa1
--cNdxnHkX5QqsyA0e
2c2fa1
Content-Type: text/plain; charset=us-ascii
2c2fa1
Content-Disposition: inline
2c2fa1
2c2fa1
On Thu, 02 Oct 2014 01:51:38 +0200, Doug Evans wrote:
2c2fa1
> I tested this patch with --target_board=dwarf4-gdb-index
2c2fa1
> and got a failure in m-static.exp:
2c2fa1
2c2fa1
That is particularly with -fdebug-types-section.
2c2fa1
2c2fa1
2c2fa1
> Type units read the line table in a separate path,
2c2fa1
2c2fa1
OK, therefore I dropped that separate struct dwarf2_lineinfo
2c2fa1
and reused struct line_header instead.
2c2fa1
2c2fa1
2c2fa1
> OTOH, I do want to avoid any confusion that this patch may inadvertently
2c2fa1
> introduce. For example, IIUC with your patch as is,
2c2fa1
> if we read a partial_unit first, before a compile_unit
2c2fa1
> that has the same stmt_list value, we'll do more processing in
2c2fa1
> dwarf_decode_lines than we really need to since we only need a file
2c2fa1
> number to symtab mapping. And if we later read in a compile_unit
2c2fa1
> with the same stmt_value we'll call dwarf_decode_lines again,
2c2fa1
> and this time we need the pc/line mapping it computes.
2c2fa1
> Whereas if we process these in the opposite order we'll only call
2c2fa1
> dwarf_decode_lines once. I'm sure this will be confusing at first
2c2fa1
> to some later developer going through this code.
2c2fa1
> [I could be missing something of course, and I'm happy for any corrections.]
2c2fa1
2c2fa1
Implemented (omitting some story why I did not include it before).
2c2fa1
2c2fa1
2c2fa1
> The code that processes stmt_list for type_units is in setup_type_unit_groups.
2c2fa1
> Note that this code goes to the trouble of re-initializing the buildsym
2c2fa1
> machinery (see the calls to restart_symtab in dwarf2read.c) when we process
2c2fa1
> the second and subsequent type units that share a stmt_list value.
2c2fa1
> This is something that used to be done before your patch and will no
2c2fa1
> longer be done with your patch (since if we get a cache hit we exit).
2c2fa1
> It may be that the type_unit support is doing this unnecessarily,
2c2fa1
> which would be great because we can then simplify it.
2c2fa1
2c2fa1
I hope this patch should no longer break -fdebug-types-section.
2c2fa1
If it additionally enables some future optimization for -fdebug-types-section
2c2fa1
the better.
2c2fa1
2c2fa1
2c2fa1
>  > +  /* Offset of line number information in .debug_line section.  */
2c2fa1
>  > +  sect_offset offset;
2c2fa1
>  > +  unsigned offset_in_dwz : 1;
2c2fa1
> 
2c2fa1
> IWBN to document why offset_in_dwz is here.
2c2fa1
> It's not obvious why it's needed.
2c2fa1
+
2c2fa1
On Thu, 02 Oct 2014 01:57:03 +0200, Doug Evans wrote:
2c2fa1
> Ah, I guess the offset_in_dwz flag will ensure dwarf_decode_lines gets called
2c2fa1
> twice regardless of order.  But is that the only reason for the flag?
2c2fa1
2c2fa1
I have added there now:
2c2fa1
+  /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile.  */
2c2fa1
2c2fa1
If one removes it regressions really happen.  What happens is that this
2c2fa1
line_header_hash (former lineinfo_hash) is in struct dwarf2_per_objfile which
2c2fa1
is common for both objfile and its objfile.dwz (that one is normally in
2c2fa1
/usr/lib/debug/.dwz/ - common for multiple objfiles).  And there are two
2c2fa1
different DIEs at offset 0xb - one in objfile and one in objfile.dwz - which
2c2fa1
would match single line_header if offset_in_dwz was not there.
2c2fa1
2c2fa1
Also existing dwarf2read.c code usually transfers "dwz flag" together with DIE
2c2fa1
offset, such as:
2c2fa1
	dwarf2_find_containing_comp_unit (sect_offset offset,
2c2fa1
					  unsigned int offset_in_dwz,
2c2fa1
					  struct objfile *objfile)
2c2fa1
This reminds me - why doesn't similar ambiguity happen also for dwp_file?
2c2fa1
I am unfortunately not much aware of the dwp implementation details.
2c2fa1
2c2fa1
2c2fa1
>  > -      struct line_header *line_header
2c2fa1
>  > -	= dwarf_decode_line_header (line_offset, cu);
2c2fa1
>  > +      dwarf2_per_objfile->lineinfo_hash =
2c2fa1
> 
2c2fa1
> As much as I prefer "=" going here, convention says to put it on the
2c2fa1
> next line.
2c2fa1
2c2fa1
I have changed it but this was just blind copy from existing line 21818.
2c2fa1
2c2fa1
2c2fa1
>  > +	htab_create_alloc_ex (127, dwarf2_lineinfo_hash, dwarf2_lineinfo_eq,
2c2fa1
> 
2c2fa1
> I don't have any data, but 127 seems high.
2c2fa1
2c2fa1
I have not changed it but this was just blind copy from existing line 21818.
2c2fa1
2c2fa1
2c2fa1
> I wouldn't change it, I just wanted to ask if you have any data
2c2fa1
> guiding this choice.
2c2fa1
2c2fa1
Tuning some constants really makes no sense when GDB has missing + insanely
2c2fa1
complicated data structures and in consequence GDB is using inappropriate data
2c2fa1
structures with bad algorithmic complexity.  One needs to switch GDB to C++
2c2fa1
and its STL before one can start talking about data structures performance.
2c2fa1
2c2fa1
2c2fa1
No regressions on {x86_64,x86_64-m32,i686}-fedora20-linux-gnu in DWZ mode and
2c2fa1
in -fdebug-types-section mode.
2c2fa1
2c2fa1
2c2fa1
Thanks,
2c2fa1
Jan
2c2fa1
2c2fa1
--cNdxnHkX5QqsyA0e
2c2fa1
Content-Type: text/plain; charset=us-ascii
2c2fa1
Content-Disposition: inline; filename="partialunit5.patch"
2c2fa1
2c2fa1
gdb/
2c2fa1
2014-10-02  Jan Kratochvil  <jan.kratochvil@redhat.com>
2c2fa1
2c2fa1
	Fix 100x slowdown regression on DWZ files.
2c2fa1
	* dwarf2read.c (struct dwarf2_per_objfile): Add line_header_hash.
2c2fa1
	(struct line_header): Add offset and offset_in_dwz.
2c2fa1
	(dwarf_decode_lines): Add parameter decode_mapping to the declaration.
2c2fa1
	(free_line_header_voidp): New declaration.
2c2fa1
	(line_header_hash, line_header_eq): New functions.
2c2fa1
	(dwarf2_build_include_psymtabs): Update dwarf_decode_lines caller.
2c2fa1
	(handle_DW_AT_stmt_list): Use dwarf2_per_objfile->line_header_hash.
2c2fa1
	(free_line_header_voidp): New function.
2c2fa1
	(dwarf_decode_line_header): Initialize offset and offset_in_dwz.
2c2fa1
	(dwarf_decode_lines): New parameter decode_mapping, use it.
2c2fa1
2c2fa1
Index: gdb-7.6.1/gdb/dwarf2read.c
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/dwarf2read.c
2c2fa1
+++ gdb-7.6.1/gdb/dwarf2read.c
2c2fa1
@@ -272,6 +272,9 @@ struct dwarf2_per_objfile
2c2fa1
 
2c2fa1
   /* The CUs we recently read.  */
2c2fa1
   VEC (dwarf2_per_cu_ptr) *just_read_cus;
2c2fa1
+
2c2fa1
+  /* Table containing line_header indexed by offset and offset_in_dwz.  */
2c2fa1
+  htab_t line_header_hash;
2c2fa1
 };
2c2fa1
 
2c2fa1
 static struct dwarf2_per_objfile *dwarf2_per_objfile;
2c2fa1
@@ -861,6 +864,12 @@ typedef void (die_reader_func_ftype) (co
2c2fa1
    which contains the following information.  */
2c2fa1
 struct line_header
2c2fa1
 {
2c2fa1
+  /* Offset of line number information in .debug_line section.  */
2c2fa1
+  sect_offset offset;
2c2fa1
+
2c2fa1
+  /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile.  */
2c2fa1
+  unsigned offset_in_dwz : 1;
2c2fa1
+
2c2fa1
   unsigned int total_length;
2c2fa1
   unsigned short version;
2c2fa1
   unsigned int header_length;
2c2fa1
@@ -1413,7 +1422,7 @@ static struct line_header *dwarf_decode_
2c2fa1
 
2c2fa1
 static void dwarf_decode_lines (struct line_header *, const char *,
2c2fa1
 				struct dwarf2_cu *, struct partial_symtab *,
2c2fa1
-				int);
2c2fa1
+				int, int decode_mapping);
2c2fa1
 
2c2fa1
 static void dwarf2_start_subfile (char *, const char *, const char *);
2c2fa1
 
2c2fa1
@@ -1746,6 +1755,8 @@ static void process_cu_includes (void);
2c2fa1
 
2c2fa1
 static void check_producer (struct dwarf2_cu *cu);
2c2fa1
 
2c2fa1
+static void free_line_header_voidp (void *arg);
2c2fa1
+
2c2fa1
 #if WORDS_BIGENDIAN
2c2fa1
 
2c2fa1
 /* Convert VALUE between big- and little-endian.  */
2c2fa1
@@ -2141,6 +2152,29 @@ dwarf2_get_dwz_file (void)
2c2fa1
   dwarf2_per_objfile->dwz_file = result;
2c2fa1
   return result;
2c2fa1
 }
2c2fa1
+
2c2fa1
+/* Hash function for line_header_hash.  */
2c2fa1
+
2c2fa1
+static hashval_t
2c2fa1
+line_header_hash (const void *item)
2c2fa1
+{
2c2fa1
+  const struct line_header *ofs = item;
2c2fa1
+
2c2fa1
+  return ofs->offset.sect_off ^ ofs->offset_in_dwz;
2c2fa1
+}
2c2fa1
+
2c2fa1
+/* Equality function for line_header_hash.  */
2c2fa1
+
2c2fa1
+static int
2c2fa1
+line_header_eq (const void *item_lhs, const void *item_rhs)
2c2fa1
+{
2c2fa1
+  const struct line_header *ofs_lhs = item_lhs;
2c2fa1
+  const struct line_header *ofs_rhs = item_rhs;
2c2fa1
+
2c2fa1
+  return (ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off
2c2fa1
+	  && ofs_lhs->offset_in_dwz == ofs_rhs->offset_in_dwz);
2c2fa1
+}
2c2fa1
+
2c2fa1
 
2c2fa1
 /* DWARF quick_symbols_functions support.  */
2c2fa1
 
2c2fa1
@@ -4139,7 +4173,7 @@ dwarf2_build_include_psymtabs (struct dw
2c2fa1
     return;  /* No linetable, so no includes.  */
2c2fa1
 
2c2fa1
   /* NOTE: pst->dirname is DW_AT_comp_dir (if present).  */
2c2fa1
-  dwarf_decode_lines (lh, pst->dirname, cu, pst, 1);
2c2fa1
+  dwarf_decode_lines (lh, pst->dirname, cu, pst, 1, 1);
2c2fa1
 
2c2fa1
   free_line_header (lh);
2c2fa1
 }
2c2fa1
@@ -7969,24 +8003,64 @@ static void
2c2fa1
 handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
2c2fa1
 			const char *comp_dir)
2c2fa1
 {
2c2fa1
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
2c2fa1
   struct attribute *attr;
2c2fa1
+  unsigned int line_offset;
2c2fa1
+  struct line_header *line_header, line_header_local;
2c2fa1
+  unsigned u;
2c2fa1
+  void **slot;
2c2fa1
+  int decode_mapping;
2c2fa1
 
2c2fa1
   gdb_assert (! cu->per_cu->is_debug_types);
2c2fa1
 
2c2fa1
   attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2c2fa1
-  if (attr)
2c2fa1
+  if (attr == NULL)
2c2fa1
+    return;
2c2fa1
+
2c2fa1
+  line_offset = DW_UNSND (attr);
2c2fa1
+
2c2fa1
+  if (dwarf2_per_objfile->line_header_hash == NULL)
2c2fa1
     {
2c2fa1
-      unsigned int line_offset = DW_UNSND (attr);
2c2fa1
-      struct line_header *line_header
2c2fa1
-	= dwarf_decode_line_header (line_offset, cu);
2c2fa1
-
2c2fa1
-      if (line_header)
2c2fa1
-	{
2c2fa1
-	  cu->line_header = line_header;
2c2fa1
-	  make_cleanup (free_cu_line_header, cu);
2c2fa1
-	  dwarf_decode_lines (line_header, comp_dir, cu, NULL, 1);
2c2fa1
-	}
2c2fa1
+      dwarf2_per_objfile->line_header_hash
2c2fa1
+	= htab_create_alloc_ex (127, line_header_hash, line_header_eq,
2c2fa1
+				free_line_header_voidp,
2c2fa1
+				&objfile->objfile_obstack,
2c2fa1
+				hashtab_obstack_allocate,
2c2fa1
+				dummy_obstack_deallocate);
2c2fa1
+    }
2c2fa1
+
2c2fa1
+  line_header_local.offset.sect_off = line_offset;
2c2fa1
+  line_header_local.offset_in_dwz = cu->per_cu->is_dwz;
2c2fa1
+  slot = htab_find_slot (dwarf2_per_objfile->line_header_hash,
2c2fa1
+			 &line_header_local, NO_INSERT);
2c2fa1
+
2c2fa1
+  /* For DW_TAG_compile_unit we need info like symtab::linetable which
2c2fa1
+     is not present in *SLOT.  */
2c2fa1
+  if (die->tag == DW_TAG_partial_unit && slot != NULL)
2c2fa1
+    {
2c2fa1
+      gdb_assert (*slot != NULL);
2c2fa1
+      cu->line_header = *slot;
2c2fa1
+      return;
2c2fa1
+    }
2c2fa1
+
2c2fa1
+  line_header = dwarf_decode_line_header (line_offset, cu);
2c2fa1
+  if (line_header == NULL)
2c2fa1
+    return;
2c2fa1
+  cu->line_header = line_header;
2c2fa1
+
2c2fa1
+  slot = htab_find_slot (dwarf2_per_objfile->line_header_hash,
2c2fa1
+			 &line_header_local, INSERT);
2c2fa1
+  gdb_assert (slot != NULL);
2c2fa1
+  if (*slot == NULL)
2c2fa1
+    *slot = line_header;
2c2fa1
+  else
2c2fa1
+    {
2c2fa1
+      gdb_assert (die->tag != DW_TAG_partial_unit);
2c2fa1
+      make_cleanup (free_cu_line_header, cu);
2c2fa1
     }
2c2fa1
+  decode_mapping = (die->tag != DW_TAG_partial_unit);
2c2fa1
+  dwarf_decode_lines (line_header, comp_dir, cu, NULL, 1,
2c2fa1
+		      decode_mapping);
2c2fa1
 }
2c2fa1
 
2c2fa1
 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit.  */
2c2fa1
@@ -15203,6 +15277,16 @@ free_line_header (struct line_header *lh
2c2fa1
   xfree (lh);
2c2fa1
 }
2c2fa1
 
2c2fa1
+/* Stub for free_line_header to match void * callback types.  */
2c2fa1
+
2c2fa1
+static void
2c2fa1
+free_line_header_voidp (void *arg)
2c2fa1
+{
2c2fa1
+  struct line_header *lh = arg;
2c2fa1
+
2c2fa1
+  free_line_header (lh);
2c2fa1
+}
2c2fa1
+
2c2fa1
 /* Add an entry to LH's include directory table.  */
2c2fa1
 
2c2fa1
 static void
2c2fa1
@@ -15333,6 +15417,9 @@ dwarf_decode_line_header (unsigned int o
2c2fa1
   back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
2c2fa1
                           (void *) lh);
2c2fa1
 
2c2fa1
+  lh->offset.sect_off = offset;
2c2fa1
+  lh->offset_in_dwz = cu->per_cu->is_dwz;
2c2fa1
+
2c2fa1
   line_ptr = section->buffer + offset;
2c2fa1
 
2c2fa1
   /* Read in the header.  */
2c2fa1
@@ -15826,18 +15913,22 @@ dwarf_decode_lines_1 (struct line_header
2c2fa1
    as the corresponding symtab.  Since COMP_DIR is not used in the name of the
2c2fa1
    symtab we don't use it in the name of the psymtabs we create.
2c2fa1
    E.g. expand_line_sal requires this when finding psymtabs to expand.
2c2fa1
-   A good testcase for this is mb-inline.exp.  */
2c2fa1
+   A good testcase for this is mb-inline.exp.
2c2fa1
+
2c2fa1
+   Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
2c2fa1
+   for its PC<->lines mapping information.  Otherwise only filenames
2c2fa1
+   tables is read in.  */
2c2fa1
 
2c2fa1
 static void
2c2fa1
 dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
2c2fa1
 		    struct dwarf2_cu *cu, struct partial_symtab *pst,
2c2fa1
-		    int want_line_info)
2c2fa1
+		    int want_line_info, int decode_mapping)
2c2fa1
 {
2c2fa1
   struct objfile *objfile = cu->objfile;
2c2fa1
   const int decode_for_pst_p = (pst != NULL);
2c2fa1
   struct subfile *first_subfile = current_subfile;
2c2fa1
 
2c2fa1
-  if (want_line_info)
2c2fa1
+  if (want_line_info && decode_mapping)
2c2fa1
     dwarf_decode_lines_1 (lh, comp_dir, cu, pst);
2c2fa1
 
2c2fa1
   if (decode_for_pst_p)