perf/hw_breakpoint: Provide hw_breakpoint_is_used() and use in test
Provide hw_breakpoint_is_used() to check if breakpoints are in use on the system. Use it in the KUnit test to verify the global state before and after a test case. 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-3-elver@google.com
This commit is contained in:
Родитель
724c299c6a
Коммит
c5b81449f9
|
@ -74,6 +74,7 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr,
|
|||
extern int register_perf_hw_breakpoint(struct perf_event *bp);
|
||||
extern void unregister_hw_breakpoint(struct perf_event *bp);
|
||||
extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events);
|
||||
extern bool hw_breakpoint_is_used(void);
|
||||
|
||||
extern int dbg_reserve_bp_slot(struct perf_event *bp);
|
||||
extern int dbg_release_bp_slot(struct perf_event *bp);
|
||||
|
@ -121,6 +122,8 @@ register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
|
|||
static inline void unregister_hw_breakpoint(struct perf_event *bp) { }
|
||||
static inline void
|
||||
unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events) { }
|
||||
static inline bool hw_breakpoint_is_used(void) { return false; }
|
||||
|
||||
static inline int
|
||||
reserve_bp_slot(struct perf_event *bp) {return -ENOSYS; }
|
||||
static inline void release_bp_slot(struct perf_event *bp) { }
|
||||
|
|
|
@ -604,6 +604,35 @@ void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events)
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(unregister_wide_hw_breakpoint);
|
||||
|
||||
/**
|
||||
* hw_breakpoint_is_used - check if breakpoints are currently used
|
||||
*
|
||||
* Returns: true if breakpoints are used, false otherwise.
|
||||
*/
|
||||
bool hw_breakpoint_is_used(void)
|
||||
{
|
||||
int cpu;
|
||||
|
||||
if (!constraints_initialized)
|
||||
return false;
|
||||
|
||||
for_each_possible_cpu(cpu) {
|
||||
for (int type = 0; type < TYPE_MAX; ++type) {
|
||||
struct bp_cpuinfo *info = get_bp_info(cpu, type);
|
||||
|
||||
if (info->cpu_pinned)
|
||||
return true;
|
||||
|
||||
for (int slot = 0; slot < nr_slots[type]; ++slot) {
|
||||
if (info->tsk_pinned[slot])
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static struct notifier_block hw_breakpoint_exceptions_nb = {
|
||||
.notifier_call = hw_breakpoint_exceptions_notify,
|
||||
/* we need to be notified first */
|
||||
|
|
|
@ -294,7 +294,14 @@ static struct kunit_case hw_breakpoint_test_cases[] = {
|
|||
static int test_init(struct kunit *test)
|
||||
{
|
||||
/* Most test cases want 2 distinct CPUs. */
|
||||
return num_online_cpus() < 2 ? -EINVAL : 0;
|
||||
if (num_online_cpus() < 2)
|
||||
return -EINVAL;
|
||||
|
||||
/* Want the system to not use breakpoints elsewhere. */
|
||||
if (hw_breakpoint_is_used())
|
||||
return -EBUSY;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_exit(struct kunit *test)
|
||||
|
@ -308,6 +315,9 @@ static void test_exit(struct kunit *test)
|
|||
kthread_stop(__other_task);
|
||||
__other_task = NULL;
|
||||
}
|
||||
|
||||
/* Verify that internal state agrees that no breakpoints are in use. */
|
||||
KUNIT_EXPECT_FALSE(test, hw_breakpoint_is_used());
|
||||
}
|
||||
|
||||
static struct kunit_suite hw_breakpoint_test_suite = {
|
||||
|
|
Загрузка…
Ссылка в новой задаче