Blame SOURCES/gdb-linux_perf-bundle.patch

5ad05e
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
5ad05e
From: Fedora GDB patches <invalid@email.com>
5ad05e
Date: Fri, 27 Oct 2017 21:07:50 +0200
5ad05e
Subject: gdb-linux_perf-bundle.patch
5ad05e
5ad05e
;; [dts+el7] [x86*] Bundle linux_perf.h for libipt (RH BZ 1256513).
5ad05e
;;=fedora
5ad05e
5ad05e
diff --git a/gdb/configure b/gdb/configure
5ad05e
--- a/gdb/configure
5ad05e
+++ b/gdb/configure
5ad05e
@@ -11905,7 +11905,7 @@ else
5ad05e
 
5ad05e
 #include <linux/perf_event.h>
5ad05e
 #ifndef PERF_ATTR_SIZE_VER5
5ad05e
-# error
5ad05e
+// error // PERF_ATTR_SIZE_VER5_BUNDLE is not available here - Fedora+RHEL
5ad05e
 #endif
5ad05e
 
5ad05e
 _ACEOF
5ad05e
diff --git a/gdb/configure.ac b/gdb/configure.ac
5ad05e
--- a/gdb/configure.ac
5ad05e
+++ b/gdb/configure.ac
5ad05e
@@ -1414,7 +1414,7 @@ else
5ad05e
   AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
5ad05e
 #include <linux/perf_event.h>
5ad05e
 #ifndef PERF_ATTR_SIZE_VER5
5ad05e
-# error
5ad05e
+// error // PERF_ATTR_SIZE_VER5_BUNDLE is not available here - Fedora+RHEL
5ad05e
 #endif
5ad05e
   ]])], [perf_event=yes], [perf_event=no])
5ad05e
   if test "$perf_event" != yes; then
5ad05e
diff --git a/gdb/gdb.c b/gdb/gdb.c
5ad05e
--- a/gdb/gdb.c
5ad05e
+++ b/gdb/gdb.c
5ad05e
@@ -20,11 +20,19 @@
5ad05e
 #include "main.h"
5ad05e
 #include "interps.h"
5ad05e
 
5ad05e
+#ifdef PERF_ATTR_SIZE_VER5_BUNDLE
5ad05e
+extern "C" void __libipt_init(void);
5ad05e
+#endif
5ad05e
+
5ad05e
 int
5ad05e
 main (int argc, char **argv)
5ad05e
 {
5ad05e
   struct captured_main_args args;
5ad05e
 
5ad05e
+#ifdef PERF_ATTR_SIZE_VER5_BUNDLE
5ad05e
+  __libipt_init();
5ad05e
+#endif
5ad05e
+
5ad05e
   memset (&args, 0, sizeof args);
5ad05e
   args.argc = argc;
5ad05e
   args.argv = argv;
5ad05e
diff --git a/gdb/nat/linux-btrace.h b/gdb/nat/linux-btrace.h
5ad05e
--- a/gdb/nat/linux-btrace.h
5ad05e
+++ b/gdb/nat/linux-btrace.h
5ad05e
@@ -27,6 +27,177 @@
5ad05e
 #  include <linux/perf_event.h>
5ad05e
 #endif
5ad05e
 
5ad05e
+#ifdef PERF_ATTR_SIZE_VER5_BUNDLE
5ad05e
+#ifndef HAVE_LINUX_PERF_EVENT_H
5ad05e
+# error "PERF_ATTR_SIZE_VER5_BUNDLE && !HAVE_LINUX_PERF_EVENT_H"
5ad05e
+#endif
5ad05e
+#ifndef PERF_ATTR_SIZE_VER5
5ad05e
+#define PERF_ATTR_SIZE_VER5
5ad05e
+#define perf_event_mmap_page perf_event_mmap_page_bundle
5ad05e
+// kernel-headers-3.10.0-493.el7.x86_64/usr/include/linux/perf_event.h
5ad05e
+/*
5ad05e
+ * Structure of the page that can be mapped via mmap
5ad05e
+ */
5ad05e
+struct perf_event_mmap_page {
5ad05e
+	__u32	version;		/* version number of this structure */
5ad05e
+	__u32	compat_version;		/* lowest version this is compat with */
5ad05e
+
5ad05e
+	/*
5ad05e
+	 * Bits needed to read the hw events in user-space.
5ad05e
+	 *
5ad05e
+	 *   u32 seq, time_mult, time_shift, index, width;
5ad05e
+	 *   u64 count, enabled, running;
5ad05e
+	 *   u64 cyc, time_offset;
5ad05e
+	 *   s64 pmc = 0;
5ad05e
+	 *
5ad05e
+	 *   do {
5ad05e
+	 *     seq = pc->lock;
5ad05e
+	 *     barrier()
5ad05e
+	 *
5ad05e
+	 *     enabled = pc->time_enabled;
5ad05e
+	 *     running = pc->time_running;
5ad05e
+	 *
5ad05e
+	 *     if (pc->cap_usr_time && enabled != running) {
5ad05e
+	 *       cyc = rdtsc();
5ad05e
+	 *       time_offset = pc->time_offset;
5ad05e
+	 *       time_mult   = pc->time_mult;
5ad05e
+	 *       time_shift  = pc->time_shift;
5ad05e
+	 *     }
5ad05e
+	 *
5ad05e
+	 *     index = pc->index;
5ad05e
+	 *     count = pc->offset;
5ad05e
+	 *     if (pc->cap_user_rdpmc && index) {
5ad05e
+	 *       width = pc->pmc_width;
5ad05e
+	 *       pmc = rdpmc(index - 1);
5ad05e
+	 *     }
5ad05e
+	 *
5ad05e
+	 *     barrier();
5ad05e
+	 *   } while (pc->lock != seq);
5ad05e
+	 *
5ad05e
+	 * NOTE: for obvious reason this only works on self-monitoring
5ad05e
+	 *       processes.
5ad05e
+	 */
5ad05e
+	__u32	lock;			/* seqlock for synchronization */
5ad05e
+	__u32	index;			/* hardware event identifier */
5ad05e
+	__s64	offset;			/* add to hardware event value */
5ad05e
+	__u64	time_enabled;		/* time event active */
5ad05e
+	__u64	time_running;		/* time event on cpu */
5ad05e
+	union {
5ad05e
+		__u64	capabilities;
5ad05e
+		struct {
5ad05e
+			__u64	cap_bit0		: 1, /* Always 0, deprecated, see commit 860f085b74e9 */
5ad05e
+				cap_bit0_is_deprecated	: 1, /* Always 1, signals that bit 0 is zero */
5ad05e
+
5ad05e
+				cap_user_rdpmc		: 1, /* The RDPMC instruction can be used to read counts */
5ad05e
+				cap_user_time		: 1, /* The time_* fields are used */
5ad05e
+				cap_user_time_zero	: 1, /* The time_zero field is used */
5ad05e
+				cap_____res		: 59;
5ad05e
+		};
5ad05e
+	};
5ad05e
+
5ad05e
+	/*
5ad05e
+	 * If cap_user_rdpmc this field provides the bit-width of the value
5ad05e
+	 * read using the rdpmc() or equivalent instruction. This can be used
5ad05e
+	 * to sign extend the result like:
5ad05e
+	 *
5ad05e
+	 *   pmc <<= 64 - width;
5ad05e
+	 *   pmc >>= 64 - width; // signed shift right
5ad05e
+	 *   count += pmc;
5ad05e
+	 */
5ad05e
+	__u16	pmc_width;
5ad05e
+
5ad05e
+	/*
5ad05e
+	 * If cap_usr_time the below fields can be used to compute the time
5ad05e
+	 * delta since time_enabled (in ns) using rdtsc or similar.
5ad05e
+	 *
5ad05e
+	 *   u64 quot, rem;
5ad05e
+	 *   u64 delta;
5ad05e
+	 *
5ad05e
+	 *   quot = (cyc >> time_shift);
5ad05e
+	 *   rem = cyc & (((u64)1 << time_shift) - 1);
5ad05e
+	 *   delta = time_offset + quot * time_mult +
5ad05e
+	 *              ((rem * time_mult) >> time_shift);
5ad05e
+	 *
5ad05e
+	 * Where time_offset,time_mult,time_shift and cyc are read in the
5ad05e
+	 * seqcount loop described above. This delta can then be added to
5ad05e
+	 * enabled and possible running (if index), improving the scaling:
5ad05e
+	 *
5ad05e
+	 *   enabled += delta;
5ad05e
+	 *   if (index)
5ad05e
+	 *     running += delta;
5ad05e
+	 *
5ad05e
+	 *   quot = count / running;
5ad05e
+	 *   rem  = count % running;
5ad05e
+	 *   count = quot * enabled + (rem * enabled) / running;
5ad05e
+	 */
5ad05e
+	__u16	time_shift;
5ad05e
+	__u32	time_mult;
5ad05e
+	__u64	time_offset;
5ad05e
+	/*
5ad05e
+	 * If cap_usr_time_zero, the hardware clock (e.g. TSC) can be calculated
5ad05e
+	 * from sample timestamps.
5ad05e
+	 *
5ad05e
+	 *   time = timestamp - time_zero;
5ad05e
+	 *   quot = time / time_mult;
5ad05e
+	 *   rem  = time % time_mult;
5ad05e
+	 *   cyc = (quot << time_shift) + (rem << time_shift) / time_mult;
5ad05e
+	 *
5ad05e
+	 * And vice versa:
5ad05e
+	 *
5ad05e
+	 *   quot = cyc >> time_shift;
5ad05e
+	 *   rem  = cyc & (((u64)1 << time_shift) - 1);
5ad05e
+	 *   timestamp = time_zero + quot * time_mult +
5ad05e
+	 *               ((rem * time_mult) >> time_shift);
5ad05e
+	 */
5ad05e
+	__u64	time_zero;
5ad05e
+	__u32	size;			/* Header size up to __reserved[] fields. */
5ad05e
+
5ad05e
+		/*
5ad05e
+		 * Hole for extension of the self monitor capabilities
5ad05e
+		 */
5ad05e
+
5ad05e
+	__u8	__reserved[118*8+4];	/* align to 1k. */
5ad05e
+
5ad05e
+	/*
5ad05e
+	 * Control data for the mmap() data buffer.
5ad05e
+	 *
5ad05e
+	 * User-space reading the @data_head value should issue an smp_rmb(),
5ad05e
+	 * after reading this value.
5ad05e
+	 *
5ad05e
+	 * When the mapping is PROT_WRITE the @data_tail value should be
5ad05e
+	 * written by userspace to reflect the last read data, after issueing
5ad05e
+	 * an smp_mb() to separate the data read from the ->data_tail store.
5ad05e
+	 * In this case the kernel will not over-write unread data.
5ad05e
+	 *
5ad05e
+	 * See perf_output_put_handle() for the data ordering.
5ad05e
+	 *
5ad05e
+	 * data_{offset,size} indicate the location and size of the perf record
5ad05e
+	 * buffer within the mmapped area.
5ad05e
+	 */
5ad05e
+	__u64   data_head;		/* head in the data section */
5ad05e
+	__u64	data_tail;		/* user-space written tail */
5ad05e
+	__u64	data_offset;		/* where the buffer starts */
5ad05e
+	__u64	data_size;		/* data buffer size */
5ad05e
+
5ad05e
+	/*
5ad05e
+	 * AUX area is defined by aux_{offset,size} fields that should be set
5ad05e
+	 * by the userspace, so that
5ad05e
+	 *
5ad05e
+	 *   aux_offset >= data_offset + data_size
5ad05e
+	 *
5ad05e
+	 * prior to mmap()ing it. Size of the mmap()ed area should be aux_size.
5ad05e
+	 *
5ad05e
+	 * Ring buffer pointers aux_{head,tail} have the same semantics as
5ad05e
+	 * data_{head,tail} and same ordering rules apply.
5ad05e
+	 */
5ad05e
+	__u64	aux_head;
5ad05e
+	__u64	aux_tail;
5ad05e
+	__u64	aux_offset;
5ad05e
+	__u64	aux_size;
5ad05e
+};
5ad05e
+#endif // PERF_ATTR_SIZE_VER5
5ad05e
+#endif // PERF_ATTR_SIZE_VER5_BUNDLE
5ad05e
+
5ad05e
 struct target_ops;
5ad05e
 
5ad05e
 #if HAVE_LINUX_PERF_EVENT_H