aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Stringer <joe@ovn.org>2016-12-08 21:46:19 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-12-20 10:00:40 -0500
commit205c8ada314f78e6637342089e5b585a051d6cf5 (patch)
treed734220371122d5df702fd4a46fda7f820b89439
parent811b4f0d785d33eabfff5d0ea60596b6b8bdc825 (diff)
samples/bpf: Remove perf_event_open() declaration
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>
-rw-r--r--samples/bpf/Makefile2
-rw-r--r--samples/bpf/bpf_load.c3
-rw-r--r--samples/bpf/libbpf.c7
-rw-r--r--samples/bpf/libbpf.h3
-rw-r--r--samples/bpf/sampleip_user.c3
-rw-r--r--samples/bpf/trace_event_user.c9
-rw-r--r--samples/bpf/trace_output_user.c3
-rw-r--r--samples/bpf/tracex6_user.c3
8 files changed, 15 insertions, 18 deletions
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 81b0ef2f7994..5a73f5a7ace1 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -109,6 +109,8 @@ always += xdp_tx_iptunnel_kern.o
109HOSTCFLAGS += -I$(objtree)/usr/include 109HOSTCFLAGS += -I$(objtree)/usr/include
110HOSTCFLAGS += -I$(srctree)/tools/lib/ 110HOSTCFLAGS += -I$(srctree)/tools/lib/
111HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/ 111HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
112HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
113HOSTCFLAGS += -I$(srctree)/tools/perf
112 114
113HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable 115HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
114HOSTLOADLIBES_fds_example += -lelf 116HOSTLOADLIBES_fds_example += -lelf
diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c
index 1bfb43394013..396e204888b3 100644
--- a/samples/bpf/bpf_load.c
+++ b/samples/bpf/bpf_load.c
@@ -23,6 +23,7 @@
23#include <ctype.h> 23#include <ctype.h>
24#include "libbpf.h" 24#include "libbpf.h"
25#include "bpf_load.h" 25#include "bpf_load.h"
26#include "perf-sys.h"
26 27
27#define DEBUGFS "/sys/kernel/debug/tracing/" 28#define DEBUGFS "/sys/kernel/debug/tracing/"
28 29
@@ -179,7 +180,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
179 id = atoi(buf); 180 id = atoi(buf);
180 attr.config = id; 181 attr.config = id;
181 182
182 efd = perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0); 183 efd = sys_perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0);
183 if (efd < 0) { 184 if (efd < 0) {
184 printf("event %d fd %d err %s\n", id, efd, strerror(errno)); 185 printf("event %d fd %d err %s\n", id, efd, strerror(errno));
185 return -1; 186 return -1;
diff --git a/samples/bpf/libbpf.c b/samples/bpf/libbpf.c
index d9af876b4a2c..bee473a494f1 100644
--- a/samples/bpf/libbpf.c
+++ b/samples/bpf/libbpf.c
@@ -34,10 +34,3 @@ int open_raw_sock(const char *name)
34 34
35 return sock; 35 return sock;
36} 36}
37
38int perf_event_open(struct perf_event_attr *attr, int pid, int cpu,
39 int group_fd, unsigned long flags)
40{
41 return syscall(__NR_perf_event_open, attr, pid, cpu,
42 group_fd, flags);
43}
diff --git a/samples/bpf/libbpf.h b/samples/bpf/libbpf.h
index cc815624aacf..09aedc320009 100644
--- a/samples/bpf/libbpf.h
+++ b/samples/bpf/libbpf.h
@@ -188,7 +188,4 @@ struct bpf_insn;
188/* create RAW socket and bind to interface 'name' */ 188/* create RAW socket and bind to interface 'name' */
189int open_raw_sock(const char *name); 189int open_raw_sock(const char *name);
190 190
191struct perf_event_attr;
192int perf_event_open(struct perf_event_attr *attr, int pid, int cpu,
193 int group_fd, unsigned long flags);
194#endif 191#endif
diff --git a/samples/bpf/sampleip_user.c b/samples/bpf/sampleip_user.c
index 5ac5adf75931..be59d7dcbdde 100644
--- a/samples/bpf/sampleip_user.c
+++ b/samples/bpf/sampleip_user.c
@@ -21,6 +21,7 @@
21#include <sys/ioctl.h> 21#include <sys/ioctl.h>
22#include "libbpf.h" 22#include "libbpf.h"
23#include "bpf_load.h" 23#include "bpf_load.h"
24#include "perf-sys.h"
24 25
25#define DEFAULT_FREQ 99 26#define DEFAULT_FREQ 99
26#define DEFAULT_SECS 5 27#define DEFAULT_SECS 5
@@ -49,7 +50,7 @@ static int sampling_start(int *pmu_fd, int freq)
49 }; 50 };
50 51
51 for (i = 0; i < nr_cpus; i++) { 52 for (i = 0; i < nr_cpus; i++) {
52 pmu_fd[i] = perf_event_open(&pe_sample_attr, -1 /* pid */, i, 53 pmu_fd[i] = sys_perf_event_open(&pe_sample_attr, -1 /* pid */, i,
53 -1 /* group_fd */, 0 /* flags */); 54 -1 /* group_fd */, 0 /* flags */);
54 if (pmu_fd[i] < 0) { 55 if (pmu_fd[i] < 0) {
55 fprintf(stderr, "ERROR: Initializing perf sampling\n"); 56 fprintf(stderr, "ERROR: Initializing perf sampling\n");
diff --git a/samples/bpf/trace_event_user.c b/samples/bpf/trace_event_user.c
index 704fe9fa77b2..0c5561d193a4 100644
--- a/samples/bpf/trace_event_user.c
+++ b/samples/bpf/trace_event_user.c
@@ -20,6 +20,7 @@
20#include <sys/resource.h> 20#include <sys/resource.h>
21#include "libbpf.h" 21#include "libbpf.h"
22#include "bpf_load.h" 22#include "bpf_load.h"
23#include "perf-sys.h"
23 24
24#define SAMPLE_FREQ 50 25#define SAMPLE_FREQ 50
25 26
@@ -125,9 +126,9 @@ static void test_perf_event_all_cpu(struct perf_event_attr *attr)
125 126
126 /* open perf_event on all cpus */ 127 /* open perf_event on all cpus */
127 for (i = 0; i < nr_cpus; i++) { 128 for (i = 0; i < nr_cpus; i++) {
128 pmu_fd[i] = perf_event_open(attr, -1, i, -1, 0); 129 pmu_fd[i] = sys_perf_event_open(attr, -1, i, -1, 0);
129 if (pmu_fd[i] < 0) { 130 if (pmu_fd[i] < 0) {
130 printf("perf_event_open failed\n"); 131 printf("sys_perf_event_open failed\n");
131 goto all_cpu_err; 132 goto all_cpu_err;
132 } 133 }
133 assert(ioctl(pmu_fd[i], PERF_EVENT_IOC_SET_BPF, prog_fd[0]) == 0); 134 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)
146 int pmu_fd; 147 int pmu_fd;
147 148
148 /* open task bound event */ 149 /* open task bound event */
149 pmu_fd = perf_event_open(attr, 0, -1, -1, 0); 150 pmu_fd = sys_perf_event_open(attr, 0, -1, -1, 0);
150 if (pmu_fd < 0) { 151 if (pmu_fd < 0) {
151 printf("perf_event_open failed\n"); 152 printf("sys_perf_event_open failed\n");
152 return; 153 return;
153 } 154 }
154 assert(ioctl(pmu_fd, PERF_EVENT_IOC_SET_BPF, prog_fd[0]) == 0); 155 assert(ioctl(pmu_fd, PERF_EVENT_IOC_SET_BPF, prog_fd[0]) == 0);
diff --git a/samples/bpf/trace_output_user.c b/samples/bpf/trace_output_user.c
index 1a1da7bddb93..f4fa6af22def 100644
--- a/samples/bpf/trace_output_user.c
+++ b/samples/bpf/trace_output_user.c
@@ -21,6 +21,7 @@
21#include <signal.h> 21#include <signal.h>
22#include "libbpf.h" 22#include "libbpf.h"
23#include "bpf_load.h" 23#include "bpf_load.h"
24#include "perf-sys.h"
24 25
25static int pmu_fd; 26static int pmu_fd;
26 27
@@ -159,7 +160,7 @@ static void test_bpf_perf_event(void)
159 }; 160 };
160 int key = 0; 161 int key = 0;
161 162
162 pmu_fd = perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0); 163 pmu_fd = sys_perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0);
163 164
164 assert(pmu_fd >= 0); 165 assert(pmu_fd >= 0);
165 assert(bpf_map_update_elem(map_fd[0], &key, &pmu_fd, BPF_ANY) == 0); 166 assert(bpf_map_update_elem(map_fd[0], &key, &pmu_fd, BPF_ANY) == 0);
diff --git a/samples/bpf/tracex6_user.c b/samples/bpf/tracex6_user.c
index 179297cb4d35..ca7874ed77f4 100644
--- a/samples/bpf/tracex6_user.c
+++ b/samples/bpf/tracex6_user.c
@@ -10,6 +10,7 @@
10#include <linux/bpf.h> 10#include <linux/bpf.h>
11#include "libbpf.h" 11#include "libbpf.h"
12#include "bpf_load.h" 12#include "bpf_load.h"
13#include "perf-sys.h"
13 14
14#define SAMPLE_PERIOD 0x7fffffffffffffffULL 15#define SAMPLE_PERIOD 0x7fffffffffffffffULL
15 16
@@ -30,7 +31,7 @@ static void test_bpf_perf_event(void)
30 }; 31 };
31 32
32 for (i = 0; i < nr_cpus; i++) { 33 for (i = 0; i < nr_cpus; i++) {
33 pmu_fd[i] = perf_event_open(&attr_insn_pmu, -1/*pid*/, i/*cpu*/, -1/*group_fd*/, 0); 34 pmu_fd[i] = sys_perf_event_open(&attr_insn_pmu, -1/*pid*/, i/*cpu*/, -1/*group_fd*/, 0);
34 if (pmu_fd[i] < 0) { 35 if (pmu_fd[i] < 0) {
35 printf("event syscall failed\n"); 36 printf("event syscall failed\n");
36 goto exit; 37 goto exit;