Blame SOURCES/gdb-linux_perf-bundle.patch

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