All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: bpf@vger.kernel.org, ast@kernel.org
Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev,
	kernel-team@fb.com, yonghong.song@linux.dev,
	jose.marchesi@oracle.com, alan.maguire@oracle.com,
	Eduard Zingerman <eddyz87@gmail.com>
Subject: [PATCH bpf-next v2 0/4] API to access btf_dump emit queue and print single type
Date: Fri, 17 May 2024 12:05:51 -0700	[thread overview]
Message-ID: <20240517190555.4032078-1-eddyz87@gmail.com> (raw)

This is a follow-up to the following discussion:
https://lore.kernel.org/bpf/20240503111836.25275-1-jose.marchesi@oracle.com/

As suggested by Andrii, this series adds several API functions to
allow more flexibility with btf dump:
- a function to add a type and all its dependencies to the emit queue;
- functions to provide access to the emit queue owned by btf_dump object;
- a function to print a given type (skipping any dependencies).

This should allow filtering printed types and also adding
attributes / pre-processor statements to specific types.

There are several ways to add such API:
1. The simplest in terms of code changes is to refactor
   btf_dump_emit_type() to push types and forward declarations
   to the emit queue, instead of printing those directly;
2. More intrusive: refactor btf_dump_emit_type() and
   btf_dump_order_type() to avoid doing topological sorting twice and
   put forward declarations to the emit queue at once.

This series opts for (2) as it seems to simplify library code a bit.
For the sake of discussion, source code for option (1) as available at:
https://github.com/eddyz87/bpf/tree/libbpf-sort-for-dump-api-simple

Also, this series opts for the following new API function:

  int btf_dump__dump_one_type(struct btf_dump *d, __u32 id, bool fwd);

As adding _opts variant of btf_dump__dump_type seems a bit clumsy:

  struct btf_dump_opts {
	size_t sz;
	bool fwd;
	bool skip_dependencies;
	bool skip_last_semi;
  };

  int btf_dump__dump_type_opts(struct btf_dump *d, __u32 id,
			       struct btf_dump_opts *opts);

but maybe community would prefer the later variant.

Changes v1->v2:
- fix for build issues reported by CI: do not mark typedefs as ORDERED

v1: https://lore.kernel.org/bpf/20240516230443.3436233-1-eddyz87@gmail.com/

Eduard Zingerman (4):
  libbpf: put forward declarations to btf_dump->emit_queue
  libbpf: API to access btf_dump emit queue and print single type
  selftests/bpf: tests for btf_dump emit queue API
  selftests/bpf: corner case for typedefs handling in btf_dump

 tools/lib/bpf/btf.h                           |  33 ++
 tools/lib/bpf/btf_dump.c                      | 386 +++++++++---------
 tools/lib/bpf/libbpf.map                      |   4 +
 .../selftests/bpf/prog_tests/btf_dump.c       |  86 ++++
 .../bpf/progs/btf_dump_test_case_ordering.c   |  10 +
 5 files changed, 315 insertions(+), 204 deletions(-)

-- 
2.34.1


             reply	other threads:[~2024-05-17 19:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-17 19:05 Eduard Zingerman [this message]
2024-05-17 19:05 ` [PATCH bpf-next v2 1/4] libbpf: put forward declarations to btf_dump->emit_queue Eduard Zingerman
2024-05-28 22:05   ` Andrii Nakryiko
2024-05-28 22:25     ` Eduard Zingerman
2024-05-28 22:39       ` Andrii Nakryiko
2024-05-28 22:41         ` Eduard Zingerman
2024-05-17 19:05 ` [PATCH bpf-next v2 2/4] libbpf: API to access btf_dump emit queue and print single type Eduard Zingerman
2024-05-28 22:18   ` Andrii Nakryiko
2024-05-28 22:53     ` Eduard Zingerman
2024-05-28 23:19       ` Andrii Nakryiko
2024-05-28 23:39         ` Eduard Zingerman
2024-06-01  7:22     ` Eduard Zingerman
2024-06-04 17:39       ` Andrii Nakryiko
2024-05-17 19:05 ` [PATCH bpf-next v2 3/4] selftests/bpf: tests for btf_dump emit queue API Eduard Zingerman
2024-05-17 19:05 ` [PATCH bpf-next v2 4/4] selftests/bpf: corner case for typedefs handling in btf_dump Eduard Zingerman

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=20240517190555.4032078-1-eddyz87@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jose.marchesi@oracle.com \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@linux.dev \
    --cc=yonghong.song@linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.