forked from iovisor/bcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
numamove.bpf.c
49 lines (41 loc) · 1.01 KB
/
numamove.bpf.c
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
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2020 Wenbo Zhang
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 10240);
__type(key, u32);
__type(value, u64);
__uint(map_flags, BPF_F_NO_PREALLOC);
} start SEC(".maps");
__u64 latency = 0;
__u64 num = 0;
SEC("fentry/migrate_misplaced_page")
int BPF_PROG(migrate_misplaced_page)
{
u32 pid = bpf_get_current_pid_tgid();
u64 ts = bpf_ktime_get_ns();
bpf_map_update_elem(&start, &pid, &ts, 0);
return 0;
}
SEC("fexit/migrate_misplaced_page")
int BPF_PROG(migrate_misplaced_page_exit)
{
u32 pid = bpf_get_current_pid_tgid();
u64 *tsp, ts = bpf_ktime_get_ns();
s64 delta;
tsp = bpf_map_lookup_elem(&start, &pid);
if (!tsp)
return 0;
delta = (s64)(ts - *tsp);
if (delta < 0)
goto cleanup;
__sync_fetch_and_add(&latency, delta / 1000000U);
__sync_fetch_and_add(&num, 1);
cleanup:
bpf_map_delete_elem(&start, &pid);
return 0;
}
char LICENSE[] SEC("license") = "GPL";