Skip to content

Commit 9caf87b

Browse files
melverPeter Zijlstra
authored andcommitted
perf/hw_breakpoint: Make hw_breakpoint_weight() inlinable
Due to being a __weak function, hw_breakpoint_weight() will cause the compiler to always emit a call to it. This generates unnecessarily bad code (register spills etc.) for no good reason; in fact it appears in profiles of `perf bench -r 100 breakpoint thread -b 4 -p 128 -t 512`: ... 0.70% [kernel] [k] hw_breakpoint_weight ... While a small percentage, no architecture defines its own hw_breakpoint_weight() nor are there users outside hw_breakpoint.c, which makes the fact it is currently __weak a poor choice. Change hw_breakpoint_weight()'s definition to follow a similar protocol to hw_breakpoint_slots(), such that if <asm/hw_breakpoint.h> defines hw_breakpoint_weight(), we'll use it instead. The result is that it is inlined and no longer shows up in profiles. Signed-off-by: Marco Elver <elver@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com> Acked-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20220829124719.675715-8-elver@google.com
1 parent be3f152 commit 9caf87b

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

include/linux/hw_breakpoint.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ extern int dbg_reserve_bp_slot(struct perf_event *bp);
8080
extern int dbg_release_bp_slot(struct perf_event *bp);
8181
extern int reserve_bp_slot(struct perf_event *bp);
8282
extern void release_bp_slot(struct perf_event *bp);
83-
int hw_breakpoint_weight(struct perf_event *bp);
8483
int arch_reserve_bp_slot(struct perf_event *bp);
8584
void arch_release_bp_slot(struct perf_event *bp);
8685
void arch_unregister_hw_breakpoint(struct perf_event *bp);

kernel/events/hw_breakpoint.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@ static __init int init_breakpoint_slots(void)
124124
}
125125
#endif
126126

127-
__weak int hw_breakpoint_weight(struct perf_event *bp)
127+
#ifndef hw_breakpoint_weight
128+
static inline int hw_breakpoint_weight(struct perf_event *bp)
128129
{
129130
return 1;
130131
}
132+
#endif
131133

132134
static inline enum bp_type_idx find_slot_idx(u64 bp_type)
133135
{

0 commit comments

Comments
 (0)