[RFC PATCH] perf/core: exposing type of context-switch-out event

From: Alexey Budankov
Date: Thu Mar 01 2018 - 10:40:23 EST


Hi,

This patch prototypes exposing the type of context-switch-out event using
PERF_RECORD_MISC_EXT_RESERVED bit for PERF_RECORD_SWITCH[_CPU_WIDE] records.

Types of context-switch-out events introduced by the patch meant to be
a) preempted (task->state == TASK_RUNNING) or b) yielded == !preempted;

The changes have been manually tested on Fedora 27 with the patched kernel:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf/core

Signed-off-by: Alexey Budankov <alexey.budankov@xxxxxxxxxxxxxxx>
---
kernel/events/core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 57898102847f..e3ca597f4e2b 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7216,6 +7216,8 @@ static void perf_event_switch(struct task_struct *task,
struct task_struct *next_prev, bool sched_in)
{
struct perf_switch_event switch_event;
+ __u16 switch_type = sched_in ? 0 : PERF_RECORD_MISC_SWITCH_OUT |
+ (task->state == TASK_RUNNING ? 0 : PERF_RECORD_MISC_EXT_RESERVED);

/* N.B. caller checks nr_switch_events != 0 */

@@ -7225,7 +7227,7 @@ static void perf_event_switch(struct task_struct *task,
.event_id = {
.header = {
/* .type */
- .misc = sched_in ? 0 : PERF_RECORD_MISC_SWITCH_OUT,
+ .misc = switch_type,
/* .size */
},
/* .next_prev_pid */