Skip to contentSkip to conversation

perf/cgroup: Do not switch system-wide events in cgroup switch

PATCH New [email protected] 1 participant 1 message Aug 7, 2019 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 perf/cgroup: Do not switch system-wide events in cgroup switch

From: Kan Liang <[email protected]>

When counting system-wide events and cgroup events simultaneously, the system-wide events are always scheduled during cgroup switch, which is wrong and brings extra overhead.

Both system-wide and cgroup are per-cpu. They share the same cpuctx groups, cpuctx->flexible_groups/pinned_groups.
In context switch, cgroup switch tries to schedule all the events from the cpuctx groups. The unmatched cgroup events can be filtered by its event->cgrp. However, system-wide events, which event->cgrp is NULL, are unconditionally scheduled. It will bring extra overhead. Furthermore, the small period between the prev cgroup schedule out and the new cgroup schedule in will be missed for system-wide events.

Add new event type EVENT_CGROUP_FLEXIBLE_ONLY, EVENT_CGROUP_PINNED_ONLY, and EVENT_CGROUP_ALL_ONLY.
- EVENT_FLEXIBLE | EVENT_CGROUP_FLEXIBLE_ONLY: Only switch cgroup events from EVENT_FLEXIBLE groups.
- EVENT_PINNED | EVENT_CGROUP_PINNED_ONLY: Only switch cgroup events from EVENT_PINNED groups.
- EVENT_ALL | EVENT_CGROUP_ALL_ONLY: Only switch cgroup events from both EVENT_FLEXIBLE and EVENT_PINNED groups.
For cgroup schedule out, only cgroup events are scheduled out now. For cgroup schedule in, to keep the priority order (cpu pinned, cpu flexible), the event type of the new cgroup has to be checked. If the new cgroup and its ancestor have pinned events, the flexible system-wide events have to be scheduled out before all events schedule in, which give the pinned events the best chance to be scheduled. Otherwise, only cgroup events are scheduled in.
Add nr_pinned_event to track the number of pinned event in a cgroup.

Here is test with 6 child cgroups (sibling cgroups), 1 parent cgroup and system-wide events.
A specjbb benchmark is running in each child cgroup.
The perf command is as below.
perf stat -e cycles,instructions -e cycles,instructions -e cycles,instructions -e cycles,instructions
-e cycles,instructions -e cycles,instructions
-e cycles,instructions -e cycles,instructions
-G cgroup1,cgroup1,cgroup2,cgroup2,cgroup3,cgroup3
-G cgroup4,cgroup4,cgroup5,cgroup5,cgroup6,cgroup6
-G cgroup_parent,cgroup_parent
-a -e cycles,instructions -I 1000

The average RT (Response Time) reported from specjbb is used as key performance metrics. (The lower the better)
RT(us) Overhead

Baseline (no perf stat):                4286.9
Use cgroup perf, no patches:            4537.1                5.84%
Use cgroup perf, apply the patch:       4440.7                3.59%
Fixes e5d1367f17ba ("perf: Add cgroup support")

---

The patch is originally from ("Optimize cgroup context switch") series.
https://lkml.kernel.org/r/[email protected]
The series tried to address two issues.
1. System-wide events are mistakenly scheduled during cgroup context switch.
2. The cgroup context switch sched_in is low efficient.

Now, Ian Rogers has taken over the patches for the second issue.
https://lkml.kernel.org/r/[email protected]

This patch is to fix the first issue.

Changes since V2:
- Modify the change log.
Move the performance data from cover letter into changelog.
- Add nr_pinned_event to track the number of pinned event in a cgroup. Check the pinned event for the new cgroup and its ancestor before schedule in.

 include/linux/perf_event.h |   1 +
 kernel/events/core.c       | 126 +++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 116 insertions(+), 11 deletions(-)
include/linux/perf_event.h +1 -0
index e8ad3c5..ebb27ed 100644
@@ -843,6 +843,7 @@ struct perf_cgroup_info {
 struct perf_cgroup {
 	struct cgroup_subsys_state	css;
 	struct perf_cgroup_info	__percpu *info;
+	unsigned int			nr_pinned_event;
 };
 
 /*
kernel/events/core.c +115 -11

248 lines not on this page · raw message

Signature · 1 line
2.7.4