Skip to contentSkip to conversation

Patch "perf/core: Fix ctx_event_type in ctx_resched()" has been added to the 4.14-stable tree

PATCH [email protected] 1 participant 1 message Mar 27, 2018

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

perf/core: Fix ctx_event_type in ctx_resched()

to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
perf-core-fix-ctx_event_type-in-ctx_resched.patch
and it can be found in the queue-4.14 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From bd903afeb504db5655a45bb4cf86f38be5b1bf62 Mon Sep 17 00:00:00 2001

From: Song Liu <[email protected]>
Date: Mon, 5 Mar 2018 21:55:04 -0800
Subject: perf/core: Fix ctx_event_type in ctx_resched()

From: Song Liu <[email protected]>

commit bd903afeb504db5655a45bb4cf86f38be5b1bf62 upstream.

In ctx_resched(), EVENT_FLEXIBLE should be sched_out when EVENT_PINNED is added. However, ctx_resched() calculates ctx_event_type before checking this condition. As a result, pinned events will NOT get higher priority than flexible events.

The following shows this issue on an Intel CPU (where ref-cycles can only use one hardware counter).

1. First start:
perf stat -C 0 -e ref-cycles -I 1000
2. Then, in the second console, run:

       perf stat -C 0 -e ref-cycles:D -I 1000

The second perf uses pinned events, which is expected to have higher priority. However, because it failed in ctx_resched(). It is never run.

This patch fixes this by calculating ctx_event_type after re-evaluating event_type.

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Vince Weaver <[email protected]>
Fixes 487f05e18aa4 ("perf/core: Optimize event rescheduling on active contexts")
---
 kernel/events/core.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/events/core.c +3 -1
@@ -2322,7 +2322,7 @@ static void ctx_resched(struct perf_cpu_
 			struct perf_event_context *task_ctx,
 			enum event_type_t event_type)
 {
-	enum event_type_t ctx_event_type = event_type & EVENT_ALL;
+	enum event_type_t ctx_event_type;
 	bool cpu_event = !!(event_type & EVENT_CPU);
 
 	/*
@@ -2332,6 +2332,8 @@ static void ctx_resched(struct perf_cpu_
 	if (event_type & EVENT_PINNED)
 		event_type |= EVENT_FLEXIBLE;
 
+	ctx_event_type = event_type & EVENT_ALL;
+
 	perf_pmu_disable(cpuctx->ctx.pmu);
 	if (task_ctx)
 		task_ctx_sched_out(cpuctx, task_ctx, event_type);

Patches currently in stable-queue which might be from [email protected] are

queue-4.14/perf-core-fix-ctx_event_type-in-ctx_resched.patch