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

perf tests sigtrap: Skip if running on a kernel with sleepable spinlocks

There are issues as reported that need some more investigation on the
RT kernel front, till that is addressed, skip this test.

This test is already skipped for multiple hardware architectures where
the tested kernel feature is not supported.

Acked-by: Marco Elver <elver@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Clark Williams <williams@redhat.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Kate Carcia <kcarcia@redhat.com>
Cc: Marco Elver <elver@google.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/e368f2c848d77fbc8d259f44e2055fe469c219cf.camel@gmx.de/
Link: https://lore.kernel.org/r/20231129154718.326330-3-acme@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+44 -2
+44 -2
tools/perf/tests/sigtrap.c
··· 103 103 104 104 return __btf_type__find_member_by_name(id, "sigtrap") != NULL; 105 105 } 106 + 107 + static bool kernel_with_sleepable_spinlocks(void) 108 + { 109 + const struct btf_member *member; 110 + const struct btf_type *type; 111 + const char *type_name; 112 + int id; 113 + 114 + if (!btf__available()) 115 + return false; 116 + 117 + id = btf__find_by_name_kind(btf, "spinlock", BTF_KIND_STRUCT); 118 + if (id < 0) 119 + return false; 120 + 121 + // Only RT has a "lock" member for "struct spinlock" 122 + member = __btf_type__find_member_by_name(id, "lock"); 123 + if (member == NULL) 124 + return false; 125 + 126 + // But check its type as well 127 + type = btf__type_by_id(btf, member->type); 128 + if (!type || !btf_is_struct(type)) 129 + return false; 130 + 131 + type_name = btf__name_by_offset(btf, type->name_off); 132 + return type_name && !strcmp(type_name, "rt_mutex_base"); 133 + } 106 134 #else /* !HAVE_BPF_SKEL */ 107 135 static bool attr_has_sigtrap(void) 108 136 { ··· 151 123 } 152 124 153 125 return ret; 126 + } 127 + 128 + static bool kernel_with_sleepable_spinlocks(void) 129 + { 130 + return false; 154 131 } 155 132 156 133 static void btf__exit(void) ··· 199 166 200 167 static int run_stress_test(int fd, pthread_t *threads, pthread_barrier_t *barrier) 201 168 { 202 - int ret; 169 + int ret, expected_sigtraps; 203 170 204 171 ctx.iterate_on = 3000; 205 172 ··· 208 175 ret = run_test_threads(threads, barrier); 209 176 TEST_ASSERT_EQUAL("disable failed", ioctl(fd, PERF_EVENT_IOC_DISABLE, 0), 0); 210 177 211 - TEST_ASSERT_EQUAL("unexpected sigtraps", ctx.signal_count, NUM_THREADS * ctx.iterate_on); 178 + expected_sigtraps = NUM_THREADS * ctx.iterate_on; 179 + 180 + if (ctx.signal_count < expected_sigtraps && kernel_with_sleepable_spinlocks()) { 181 + pr_debug("Expected %d sigtraps, got %d, running on a kernel with sleepable spinlocks.\n", 182 + expected_sigtraps, ctx.signal_count); 183 + pr_debug("See https://lore.kernel.org/all/e368f2c848d77fbc8d259f44e2055fe469c219cf.camel@gmx.de/\n"); 184 + return TEST_SKIP; 185 + } else 186 + TEST_ASSERT_EQUAL("unexpected sigtraps", ctx.signal_count, expected_sigtraps); 187 + 212 188 TEST_ASSERT_EQUAL("missing signals or incorrectly delivered", ctx.tids_want_signal, 0); 213 189 TEST_ASSERT_VAL("unexpected si_addr", ctx.first_siginfo.si_addr == &ctx.iterate_on); 214 190 #if 0 /* FIXME: enable when libc's signal.h has si_perf_{type,data} */