1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright Amazon.com Inc. or its affiliates */
3 #include <linux/types.h>
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_tracing.h>
10 /* Will be updated by benchmark before program loading */
11 char to_buff[BUFF_SZ];
12 const volatile unsigned int to_buff_len = 0;
13 char from_buff[BUFF_SZ];
14 const volatile unsigned int from_buff_len = 0;
15 unsigned short seed = 0;
19 char _license[] SEC("license") = "GPL";
22 int compute_checksum(void *ctx)
24 int to_len_half = to_buff_len / 2;
25 int from_len_half = from_buff_len / 2;
28 /* Calculate checksum in one go */
29 result2 = bpf_csum_diff((void *)from_buff, from_buff_len,
30 (void *)to_buff, to_buff_len, seed);
32 /* Calculate checksum by concatenating bpf_csum_diff()*/
33 result = bpf_csum_diff((void *)from_buff, from_buff_len - from_len_half,
34 (void *)to_buff, to_buff_len - to_len_half, seed);
36 result = bpf_csum_diff((void *)from_buff + (from_buff_len - from_len_half), from_len_half,
37 (void *)to_buff + (to_buff_len - to_len_half), to_len_half, result);
39 result = (result == result2) ? result : 0;