File: test_urandom_usdt.c

package info (click to toggle)
linux 6.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,488,076 kB
  • sloc: ansic: 23,401,844; asm: 266,744; sh: 108,976; makefile: 49,705; python: 36,927; perl: 36,810; cpp: 6,044; yacc: 4,904; lex: 2,722; awk: 1,440; ruby: 25; sed: 5
file content (70 lines) | stat: -rw-r--r-- 1,928 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */

#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/usdt.bpf.h>

int urand_pid;

int urand_read_without_sema_call_cnt;
int urand_read_without_sema_buf_sz_sum;

SEC("usdt/./urandom_read:urand:read_without_sema")
int BPF_USDT(urand_read_without_sema, int iter_num, int iter_cnt, int buf_sz)
{
	if (urand_pid != (bpf_get_current_pid_tgid() >> 32))
		return 0;

	__sync_fetch_and_add(&urand_read_without_sema_call_cnt, 1);
	__sync_fetch_and_add(&urand_read_without_sema_buf_sz_sum, buf_sz);

	return 0;
}

int urand_read_with_sema_call_cnt;
int urand_read_with_sema_buf_sz_sum;

SEC("usdt/./urandom_read:urand:read_with_sema")
int BPF_USDT(urand_read_with_sema, int iter_num, int iter_cnt, int buf_sz)
{
	if (urand_pid != (bpf_get_current_pid_tgid() >> 32))
		return 0;

	__sync_fetch_and_add(&urand_read_with_sema_call_cnt, 1);
	__sync_fetch_and_add(&urand_read_with_sema_buf_sz_sum, buf_sz);

	return 0;
}

int urandlib_read_without_sema_call_cnt;
int urandlib_read_without_sema_buf_sz_sum;

SEC("usdt/./liburandom_read.so:urandlib:read_without_sema")
int BPF_USDT(urandlib_read_without_sema, int iter_num, int iter_cnt, int buf_sz)
{
	if (urand_pid != (bpf_get_current_pid_tgid() >> 32))
		return 0;

	__sync_fetch_and_add(&urandlib_read_without_sema_call_cnt, 1);
	__sync_fetch_and_add(&urandlib_read_without_sema_buf_sz_sum, buf_sz);

	return 0;
}

int urandlib_read_with_sema_call_cnt;
int urandlib_read_with_sema_buf_sz_sum;

SEC("usdt/./liburandom_read.so:urandlib:read_with_sema")
int BPF_USDT(urandlib_read_with_sema, int iter_num, int iter_cnt, int buf_sz)
{
	if (urand_pid != (bpf_get_current_pid_tgid() >> 32))
		return 0;

	__sync_fetch_and_add(&urandlib_read_with_sema_call_cnt, 1);
	__sync_fetch_and_add(&urandlib_read_with_sema_buf_sz_sum, buf_sz);

	return 0;
}

char _license[] SEC("license") = "GPL";