If you wanted something architecture-agnostic, and you didn’t mind slightly worse performance, you could use a C toolchain to compile ubpf (stripped of certain features) directly for the microcontroller once, and then use BPFnative.jl to emit BPF kernels to run on the ubpf interpreter. While it wasn’t originally designed for embedded use, I could see it being quite effective for hardware-agnostic event-driven programming.
Hi @jpsamaroo, can you describe what it is that BPFnative does exactly? it sounds awesome, and I’m imagining using it to program packet classifiers in Julia with eBPF emitted, but there don’t seem to be any docs? How do I use it, or at least where do I read about how to use it?
BPFnative allows generating eBPF bytecode from simple Julia functions, using the same compilation infrastructure used by CUDA.jl and the other GPU frontends. Currently it just has bindings to support calling into libbpf (the Linux library for attaching BPF programs), but there’s no reason you can’t use
BPFnative.bpffunction directly to emit bytecode to a file or stream and load it onto an MCU running ubpf.
I would recommend reading the tests in lieu of documentation right now; they’re pretty comprehensive and show how to do various kinds of fancy things, like modifying packets, printing kernel stacktraces, etc.
Thanks, I’ve been wanting to use eBPF in some applications with OpenWrt but I don’t really want to get into compiling C to eBPF, so I’m excited to think that you could do it in Julia which is just substantially more friendly (and generally awesome).
I’ll post over at forum.openwrt.org to see if anyone wants to work on it and test it out. If you’re interested in this application I invite you to go over there and participate!
As this post is now the top result for “julia xtensa” for me, I just want to add that LLVM has merged the patches for xtensa support and support is available in LLVM 16 (maybe the support is still label as experimental). Julia 1.10 currently uses LLVM 15.
Here is a nice post on how to use julia on Arduino:
Maybe this approach is similar to get julia on xtensa working (with a newer LLVM).