Skip to content

Commit 101592b

Browse files
Alexey Budankovacmel
authored andcommitted
perf/core: Store context switch out type in PERF_RECORD_SWITCH[_CPU_WIDE]
Store preempting context switch out event into Perf trace as a part of PERF_RECORD_SWITCH[_CPU_WIDE] record. Percentage of preempting and non-preempting context switches help understanding the nature of workloads (CPU or IO bound) that are running on a machine; The event is treated as preemption one when task->state value of the thread being switched out is TASK_RUNNING. Event type encoding is implemented using PERF_RECORD_MISC_SWITCH_OUT_PREEMPT bit; Signed-off-by: Alexey Budankov <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent e2f73a1 commit 101592b

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

include/uapi/linux/perf_event.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,11 +650,23 @@ struct perf_event_mmap_page {
650650
#define PERF_RECORD_MISC_COMM_EXEC (1 << 13)
651651
#define PERF_RECORD_MISC_SWITCH_OUT (1 << 13)
652652
/*
653-
* Indicates that the content of PERF_SAMPLE_IP points to
654-
* the actual instruction that triggered the event. See also
655-
* perf_event_attr::precise_ip.
653+
* These PERF_RECORD_MISC_* flags below are safely reused
654+
* for the following events:
655+
*
656+
* PERF_RECORD_MISC_EXACT_IP - PERF_RECORD_SAMPLE of precise events
657+
* PERF_RECORD_MISC_SWITCH_OUT_PREEMPT - PERF_RECORD_SWITCH* events
658+
*
659+
*
660+
* PERF_RECORD_MISC_EXACT_IP:
661+
* Indicates that the content of PERF_SAMPLE_IP points to
662+
* the actual instruction that triggered the event. See also
663+
* perf_event_attr::precise_ip.
664+
*
665+
* PERF_RECORD_MISC_SWITCH_OUT_PREEMPT:
666+
* Indicates that thread was preempted in TASK_RUNNING state.
656667
*/
657668
#define PERF_RECORD_MISC_EXACT_IP (1 << 14)
669+
#define PERF_RECORD_MISC_SWITCH_OUT_PREEMPT (1 << 14)
658670
/*
659671
* Reserve the last bit to indicate some extended misc field
660672
*/

kernel/events/core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7587,6 +7587,10 @@ static void perf_event_switch(struct task_struct *task,
75877587
},
75887588
};
75897589

7590+
if (!sched_in && task->state == TASK_RUNNING)
7591+
switch_event.event_id.header.misc |=
7592+
PERF_RECORD_MISC_SWITCH_OUT_PREEMPT;
7593+
75907594
perf_iterate_sb(perf_event_switch_output,
75917595
&switch_event,
75927596
NULL);

tools/include/uapi/linux/perf_event.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,11 +650,23 @@ struct perf_event_mmap_page {
650650
#define PERF_RECORD_MISC_COMM_EXEC (1 << 13)
651651
#define PERF_RECORD_MISC_SWITCH_OUT (1 << 13)
652652
/*
653-
* Indicates that the content of PERF_SAMPLE_IP points to
654-
* the actual instruction that triggered the event. See also
655-
* perf_event_attr::precise_ip.
653+
* These PERF_RECORD_MISC_* flags below are safely reused
654+
* for the following events:
655+
*
656+
* PERF_RECORD_MISC_EXACT_IP - PERF_RECORD_SAMPLE of precise events
657+
* PERF_RECORD_MISC_SWITCH_OUT_PREEMPT - PERF_RECORD_SWITCH* events
658+
*
659+
*
660+
* PERF_RECORD_MISC_EXACT_IP:
661+
* Indicates that the content of PERF_SAMPLE_IP points to
662+
* the actual instruction that triggered the event. See also
663+
* perf_event_attr::precise_ip.
664+
*
665+
* PERF_RECORD_MISC_SWITCH_OUT_PREEMPT:
666+
* Indicates that thread was preempted in TASK_RUNNING state.
656667
*/
657668
#define PERF_RECORD_MISC_EXACT_IP (1 << 14)
669+
#define PERF_RECORD_MISC_SWITCH_OUT_PREEMPT (1 << 14)
658670
/*
659671
* Reserve the last bit to indicate some extended misc field
660672
*/

0 commit comments

Comments
 (0)