Blame SOURCES/gdb-linux_perf-bundle.patch

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