Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf/core: Hoist perf_instruction_pointer() and perf_misc_flags()

For clarity, rename the arch-specific definitions of these functions
to perf_arch_* to denote they are arch-specifc. Define the
generic-named functions in one place where they can call the
arch-specific ones as needed.

Signed-off-by: Colton Lewis <coltonlewis@google.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Acked-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Acked-by: Kan Liang <kan.liang@linux.intel.com>
Link: https://lore.kernel.org/r/20241113190156.2145593-3-coltonlewis@google.com

authored by

Colton Lewis and committed by
Ingo Molnar
04782e63 e33ed362

+38 -25
+3 -3
arch/arm64/include/asm/perf_event.h
··· 11 11 12 12 #ifdef CONFIG_PERF_EVENTS 13 13 struct pt_regs; 14 - extern unsigned long perf_instruction_pointer(struct pt_regs *regs); 15 - extern unsigned long perf_misc_flags(struct pt_regs *regs); 16 - #define perf_misc_flags(regs) perf_misc_flags(regs) 14 + extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); 15 + extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); 16 + #define perf_arch_misc_flags(regs) perf_misc_flags(regs) 17 17 #define perf_arch_bpf_user_pt_regs(regs) &regs->user_regs 18 18 #endif 19 19
+2 -2
arch/arm64/kernel/perf_callchain.c
··· 39 39 arch_stack_walk(callchain_trace, entry, current, regs); 40 40 } 41 41 42 - unsigned long perf_instruction_pointer(struct pt_regs *regs) 42 + unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) 43 43 { 44 44 if (perf_guest_state()) 45 45 return perf_guest_get_ip(); ··· 47 47 return instruction_pointer(regs); 48 48 } 49 49 50 - unsigned long perf_misc_flags(struct pt_regs *regs) 50 + unsigned long perf_arch_misc_flags(struct pt_regs *regs) 51 51 { 52 52 unsigned int guest_state = perf_guest_state(); 53 53 int misc = 0;
+3 -3
arch/powerpc/include/asm/perf_event_server.h
··· 102 102 int __init register_power_pmu(struct power_pmu *pmu); 103 103 104 104 struct pt_regs; 105 - extern unsigned long perf_misc_flags(struct pt_regs *regs); 106 - extern unsigned long perf_instruction_pointer(struct pt_regs *regs); 105 + extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); 106 + extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); 107 107 extern unsigned long int read_bhrb(int n); 108 108 109 109 /* ··· 111 111 * if we have hardware PMU support. 112 112 */ 113 113 #ifdef CONFIG_PPC_PERF_CTRS 114 - #define perf_misc_flags(regs) perf_misc_flags(regs) 114 + #define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs) 115 115 #endif 116 116 117 117 /*
+2 -2
arch/powerpc/perf/core-book3s.c
··· 2332 2332 * Called from generic code to get the misc flags (i.e. processor mode) 2333 2333 * for an event_id. 2334 2334 */ 2335 - unsigned long perf_misc_flags(struct pt_regs *regs) 2335 + unsigned long perf_arch_misc_flags(struct pt_regs *regs) 2336 2336 { 2337 2337 u32 flags = perf_get_misc_flags(regs); 2338 2338 ··· 2346 2346 * Called from generic code to get the instruction pointer 2347 2347 * for an event_id. 2348 2348 */ 2349 - unsigned long perf_instruction_pointer(struct pt_regs *regs) 2349 + unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) 2350 2350 { 2351 2351 unsigned long siar = mfspr(SPRN_SIAR); 2352 2352
+3 -3
arch/s390/include/asm/perf_event.h
··· 37 37 38 38 /* Perf callbacks */ 39 39 struct pt_regs; 40 - extern unsigned long perf_instruction_pointer(struct pt_regs *regs); 41 - extern unsigned long perf_misc_flags(struct pt_regs *regs); 42 - #define perf_misc_flags(regs) perf_misc_flags(regs) 40 + extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); 41 + extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); 42 + #define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs) 43 43 #define perf_arch_bpf_user_pt_regs(regs) &regs->user_regs 44 44 45 45 /* Perf pt_regs extension for sample-data-entry indicators */
+2 -2
arch/s390/kernel/perf_event.c
··· 57 57 return sie_block(regs)->gpsw.addr; 58 58 } 59 59 60 - unsigned long perf_instruction_pointer(struct pt_regs *regs) 60 + unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) 61 61 { 62 62 return is_in_guest(regs) ? instruction_pointer_guest(regs) 63 63 : instruction_pointer(regs); ··· 84 84 return flags; 85 85 } 86 86 87 - unsigned long perf_misc_flags(struct pt_regs *regs) 87 + unsigned long perf_arch_misc_flags(struct pt_regs *regs) 88 88 { 89 89 /* Check if the cpum_sf PMU has created the pt_regs structure. 90 90 * In this case, perf misc flags can be easily extracted. Otherwise,
+2 -2
arch/x86/events/core.c
··· 3003 3003 return 0; 3004 3004 } 3005 3005 3006 - unsigned long perf_instruction_pointer(struct pt_regs *regs) 3006 + unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) 3007 3007 { 3008 3008 if (perf_guest_state()) 3009 3009 return perf_guest_get_ip(); ··· 3011 3011 return regs->ip + code_segment_base(regs); 3012 3012 } 3013 3013 3014 - unsigned long perf_misc_flags(struct pt_regs *regs) 3014 + unsigned long perf_arch_misc_flags(struct pt_regs *regs) 3015 3015 { 3016 3016 unsigned int guest_state = perf_guest_state(); 3017 3017 int misc = 0;
+5 -5
arch/x86/include/asm/perf_event.h
··· 536 536 u64 *xmm_regs; 537 537 }; 538 538 539 - extern unsigned long perf_instruction_pointer(struct pt_regs *regs); 540 - extern unsigned long perf_misc_flags(struct pt_regs *regs); 541 - #define perf_misc_flags(regs) perf_misc_flags(regs) 539 + extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); 540 + extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); 541 + #define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs) 542 542 543 543 #include <asm/stacktrace.h> 544 544 545 545 /* 546 - * We abuse bit 3 from flags to pass exact information, see perf_misc_flags 547 - * and the comment with PERF_EFLAGS_EXACT. 546 + * We abuse bit 3 from flags to pass exact information, see 547 + * perf_arch_misc_flags() and the comment with PERF_EFLAGS_EXACT. 548 548 */ 549 549 #define perf_arch_fetch_caller_regs(regs, __ip) { \ 550 550 (regs)->ip = (__ip); \
+6 -3
include/linux/perf_event.h
··· 1676 1676 struct task_struct *task); 1677 1677 extern void perf_bp_event(struct perf_event *event, void *data); 1678 1678 1679 - #ifndef perf_misc_flags 1680 - # define perf_misc_flags(regs) \ 1679 + extern unsigned long perf_misc_flags(struct pt_regs *regs); 1680 + extern unsigned long perf_instruction_pointer(struct pt_regs *regs); 1681 + 1682 + #ifndef perf_arch_misc_flags 1683 + # define perf_arch_misc_flags(regs) \ 1681 1684 (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL) 1682 - # define perf_instruction_pointer(regs) instruction_pointer(regs) 1685 + # define perf_arch_instruction_pointer(regs) instruction_pointer(regs) 1683 1686 #endif 1684 1687 #ifndef perf_arch_bpf_user_pt_regs 1685 1688 # define perf_arch_bpf_user_pt_regs(regs) regs
+10
kernel/events/core.c
··· 7026 7026 EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks); 7027 7027 #endif 7028 7028 7029 + unsigned long perf_misc_flags(struct pt_regs *regs) 7030 + { 7031 + return perf_arch_misc_flags(regs); 7032 + } 7033 + 7034 + unsigned long perf_instruction_pointer(struct pt_regs *regs) 7035 + { 7036 + return perf_arch_instruction_pointer(regs); 7037 + } 7038 + 7029 7039 static void 7030 7040 perf_output_sample_regs(struct perf_output_handle *handle, 7031 7041 struct pt_regs *regs, u64 mask)