Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libbpf as a submodule (take 2) #168

Merged
merged 1 commit into from
Mar 2, 2024

Conversation

jordalgo
Copy link
Contributor

This is to potentinally reduce issues with folks
using different versions of libbpf at runtime.

This also:

  • makes static linking of libbpf the default
  • adds steps in meson setup to fetch libbpf and make it

@jordalgo
Copy link
Contributor Author

I tested a bunch but if folks want to experiment with the setup:

git clone https://github.com/jordalgo/scx.git --branch libbpf-submodule-2

@jordalgo jordalgo changed the title Add libbpf as a submodule Add libbpf as a submodule (take 2) Feb 29, 2024
meson.build Outdated
if get_option('libbpf_a') == ''
message('Checking out libbpf submodule and building it...')
run_command('git', 'submodule', 'update', '--init', '--recursive', check: true)
run_command('make', '-C', 'libbpf/src', check: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it pass cc and other build options (CFLGAS, LDFLAGS) down to make? Also, what about build concurrency? Can we specify a reasonable -j option by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't cc (and the other build options) get picked up by make in the same way that meson grabs it with meson.get_compiler? When I'm building locally if I run setup with the env CC=clang then it builds libbpf with clang as well (as opposed to gcc which is my default).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we specify a reasonable -j option by default?

Sure. Is there a decent middle ground here? -j32 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't cc (and the other build options) get picked up by make in the same way that meson grabs it with meson.get_compiler? When I'm building locally if I run setup with the env CC=clang then it builds libbpf with clang as well (as opposed to gcc which is my default).

Well, depends on how the flags are specified, I think. e.g. I don't think CFLAGS is the only way to pass in compiler flags to meson. Best to explicitly set relavent enviroments as when we're calling e.g. cargo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we specify a reasonable -j option by default?

Sure. Is there a decent middle ground here? -j32 ?

Add nproc as dependency and run that to get the answer?

Copy link
Contributor Author

@jordalgo jordalgo Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. I don't think CFLAGS is the only way to pass in compiler flags to meson

In looking at the docs, I think this is the recommended way to do this: https://mesonbuild.com/howtox.html#set-extra-compiler-and-linker-flags-from-the-outside-when-eg-building-distro-packages

I think if there are specific flags that we want to pass to either clang or gcc then we have to do that explicitly in the build file. e.g. do we want to check if the compiler is clang and pass the BPF_BASE_CFLAGS ? Maybe I'm missing something.

meson.build Outdated
endif

if libbpf_a != ''
if not fs.exists(libbpf_a)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we end up running this once. Wouldn't it be better to have a more permanent way of detecting the default case (it can just be a bool from the above if/else block too) and run make each time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. If people pull and we've update the submodule we'd want to run it again.

meson.options Outdated Show resolved Hide resolved
@jordalgo jordalgo force-pushed the libbpf-submodule-2 branch 3 times, most recently from 63b06fa to 494e9be Compare March 1, 2024 19:24
This is to potentinally reduce issues with folks
using different versions of libbpf at runtime.

This also:
- makes static linking of libbpf the default
- adds steps in `meson setup` to fetch libbpf and make it
@ptr1337
Copy link
Contributor

ptr1337 commented Mar 1, 2024

LGTM.
Tested locally:

The Meson build system
Version: 1.3.2
Source dir: /tmp/makepkg/scx-scheds-git/src/scx
Build dir: /tmp/makepkg/scx-scheds-git/src/scx/build
Build type: native build
Project name: sched_ext schedulers
Project version: 0.1.7
C compiler for the host machine: cc (gcc 13.2.1 "cc (GCC) 13.2.1 20230801")
C linker for the host machine: cc ld.bfd 2.42.0
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program clang found: YES (/usr/bin/clang)
Program bpftool found: YES (/usr/bin/bpftool)
Program cargo found: YES (/usr/bin/cargo)
Program /tmp/makepkg/scx-scheds-git/src/scx/meson-scripts/get_clang_ver found: YES (/tmp/makepkg/scx-scheds-git/src/scx/meson-scripts/get_clang_ver)
Program /tmp/makepkg/scx-scheds-git/src/scx/meson-scripts/bpftool_build_skel found: YES (/tmp/makepkg/scx-scheds-git/src/scx/meson-scripts/bpftool_build_skel)
Program /tmp/makepkg/scx-scheds-git/src/scx/meson-scripts/get_sys_incls found: YES (/tmp/makepkg/scx-scheds-git/src/scx/meson-scripts/get_sys_incls)
Program /tmp/makepkg/scx-scheds-git/src/scx/meson-scripts/test_sched found: YES (/tmp/makepkg/scx-scheds-git/src/scx/meson-scripts/test_sched)
Program /tmp/makepkg/scx-scheds-git/src/scx/meson-scripts/build_libbpf found: YES (/tmp/makepkg/scx-scheds-git/src/scx/meson-scripts/build_libbpf)
Program /tmp/makepkg/scx-scheds-git/src/scx/meson-scripts/cargo_fetch found: YES (/tmp/makepkg/scx-scheds-git/src/scx/meson-scripts/cargo_fetch)
meson.build:45: WARNING: clang >= 17 recommended (/usr/bin/clang ver=16.0.6)
Program jq found: YES (/usr/bin/jq)
Program make found: YES (/usr/bin/make)
Program nproc found: YES (/usr/bin/nproc)
Message: Updating libbpf submodule
Library elf found: YES
Library z found: YES
Library zstd found: YES
Message: cpu=x86_64 bpf_base_cflags=['-g', '-O2', '-Wall', '-Wno-compare-distinct-pointer-types', '-D__TARGET_ARCH_x86', '-mcpu=v3', '-mlittle-endian', '-idirafter /usr/lib/clang/16/include', '-idirafter /usr/local/include', '-idirafter /usr/include']
Run-time dependency threads found: YES
Dependency threads found: YES unknown (cached)
Dependency threads found: YES unknown (cached)
Dependency threads found: YES unknown (cached)
Dependency threads found: YES unknown (cached)
Dependency threads found: YES unknown (cached)
Dependency threads found: YES unknown (cached)
Found pkg-config: YES (/usr/bin/pkg-config) 2.1.0
Run-time dependency systemd found: YES 255
Build targets in project: 17

sched_ext schedulers 0.1.7

  User defined options
    auto_features     : enabled
    buildtype         : plain
    libexecdir        : lib
    prefix            : /usr
    sbindir           : bin
    wrap_mode         : nodownload
    python.bytecompile: 1
    b_pie             : true

Found ninja-1.11.1 at /usr/bin/ninja
INFO: autodetecting backend as ninja                                                                                                                                                                                                        
INFO: calculating backend command to run: /usr/bin/ninja -C /tmp/makepkg/scx-scheds-git/src/scx/build
ninja: Entering directory `/tmp/makepkg/scx-scheds-git/src/scx/build'
[3/37] Generating libbpf with a custom command
In function ‘elf_close’,
    inlined from ‘elf_close’ at elf.c:55:6,
    inlined from ‘elf_find_func_offset_from_file’ at elf.c:386:2:
elf.c:59:9: warning: ‘elf_fd.elf’ may be used uninitialized [-Wmaybe-uninitialized]
   59 |         elf_end(elf_fd->elf);
      |         ^~~~~~~~~~~~~~~~~~~~
elf.c: In function ‘elf_find_func_offset_from_file’:
elf.c:379:23: note: ‘elf_fd.elf’ was declared here
  379 |         struct elf_fd elf_fd;
      |                       ^~~~~~
In function ‘elf_close’,
    inlined from ‘elf_close’ at elf.c:55:6,
    inlined from ‘elf_find_func_offset_from_file’ at elf.c:386:2:
elf.c:60:9: warning: ‘elf_fd.fd’ may be used uninitialized [-Wmaybe-uninitialized]
   60 |         close(elf_fd->fd);
      |         ^~~~~~~~~~~~~~~~~
elf.c: In function ‘elf_find_func_offset_from_file’:
elf.c:379:23: note: ‘elf_fd.fd’ was declared here
  379 |         struct elf_fd elf_fd;
      |                       ^~~~~~
At top level:
cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
In function ‘elf_close’,
    inlined from ‘elf_close’ at elf.c:55:6,
    inlined from ‘elf_find_func_offset_from_file’ at elf.c:386:2:
elf.c:59:9: warning: ‘elf_fd.elf’ may be used uninitialized [-Wmaybe-uninitialized]
   59 |         elf_end(elf_fd->elf);
      |         ^~~~~~~~~~~~~~~~~~~~
elf.c: In function ‘elf_find_func_offset_from_file’:
elf.c:379:23: note: ‘elf_fd.elf’ was declared here
  379 |         struct elf_fd elf_fd;
      |                       ^~~~~~
In function ‘elf_close’,
    inlined from ‘elf_close’ at elf.c:55:6,
    inlined from ‘elf_find_func_offset_from_file’ at elf.c:386:2:
elf.c:60:9: warning: ‘elf_fd.fd’ may be used uninitialized [-Wmaybe-uninitialized]
   60 |         close(elf_fd->fd);
      |         ^~~~~~~~~~~~~~~~~
elf.c: In function ‘elf_find_func_offset_from_file’:
elf.c:379:23: note: ‘elf_fd.fd’ was declared here
  379 |         struct elf_fd elf_fd;
      |                       ^~~~~~
At top level:
cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
[37/37] Generating scheds/rust/scx_rlfifo/scx_rlfifo with a custom command (wrapped by meson to set env)

Size diff:

Package (1)     Old Version          New Version           Net Change

scx-scheds-git  0.1.7.r0.g37dde8a-1  0.1.6.r65.g1c00de9-1   24,15 MiB

Total Installed Size:  29,68 MiB
Net Upgrade Size:      24,15 MiB

@jordalgo
Copy link
Contributor Author

jordalgo commented Mar 1, 2024

@ptr1337 Thanks for testing! The size increase is a little sad but I guess that's expected pulling in a submodule.

@sirlucjan
Copy link
Collaborator

@jordalgo It seems that everything is working properly.

@jordalgo jordalgo merged commit 143743c into sched-ext:main Mar 2, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants