samples/bpf: Remove perf_event_open() declaration
authorJoe Stringer <joe@ovn.org>
Fri, 9 Dec 2016 02:46:19 +0000 (18:46 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 20 Dec 2016 15:00:40 +0000 (12:00 -0300)
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>
samples/bpf/Makefile
samples/bpf/bpf_load.c
samples/bpf/libbpf.c
samples/bpf/libbpf.h
samples/bpf/sampleip_user.c
samples/bpf/trace_event_user.c
samples/bpf/trace_output_user.c
samples/bpf/tracex6_user.c

index 81b0ef2f7994005e726f75cd258158388a433a0e..5a73f5a7ace1a054ce7f7dafa5369322031336e5 100644 (file)
@@ -109,6 +109,8 @@ always += xdp_tx_iptunnel_kern.o
 HOSTCFLAGS += -I$(objtree)/usr/include
 HOSTCFLAGS += -I$(srctree)/tools/lib/
 HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
+HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
+HOSTCFLAGS += -I$(srctree)/tools/perf
 
 HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
 HOSTLOADLIBES_fds_example += -lelf
index 1bfb433940131e047c796cc1ad1588fb141bef95..396e204888b34f342bd8f01afc4e0d1a3d52f823 100644 (file)
@@ -23,6 +23,7 @@
 #include <ctype.h>
 #include "libbpf.h"
 #include "bpf_load.h"
+#include "perf-sys.h"
 
 #define DEBUGFS "/sys/kernel/debug/tracing/"
 
@@ -179,7 +180,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
        id = atoi(buf);
        attr.config = id;
 
-       efd = perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0);
+       efd = sys_perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0);
        if (efd < 0) {
                printf("event %d fd %d err %s\n", id, efd, strerror(errno));
                return -1;
index d9af876b4a2cbd1d02c4d8207b3c29840090c8ab..bee473a494f1767ce2ddf0361af8b675dacd632d 100644 (file)
@@ -34,10 +34,3 @@ int open_raw_sock(const char *name)
 
        return sock;
 }
-
-int perf_event_open(struct perf_event_attr *attr, int pid, int cpu,
-                   int group_fd, unsigned long flags)
-{
-       return syscall(__NR_perf_event_open, attr, pid, cpu,
-                      group_fd, flags);
-}
index cc815624aacf4e24df28d1399e36772971a60e8a..09aedc320009db23e8800145b8518da9b0e5ce77 100644 (file)
@@ -188,7 +188,4 @@ struct bpf_insn;
 /* create RAW socket and bind to interface 'name' */
 int open_raw_sock(const char *name);
 
-struct perf_event_attr;
-int perf_event_open(struct perf_event_attr *attr, int pid, int cpu,
-                   int group_fd, unsigned long flags);
 #endif
index 5ac5adf7593121adba8426a67974c54567f1969d..be59d7dcbdde3664c573a78d6d27adee03234a16 100644 (file)
@@ -21,6 +21,7 @@
 #include <sys/ioctl.h>
 #include "libbpf.h"
 #include "bpf_load.h"
+#include "perf-sys.h"
 
 #define DEFAULT_FREQ   99
 #define DEFAULT_SECS   5
@@ -49,7 +50,7 @@ static int sampling_start(int *pmu_fd, int freq)
        };
 
        for (i = 0; i < nr_cpus; i++) {
-               pmu_fd[i] = perf_event_open(&pe_sample_attr, -1 /* pid */, i,
+               pmu_fd[i] = sys_perf_event_open(&pe_sample_attr, -1 /* pid */, i,
                                            -1 /* group_fd */, 0 /* flags */);
                if (pmu_fd[i] < 0) {
                        fprintf(stderr, "ERROR: Initializing perf sampling\n");
index 704fe9fa77b2b2bc2b45b48903e3dd6b9c188e27..0c5561d193a487f2257ccece359530b97b06a170 100644 (file)
@@ -20,6 +20,7 @@
 #include <sys/resource.h>
 #include "libbpf.h"
 #include "bpf_load.h"
+#include "perf-sys.h"
 
 #define SAMPLE_FREQ 50
 
@@ -125,9 +126,9 @@ static void test_perf_event_all_cpu(struct perf_event_attr *attr)
 
        /* open perf_event on all cpus */
        for (i = 0; i < nr_cpus; i++) {
-               pmu_fd[i] = perf_event_open(attr, -1, i, -1, 0);
+               pmu_fd[i] = sys_perf_event_open(attr, -1, i, -1, 0);
                if (pmu_fd[i] < 0) {
-                       printf("perf_event_open failed\n");
+                       printf("sys_perf_event_open failed\n");
                        goto all_cpu_err;
                }
                assert(ioctl(pmu_fd[i], PERF_EVENT_IOC_SET_BPF, prog_fd[0]) == 0);
@@ -146,9 +147,9 @@ static void test_perf_event_task(struct perf_event_attr *attr)
        int pmu_fd;
 
        /* open task bound event */
-       pmu_fd = perf_event_open(attr, 0, -1, -1, 0);
+       pmu_fd = sys_perf_event_open(attr, 0, -1, -1, 0);
        if (pmu_fd < 0) {
-               printf("perf_event_open failed\n");
+               printf("sys_perf_event_open failed\n");
                return;
        }
        assert(ioctl(pmu_fd, PERF_EVENT_IOC_SET_BPF, prog_fd[0]) == 0);
index 1a1da7bddb9347ffaa2350e15e4e909b5e13c887..f4fa6af22def9fa9c01df1525c7a61b3aecb8cdd 100644 (file)
@@ -21,6 +21,7 @@
 #include <signal.h>
 #include "libbpf.h"
 #include "bpf_load.h"
+#include "perf-sys.h"
 
 static int pmu_fd;
 
@@ -159,7 +160,7 @@ static void test_bpf_perf_event(void)
        };
        int key = 0;
 
-       pmu_fd = perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0);
+       pmu_fd = sys_perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0);
 
        assert(pmu_fd >= 0);
        assert(bpf_map_update_elem(map_fd[0], &key, &pmu_fd, BPF_ANY) == 0);
index 179297cb4d352556359c4035ff243f641e9aad37..ca7874ed77f4326db742366641c982612e9261b0 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/bpf.h>
 #include "libbpf.h"
 #include "bpf_load.h"
+#include "perf-sys.h"
 
 #define SAMPLE_PERIOD  0x7fffffffffffffffULL
 
@@ -30,7 +31,7 @@ static void test_bpf_perf_event(void)
        };
 
        for (i = 0; i < nr_cpus; i++) {
-               pmu_fd[i] = perf_event_open(&attr_insn_pmu, -1/*pid*/, i/*cpu*/, -1/*group_fd*/, 0);
+               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;