Skip to content

Commit abf6fa0

Browse files
committed
feat: Add xdp cpumap
1 parent 5a79477 commit abf6fa0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3041
-429
lines changed

.gitignore

+8-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ target/
5151
/agent/src/ebpf/samples/rust/socket-tracer/target
5252
/agent/src/ebpf/samples/rust/socket-tracer/src/ebpf.rs
5353
/agent/src/ebpf/.flamegraph.pl
54-
/agent/src/ebpf/kernel/*.tmp
55-
56-
57-
54+
/agent/src/ebpf/user/extended/bpf/*.tmp
55+
/agent/src/ebpf/user/extended/bpf/*.ll
56+
/agent/src/ebpf/user/extended/bpf/*.objdump
57+
/agent/src/ebpf/user/extended/bpf/*.elf
58+
/agent/src/ebpf/user/extended/bpf/.ebpf-compile.ok
59+
/agent/src/ebpf/user/extended/bpf/cpu_balancer_bpf_bytecode.c
60+
/agent/src/ebpf/user/extended/*.o
61+
/agent/src/ebpf/user/extended/test/*.o

agent/src/ebpf/Makefile

+26-12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ GNU_CC ?= gcc
3737
MUSL_CC ?= musl-gcc
3838
OBJDIR ?= .
3939
STATIC_OBJDIR := $(OBJDIR)/staticobjs
40+
EXTDIR := $(OBJDIR)/user/extended
4041

4142
define compile_socket_trace_elf
4243
@echo " COMPILE ELF kernel version $(1)"
@@ -71,7 +72,7 @@ CLANG_VER := $(shell ${CLANG} --version | grep "version" | awk '{if ($$3!="versi
7172
CLANG_VER_MAIN := $(shell ${CLANG} --version | grep "version" | awk '{print $$3}' | awk -F. '{print $$1}' | awk '{if (int($$0)!=0){print $$0}else{exit -1}}' || ${CLANG} --version | grep "version" | awk '{print $$4}' | awk -F. '{print $$1}' | awk '{if (int($$0)!=0){print $$0}else{exit -1}}')
7273
LIBTRACE := libtrace.a
7374
OBJS := user/elf.o \
74-
user/common.o \
75+
user/utils.o \
7576
user/symbol.o \
7677
user/proc.o \
7778
user/go_tracer.o \
@@ -91,8 +92,8 @@ OBJS := user/elf.o \
9192
user/vec.o \
9293
user/bihash.o \
9394
user/profile/profile_common.o \
94-
$(patsubst %.c,%.o,$(wildcard user/extended/*.c)) \
95-
$(patsubst %.c,%.o,$(wildcard user/extended/profile/*.c)) \
95+
$(patsubst %.c,%.o,$(wildcard $(EXTDIR)/*.c)) \
96+
$(patsubst %.c,%.o,$(wildcard $(EXTDIR)/profile/*.c)) \
9697
user/profile/perf_profiler.o \
9798
user/profile/stringifier.o \
9899
user/profile/java/jvm_symbol_collect.o \
@@ -107,7 +108,7 @@ JAVA_AGENT_SRC := user/profile/java/symbol_collect_agent.c
107108
JAVA_AGENT_MACROS := -DAGENT_LIB_NAME="\"$(JAVA_AGENT_GNU_SO)\"" -DAGENT_MUSL_LIB_NAME="\"$(JAVA_AGENT_MUSL_SO)\""
108109

109110
STATIC_OBJS := $(addprefix $(STATIC_OBJDIR)/,$(OBJS))
110-
CFLAGS ?= -std=gnu99 -g -O2 -ffunction-sections -fdata-sections -fPIC -Wall -Wno-strict-aliasing -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers -I/usr/include/bcc -I../../../crates/trace-utils/src/
111+
CFLAGS ?= -std=gnu99 -g -O0 -ffunction-sections -fdata-sections -fPIC -Wall -Wno-strict-aliasing -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers -I/usr/include/bcc -I../../../crates/trace-utils/src/
111112
# '-Wformat-truncation' : The warning was added in gcc7.1
112113
GCC_VER_GTE71 := $(shell echo `gcc --version | grep ^gcc | cut -f3 -d' '|cut -f1-2 -d.` \>= 7.1 | sed -e 's/\./*100+/g' | bc )
113114
ifeq ($(GCC_VER_GTE71),1)
@@ -127,7 +128,7 @@ CFLAGS += -I../../crates/trace-utils/src
127128
# where the error occurred.
128129
# -DDF_MEM_DEBUG Used for memory leak detection, to check for memory
129130
# leak issues during the debugging phase.
130-
CFLAGS += $(MACHINE_CFLAGS) -fno-omit-frame-pointer -I/usr/lib/jvm/java/include -I/usr/lib/jvm/java/include/linux -I.
131+
CFLAGS += $(MACHINE_CFLAGS) -DBPF_DEBUG -fno-omit-frame-pointer -I/usr/lib/jvm/java/include -I/usr/lib/jvm/java/include/linux -I.
131132
ifeq ($(findstring musl,$(CC)),musl)
132133
IS_MUSL := 1
133134
ifeq ($(findstring aarch64,$(ARCH)),aarch64)
@@ -139,14 +140,16 @@ endif
139140

140141
all: build
141142

142-
SOCKET_TRACE_ELFS := user/socket_trace_bpf_common.c \
143-
user/socket_trace_bpf_3_10_0.c \
143+
SOCKET_TRACE_ELFS :=
144+
#user/socket_trace_bpf_common.c
145+
# user/socket_trace_bpf_3_10_0.c \
144146
user/socket_trace_bpf_5_2_plus.c \
145147
user/socket_trace_bpf_kfunc.c \
146148
user/socket_trace_bpf_kylin.c \
147149
user/socket_trace_bpf_rt.c
148150

149-
PERF_PROFILER_ELFS := user/perf_profiler_bpf_common.c \
151+
PERF_PROFILER_ELFS :=
152+
#user/perf_profiler_bpf_common.c \
150153
user/perf_profiler_bpf_5_2_plus.c \
151154
152155
ELFFILES := $(SOCKET_TRACE_ELFS) $(PERF_PROFILER_ELFS)
@@ -163,6 +166,11 @@ define check_clang
163166
@rm -rf data
164167
endef
165168

169+
ext-bpf: $(EXTDIR)/bpf/.ebpf-compile.ok
170+
$(EXTDIR)/bpf/.ebpf-compile.ok: tools/bintobuffer
171+
@make -C $(EXTDIR)/bpf -f extended.bpf.mk --no-print-directory
172+
@touch $@
173+
166174
user/socket_trace_bpf_common.c: tools/bintobuffer kernel/socket_trace.bpf.c
167175
$(call check_clang)
168176
$(call compile_socket_trace_elf, common)
@@ -228,15 +236,15 @@ $(JAVA_AGENT_MUSL_SO): tools/bintobuffer $(JAVA_AGENT_SRC)
228236
@rm -rf user/profile/java_agent_so_musl.c
229237
@./tools/bintobuffer ./$@ user/profile/java_agent_so_musl.c java_agent_so_musl
230238

231-
build: $(ELFFILES) $(JAVA_TOOL) $(LIBTRACE)
239+
build: $(ELFFILES) $(EXTDIR)/bpf/.ebpf-compile.ok $(JAVA_TOOL) $(LIBTRACE)
232240

233241
tools: $(LIBTRACE)
234242
$(call msg,TOOLS,deepflow-ebpfctl)
235243
$(Q)$(CC) $(CFLAGS) --static -g -O2 user/ctrl_tracer.c user/ctrl.c $(LIBTRACE) -o deepflow-ebpfctl -lelf -lz -lpthread
236244

237-
$(JAVA_TOOL): $(JAVA_AGENT_SO) user/log.c user/common.c user/mem.c user/vec.c user/profile/java/jvm_symbol_collect.c libs/jattach/build/libjattach.a
245+
$(JAVA_TOOL): $(JAVA_AGENT_SO) user/log.c user/utils.c user/mem.c user/vec.c user/profile/java/jvm_symbol_collect.c libs/jattach/build/libjattach.a
238246
$(call msg,TOOLS,$@)
239-
@$(GNU_CC) $(CFLAGS) -DJAVA_AGENT_ATTACH_TOOL user/log.c user/common.c user/mem.c user/vec.c user/profile/java/jvm_symbol_collect.c libs/jattach/build/libjattach.a -o $@ -ldl -lpthread
247+
@$(GNU_CC) $(CFLAGS) -DJAVA_AGENT_ATTACH_TOOL user/log.c user/utils.c user/mem.c user/vec.c user/profile/java/jvm_symbol_collect.c libs/jattach/build/libjattach.a -o $@ -ldl -lpthread
240248
@rm -rf user/profile/deepflow_jattach_bin.c
241249
@./tools/bintobuffer ./$@ user/profile/deepflow_jattach_bin.c deepflow_jattach_bin
242250

@@ -320,9 +328,15 @@ clean:
320328
$(Q)rm -rf samples/rust/socket-tracer/target
321329
$(Q)rm -rf samples/rust/profiler/target
322330
$(Q)rm -rf $(JAVA_AGENT_SO) $(JAVA_TOOL) tools/bintobuffer
331+
$(Q)make -C $(EXTDIR)/bpf -f extended.bpf.mk clean --no-print-directory
332+
$(Q)rm -rf $(EXTDIR)/bpf/.ebpf-compile.ok
323333

324334
test: $(ELFFILES) $(LIBTRACE)
325335
$(Q)$(MAKE) -C test --no-print-directory
326336

327-
.PHONY: all build clean tools test rust-sample .socket-tracer .profiler
337+
ext-test: $(ELFFILES) $(LIBTRACE)
338+
$(Q)$(MAKE) -C $(EXTDIR)/test clean --no-print-directory
339+
$(Q)$(MAKE) -C $(EXTDIR)/test --no-print-directory
340+
341+
.PHONY: all build ext-bpf clean tools test rust-sample .socket-tracer .profiler
328342

agent/src/ebpf/kernel/include/bpf_base.h

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ static int
118118
__attribute__ ((__unused__)) (*bpf_get_stack) (void *ctx, void *buf, __u32 size,
119119
int flags) = (void *)67;
120120

121+
// Linux 4.14: Added support for BPF_MAP_TYPE_CPUMAP, allowing packets to be redirected to specific CPUs.
122+
static long
123+
__attribute__ ((__unused__)) (*bpf_redirect_map)(void *map, __u32 key, __u64 flags) =
124+
(void *)51;
125+
121126
#if __GNUC__ && !__clang__
122127
#define SEC(name) __attribute__((section(name), used))
123128
#else
@@ -292,6 +297,7 @@ _Pragma("GCC error \"PT_GO_REGS_PARM\"");
292297

293298
#define TP_SYSCALL_PROG(F) SEC("tracepoint/syscalls/sys_"__stringify(F)) int df_T_##F
294299
#define TP_SCHED_PROG(F) SEC("tracepoint/sched/sched_"__stringify(F)) int df_T_##F
300+
#define TP_XDP_PROG(F) SEC("tracepoint/xdp/xdp_"__stringify(F)) int df_T_##F
295301
#define PROGTP(F) SEC("prog/tp/"__stringify(F)) int df_TP_##F
296302
#define PROGKP(F) SEC("prog/kp/"__stringify(F)) int df_KP_##F
297303
#define PROGPE(F) SEC("prog/pe/"__stringify(F)) int df_PE_##F

agent/src/ebpf/kernel/include/utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define DF_UTILS_H
2424

2525
#include <arpa/inet.h>
26-
#include "../../user/utils.h"
26+
#include "../../user/common_utils.h"
2727

2828
#undef __inline
2929
#define __inline inline __attribute__((__always_inline__))

agent/src/ebpf/tools/bintobuffer.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
#include <stdio.h>
29+
#include <errno.h>
2930
#include <sys/types.h>
3031
#include <sys/stat.h>
3132
#include <fcntl.h>
@@ -42,7 +43,8 @@ static unsigned char *read_bin_file(char *name, int *len)
4243
//Open file
4344
file = fopen(name, "rb");
4445
if (!file) {
45-
fprintf(stderr, "Unable to open file %s", name);
46+
fprintf(stderr, "Unable to open file %s, with %s(%d)",
47+
name, strerror(errno), errno);
4648
return NULL;
4749
}
4850
//Get file length

agent/src/ebpf/user/bihash.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include "../user/common.h"
17+
#include "../user/utils.h"
1818
#include "../user/mem.h"
1919
#include "../user/log.h"
2020
#include "../user/types.h"

agent/src/ebpf/user/btf_core.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <stdlib.h>
2424
#include <limits.h>
2525
#include <sys/utsname.h>
26-
#include "common.h"
26+
#include "utils.h"
2727
#include "log.h"
2828
#include "elf.h"
2929
#include <bcc/linux/bpf.h>

0 commit comments

Comments
 (0)