oracle / bpftune

bpftune uses BPF to auto-tune Linux systems
Other
654 stars 55 forks source link

Add support of gcc BPF backend #89

Closed brianwitte closed 1 month ago

brianwitte commented 1 month ago

Hey, Alan.

Thanks for all the work on bpftune (and your informative talks on BTF :smile: ).

I wanted to begin the process of porting bpftune to support the BPF backend for gcc.

I started with the Makefile(s).

On my fork, you can:

GCC_BPF=bpf-gcc make && sudo make install

It compiles successfully (and throws warnings due to ignoring unkown clang #pragmas).

Then you can run bpftune in legacy mode:

$ sudo bpftune -S     
bpftune: bpftune works in legacy mode
bpftune: bpftune supports per-netns policy (via netns cookie)

Below are the specifications for the machine I am testing on. I use upstream Debian for my work as much as possible:

$ bpf-gcc --version 
bpf-gcc (14.1.0-1+2) 14.1.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ bpftool version                       
bpftool v7.4.0
using libbpf v1.4
features:

$ ll /usr/lib64/ | sudo grep libbpf.so                       
lrwxrwxrwx 1 root root   11 Jun  6 13:33 libbpf.so -> libbpf.so.1
lrwxrwxrwx 1 root root   15 Jun  6 13:33 libbpf.so.1 -> libbpf.so.1.4.3
-rwxr-xr-x 1 root root 1.6M Jun  6 13:33 libbpf.so.1.4.3

$ uname -m && lsb_release -d && uname -r
x86_64
No LSB modules are available.
Description:    Debian GNU/Linux trixie/sid
6.7.12-amd64

I was wondering how I could help bpftune support the gcc backend for BPF and get bpftune to work "fully" out of the box with it.

oracle-contributor-agreement[bot] commented 1 month ago

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA). The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

brianwitte commented 1 month ago

These appear to be what the gcc bpf backend is throwing warnings about:

bpf-gcc -g -O2 -g -fno-stack-protector -Wall -D__TARGET_ARCH_x86 -gbtf -mcpu=v3 -Wno-error=attributes -Wno-error=address-of-packed-member -Wno-compare-distinct-pointer-types -I../include -I/usr/include -I/usr/include/libnl3 -I../include/uapi -c tcp_buffer_tuner.bpf.c \
        -o tcp_buffer_tuner.bpf.o
In file included from ../include/bpftune/bpftune.bpf.h:36,
                 from tcp_buffer_tuner.bpf.c:20:
../include/bpftune/vmlinux_x86_64.h:5: warning: ignoring ‘#pragma clang attribute’ [-Wunknown-pragmas]
    5 | #pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
../include/bpftune/vmlinux_x86_64.h:121955: warning: ignoring ‘#pragma clang attribute’ [-Wunknown-pragmas]
121955 | #pragma clang attribute pop
]

Here are the files grepped from project root:

$ rg "#pragma clang"
include/bpftune/bpftune.bpf.h
284:#pragma clang loop unroll(full)

include/bpftune/vmlinux_x86_64.h
5:#pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
121955:#pragma clang attribute pop

include/bpftune/vmlinux_aarch64.h
5:#pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
135255:#pragma clang attribute pop

Let me know how I can help with this! :smiley:

oracle-contributor-agreement[bot] commented 1 month ago

Thank you for signing the OCA.

alan-maguire commented 1 month ago

your efforts are greatly appreciated, thanks Brian! On the subject of the warnings, the push attribute for Compile Once, Run Everywhere (CO-RE) is in the bpftool-generated vmlinux files as you've observed. That attribute is not supported in gcc so there are efforts upstream to support a gcc-friendly vmlinux.h generation. That said, gcc-bpf does support CO-Re so I think we should be able to get BTF relocations to work regardless. I suggest we regenerate our vmlinux.h files once the upstream efforts are complete.

brianwitte commented 1 month ago

Ok, got it! Thank you for getting back to the PR so quickly. That was awesome.

I will look into what the upstream situation is and see if I can get clarity on options available for bpftune.

alan-maguire commented 1 month ago

thanks for working on this! see this thread for more on the bpftool stuff: https://lore.kernel.org/bpf/20240507095011.15867-1-jose.marchesi@oracle.com/