Blame SOURCES/gdb-linux_perf-bundle.patch

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