2016-04-07 09:43:31 +08:00
|
|
|
/* Copyright (c) 2016 Facebook
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of version 2 of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation.
|
|
|
|
*/
|
2023-01-15 15:16:12 +08:00
|
|
|
#include "vmlinux.h"
|
2016-04-07 09:43:31 +08:00
|
|
|
#include <linux/version.h>
|
2020-01-20 21:06:49 +08:00
|
|
|
#include <bpf/bpf_helpers.h>
|
|
|
|
#include <bpf/bpf_tracing.h>
|
2016-04-07 09:43:31 +08:00
|
|
|
|
2020-07-20 19:48:06 +08:00
|
|
|
#define _(P) \
|
|
|
|
({ \
|
|
|
|
typeof(P) val = 0; \
|
|
|
|
bpf_probe_read_kernel(&val, sizeof(val), &(P)); \
|
|
|
|
val; \
|
|
|
|
})
|
2016-04-07 09:43:31 +08:00
|
|
|
|
|
|
|
SEC("kprobe/__set_task_comm")
|
|
|
|
int prog(struct pt_regs *ctx)
|
|
|
|
{
|
|
|
|
struct signal_struct *signal;
|
|
|
|
struct task_struct *tsk;
|
2022-01-20 10:08:33 +08:00
|
|
|
char oldcomm[TASK_COMM_LEN] = {};
|
|
|
|
char newcomm[TASK_COMM_LEN] = {};
|
2016-04-07 09:43:31 +08:00
|
|
|
u16 oom_score_adj;
|
|
|
|
u32 pid;
|
|
|
|
|
|
|
|
tsk = (void *)PT_REGS_PARM1(ctx);
|
|
|
|
|
|
|
|
pid = _(tsk->pid);
|
2022-01-20 10:08:33 +08:00
|
|
|
bpf_probe_read_kernel_str(oldcomm, sizeof(oldcomm), &tsk->comm);
|
|
|
|
bpf_probe_read_kernel_str(newcomm, sizeof(newcomm),
|
|
|
|
(void *)PT_REGS_PARM2(ctx));
|
2016-04-07 09:43:31 +08:00
|
|
|
signal = _(tsk->signal);
|
|
|
|
oom_score_adj = _(signal->oom_score_adj);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
samples/bpf: replace broken overhead microbenchmark with fib_table_lookup
The test_overhead bpf program is designed to compare performance
between tracepoint and kprobe. Initially it used task_rename and
urandom_read tracepoint.
However, commit 14c174633f34 ("random: remove unused tracepoints")
removed urandom_read tracepoint, and for this reason the test_overhead
got broken.
This commit introduces new microbenchmark using fib_table_lookup.
This microbenchmark sends UDP packets to localhost in order to invoke
fib_table_lookup.
In a nutshell:
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
addr.sin_addr.s_addr = inet_addr(DUMMY_IP);
addr.sin_port = htons(DUMMY_PORT);
for() {
sendto(fd, buf, strlen(buf), 0,
(struct sockaddr *)&addr, sizeof(addr));
}
on 4 cpus in parallel:
lookup per sec
base (no tracepoints, no kprobes) 381k
with kprobe at fib_table_lookup() 325k
with tracepoint at fib:fib_table_lookup 330k
with raw_tracepoint at fib:fib_table_lookup 365k
Fixes: 14c174633f34 ("random: remove unused tracepoints")
Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Link: https://lore.kernel.org/r/20230115071613.125791-6-danieltimlee@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2023-01-15 15:16:08 +08:00
|
|
|
SEC("kprobe/fib_table_lookup")
|
2016-04-07 09:43:31 +08:00
|
|
|
int prog2(struct pt_regs *ctx)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
u32 _version SEC("version") = LINUX_VERSION_CODE;
|