libbpf-tools/softirqslower: Add libbpf CO-RE port of softirqslower#5516
libbpf-tools/softirqslower: Add libbpf CO-RE port of softirqslower#5516ismhong wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Ports the BCC Python softirqslower tool to a libbpf CO-RE implementation under libbpf-tools/. The new tool traces two latency dimensions of softirq processing — raise→entry and entry→exit — emitting events via a perf buffer when latency exceeds a configurable threshold, with optional per-CPU filtering and tp_btf/raw_tp fallback paths.
Changes:
- New
softirqslower.bpf.cwith per-CPU arrays indexed by vector and matched tp_btf/raw_tp programs for raise/entry/exit. - New
softirqslower.cuserspace driver (argp, rodata configuration, BTF probe, perf buffer polling). - Shared
softirqslower.hdefining event layout and stage enum; MakefileAPPSupdated.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| libbpf-tools/softirqslower.h | Shared event struct, stage enum, NR_SOFTIRQS constant. |
| libbpf-tools/softirqslower.bpf.c | BPF programs and helpers for raise/entry/exit tracking. |
| libbpf-tools/softirqslower.c | Userspace argp, BTF/raw_tp selection, perf buffer loop. |
| libbpf-tools/Makefile | Adds softirqslower to APPS. |
|
|
||
| printf("%-8s %-20s %-8s %-14llu %-6u %-16s\n", | ||
| ts, | ||
| e.stage < 2 ? stage_names[e.stage] : "unknown", |
There was a problem hiding this comment.
Fixed. Added ARRAY_SIZE(stage_names) macro and replaced the magic number with it, so the bound stays in sync automatically when new stages are added.
| sigsnoop \ | ||
| slabratetop \ | ||
| softirqs \ | ||
| softirqslower \ |
There was a problem hiding this comment.
Checked the existing libbpf-tools ports (runqslower, hardirqs, softirqs, etc.) — none of them add a separate entry to the top-level README.md. That file lists BCC Python tools only; libbpf-tools/README.md covers the libbpf side but does not enumerate individual tools either.
The man/man8/softirqslower.8 SYNOPSIS has been updated from softirqslower.py to softirqslower to reflect the libbpf binary.
| /* Matches NR_SOFTIRQS in linux/interrupt.h | ||
| * Update if kernel adds new vectors */ | ||
| #define NR_SOFTIRQS 10 |
There was a problem hiding this comment.
The BPF programs already guard against out-of-bounds access with vec >= NR_SOFTIRQS before any map lookup (softirqslower.bpf.c lines 77, 104, 135), so there is no silent data corruption.
The concern about future kernel vectors is valid, but increasing the map size would only defer the problem — the vec_names[] table in userspace would still need a matching update. Keeping NR_SOFTIRQS = 10 makes the two tables explicitly coupled: when the kernel adds a new vector, both the map size and the name table must be updated together. Happy to increase it to a safe upper bound if the maintainers prefer that style.
Port softirqslower from BCC Python to libbpf CO-RE. The tool traces two latency dimensions of softirq processing: - raise->entry: delay from raise_softirq() until handler starts - entry->exit: actual handler execution duration Uses PERCPU_ARRAY maps indexed by softirq vector for lock-free per-CPU tracking, with tp_btf (preferred) and raw_tp fallback. Change-Id: Ie1d6eae35397a3181e9432d24137e92d66f815af
Description
Convert from legacy Python/bcc to modern libbpf-based C implementation. This tool traces slow softirq events by measuring two critical latency dimensions of softirq handling.
Features:
Test on x86_64/Manjaro/5.15.60
Test on arm64/Android/6.12.38
Why this approach
Just port softirqslower from BCC to libbpf
Checklist
tools/toolname:,libbpf-tools/toolname:,src/cc:,docs:,build:,tests/python:)