tools/testing/selftests/bpf/progs/user_ringbuf_success.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/user_ringbuf_success.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/user_ringbuf_success.c- Extension
.c- Size
- 4178 bytes
- Lines
- 213
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bpf.hbpf/bpf_helpers.hbpf_misc.htest_user_ringbuf.h
Detected Declarations
function is_test_processfunction record_samplefunction handle_sample_msgfunction read_protocol_msgfunction publish_next_kern_msgfunction publish_kern_messagesfunction test_user_ringbuf_protocolfunction test_user_ringbuffunction do_nothing_cbfunction test_user_ringbuf_epoll
Annotated Snippet
if (status) {
bpf_printk("bpf_dynptr_read() failed: %d\n", status);
err = 1;
return 1;
}
} else {
sample = bpf_dynptr_data(dynptr, 0, sizeof(*sample));
if (!sample) {
bpf_printk("Unexpectedly failed to get sample\n");
err = 2;
return 1;
}
stack_sample = *sample;
}
__sync_fetch_and_add(&read, 1);
return 0;
}
static void
handle_sample_msg(const struct test_msg *msg)
{
switch (msg->msg_op) {
case TEST_MSG_OP_INC64:
kern_mutated += msg->operand_64;
break;
case TEST_MSG_OP_INC32:
kern_mutated += msg->operand_32;
break;
case TEST_MSG_OP_MUL64:
kern_mutated *= msg->operand_64;
break;
case TEST_MSG_OP_MUL32:
kern_mutated *= msg->operand_32;
break;
default:
bpf_printk("Unrecognized op %d\n", msg->msg_op);
err = 2;
}
}
static long
read_protocol_msg(struct bpf_dynptr *dynptr, void *context)
{
const struct test_msg *msg = NULL;
msg = bpf_dynptr_data(dynptr, 0, sizeof(*msg));
if (!msg) {
err = 1;
bpf_printk("Unexpectedly failed to get msg\n");
return 0;
}
handle_sample_msg(msg);
return 0;
}
static int publish_next_kern_msg(__u32 index, void *context)
{
struct test_msg *msg = NULL;
int operand_64 = TEST_OP_64;
int operand_32 = TEST_OP_32;
msg = bpf_ringbuf_reserve(&kernel_ringbuf, sizeof(*msg), 0);
if (!msg) {
err = 4;
return 1;
}
switch (index % TEST_MSG_OP_NUM_OPS) {
case TEST_MSG_OP_INC64:
msg->operand_64 = operand_64;
msg->msg_op = TEST_MSG_OP_INC64;
expected_user_mutated += operand_64;
break;
case TEST_MSG_OP_INC32:
msg->operand_32 = operand_32;
msg->msg_op = TEST_MSG_OP_INC32;
expected_user_mutated += operand_32;
break;
case TEST_MSG_OP_MUL64:
msg->operand_64 = operand_64;
msg->msg_op = TEST_MSG_OP_MUL64;
expected_user_mutated *= operand_64;
break;
case TEST_MSG_OP_MUL32:
msg->operand_32 = operand_32;
msg->msg_op = TEST_MSG_OP_MUL32;
expected_user_mutated *= operand_32;
Annotation
- Immediate include surface: `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`, `test_user_ringbuf.h`.
- Detected declarations: `function is_test_process`, `function record_sample`, `function handle_sample_msg`, `function read_protocol_msg`, `function publish_next_kern_msg`, `function publish_kern_messages`, `function test_user_ringbuf_protocol`, `function test_user_ringbuf`, `function do_nothing_cb`, `function test_user_ringbuf_epoll`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.