Blame SOURCES/gdb-linux_perf-bundle.patch

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