Skip to content

Commit

Permalink
Done primary benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Officeyutong committed Aug 19, 2023
1 parent 9dfb929 commit f204eb0
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 409 deletions.
1 change: 1 addition & 0 deletions bpf_progs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.bpf.bin
*.bpf.o
*.native
10 changes: 7 additions & 3 deletions bpf_progs/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
ALL_PROGS = $(patsubst %.bpf.c,%.bpf.bin,$(shell ls *.bpf.c))
ALL_EBPF_PROGS = $(patsubst %.bpf.c,%.bpf.bin,$(shell ls *.bpf.c))
ALL_NATIVE_PROGS = $(patsubst %.bpf.c,%.native,$(shell ls *.bpf.c))

all: $(ALL_PROGS)
all: $(ALL_EBPF_PROGS) $(ALL_NATIVE_PROGS)

%.bpf.o: %.bpf.c
clang -Wall -O2 -target bpf -c -o $@ $<
%.bpf.bin: %.bpf.o
llvm-objcopy -j .text -O binary $< $@
%.native: %.bpf.c native_wrapper.c
clang -Wall -O2 -o $@ $^

clean:
rm -rf *.bpf.o *.bpf.bin
rm -rf *.bpf.o *.bpf.bin *.native
1 change: 1 addition & 0 deletions bpf_progs/memory_a_plus_b.bpf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unsigned long long bpf_main(unsigned long long *mem) { return mem[0] + mem[1]; }
1 change: 1 addition & 0 deletions bpf_progs/memory_a_plus_b.mem
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
 0@P`p�
32 changes: 32 additions & 0 deletions bpf_progs/native_wrapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <assert.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
uint64_t get_time_ns() {
struct timespec ts;
int err = clock_gettime(CLOCK_MONOTONIC, &ts);
assert(err == 0);
return (uint64_t)ts.tv_sec * 1000000000 + (uint64_t)ts.tv_nsec;
}

extern uint64_t bpf_main(void *);
int main(int argc, const char **argv) {
void *memory = NULL;
if (argc == 2) {
FILE *fp = fopen(argv[1], "r");
assert(fp != NULL);
fseek(fp, 0, SEEK_END);
long file_size = ftell(fp);
fseek(fp, 0, SEEK_SET);
memory = malloc(file_size);
fread(memory, 1, file_size, fp);
}
uint64_t start = get_time_ns();
uint64_t ret = bpf_main(memory);
uint64_t end = get_time_ns();
printf("0 %" PRIu64 " %" PRIu64 "\n", end - start, ret);
free(memory);
return 0;
}
4 changes: 2 additions & 2 deletions bpf_progs/prime.bpf.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
int main() {
unsigned long long bpf_main(void *m) {
long cnt = 0;
for (int i = 1; i < 1e4; i++) {
int ok = 1;
for (int j = 1; j * j <= i && ok; j++) {
for (int j = 2; j * j <= i && ok; j++) {
if (i % j == 0)
ok = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion bpf_progs/simple.bpf.c
Original file line number Diff line number Diff line change
@@ -1 +1 @@
int main() { return 12345678; }
unsigned long long bpf_main(void * m) { return 12345678; }
3 changes: 3 additions & 0 deletions bpftime-cli-rbpf/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
rustflags = ["-C", "target-feature=+crt-static"]
target = "x86_64-unknown-linux-gnu"
1 change: 1 addition & 0 deletions bpftime-cli-rbpf/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
Cargo.lock
Loading

0 comments on commit f204eb0

Please sign in to comment.