Skip to content

Commit 3448375

Browse files
kkdwvdAlexei Starovoitov
authored andcommitted
selftests/bpf: Add success stats to rqspinlock stress test
Add stats to observe the success and failure rate of lock acquisition attempts in various contexts. Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 087849c commit 3448375

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

tools/testing/selftests/bpf/test_kmods/bpf_test_rqspinlock.c

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@ static const unsigned int rqsl_hist_ms[] = {
3333
};
3434
#define RQSL_NR_HIST_BUCKETS ARRAY_SIZE(rqsl_hist_ms)
3535

36+
enum rqsl_context {
37+
RQSL_CTX_NORMAL = 0,
38+
RQSL_CTX_NMI,
39+
RQSL_CTX_MAX,
40+
};
41+
3642
struct rqsl_cpu_hist {
37-
atomic64_t normal[RQSL_NR_HIST_BUCKETS];
38-
atomic64_t nmi[RQSL_NR_HIST_BUCKETS];
43+
atomic64_t hist[RQSL_CTX_MAX][RQSL_NR_HIST_BUCKETS];
44+
atomic64_t success[RQSL_CTX_MAX];
45+
atomic64_t failure[RQSL_CTX_MAX];
3946
};
4047

4148
static DEFINE_PER_CPU(struct rqsl_cpu_hist, rqsl_cpu_hists);
@@ -117,14 +124,18 @@ static u32 rqsl_hist_bucket_idx(u32 delta_ms)
117124
return RQSL_NR_HIST_BUCKETS - 1;
118125
}
119126

120-
static void rqsl_record_lock_time(u64 delta_ns, bool is_nmi)
127+
static void rqsl_record_lock_result(u64 delta_ns, enum rqsl_context ctx, int ret)
121128
{
122129
struct rqsl_cpu_hist *hist = this_cpu_ptr(&rqsl_cpu_hists);
123130
u32 delta_ms = DIV_ROUND_UP_ULL(delta_ns, NSEC_PER_MSEC);
124131
u32 bucket = rqsl_hist_bucket_idx(delta_ms);
125-
atomic64_t *buckets = is_nmi ? hist->nmi : hist->normal;
132+
atomic64_t *buckets = hist->hist[ctx];
126133

127134
atomic64_inc(&buckets[bucket]);
135+
if (!ret)
136+
atomic64_inc(&hist->success[ctx]);
137+
else
138+
atomic64_inc(&hist->failure[ctx]);
128139
}
129140

130141
static int rqspinlock_worker_fn(void *arg)
@@ -147,7 +158,8 @@ static int rqspinlock_worker_fn(void *arg)
147158
}
148159
start_ns = ktime_get_mono_fast_ns();
149160
ret = raw_res_spin_lock_irqsave(worker_lock, flags);
150-
rqsl_record_lock_time(ktime_get_mono_fast_ns() - start_ns, false);
161+
rqsl_record_lock_result(ktime_get_mono_fast_ns() - start_ns,
162+
RQSL_CTX_NORMAL, ret);
151163
mdelay(normal_delay);
152164
if (!ret)
153165
raw_res_spin_unlock_irqrestore(worker_lock, flags);
@@ -190,7 +202,8 @@ static void nmi_cb(struct perf_event *event, struct perf_sample_data *data,
190202
locks = rqsl_get_lock_pair(cpu);
191203
start_ns = ktime_get_mono_fast_ns();
192204
ret = raw_res_spin_lock_irqsave(locks.nmi_lock, flags);
193-
rqsl_record_lock_time(ktime_get_mono_fast_ns() - start_ns, true);
205+
rqsl_record_lock_result(ktime_get_mono_fast_ns() - start_ns,
206+
RQSL_CTX_NMI, ret);
194207

195208
mdelay(nmi_delay);
196209

@@ -300,12 +313,14 @@ static void rqsl_print_histograms(void)
300313
u64 norm_counts[RQSL_NR_HIST_BUCKETS];
301314
u64 nmi_counts[RQSL_NR_HIST_BUCKETS];
302315
u64 total_counts[RQSL_NR_HIST_BUCKETS];
316+
u64 norm_success, nmi_success, success_total;
317+
u64 norm_failure, nmi_failure, failure_total;
303318
u64 norm_total = 0, nmi_total = 0, total = 0;
304319
bool has_slow = false;
305320

306321
for (i = 0; i < RQSL_NR_HIST_BUCKETS; i++) {
307-
norm_counts[i] = atomic64_read(&hist->normal[i]);
308-
nmi_counts[i] = atomic64_read(&hist->nmi[i]);
322+
norm_counts[i] = atomic64_read(&hist->hist[RQSL_CTX_NORMAL][i]);
323+
nmi_counts[i] = atomic64_read(&hist->hist[RQSL_CTX_NMI][i]);
309324
total_counts[i] = norm_counts[i] + nmi_counts[i];
310325
norm_total += norm_counts[i];
311326
nmi_total += nmi_counts[i];
@@ -315,17 +330,33 @@ static void rqsl_print_histograms(void)
315330
has_slow = true;
316331
}
317332

333+
norm_success = atomic64_read(&hist->success[RQSL_CTX_NORMAL]);
334+
nmi_success = atomic64_read(&hist->success[RQSL_CTX_NMI]);
335+
norm_failure = atomic64_read(&hist->failure[RQSL_CTX_NORMAL]);
336+
nmi_failure = atomic64_read(&hist->failure[RQSL_CTX_NMI]);
337+
success_total = norm_success + nmi_success;
338+
failure_total = norm_failure + nmi_failure;
339+
318340
if (!total)
319341
continue;
320342

321343
if (!has_slow) {
322-
pr_err(" cpu%d: total %llu (normal %llu, nmi %llu), all within 0-%ums\n",
323-
cpu, total, norm_total, nmi_total, RQSL_SLOW_THRESHOLD_MS);
344+
pr_err(" cpu%d: total %llu (normal %llu, nmi %llu) | "
345+
"success %llu (normal %llu, nmi %llu) | "
346+
"failure %llu (normal %llu, nmi %llu), all within 0-%ums\n",
347+
cpu, total, norm_total, nmi_total,
348+
success_total, norm_success, nmi_success,
349+
failure_total, norm_failure, nmi_failure,
350+
RQSL_SLOW_THRESHOLD_MS);
324351
continue;
325352
}
326353

327-
pr_err(" cpu%d: total %llu (normal %llu, nmi %llu)\n",
328-
cpu, total, norm_total, nmi_total);
354+
pr_err(" cpu%d: total %llu (normal %llu, nmi %llu) | "
355+
"success %llu (normal %llu, nmi %llu) | "
356+
"failure %llu (normal %llu, nmi %llu)\n",
357+
cpu, total, norm_total, nmi_total,
358+
success_total, norm_success, nmi_success,
359+
failure_total, norm_failure, nmi_failure);
329360
for (i = 0; i < RQSL_NR_HIST_BUCKETS; i++) {
330361
unsigned int start_ms;
331362

0 commit comments

Comments
 (0)