Blame SOURCES/gdb-linux_perf-bundle.patch

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