[2/2] Fast tracepoint for powerpc64le

Message ID 54E77751.2040707@gmail.com
State New, archived
Headers

Commit Message

Wei-cheng, Wang Feb. 20, 2015, 6:05 p.m. UTC
  Hi,

This patch adds an IPA function, jump_pad_area_hint, for giving a hint
where to map jump pad buffer.  addr = pagesize is too low for powerpr
executable.

Besides, "MAP_FIXED" flag is removed.  See MMAP(2)

    If the memory region specified by addr and len  overlaps  pages
    of any existing mapping(s), then the overlapped part of the existing
                                                            ^^^^^^^^^^^^
    mapping(s) will be discarded.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Thanks,
Wei-cheng
---

gdb/gdbserver/ChangeLog

2015-02-20  Wei-cheng Wang  <cole945@gmail.com>

	* tracepoint.c (initialize_tracepoint): Calling jump_pad_area_hint()
	to get where to map gdb_jump_pad_buffer.  Remove MAP_FIXED.
	* tracepoint.h (jump_pad_area_hint): Add declaration.
	* linux-amd64-ipa.c (jump_pad_area_hint): New function.
	* linux-i386-ipa.c (jump_pad_area_hint): New function.
	* linux-ppc-ipa.c (jump_pad_area_hint): New function.
---
  gdb/gdbserver/linux-amd64-ipa.c | 11 +++++++++++
  gdb/gdbserver/linux-i386-ipa.c  | 11 +++++++++++
  gdb/gdbserver/linux-ppc-ipa.c   | 12 ++++++++++++
  gdb/gdbserver/tracepoint.c      |  7 +++----
  gdb/gdbserver/tracepoint.h      |  1 +
  5 files changed, 38 insertions(+), 4 deletions(-)
  

Comments

Pedro Alves March 4, 2015, 7:06 p.m. UTC | #1
On 02/20/2015 06:05 PM, Wei-cheng Wang wrote:

> gdb/gdbserver/ChangeLog
> 
> 2015-02-20  Wei-cheng Wang  <cole945@gmail.com>
> 
> 	* tracepoint.c (initialize_tracepoint): Calling jump_pad_area_hint()
> 	to get where to map gdb_jump_pad_buffer.  Remove MAP_FIXED.

Write:

	* tracepoint.c (initialize_tracepoint): Call jump_pad_area_hint
	to get where to map gdb_jump_pad_buffer.  Remove MAP_FIXED.

> 	* tracepoint.h (jump_pad_area_hint): Add declaration.
> 	* linux-amd64-ipa.c (jump_pad_area_hint): New function.
> 	* linux-i386-ipa.c (jump_pad_area_hint): New function.
> 	* linux-ppc-ipa.c (jump_pad_area_hint): New function.


I'll leave the PPC-specifics to Ulrich, but otherwise this looks
fine to me, with a nit.

> 
> +/* Return the address for where to allocate buffer for jump pad.
> +   The buffer should be close enough for tracepoints.  */
> +
> +uintptr_t
> +jump_pad_area_hint (void)


> +/* Return the address for where to allocate buffer for jump pad.
> +   The buffer should be close enough for tracepoints.  */
> +
> +uintptr_t
> +jump_pad_area_hint (void)

> +/* Return the address for where to allocate buffer for jump pad.
> +   The buffer should be close enough for tracepoints.  */
> +
> +uintptr_t
> +jump_pad_area_hint (void)

Could you move this duplicated comments to the declaration
instead?  Then in the implementations' comment you can
just write:

/* See tracepoint.h.  */

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/gdbserver/linux-amd64-ipa.c b/gdb/gdbserver/linux-amd64-ipa.c
index c27ef21..db27d2a 100644
--- a/gdb/gdbserver/linux-amd64-ipa.c
+++ b/gdb/gdbserver/linux-amd64-ipa.c
@@ -77,6 +77,17 @@  gdb_agent_get_raw_reg (const unsigned char *raw_regs, int regnum)
    return *(ULONGEST *) (raw_regs + x86_64_ft_collect_regmap[regnum]);
  }

+/* Return the address for where to allocate buffer for jump pad.
+   The buffer should be close enough for tracepoints.  */
+
+uintptr_t
+jump_pad_area_hint (void)
+{
+  /* Allocate scratch buffer aligned on a page boundary, at a low
+     address (close to the main executable's code).  */
+  return sysconf (_SC_PAGE_SIZE);
+}
+
  #ifdef HAVE_UST

  #include <ust/processor.h>
diff --git a/gdb/gdbserver/linux-i386-ipa.c b/gdb/gdbserver/linux-i386-ipa.c
index 6381a55..1fc4bd2 100644
--- a/gdb/gdbserver/linux-i386-ipa.c
+++ b/gdb/gdbserver/linux-i386-ipa.c
@@ -114,6 +114,17 @@  gdb_agent_get_raw_reg (unsigned char *raw_regs, int regnum)
      return *(int *) (raw_regs + i386_ft_collect_regmap[regnum]);
  }

+/* Return the address for where to allocate buffer for jump pad.
+   The buffer should be close enough for tracepoints.  */
+
+uintptr_t
+jump_pad_area_hint (void)
+{
+  /* Allocate scratch buffer aligned on a page boundary, at a low
+     address (close to the main executable's code).  */
+  return sysconf (_SC_PAGE_SIZE);
+}
+
  #ifdef HAVE_UST

  #include <ust/processor.h>
diff --git a/gdb/gdbserver/linux-ppc-ipa.c b/gdb/gdbserver/linux-ppc-ipa.c
index 34b26d0..be6919b 100644
--- a/gdb/gdbserver/linux-ppc-ipa.c
+++ b/gdb/gdbserver/linux-ppc-ipa.c
@@ -105,6 +105,18 @@  gdb_agent_get_raw_reg (const unsigned char *raw_regs, int regnum)
  			+ ppc_ft_collect_regmap[regnum] * REGSZ);
  }

+/* Return the address for where to allocate buffer for jump pad.
+   The buffer should be close enough for tracepoints.  */
+
+uintptr_t
+jump_pad_area_hint (void)
+{
+  /* Main executables are normally mapped at 256MB.  Unconditional branch
+     can jump +/- 25-bit far (+/- 32MB), so allocate the buffer at 240MB
+     should be close enough in most cases.  */
+  return 0xf000000;
+}
+
  /* Initialize ipa_tdesc and others.  */

  void
diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c
index 2382a11..ad81d7a 100644
--- a/gdb/gdbserver/tracepoint.c
+++ b/gdb/gdbserver/tracepoint.c
@@ -7388,13 +7388,12 @@  initialize_tracepoint (void)

  #define SCRATCH_BUFFER_NPAGES 20

-    /* Allocate scratch buffer aligned on a page boundary, at a low
-       address (close to the main executable's code).  */
-    for (addr = pagesize; addr != 0; addr += pagesize)
+    addr = jump_pad_area_hint ();
+    for (; addr != 0; addr += pagesize)
        {
  	gdb_jump_pad_buffer = mmap ((void *) addr, pagesize * SCRATCH_BUFFER_NPAGES,
  				    PROT_READ | PROT_WRITE | PROT_EXEC,
-				    MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
+				    MAP_PRIVATE | MAP_ANONYMOUS,
  				    -1, 0);
  	if (gdb_jump_pad_buffer != MAP_FAILED)
  	  break;
diff --git a/gdb/gdbserver/tracepoint.h b/gdb/gdbserver/tracepoint.h
index 2adcd56..05a0c2a 100644
--- a/gdb/gdbserver/tracepoint.h
+++ b/gdb/gdbserver/tracepoint.h
@@ -88,6 +88,7 @@  void supply_static_tracepoint_registers (struct regcache *regcache,
  					 CORE_ADDR pc);
  void set_trampoline_buffer_space (CORE_ADDR begin, CORE_ADDR end,
  				  char *errmsg);
+uintptr_t jump_pad_area_hint (void);

  extern const struct target_desc *ipa_tdesc;