Skip to content

Commit 237cbb5

Browse files
authored
vm: integrate ubpf & add compat layer for different vm implementations (eunomia-bpf#273)
1 parent 8ae9c71 commit 237cbb5

Some content is hidden

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

66 files changed

+1001
-4643
lines changed

.github/workflows/test-examples.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ jobs:
112112
executable: ./funclatency -i 1 ./victim:plus
113113
victim: ./victim
114114
syscall_trace: false
115-
expected_str: ": 1"
115+
expected_str: "|*"
116116
- path: libbpf-tools/mountsnoop
117117
executable: ./mountsnoop
118118
victim: ./victim
@@ -147,7 +147,10 @@ jobs:
147147
with:
148148
name: runtime-package-no-jit-${{matrix.container.name}}
149149
path: ~/.bpftime
150-
150+
- name: Install which(required by funclatency on fedora)
151+
if: ${{matrix.container.name=='fedora' && matrix.examples.path=='libbpf-tools/funclatency'}}
152+
run: |
153+
yum install -y which
151154
- name: Set permissions
152155
run: |
153156
chmod +x ~/.bpftime/*

.github/workflows/test-llvm-jit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ jobs:
3333
- name: build llvm JIT/AOT as a standalone library
3434
run: |
3535
cd vm/llvm-jit &&\
36-
cmake -B build -DCMAKE_BUILD_TYPE=Release &&\
36+
cmake -B build -DCMAKE_BUILD_TYPE=Release -DBPFTIME_BUILD_STANDALONE_LLVM_VM=YES &&\
3737
cmake --build build --target all -j
3838
3939
- name: build vm as a standalone library
4040
run: |
41-
cd vm && make build-llvm -j
41+
cd vm && make build-llvm -j

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ add_subdirectory(third_party/argparse)
9090

9191
# main library
9292
add_subdirectory(vm)
93-
if (BPFTIME_LLVM_JIT)
94-
add_subdirectory(vm/cli)
95-
endif()
9693

9794
add_subdirectory(attach)
9895

benchmark/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
add_executable(simple-benchmark-with-embed-ebpf-calling test_embed.c)
22

3-
add_dependencies(simple-benchmark-with-embed-ebpf-calling vm-bpf libbpf)
3+
add_dependencies(simple-benchmark-with-embed-ebpf-calling bpftime_vm libbpf)
44
target_compile_definitions(simple-benchmark-with-embed-ebpf-calling
55
PRIVATE
66
)
7-
target_link_libraries(simple-benchmark-with-embed-ebpf-calling vm-bpf ${LIBBPF_LIBRARIES} elf z)
7+
target_link_libraries(simple-benchmark-with-embed-ebpf-calling bpftime_vm ${LIBBPF_LIBRARIES} elf z)
88
target_include_directories(simple-benchmark-with-embed-ebpf-calling
99
PRIVATE
1010
${CMAKE_CURRENT_SOURCE_DIR}../vm/include

cmake/libbpf.cmake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Setup libbpf
33
#
4-
set(LIBBPF_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/libbpf/)
4+
set(LIBBPF_DIR ${CMAKE_CURRENT_LIST_DIR}/../third_party/libbpf/)
55
include(ExternalProject)
66
ExternalProject_Add(libbpf
77
PREFIX libbpf
@@ -20,7 +20,6 @@ ExternalProject_Add(libbpf
2020
set(LIBBPF_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/libbpf/)
2121
set(LIBBPF_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/libbpf/libbpf.a)
2222

23-
set(header_output_list)
2423

2524
function(copy_header SRC_DIR TARGET_DIR)
2625
file(GLOB_RECURSE FILES RELATIVE "${SRC_DIR}" "${SRC_DIR}/*")
@@ -67,8 +66,12 @@ endforeach()
6766

6867
add_dependencies(copy_headers libbpf)
6968

69+
add_custom_target(libbpf_with_headers)
70+
71+
add_dependencies(libbpf_with_headers libbpf copy_headers)
72+
7073
# # Setup bpftool
71-
set(BPFTOOL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/bpftool)
74+
set(BPFTOOL_DIR ${CMAKE_CURRENT_LIST_DIR}/../third_party/bpftool)
7275
set(BPFTOOL_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/bpftool)
7376
ExternalProject_Add(bpftool
7477
PREFIX bpftool

example/libbpf-tools/funclatency/funclatency.bpf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ static void exit(void)
6969
slot = log2l(delta);
7070
if (slot >= MAX_SLOTS)
7171
slot = MAX_SLOTS - 1;
72-
__sync_fetch_and_add(&hist[slot], 1);
72+
// ubpf does not support atomic instructions yet
73+
// __sync_fetch_and_add(&hist[slot], 1);
74+
hist[slot] += 1;
7375
}
7476

7577

example/libbpf-tools/funclatency/funclatency.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* - support uprobes on libraries without -p PID. (parse ld.so.cache)
99
* - support regexp pattern matching and per-function histograms
1010
*/
11+
#define _GNU_SOURCE
1112
#include <argp.h>
1213
#include <errno.h>
1314
#include <signal.h>

runtime/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ target_include_directories(${PROJECT_NAME}
123123

124124
target_link_libraries(${PROJECT_NAME}
125125
PUBLIC
126-
vm-bpf
126+
bpftime_vm
127127
spdlog::spdlog
128128
bpftime_base_attach_impl
129129
)
130-
add_dependencies(${PROJECT_NAME} vm-bpf FridaGum spdlog::spdlog libbpf bpftime_base_attach_impl)
130+
add_dependencies(${PROJECT_NAME} bpftime_vm FridaGum spdlog::spdlog libbpf bpftime_base_attach_impl)
131131

132132
if(BPFTIME_ENABLE_IOURING_EXT)
133133
target_link_libraries(${PROJECT_NAME}

runtime/object/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ add_library(bpftime-object OBJECT
33
bpf_object.cpp
44
)
55

6-
add_dependencies(bpftime-object copy_headers)
7-
add_dependencies(bpftime-object libbpf)
8-
add_dependencies(bpftime-object spdlog::spdlog)
6+
add_dependencies(bpftime-object copy_headers libbpf spdlog::spdlog bpftime_vm)
97

108
target_link_libraries(bpftime-object
119
PUBLIC
@@ -17,6 +15,7 @@ target_link_libraries(bpftime-object
1715
-lelf
1816
-lz
1917
spdlog::spdlog
18+
bpftime_vm
2019
)
2120

2221
target_include_directories(bpftime-object PUBLIC

runtime/object/bpf_object.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ namespace bpftime
1818
{
1919

2020
// ebpf object file
21-
class bpftime_object {
21+
class bpftime_object
22+
{
2223
public:
2324
bpftime_object(std::string_view path);
2425
~bpftime_object() = default;
@@ -31,7 +32,7 @@ class bpftime_object {
3132
void create_programs();
3233
bpftime_prog *find_program_by_name(std::string_view name) const;
3334
bpftime_prog *find_program_by_secname(std::string_view name) const;
34-
bpftime_prog *next_program(bpftime_prog *prog) const;
35+
bpftime_prog *next_program(bpftime_prog * prog) const;
3536
};
3637

3738
bpftime_prog *bpftime_object::next_program(bpftime_prog *prog) const
@@ -68,7 +69,7 @@ void bpftime_object::create_programs()
6869
const char *name = bpf_program__name(prog);
6970
if (!insns || !name) {
7071
SPDLOG_ERROR("Failed to get insns or name for prog {}",
71-
name || "<NULL>");
72+
name || "<NULL>");
7273
continue;
7374
}
7475
progs.emplace_back(
@@ -81,7 +82,7 @@ bpftime_object::find_program_by_secname(std::string_view name) const
8182
{
8283
const char *sec_name;
8384
struct bpf_program *prog = NULL;
84-
struct bpftime_prog *time_prog = progs.front().get();
85+
bpftime_prog *time_prog = progs.front().get();
8586
// iterate through the bpftime_prog from prog and bpf_program
8687
bpf_object__for_each_program(prog, obj.get())
8788
{
@@ -125,14 +126,14 @@ bpftime_object::bpftime_object(std::string_view path)
125126
}
126127

127128
// open the object elf file and load it into the context
128-
struct bpftime_object *bpftime_object_open(const char *obj_path)
129+
bpftime_object *bpftime_object_open(const char *obj_path)
129130
{
130-
struct bpftime_object *obj = new bpftime_object(obj_path);
131+
bpftime_object *obj = new bpftime_object(obj_path);
131132
return obj;
132133
}
133134

134135
// close and free the object
135-
void bpftime_object_close(struct bpftime_object *obj)
136+
void bpftime_object_close(bpftime_object *obj)
136137
{
137138
if (!obj) {
138139
return;
@@ -151,31 +152,28 @@ static int libbpf_print_fn(enum libbpf_print_level level, const char *format,
151152
}
152153

153154
// The execution unit or bpf function.
154-
struct bpftime_prog;
155+
class bpftime_prog;
155156
// find the program by section name
156-
struct bpftime_prog *
157-
bpftime_object_find_program_by_name(struct bpftime_object *obj,
158-
const char *name)
157+
class bpftime_prog *bpftime_object_find_program_by_name(bpftime_object *obj,
158+
const char *name)
159159
{
160160
if (!obj || !name) {
161161
return NULL;
162162
}
163163
return obj->find_program_by_name(name);
164164
}
165165

166-
struct bpftime_prog *
167-
bpftime_object_find_program_by_secname(struct bpftime_object *obj,
168-
const char *secname)
166+
class bpftime_prog *bpftime_object_find_program_by_secname(bpftime_object *obj,
167+
const char *secname)
169168
{
170169
if (!obj || !secname) {
171170
return NULL;
172171
}
173172
return obj->find_program_by_secname(secname);
174173
}
175174

176-
struct bpftime_prog *
177-
bpftime_object__next_program(const struct bpftime_object *obj,
178-
struct bpftime_prog *prog)
175+
class bpftime_prog *bpftime_object__next_program(const bpftime_object *obj,
176+
class bpftime_prog *prog)
179177
{
180178
if (!obj) {
181179
return NULL;

runtime/src/handler/handler_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ handler_manager::handler_manager(managed_shared_memory &mem,
2323
handler_manager::~handler_manager()
2424
{
2525
for (std::size_t i = 0; i < handlers.size(); i++) {
26-
SPDLOG_ERROR(
26+
SPDLOG_TRACE(
2727
"Handler at {} is not destroyed, but handler_manager is being destroyed",
2828
i);
2929
}

runtime/unit-test/assets/filter.bpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ enum filter_op {
1616
};
1717

1818
static const int (*test_pass_param)(char *str, char c,
19-
long long parm1) = (void *)4097;
19+
long long parm1) = (void *)40;
2020

2121
uint64_t BPF_UPROBE(my_function, char *str, char c, long long parm1)
2222
{

runtime/unit-test/attach_with_ebpf/test_attach_filter_with_ebpf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ TEST_CASE("Test attaching filter program with ebpf, and reverting")
4747
REQUIRE(bpftime_helper_group::get_kernel_utils_helper_group()
4848
.add_helper_group_to_prog(prog) >= 0);
4949
bpftime_helper_info info = {
50-
.index = 4097,
50+
.index = 40,
5151
.name = "test_pass_param",
5252
.fn = (void *)__bpftime_attach_filter_with_ebpf__test_pass_param,
5353
};

runtime/unit-test/maps/test_external_map_ops.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ TEST_CASE("Test basic operations of external hash map ops")
8787
uint32_t key = i;
8888
auto val = *(uint64_t *)(map_handler.map_lookup_elem(&key));
8989
REQUIRE(val == i);
90-
spdlog::info("val for {} = {:x}", i, val);
90+
spdlog::debug("val for {} = {:x}", i, val);
9191
}
9292
}

runtime/unit-test/maps/test_shm_hash_maps.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void test_lookup_map(int fd, bpftime::handler_manager &manager_ref,
3737
uint32_t key = i;
3838
auto val = *(uint64_t *)(map_handler.map_lookup_elem(&key));
3939
REQUIRE(val == ((((uint64_t)key) << 32) | 0xffffffff));
40-
spdlog::info("val for {} = {:x}", i, val);
40+
spdlog::debug("val for {} = {:x}", i, val);
4141
}
4242
}
4343

@@ -58,10 +58,10 @@ static void test_get_next_element(int fd, bpftime::handler_manager &manager_ref,
5858
uint32_t key = 0;
5959
uint32_t next_key = 0;
6060
while (map_handler.bpf_map_get_next_key(&key, &next_key) == 0) {
61-
spdlog::info("key = {}, next_key = {}", key, next_key);
61+
spdlog::debug("key = {}, next_key = {}", key, next_key);
6262
key = next_key;
6363
}
64-
spdlog::info("key = {}, next_key = {}", key, next_key);
64+
spdlog::debug("key = {}, next_key = {}", key, next_key);
6565
}
6666

6767
static void handle_sub_process()

tools/aot/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ target_include_directories(bpftime-aot-cli PRIVATE
1313
../../runtime/include/
1414
../../runtime/src/
1515
${LIBBPF_INCLUDE_DIRS})
16-
target_link_libraries(bpftime-aot-cli PRIVATE spdlog::spdlog argparse vm-bpf runtime ${LIBBPF_LIBRARIES} elf z)
16+
target_link_libraries(bpftime-aot-cli PRIVATE spdlog::spdlog argparse bpftime_vm_compat bpftime_llvm_jit_vm runtime ${LIBBPF_LIBRARIES} elf z)
1717
set_property(TARGET bpftime-aot-cli PROPERTY CXX_STANDARD 20)
1818

1919
target_compile_definitions(bpftime-aot-cli PRIVATE _GNU_SOURCE)
2020

21-
add_dependencies(bpftime-aot-cli spdlog::spdlog argparse vm-bpf libbpf)
21+
add_dependencies(bpftime-aot-cli spdlog::spdlog argparse bpftime_vm_compat bpftime_llvm_jit_vm libbpf)
2222

2323
install(TARGETS bpftime-aot-cli CONFIGURATIONS Release Debug RelWithDebInfo DESTINATION ~/.bpftime)

0 commit comments

Comments
 (0)