Blame SOURCES/gdb-linux_perf-bundle.patch

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