Blame SOURCES/gdb-linux_perf-bundle.patch

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