Skip to content

Commit baff01f

Browse files
coltonlewisIngo Molnar
authored andcommitted
perf/x86: Refactor misc flag assignments
Break the assignment logic for misc flags into their own respective functions to reduce the complexity of the nested logic. Signed-off-by: Colton Lewis <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Acked-by: Kan Liang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3e807cf commit baff01f

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

arch/x86/events/core.c

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,27 +3011,52 @@ unsigned long perf_arch_instruction_pointer(struct pt_regs *regs)
30113011
return regs->ip + code_segment_base(regs);
30123012
}
30133013

3014-
unsigned long perf_arch_misc_flags(struct pt_regs *regs)
3014+
static unsigned long common_misc_flags(struct pt_regs *regs)
30153015
{
3016-
unsigned int guest_state = perf_guest_state();
3017-
int misc = 0;
3016+
if (regs->flags & PERF_EFLAGS_EXACT)
3017+
return PERF_RECORD_MISC_EXACT_IP;
30183018

3019-
if (guest_state) {
3020-
if (guest_state & PERF_GUEST_USER)
3021-
misc |= PERF_RECORD_MISC_GUEST_USER;
3022-
else
3023-
misc |= PERF_RECORD_MISC_GUEST_KERNEL;
3024-
} else {
3025-
if (user_mode(regs))
3026-
misc |= PERF_RECORD_MISC_USER;
3027-
else
3028-
misc |= PERF_RECORD_MISC_KERNEL;
3029-
}
3019+
return 0;
3020+
}
30303021

3031-
if (regs->flags & PERF_EFLAGS_EXACT)
3032-
misc |= PERF_RECORD_MISC_EXACT_IP;
3022+
static unsigned long guest_misc_flags(struct pt_regs *regs)
3023+
{
3024+
unsigned long guest_state = perf_guest_state();
3025+
3026+
if (!(guest_state & PERF_GUEST_ACTIVE))
3027+
return 0;
3028+
3029+
if (guest_state & PERF_GUEST_USER)
3030+
return PERF_RECORD_MISC_GUEST_USER;
3031+
else
3032+
return PERF_RECORD_MISC_GUEST_KERNEL;
3033+
3034+
}
3035+
3036+
static unsigned long host_misc_flags(struct pt_regs *regs)
3037+
{
3038+
if (user_mode(regs))
3039+
return PERF_RECORD_MISC_USER;
3040+
else
3041+
return PERF_RECORD_MISC_KERNEL;
3042+
}
3043+
3044+
unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs)
3045+
{
3046+
unsigned long flags = common_misc_flags(regs);
3047+
3048+
flags |= guest_misc_flags(regs);
3049+
3050+
return flags;
3051+
}
3052+
3053+
unsigned long perf_arch_misc_flags(struct pt_regs *regs)
3054+
{
3055+
unsigned long flags = common_misc_flags(regs);
3056+
3057+
flags |= host_misc_flags(regs);
30333058

3034-
return misc;
3059+
return flags;
30353060
}
30363061

30373062
void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap)

arch/x86/include/asm/perf_event.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,9 @@ struct x86_perf_regs {
538538

539539
extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs);
540540
extern unsigned long perf_arch_misc_flags(struct pt_regs *regs);
541+
extern unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs);
541542
#define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs)
543+
#define perf_arch_guest_misc_flags(regs) perf_arch_guest_misc_flags(regs)
542544

543545
#include <asm/stacktrace.h>
544546

0 commit comments

Comments
 (0)