-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9dfb929
commit f204eb0
Showing
16 changed files
with
175 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.bpf.bin | ||
*.bpf.o | ||
*.native |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0@P`p� |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/target | ||
Cargo.lock |
Oops, something went wrong.