Blame SOURCES/gdb-linux_perf-bundle.patch

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