tools/testing/selftests/bpf/progs/iters.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/iters.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/iters.c- Extension
.c- Size
- 43481 bytes
- Lines
- 2070
- 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
stdbool.hlinux/bpf.hbpf/bpf_helpers.hbpf_misc.hbpf_compiler.h
Detected Declarations
function __msgfunction __msgfunction iter_while_loopfunction iter_while_loop_auto_cleanupfunction iter_for_loopfunction iter_bpf_for_each_macrofunction bpf_for_eachfunction iter_bpf_for_macrofunction bpf_forfunction iter_pragma_unroll_loopfunction iter_manual_unroll_loopfunction iter_multiple_sequential_loopsfunction iter_limit_cond_break_loopfunction iter_obfuscate_counterfunction iter_search_loopfunction iter_array_fillfunction bpf_forfunction iter_nested_itersfunction bpf_forfunction bpf_forfunction iter_nested_deeply_itersfunction bpf_repeatfunction fill_inner_dimensionfunction bpf_forfunction sum_inner_dimensionfunction bpf_forfunction iter_subprog_itersfunction bpf_forfunction __msgfunction bpf_repeatfunction __msgfunction bpf_repeatfunction __msgfunction bpf_repeatfunction iter_tricky_but_finefunction bpf_repeatfunction iter_stack_array_loopfunction bpf_forfunction fillfunction sumfunction iter_pass_iter_ptr_to_subprogfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction triple_continuefunction widen_spill
Annotated Snippet
if (*v == 2) {
found = true;
elem = v;
barrier_var(elem);
}
}
/* should fail to verify if bpf_iter_num_destroy() is here */
if (found)
/* here found element will be wrong, we should have copied
* value to a variable, but here we want to make sure we can
* access memory after the loop anyways
*/
bpf_printk("ITER_SEARCH_LOOP: FOUND IT = %d!\n", *elem);
else
bpf_printk("ITER_SEARCH_LOOP: NOT FOUND IT!\n");
bpf_iter_num_destroy(&it);
return 0;
}
SEC("raw_tp")
__success
int iter_array_fill(const void *ctx)
{
int sum, i;
MY_PID_GUARD();
bpf_for(i, 0, ARRAY_SIZE(arr)) {
arr[i] = i * 2;
}
sum = 0;
bpf_for(i, 0, ARRAY_SIZE(arr)) {
sum += arr[i];
}
bpf_printk("ITER_ARRAY_FILL: sum=%d (should be %d)\n", sum, 255 * 256);
return 0;
}
static int arr2d[4][5];
static int arr2d_row_sums[4];
static int arr2d_col_sums[5];
SEC("raw_tp")
__success
int iter_nested_iters(const void *ctx)
{
int sum, row, col;
MY_PID_GUARD();
bpf_for(row, 0, ARRAY_SIZE(arr2d)) {
bpf_for( col, 0, ARRAY_SIZE(arr2d[0])) {
arr2d[row][col] = row * col;
}
}
/* zero-initialize sums */
sum = 0;
bpf_for(row, 0, ARRAY_SIZE(arr2d)) {
arr2d_row_sums[row] = 0;
}
bpf_for(col, 0, ARRAY_SIZE(arr2d[0])) {
arr2d_col_sums[col] = 0;
}
/* calculate sums */
bpf_for(row, 0, ARRAY_SIZE(arr2d)) {
bpf_for(col, 0, ARRAY_SIZE(arr2d[0])) {
sum += arr2d[row][col];
arr2d_row_sums[row] += arr2d[row][col];
arr2d_col_sums[col] += arr2d[row][col];
}
}
bpf_printk("ITER_NESTED_ITERS: total sum=%d", sum);
bpf_for(row, 0, ARRAY_SIZE(arr2d)) {
bpf_printk("ITER_NESTED_ITERS: row #%d sum=%d", row, arr2d_row_sums[row]);
}
bpf_for(col, 0, ARRAY_SIZE(arr2d[0])) {
bpf_printk("ITER_NESTED_ITERS: col #%d sum=%d%s",
col, arr2d_col_sums[col],
col == ARRAY_SIZE(arr2d[0]) - 1 ? "\n" : "");
}
Annotation
- Immediate include surface: `stdbool.h`, `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`, `bpf_compiler.h`.
- Detected declarations: `function __msg`, `function __msg`, `function iter_while_loop`, `function iter_while_loop_auto_cleanup`, `function iter_for_loop`, `function iter_bpf_for_each_macro`, `function bpf_for_each`, `function iter_bpf_for_macro`, `function bpf_for`, `function iter_pragma_unroll_loop`.
- 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.