mm, memory_hotplug: try to migrate full pfn range
[linux/fpc-iii.git] / samples / bpf / Makefile
blob35444f4a846bdfdbbadb836f8ccb48c9d34293d3
1 # SPDX-License-Identifier: GPL-2.0
3 BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
4 TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
6 # List of programs to build
7 hostprogs-y := test_lru_dist
8 hostprogs-y += sock_example
9 hostprogs-y += fds_example
10 hostprogs-y += sockex1
11 hostprogs-y += sockex2
12 hostprogs-y += sockex3
13 hostprogs-y += tracex1
14 hostprogs-y += tracex2
15 hostprogs-y += tracex3
16 hostprogs-y += tracex4
17 hostprogs-y += tracex5
18 hostprogs-y += tracex6
19 hostprogs-y += tracex7
20 hostprogs-y += test_probe_write_user
21 hostprogs-y += trace_output
22 hostprogs-y += lathist
23 hostprogs-y += offwaketime
24 hostprogs-y += spintest
25 hostprogs-y += map_perf_test
26 hostprogs-y += test_overhead
27 hostprogs-y += test_cgrp2_array_pin
28 hostprogs-y += test_cgrp2_attach
29 hostprogs-y += test_cgrp2_attach2
30 hostprogs-y += test_cgrp2_sock
31 hostprogs-y += test_cgrp2_sock2
32 hostprogs-y += xdp1
33 hostprogs-y += xdp2
34 hostprogs-y += xdp_router_ipv4
35 hostprogs-y += test_current_task_under_cgroup
36 hostprogs-y += trace_event
37 hostprogs-y += sampleip
38 hostprogs-y += tc_l2_redirect
39 hostprogs-y += lwt_len_hist
40 hostprogs-y += xdp_tx_iptunnel
41 hostprogs-y += test_map_in_map
42 hostprogs-y += per_socket_stats_example
43 hostprogs-y += load_sock_ops
44 hostprogs-y += xdp_redirect
45 hostprogs-y += xdp_redirect_map
46 hostprogs-y += xdp_redirect_cpu
47 hostprogs-y += xdp_monitor
48 hostprogs-y += xdp_rxq_info
49 hostprogs-y += syscall_tp
50 hostprogs-y += cpustat
51 hostprogs-y += xdp_adjust_tail
52 hostprogs-y += xdpsock
53 hostprogs-y += xdp_fwd
54 hostprogs-y += task_fd_query
55 hostprogs-y += xdp_sample_pkts
57 # Libbpf dependencies
58 LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a
60 CGROUP_HELPERS := ../../tools/testing/selftests/bpf/cgroup_helpers.o
61 TRACE_HELPERS := ../../tools/testing/selftests/bpf/trace_helpers.o
63 fds_example-objs := bpf_load.o fds_example.o
64 sockex1-objs := bpf_load.o sockex1_user.o
65 sockex2-objs := bpf_load.o sockex2_user.o
66 sockex3-objs := bpf_load.o sockex3_user.o
67 tracex1-objs := bpf_load.o tracex1_user.o
68 tracex2-objs := bpf_load.o tracex2_user.o
69 tracex3-objs := bpf_load.o tracex3_user.o
70 tracex4-objs := bpf_load.o tracex4_user.o
71 tracex5-objs := bpf_load.o tracex5_user.o
72 tracex6-objs := bpf_load.o tracex6_user.o
73 tracex7-objs := bpf_load.o tracex7_user.o
74 load_sock_ops-objs := bpf_load.o load_sock_ops.o
75 test_probe_write_user-objs := bpf_load.o test_probe_write_user_user.o
76 trace_output-objs := bpf_load.o trace_output_user.o $(TRACE_HELPERS)
77 lathist-objs := bpf_load.o lathist_user.o
78 offwaketime-objs := bpf_load.o offwaketime_user.o $(TRACE_HELPERS)
79 spintest-objs := bpf_load.o spintest_user.o $(TRACE_HELPERS)
80 map_perf_test-objs := bpf_load.o map_perf_test_user.o
81 test_overhead-objs := bpf_load.o test_overhead_user.o
82 test_cgrp2_array_pin-objs := test_cgrp2_array_pin.o
83 test_cgrp2_attach-objs := test_cgrp2_attach.o
84 test_cgrp2_attach2-objs := test_cgrp2_attach2.o $(CGROUP_HELPERS)
85 test_cgrp2_sock-objs := test_cgrp2_sock.o
86 test_cgrp2_sock2-objs := bpf_load.o test_cgrp2_sock2.o
87 xdp1-objs := xdp1_user.o
88 # reuse xdp1 source intentionally
89 xdp2-objs := xdp1_user.o
90 xdp_router_ipv4-objs := bpf_load.o xdp_router_ipv4_user.o
91 test_current_task_under_cgroup-objs := bpf_load.o $(CGROUP_HELPERS) \
92 test_current_task_under_cgroup_user.o
93 trace_event-objs := bpf_load.o trace_event_user.o $(TRACE_HELPERS)
94 sampleip-objs := bpf_load.o sampleip_user.o $(TRACE_HELPERS)
95 tc_l2_redirect-objs := bpf_load.o tc_l2_redirect_user.o
96 lwt_len_hist-objs := bpf_load.o lwt_len_hist_user.o
97 xdp_tx_iptunnel-objs := bpf_load.o xdp_tx_iptunnel_user.o
98 test_map_in_map-objs := bpf_load.o test_map_in_map_user.o
99 per_socket_stats_example-objs := cookie_uid_helper_example.o
100 xdp_redirect-objs := bpf_load.o xdp_redirect_user.o
101 xdp_redirect_map-objs := bpf_load.o xdp_redirect_map_user.o
102 xdp_redirect_cpu-objs := bpf_load.o xdp_redirect_cpu_user.o
103 xdp_monitor-objs := bpf_load.o xdp_monitor_user.o
104 xdp_rxq_info-objs := xdp_rxq_info_user.o
105 syscall_tp-objs := bpf_load.o syscall_tp_user.o
106 cpustat-objs := bpf_load.o cpustat_user.o
107 xdp_adjust_tail-objs := xdp_adjust_tail_user.o
108 xdpsock-objs := xdpsock_user.o
109 xdp_fwd-objs := xdp_fwd_user.o
110 task_fd_query-objs := bpf_load.o task_fd_query_user.o $(TRACE_HELPERS)
111 xdp_sample_pkts-objs := xdp_sample_pkts_user.o $(TRACE_HELPERS)
113 # Tell kbuild to always build the programs
114 always := $(hostprogs-y)
115 always += sockex1_kern.o
116 always += sockex2_kern.o
117 always += sockex3_kern.o
118 always += tracex1_kern.o
119 always += tracex2_kern.o
120 always += tracex3_kern.o
121 always += tracex4_kern.o
122 always += tracex5_kern.o
123 always += tracex6_kern.o
124 always += tracex7_kern.o
125 always += sock_flags_kern.o
126 always += test_probe_write_user_kern.o
127 always += trace_output_kern.o
128 always += tcbpf1_kern.o
129 always += tc_l2_redirect_kern.o
130 always += lathist_kern.o
131 always += offwaketime_kern.o
132 always += spintest_kern.o
133 always += map_perf_test_kern.o
134 always += test_overhead_tp_kern.o
135 always += test_overhead_raw_tp_kern.o
136 always += test_overhead_kprobe_kern.o
137 always += parse_varlen.o parse_simple.o parse_ldabs.o
138 always += test_cgrp2_tc_kern.o
139 always += xdp1_kern.o
140 always += xdp2_kern.o
141 always += xdp_router_ipv4_kern.o
142 always += test_current_task_under_cgroup_kern.o
143 always += trace_event_kern.o
144 always += sampleip_kern.o
145 always += lwt_len_hist_kern.o
146 always += xdp_tx_iptunnel_kern.o
147 always += test_map_in_map_kern.o
148 always += cookie_uid_helper_example.o
149 always += tcp_synrto_kern.o
150 always += tcp_rwnd_kern.o
151 always += tcp_bufs_kern.o
152 always += tcp_cong_kern.o
153 always += tcp_iw_kern.o
154 always += tcp_clamp_kern.o
155 always += tcp_basertt_kern.o
156 always += tcp_tos_reflect_kern.o
157 always += xdp_redirect_kern.o
158 always += xdp_redirect_map_kern.o
159 always += xdp_redirect_cpu_kern.o
160 always += xdp_monitor_kern.o
161 always += xdp_rxq_info_kern.o
162 always += xdp2skb_meta_kern.o
163 always += syscall_tp_kern.o
164 always += cpustat_kern.o
165 always += xdp_adjust_tail_kern.o
166 always += xdpsock_kern.o
167 always += xdp_fwd_kern.o
168 always += task_fd_query_kern.o
169 always += xdp_sample_pkts_kern.o
171 KBUILD_HOSTCFLAGS += -I$(objtree)/usr/include
172 KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/
173 KBUILD_HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
174 KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
175 KBUILD_HOSTCFLAGS += -I$(srctree)/tools/perf
177 HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
178 HOSTCFLAGS_trace_helpers.o += -I$(srctree)/tools/lib/bpf/
180 HOSTCFLAGS_trace_output_user.o += -I$(srctree)/tools/lib/bpf/
181 HOSTCFLAGS_offwaketime_user.o += -I$(srctree)/tools/lib/bpf/
182 HOSTCFLAGS_spintest_user.o += -I$(srctree)/tools/lib/bpf/
183 HOSTCFLAGS_trace_event_user.o += -I$(srctree)/tools/lib/bpf/
184 HOSTCFLAGS_sampleip_user.o += -I$(srctree)/tools/lib/bpf/
185 HOSTCFLAGS_task_fd_query_user.o += -I$(srctree)/tools/lib/bpf/
186 HOSTCFLAGS_xdp_sample_pkts_user.o += -I$(srctree)/tools/lib/bpf/
188 KBUILD_HOSTLDLIBS += $(LIBBPF) -lelf
189 HOSTLDLIBS_tracex4 += -lrt
190 HOSTLDLIBS_trace_output += -lrt
191 HOSTLDLIBS_map_perf_test += -lrt
192 HOSTLDLIBS_test_overhead += -lrt
193 HOSTLDLIBS_xdpsock += -pthread
195 # Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
196 # make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
197 LLC ?= llc
198 CLANG ?= clang
199 LLVM_OBJCOPY ?= llvm-objcopy
200 BTF_PAHOLE ?= pahole
202 # Detect that we're cross compiling and use the cross compiler
203 ifdef CROSS_COMPILE
204 HOSTCC = $(CROSS_COMPILE)gcc
205 CLANG_ARCH_ARGS = -target $(ARCH)
206 endif
208 BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris)
209 BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF)
210 BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm')
211 BTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \
212 $(CLANG) -target bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \
213 readelf -S ./llvm_btf_verify.o | grep BTF; \
214 /bin/rm -f ./llvm_btf_verify.o)
216 ifneq ($(BTF_LLVM_PROBE),)
217 EXTRA_CFLAGS += -g
218 else
219 ifneq ($(and $(BTF_LLC_PROBE),$(BTF_PAHOLE_PROBE),$(BTF_OBJCOPY_PROBE)),)
220 EXTRA_CFLAGS += -g
221 LLC_FLAGS += -mattr=dwarfris
222 DWARF2BTF = y
223 endif
224 endif
226 # Trick to allow make to be run from this directory
227 all:
228 $(MAKE) -C ../../ $(CURDIR)/ BPF_SAMPLES_PATH=$(CURDIR)
230 clean:
231 $(MAKE) -C ../../ M=$(CURDIR) clean
232 @rm -f *~
234 $(LIBBPF): FORCE
235 # Fix up variables inherited from Kbuild that tools/ build system won't like
236 $(MAKE) -C $(dir $@) RM='rm -rf' LDFLAGS= srctree=$(BPF_SAMPLES_PATH)/../../ O=
238 $(obj)/syscall_nrs.s: $(src)/syscall_nrs.c
239 $(call if_changed_dep,cc_s_c)
241 $(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE
242 $(call filechk,offsets,__SYSCALL_NRS_H__)
244 clean-files += syscall_nrs.h
246 FORCE:
249 # Verify LLVM compiler tools are available and bpf target is supported by llc
250 .PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
252 verify_cmds: $(CLANG) $(LLC)
253 @for TOOL in $^ ; do \
254 if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
255 echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
256 exit 1; \
257 else true; fi; \
258 done
260 verify_target_bpf: verify_cmds
261 @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
262 echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
263 echo " NOTICE: LLVM version >= 3.7.1 required" ;\
264 exit 2; \
265 else true; fi
267 $(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF)
268 $(src)/*.c: verify_target_bpf $(LIBBPF)
270 $(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
272 # asm/sysreg.h - inline assembly used by it is incompatible with llvm.
273 # But, there is no easy way to fix it, so just exclude it since it is
274 # useless for BPF samples.
275 $(obj)/%.o: $(src)/%.c
276 @echo " CLANG-bpf " $@
277 $(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
278 -I$(srctree)/tools/testing/selftests/bpf/ \
279 -D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \
280 -D__TARGET_ARCH_$(ARCH) -Wno-compare-distinct-pointer-types \
281 -Wno-gnu-variable-sized-type-not-at-end \
282 -Wno-address-of-packed-member -Wno-tautological-compare \
283 -Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
284 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@
285 ifeq ($(DWARF2BTF),y)
286 $(BTF_PAHOLE) -J $@
287 endif