eunomia-bpf / bpftime

Userspace eBPF runtime for fast Uprobe & Syscall hook & Extensions
https://eunomia.dev/bpftime/
MIT License
744 stars 73 forks source link

llvm-jit: implement AOT compilation #127

Closed Officeyutong closed 8 months ago

Officeyutong commented 8 months ago

Closes #10

Adds AOT compilation support for llvm-jit.

AOT is transparent for users. llvm-jit will automatically handle the compilation, cache, and load of aot objects. By default, an ebpf program will be compiled AOT and cached at ~/.bpftime/aot-cache/<SHA256-OF-EBPF-PROGRAM>. In subsequent compiling process, if llvm-jit detected the aot cache of the same ebpf program, it will read and load the cached object file into the LLJIT instance, instead of compiling the ebpf program from IRBuilder.

AOT is enabled if environment variable BPFTIME_ENABLE_AOT is set for the agent

yunwei37 commented 8 months ago

Maybe we can use basic vm cli to enable end users to use aot compiled eBPF objects?

We will need a small demo for them.

Officeyutong commented 8 months ago

Can we change the cache path to ~/.bpftime/aot-cache/?

So there will not be multiple folders in home.

It's fixed now

Officeyutong commented 8 months ago

Maybe we can use basic vm cli to enable end users to use aot compiled eBPF objects?

We will need a small demo for them.

Updated now. Documents in README.md is also updated. Now we may use bpftime [start|attach] --no-aot, or set BPFTIME_DISABLE_AOT=11 to disable aot.

Do we need the feature that allows a user to specify an elf object as the compiled object of a certain ebpf program that is going to be loaded by bpftime? (allow users to manually specify the compiled result, instead of loading & cache-ing them automatically)

yunwei37 commented 8 months ago

Well... I think aot should not always be enabled by default...

We can implement 2 options in https://github.com/eunomia-bpf/bpftime/tree/master/vm/cli, do not need to change the bpftime cli?

1.compile option: allow users to compile a eBPF elf file into a native elf file

  1. Load option: allow load and exec the native elf directly

We may not need to change the bpftime cli in tools directory in this pr? It can be done in the next PR.

Officeyutong commented 8 months ago

Well... I think aot should not always be enabled by default...

We can implement 2 options in https://github.com/eunomia-bpf/bpftime/tree/master/vm/cli, do not need to change the bpftime cli?

1.compile option: allow users to compile a eBPF elf file into a native elf file 2. Load option: allow load and exec the native elf directly

We may not need to change the bpftime cli in tools directory in this pr? It can be done in the next PR.

The CLI https://github.com/eunomia-bpf/bpftime/tree/master/vm/cli is in fact a program used for bpf-conformance and performance test. If we want a program that compiles and executes ebpf programs, a new target might be better

I think the changes to bpftime-cli (/tools) and a seperate cli that can compile and loads ebpf program might be added in another PR. So I will put changes to bpftime cli in another PR, and disable AOT by default

Officeyutong commented 8 months ago

Well... I think aot should not always be enabled by default...

We can implement 2 options in https://github.com/eunomia-bpf/bpftime/tree/master/vm/cli, do not need to change the bpftime cli?

1.compile option: allow users to compile a eBPF elf file into a native elf file 2. Load option: allow load and exec the native elf directly

We may not need to change the bpftime cli in tools directory in this pr? It can be done in the next PR.

I've updated this PR: