tools/testing/selftests/bpf/progs/stream.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/stream.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/stream.c- Extension
.c- Size
- 6815 bytes
- Lines
- 291
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hbpf/bpf_tracing.hbpf/bpf_helpers.hbpf_misc.hbpf_experimental.hbpf_arena_common.h
Detected Declarations
struct arr_elemstruct elemfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction subprogfunction __retvalfunction timer_cbfunction __retvalfunction __retvalfunction __retvalfunction __retval
Annotated Snippet
struct arr_elem {
struct bpf_res_spin_lock lock;
};
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, int);
__type(value, struct arr_elem);
} arrmap SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_ARENA);
__uint(map_flags, BPF_F_MMAPABLE);
__uint(max_entries, 1); /* number of pages */
} arena SEC(".maps");
struct elem {
struct bpf_timer timer;
};
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, int);
__type(value, struct elem);
} array SEC(".maps");
#define ENOSPC 28
#define _STR "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
int size;
u64 fault_addr;
void *arena_ptr;
#define private(name) SEC(".bss." #name) __hidden __attribute__((aligned(8)))
private(STREAM) struct bpf_spin_lock block;
SEC("syscall")
__success __retval(0)
int stream_exhaust(void *ctx)
{
/* Use global variable for loop convergence. */
size = 0;
bpf_repeat(BPF_MAX_LOOPS) {
if (bpf_stream_printk(BPF_STDOUT, _STR) == -ENOSPC && size == 99954)
return 0;
size += sizeof(_STR) - 1;
}
return 1;
}
SEC("syscall")
__arch_x86_64
__arch_arm64
__arch_s390x
__success __retval(0)
__stderr("ERROR: Timeout detected for may_goto instruction")
__stderr("CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}")
__stderr("Call trace:\n"
"{{([a-zA-Z_][a-zA-Z0-9_]*\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\n"
"|[ \t]+[^\n]+\n)*}}")
int stream_cond_break(void *ctx)
{
while (can_loop)
;
return 0;
}
SEC("syscall")
__success __retval(0)
__stderr("ERROR: AA or ABBA deadlock detected for bpf_res_spin_lock")
__stderr("{{Attempted lock = (0x[0-9a-fA-F]+)\n"
"Total held locks = 1\n"
"Held lock\\[ 0\\] = \\1}}")
__stderr("...")
__stderr("CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}")
__stderr("Call trace:\n"
"{{([a-zA-Z_][a-zA-Z0-9_]*\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\n"
"|[ \t]+[^\n]+\n)*}}")
int stream_deadlock(void *ctx)
{
struct bpf_res_spin_lock *lock, *nlock;
lock = bpf_map_lookup_elem(&arrmap, &(int){0});
if (!lock)
return 1;
nlock = bpf_map_lookup_elem(&arrmap, &(int){0});
if (!nlock)
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_tracing.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`, `bpf_experimental.h`, `bpf_arena_common.h`.
- Detected declarations: `struct arr_elem`, `struct elem`, `function __retval`, `function __retval`, `function __retval`, `function __retval`, `function __retval`, `function __retval`, `function subprog`, `function __retval`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.