forked from luck/tmp_suning_uos_patched
205c8ada31
This declaration was made in samples/bpf/libbpf.c for convenience, but there's already one in tools/perf/perf-sys.h. Reuse that one. Committer notes: Testing it: $ make -j4 O=../build/v4.9.0-rc8+ samples/bpf/ make[1]: Entering directory '/home/build/v4.9.0-rc8+' CHK include/config/kernel.release GEN ./Makefile CHK include/generated/uapi/linux/version.h Using /home/acme/git/linux as source for kernel CHK include/generated/utsrelease.h CHK include/generated/timeconst.h CHK include/generated/bounds.h CHK include/generated/asm-offsets.h CALL /home/acme/git/linux/scripts/checksyscalls.sh HOSTCC samples/bpf/test_verifier.o HOSTCC samples/bpf/libbpf.o HOSTCC samples/bpf/../../tools/lib/bpf/bpf.o HOSTCC samples/bpf/test_maps.o HOSTCC samples/bpf/sock_example.o HOSTCC samples/bpf/bpf_load.o <SNIP> HOSTLD samples/bpf/trace_event HOSTLD samples/bpf/sampleip HOSTLD samples/bpf/tc_l2_redirect make[1]: Leaving directory '/home/build/v4.9.0-rc8+' $ Also tested the offwaketime resulting from the rebuild, seems to work as before. Signed-off-by: Joe Stringer <joe@ovn.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Alexei Starovoitov <ast@fb.com> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/r/20161209024620.31660-7-joe@ovn.org [ Use -I$(srctree)/tools/lib/ to support out of source code tree builds ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
74 lines
1.4 KiB
C
74 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
#include <fcntl.h>
|
|
#include <poll.h>
|
|
#include <sys/ioctl.h>
|
|
#include <linux/perf_event.h>
|
|
#include <linux/bpf.h>
|
|
#include "libbpf.h"
|
|
#include "bpf_load.h"
|
|
#include "perf-sys.h"
|
|
|
|
#define SAMPLE_PERIOD 0x7fffffffffffffffULL
|
|
|
|
static void test_bpf_perf_event(void)
|
|
{
|
|
int nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
|
|
int *pmu_fd = malloc(nr_cpus * sizeof(int));
|
|
int status, i;
|
|
|
|
struct perf_event_attr attr_insn_pmu = {
|
|
.freq = 0,
|
|
.sample_period = SAMPLE_PERIOD,
|
|
.inherit = 0,
|
|
.type = PERF_TYPE_HARDWARE,
|
|
.read_format = 0,
|
|
.sample_type = 0,
|
|
.config = 0,/* PMU: cycles */
|
|
};
|
|
|
|
for (i = 0; i < nr_cpus; i++) {
|
|
pmu_fd[i] = sys_perf_event_open(&attr_insn_pmu, -1/*pid*/, i/*cpu*/, -1/*group_fd*/, 0);
|
|
if (pmu_fd[i] < 0) {
|
|
printf("event syscall failed\n");
|
|
goto exit;
|
|
}
|
|
|
|
bpf_map_update_elem(map_fd[0], &i, &pmu_fd[i], BPF_ANY);
|
|
ioctl(pmu_fd[i], PERF_EVENT_IOC_ENABLE, 0);
|
|
}
|
|
|
|
status = system("ls > /dev/null");
|
|
if (status)
|
|
goto exit;
|
|
status = system("sleep 2");
|
|
if (status)
|
|
goto exit;
|
|
|
|
exit:
|
|
for (i = 0; i < nr_cpus; i++)
|
|
close(pmu_fd[i]);
|
|
close(map_fd[0]);
|
|
free(pmu_fd);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
char filename[256];
|
|
|
|
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
|
|
|
|
if (load_bpf_file(filename)) {
|
|
printf("%s", bpf_log_buf);
|
|
return 1;
|
|
}
|
|
|
|
test_bpf_perf_event();
|
|
read_trace_pipe();
|
|
|
|
return 0;
|
|
}
|