tools/testing/selftests/bpf/progs/csum_diff_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/csum_diff_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/csum_diff_test.c- Extension
.c- Size
- 1192 bytes
- Lines
- 43
- 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.
Dependency Surface
linux/types.hlinux/bpf.hbpf/bpf_helpers.hbpf/bpf_tracing.h
Detected Declarations
function compute_checksum
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright Amazon.com Inc. or its affiliates */
#include <linux/types.h>
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#define BUFF_SZ 512
/* Will be updated by benchmark before program loading */
char to_buff[BUFF_SZ];
const volatile unsigned int to_buff_len = 0;
char from_buff[BUFF_SZ];
const volatile unsigned int from_buff_len = 0;
unsigned short seed = 0;
short result;
char _license[] SEC("license") = "GPL";
SEC("tc")
int compute_checksum(void *ctx)
{
int to_len_half = to_buff_len / 2;
int from_len_half = from_buff_len / 2;
short result2;
/* Calculate checksum in one go */
result2 = bpf_csum_diff((void *)from_buff, from_buff_len,
(void *)to_buff, to_buff_len, seed);
/* Calculate checksum by concatenating bpf_csum_diff()*/
result = bpf_csum_diff((void *)from_buff, from_buff_len - from_len_half,
(void *)to_buff, to_buff_len - to_len_half, seed);
result = bpf_csum_diff((void *)from_buff + (from_buff_len - from_len_half), from_len_half,
(void *)to_buff + (to_buff_len - to_len_half), to_len_half, result);
result = (result == result2) ? result : 0;
return 0;
}
Annotation
- Immediate include surface: `linux/types.h`, `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`.
- Detected declarations: `function compute_checksum`.
- 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.