Blame SOURCES/gdb-linux_perf-bundle.patch

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