2018-03-01 15:41:11

by Alexey Budankov

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

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 <[email protected]>
---
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 */


2018-03-01 18:09:19

by Andi Kleen

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

On Thu, Mar 01, 2018 at 06:40:04PM +0300, Alexey Budankov wrote:
> 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.

It would be better to define an actually named bit in perf_event.h.
It can be the same value.

Also we would need a patch for perf script / perf report -D to print this
information.

The rest looks good to me.

-Andi

2018-03-01 19:31:17

by Milian Wolff

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

On Donnerstag, 1. M?rz 2018 19:08:05 CET Andi Kleen wrote:
> On Thu, Mar 01, 2018 at 06:40:04PM +0300, Alexey Budankov wrote:
> > 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.
> It would be better to define an actually named bit in perf_event.h.
> It can be the same value.
>
> Also we would need a patch for perf script / perf report -D to print this
> information.
>
> The rest looks good to me.

Please also add documentation Documentation/perf.data-file-format.txt, but I
just noticed that not even PERF_RECORD_SWITCH is documented there...

Otherwise I also think that this would be a very nice feature addition!

--
Milian Wolff | [email protected] | Senior Software Engineer
KDAB (Deutschland) GmbH, a KDAB Group company
Tel: +49-30-521325470
KDAB - The Qt, C++ and OpenGL Experts


Attachments:
smime.p7s (3.74 kB)

2018-03-01 19:39:52

by Andi Kleen

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

> Please also add documentation Documentation/perf.data-file-format.txt, but I
> just noticed that not even PERF_RECORD_SWITCH is documented there...

That file only covers fields not generated by the kernel, but this
is coming from the kernel.

Kernel records are documented in the manpage, but Vince usually updates
that on his own.

-Andi

2018-03-01 20:58:38

by Milian Wolff

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

On Donnerstag, 1. M?rz 2018 20:36:59 CET Andi Kleen wrote:
> > Please also add documentation Documentation/perf.data-file-format.txt, but
> > I just noticed that not even PERF_RECORD_SWITCH is documented there...
>
> That file only covers fields not generated by the kernel, but this
> is coming from the kernel.
>
> Kernel records are documented in the manpage, but Vince usually updates
> that on his own.

Ah, TIL - thanks for that tip! But I still think it would be good to have a
complete documentation of the perf.data file format in one place. I guess
patches would be welcome to add more aspects of the file format there, even if
it's generated by the kernel? That helps for thirdparty tools that parse the
perf.data files (like perfparser used by QtCreator and hotspot).

Cheers

--
Milian Wolff | [email protected] | Senior Software Engineer
KDAB (Deutschland) GmbH, a KDAB Group company
Tel: +49-30-521325470
KDAB - The Qt, C++ and OpenGL Experts


Attachments:
smime.p7s (3.74 kB)