bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Alexei Starovoitov <ast@fb.com>
Cc: Andrii Nakryiko <andriin@fb.com>, bpf <bpf@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH v4 bpf-next 5/7] selftests/bpf: replace test_progs and test_maps w/ general rule
Date: Thu, 17 Oct 2019 11:19:39 -0700	[thread overview]
Message-ID: <CAEf4BzbFEHUqL00cF8bckOfEzeCky9vcRbgaiNK2=mAe=rAY_w@mail.gmail.com> (raw)
In-Reply-To: <a5076b0f-9cc2-8f5c-7b3c-5882aa595332@fb.com>

On Thu, Oct 17, 2019 at 10:54 AM Alexei Starovoitov <ast@fb.com> wrote:
>
> On 10/17/19 10:50 AM, Andrii Nakryiko wrote:
> > On Tue, Oct 15, 2019 at 11:01 PM Andrii Nakryiko <andriin@fb.com> wrote:
> >>
> >> Define test runner generation meta-rule that codifies dependencies
> >> between test runner, its tests, and its dependent BPF programs. Use that
> >> for defining test_progs and test_maps test-runners. Also additionally define
> >> 2 flavors of test_progs:
> >> - alu32, which builds BPF programs with 32-bit registers codegen;
> >> - bpf_gcc, which build BPF programs using GCC, if it supports BPF target.
> >>
> >> Overall, this is accomplished through $(eval)'ing a set of generic
> >> rules, which defines Makefile targets dynamically at runtime. See
> >> comments explaining the need for 2 $(evals), though.
> >>
> >> For each test runner we have (test_maps and test_progs, currently), and,
> >> optionally, their flavors, the logic of build process is modeled as
> >> follows (using test_progs as an example):
> >> - all BPF objects are in progs/:
> >>    - BPF object's .o file is built into output directory from
> >>      corresponding progs/.c file;
> >>    - all BPF objects in progs/*.c depend on all progs/*.h headers;
> >>    - all BPF objects depend on bpf_*.h helpers from libbpf (but not
> >>      libbpf archive). There is an extra rule to trigger bpf_helper_defs.h
> >>      (re-)build, if it's not present/outdated);
> >>    - build recipe for BPF object can be re-defined per test runner/flavor;
> >> - test files are built from prog_tests/*.c:
> >>    - all such test file objects are built on individual file basis;
> >>    - currently, every single test file depends on all BPF object files;
> >>      this might be improved in follow up patches to do 1-to-1 dependency,
> >>      but allowing to customize this per each individual test;
> >>    - each test runner definition can specify a list of extra .c and .h
> >>      files to be built along test files and test runner binary; all such
> >>      headers are becoming automatic dependency of each test .c file;
> >>    - due to test files sometimes embedding (using .incbin assembly
> >>      directive) contents of some BPF objects at compilation time, which are
> >>      expected to be in CWD of compiler, compilation for test file object does
> >>      cd into test runner's output directory; to support this mode all the
> >>      include paths are turned into absolute paths using $(abspath) make
> >>      function;
> >> - prog_tests/test.h is automatically (re-)generated with an entry for
> >>    each .c file in prog_tests/;
> >> - final test runner binary is linked together from test object files and
> >>    extra object files, linking together libbpf's archive as well;
> >> - it's possible to specify extra "resource" files/targets, which will be
> >>    copied into test runner output directory, if it differes from
> >>    Makefile-wide $(OUTPUT). This is used to ensure btf_dump test cases and
> >>    urandom_read binary is put into a test runner's CWD for tests to find
> >>    them in runtime.
> >>
> >> For flavored test runners, their output directory is a subdirectory of
> >> common Makefile-wide $(OUTPUT) directory with flavor name used as
> >> subdirectory name.
> >>
> >> BPF objects targets might be reused between different test runners, so
> >> extra checks are employed to not double-define them. Similarly, we have
> >> redefinition guards for output directories and test headers.
> >>
> >> test_verifier follows slightly different patterns and is simple enough
> >> to not justify generalizing TEST_RUNNER_DEFINE/TEST_RUNNER_DEFINE_RULES
> >> further to accomodate these differences. Instead, rules for
> >> test_verifier are minimized and simplified, while preserving correctness
> >> of dependencies.
> >>
> >> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> >> ---
> >
> > BTW, if correctness and DRY-ness argument is not strong enough, these
> > changes makes clean rebuild from scratch about 2x faster for me:
> >
> > BEFORE: `make clean && time make -j50` is 14-15 seconds
> > AFTER: `make clean && time make -j50` is 7-8 seconds
>
> I noticed that too and was about to ask "why?" .. :)

alu32 BPF .o's were dependent on alu32/test_progs for some reason, so
they blocked on all tests be built first, which is completely
backwards and slower. Now all the flavors are built completely in
parallel. Overall CPU usage across all cores increased (because we do
more work compiling binaries), but it's more parallel.

  reply	other threads:[~2019-10-17 18:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-16  6:00 [PATCH v4 bpf-next 0/7] Fix, clean up, and revamp selftests/bpf Makefile Andrii Nakryiko
2019-10-16  6:00 ` [PATCH v4 bpf-next 1/7] selftests/bpf: teach test_progs to cd into subdir Andrii Nakryiko
2019-10-16  6:00 ` [PATCH v4 bpf-next 2/7] selftests/bpf: make CO-RE reloc test impartial to test_progs flavor Andrii Nakryiko
2019-10-16  6:00 ` [PATCH v4 bpf-next 3/7] selftests/bpf: switch test_maps to test_progs' test.h format Andrii Nakryiko
2019-10-16  6:00 ` [PATCH v4 bpf-next 4/7] selftests/bpf: add simple per-test targets to Makefile Andrii Nakryiko
2019-10-16  6:00 ` [PATCH v4 bpf-next 5/7] selftests/bpf: replace test_progs and test_maps w/ general rule Andrii Nakryiko
2019-10-16 16:32   ` Stanislav Fomichev
2019-10-16 20:47     ` Andrii Nakryiko
2019-10-17 16:07       ` Stanislav Fomichev
2019-10-17 17:48         ` Andrii Nakryiko
2019-10-17 20:44           ` Stanislav Fomichev
2019-10-17 17:50   ` Andrii Nakryiko
2019-10-17 17:54     ` Alexei Starovoitov
2019-10-17 18:19       ` Andrii Nakryiko [this message]
2020-05-12 20:16   ` Yauheni Kaliuta
2020-05-12 22:13     ` Andrii Nakryiko
2020-05-13  1:58       ` Yauheni Kaliuta
2019-10-16  6:00 ` [PATCH v4 bpf-next 6/7] selftests/bpf: move test_queue_stack_map.h into progs/ where it belongs Andrii Nakryiko
2019-10-16  6:00 ` [PATCH v4 bpf-next 7/7] selftest/bpf: remove test_libbpf.sh and test_libbpf_open Andrii Nakryiko
2019-10-17  4:27 ` [PATCH v4 bpf-next 0/7] Fix, clean up, and revamp selftests/bpf Makefile Alexei Starovoitov
2019-10-17  6:52   ` Andrii Nakryiko
2019-10-17  8:08     ` Jakub Sitnicki
2019-10-17 19:18       ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEf4BzbFEHUqL00cF8bckOfEzeCky9vcRbgaiNK2=mAe=rAY_w@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=Kernel-team@fb.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).