Live data from Hacker News

eBPF Is Awesome

filipnikolovski.com

11–20 of 46 posts

Re: eBPF Is Awesome

#11
post #10

That sounds extremely cool. Sadly, I don't program in Linux, so I can't use it. :'(

You may try out generic eBPF outside of Linux: https://github.com/generic-ebpf/generic-ebpf

LLVM also has a BPF backend so you can compile any C++/C program to run on BPF.

Re: eBPF Is Awesome

#12
post #8

It seems worth mentioning that the code actually executing in the kernel, when it is running your eBPF, is native machine code, ahead-of-time compiled from the bytecode program you gave to the kernel.

Technically it's JITted not AOT compiled.

Re: eBPF Is Awesome

#13
post #3

Most examples of BPF code are written in a mix of Python and C using BCC, the "BPF Compiler Collection", which essentially treats all of LLVM and clang as a library callable from Python code. I can't get my head around using it that way, and have found it pretty straightforward to just write C programs, compiled with clang `-target bpf`. Until very recently, writing anything interesting this way required you to decla…

I got a bunch of Numba version related errors (Python 3.7) when I tried to run the example code in the website and my thoughts were in the same direction. Was wondering if it is possible to write something like this in, say, Golang instead of Python.

Re: eBPF Is Awesome

#14
post #3

Most examples of BPF code are written in a mix of Python and C using BCC, the "BPF Compiler Collection", which essentially treats all of LLVM and clang as a library callable from Python code. I can't get my head around using it that way, and have found it pretty straightforward to just write C programs, compiled with clang `-target bpf`. Until very recently, writing anything interesting this way required you to decla…

I got a bunch of Numba version related errors (Python 3.7) when I tried to run the example code in the website and my thoughts were in the same direction. Was wondering if it is possible to write something like this in, say, Golang instead of Python.

There are Go bindings for BPF and BCC: https://github.com/iovisor/gobpf

I'm not sure the state of them at this point, but it's the same paradigm GP mentioned.

Re: eBPF Is Awesome

#15

That sounds extremely cool. Sadly, I don't program in Linux, so I can't use it. :'(

If you're using an old enough MacOS X (I think 10.12 or older), DTrace has similar functionality. Unfortunately it has been broken in recent MacOS versions, at least unless you disable SIP.

Re: eBPF Is Awesome

#16
post #3

Most examples of BPF code are written in a mix of Python and C using BCC, the "BPF Compiler Collection", which essentially treats all of LLVM and clang as a library callable from Python code. I can't get my head around using it that way, and have found it pretty straightforward to just write C programs, compiled with clang `-target bpf`. Until very recently, writing anything interesting this way required you to decla…

Handling input options and displaying output is a little easier in python. It also let's you hack the tools quick and run any changes instantly.

Re: eBPF Is Awesome

#17
post #7
post #3

Most examples of BPF code are written in a mix of Python and C using BCC, the "BPF Compiler Collection", which essentially treats all of LLVM and clang as a library callable from Python code. I can't get my head around using it that way, and have found it pretty straightforward to just write C programs, compiled with clang `-target bpf`. Until very recently, writing anything interesting this way required you to decla…

I think dtrace has the same problem, i.e. it's pretty tightly coupled to the exact functions / trace points in the kernel. A different kernel can break a dtrace script, although I think their code changes a lot less than Linux does. It seems somewhat unavoidable, if the goal is to introspect the kernel at a very intimate level ...

BTF is designed to avoid the problem, by having the live kernel export symbols; supposedly --- I haven't used it --- the toolchain even converts it to a header file, so BPF programs just include a "vmlinux.h" instead of includes pointing into kernel source (which is a nightmare). It's ambitious and I'm surprised it does as much as it does but apparently they're solving this problem.

Re: eBPF Is Awesome

#18
post #14

Earlier quoted context omitted.

I got a bunch of Numba version related errors (Python 3.7) when I tried to run the example code in the website and my thoughts were in the same direction. Was wondering if it is possible to write something like this in, say, Golang instead of Python.

There are Go bindings for BPF and BCC: https://github.com/iovisor/gobpf I'm not sure the state of them at this point, but it's the same paradigm GP mentioned.

I think the more idiomatic thing to use in Go is Cilium, which has tooling support for loading and attaching eBPF programs, and also a weird embedding system that calls clang9 directly.

I find the Cilium libraries sort of hit-or-miss† but they mostly work well, but, again, I just build my BPF programs themselves with Makefiles into .o's, and use Cilium (or, for XDP/TC, iproute2) to load them.

https://twitter.com/tqbf/status/1336825568478834689

Re: eBPF Is Awesome

#19
post #3

Most examples of BPF code are written in a mix of Python and C using BCC, the "BPF Compiler Collection", which essentially treats all of LLVM and clang as a library callable from Python code. I can't get my head around using it that way, and have found it pretty straightforward to just write C programs, compiled with clang `-target bpf`. Until very recently, writing anything interesting this way required you to decla…

There's also https://github.com/alessandrod/bpf-linker to make compiling a bit easier, as it does necessary inlining at link-time.

Re: eBPF Is Awesome

#20
post #11
post #10

Earlier quoted context omitted.

You may try out generic eBPF outside of Linux: https://github.com/generic-ebpf/generic-ebpf

LLVM also has a BPF backend so you can compile any C++/C program to run on BPF.

There is also a bpf triple for gcc (I say that having never been able to actually use it)
Post reply on HN