Skip to contentSkip to conversation

perf/core: addressing 4x slowdown during per-process profiling of STREAM benchmark on Intel Xeon Phi

PATCH New Alexey Budankov 1 participant 1 message Jun 30, 2017 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v5 4/4 perf/core: addressing 4x slowdown during per-process profiling of STREAM benchmark on Intel Xeon Phi

perf/core: complete replace of lists by rb trees for pinned and
flexible groups at perf_event_context

By default, the userspace perf tool opens per-cpu task-bound events when sampling, so for N logical events requested by the user, the tool will open N * NR_CPUS events.

In the kernel, we mux events with a hrtimer, periodically rotating the flexible group list and trying to schedule each group in turn. We skip groups whose cpu filter doesn't match. So when we get unlucky, we can walk N * (NR_CPUS - 1) groups pointlessly for each hrtimer invocation.

This has been observed to result in significant overhead when running the STREAM benchmark on 272 core Xeon Phi systems.

One way to avoid this is to place our events into an rb tree sorted by CPU filter, so that our hrtimer can skip to the current CPU's list and ignore everything else.

This patch implements complete replacement of lists by rb trees for pinned and flexible groups.

---
 include/linux/perf_event.h | 20 +---------
 kernel/events/core.c       | 92 ++++++++++++++++------------------------------
 2 files changed, 34 insertions(+), 78 deletions(-)

1. removed group_list_entry from perf_event type reusing group_entry instead.

2. removed perf_event_groups type replacing it by rb_tree for pinned and flexible groups at perf_event_context and all over the code.

3. removed perf_event_groups_init() and perf_event_groups_empty() employing natural rb tree API instead.

4. updated perf_event_groups_iterate() implementation to go thru tree instead of list.

The patch set was tested on Xeon Phi using perf_fuzzer and tests from here: https://github.com/deater/perf_event_tests

The full patch set (v1-4) is attached for convenience.

Branch revision:
* perf/core 007b811b4041989ec2dc91b9614aa2c41332723e
Merge tag 'perf-core-for-mingo-4.13-20170719' of
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core

include/linux/perf_event.h +2 -18
index 7b2cddf..8e1967f 100644
@@ -603,13 +603,6 @@ struct perf_event {
 	 */
 	struct list_head		group_list;
 	/*
-	 * Entry into the group_list list above;
-	 * the entry may be attached to the self group_list list above
-	 * in case the event is directly attached to the tree;
-	 */
-	struct list_head		group_list_entry;
-
-	/*
 	 * We need storage to track the entries in perf_pmu_migrate_context; we
 	 * cannot use the event_entry because of RCU and we want to keep the
 	 * group in tact which avoids us using the other two entries.
@@ -749,15 +742,6 @@ struct perf_event {
 #endif /* CONFIG_PERF_EVENTS */
 };
 
-/*
- * event groups keep group leader events arranged as an rb tree with
- * event->cpu key and as a list for the whole tree iterations;
- */
-struct perf_event_groups {
-	struct list_head list;
-	struct rb_root	 tree;
-};
-
 /**
  * struct perf_event_context - event context structure
  *
@@ -778,8 +762,8 @@ struct perf_event_context {
 	struct mutex			mutex;
 
 	struct list_head		active_ctx_list;
-	struct perf_event_groups	pinned_groups;
-	struct perf_event_groups	flexible_groups;
+	struct rb_root			pinned_groups;
+	struct rb_root			flexible_groups;
 	struct list_head		event_list;
 	int				nr_events;
 	int				nr_active;
kernel/events/core.c +32 -60

215 lines not on this page · raw message

 include/linux/perf_event.h |  55 +++--
 kernel/events/core.c       | 604 +++++++++++++++++++++++++++++++++------------
 2 files changed, 491 insertions(+), 168 deletions(-)
include/linux/perf_event.h +40 -15

86 lines not on this page · raw message

kernel/events/core.c +451 -153

1,037 lines not on this page · raw message