From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
Donglin Peng <dolinux.peng@gmail.com>
Cc: ast@kernel.org, zhangxiaoqin@xiaomi.com,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
Donglin Peng <pengdonglin@xiaomi.com>,
Alan Maguire <alan.maguire@oracle.com>,
Song Liu <song@kernel.org>
Subject: Re: [RFC PATCH v7 1/7] libbpf: Add BTF permutation support for type reordering
Date: Thu, 20 Nov 2025 15:21:25 -0800 [thread overview]
Message-ID: <5315c03cd97af176065c86c0640461321c818887.camel@gmail.com> (raw)
In-Reply-To: <CAEf4Bzb76SfWfNtxP2WVJ44hsVU-GrePmeKKxH25Q8KOn_Mkfw@mail.gmail.com>
On Wed, 2025-11-19 at 10:21 -0800, Andrii Nakryiko wrote:
> On Tue, Nov 18, 2025 at 7:21 PM Donglin Peng <dolinux.peng@gmail.com> wrote:
[...]
> > + nt = new_types;
> > + for (i = 0; i < new_nr_types; i++) {
> > + struct btf_field_iter it;
> > + const struct btf_type *t;
> > + __u32 *type_id;
> > + int type_size;
> > +
> > + id = order_map[i];
> > + /* must be a valid type ID */
>
> redundant comment, please drop
>
> > + t = btf__type_by_id(btf, id);
> > + if (!t) {
>
> no need to check this, we already validated that all types are valid earlier
>
> > + err = -EINVAL;
> > + goto done;
> > + }
> > + type_size = btf_type_size(t);
> > + memcpy(nt, t, type_size);
> > +
> > + /* Fix up referenced IDs for BTF */
> > + err = btf_field_iter_init(&it, nt, BTF_FIELD_ITER_IDS);
> > + if (err)
> > + goto done;
> > + while ((type_id = btf_field_iter_next(&it))) {
> > + err = btf_permute_remap_type_id(type_id, &p);
> > + if (err)
> > + goto done;
> > + }
> > +
> > + nt += type_size;
> > + }
> > +
> > + /* Fix up referenced IDs for btf_ext */
> > + btf_ext = OPTS_GET(opts, btf_ext, NULL);
> > + if (btf_ext) {
> > + err = btf_ext_visit_type_ids(btf_ext, btf_permute_remap_type_id, &p);
> > + if (err)
> > + goto done;
> > + }
> > +
> > + new_type_len = nt - new_types;
>
>
> new_type_len has to be exactly the same as the old size, this is redundant
>
> > + next_type = new_types;
> > + end_type = next_type + new_type_len;
> > + i = 0;
> > + while (next_type + sizeof(struct btf_type) <= end_type) {
>
> while (next_type < end_type)?
>
> Reference to struct btf_type is confusing, as generally type is bigger
> than just sizeof(struct btf_type). But there is no need for this, with
> correct code next_type < end_type is sufficient check
>
> But really, this can also be written cleanly as a simple for loop
>
> for (i = 0; i < nr_types; i++) {
> btf->type_offs[i] = next_type - new_types;
> next_type += btf_type_size(next_type);
> }
>
Adding to what Andrii says, the whole group of assignments is
reducible:
+ new_type_len = nt - new_types;
+ next_type = new_types;
+ end_type = next_type + new_type_len;
=> end_type = new_types + new_type_len; // subst next_type -> new_types
=> end_type = new_types + nt - new_types; // subst new_types -> nt - new_types
=> end_type = nt
Why recomputing it in such a convoluted way?
> > + btf->type_offs[i++] = next_type - new_types;
> > + next_type += btf_type_size(next_type);
> > + }
> > +
[...]
next prev parent reply other threads:[~2025-11-20 23:21 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-19 3:15 [RFC PATCH v7 0/7] Improve the performance of BTF type lookups with binary search Donglin Peng
2025-11-19 3:15 ` [RFC PATCH v7 1/7] libbpf: Add BTF permutation support for type reordering Donglin Peng
2025-11-19 18:21 ` Andrii Nakryiko
2025-11-20 5:02 ` Donglin Peng
2025-11-20 23:21 ` Eduard Zingerman [this message]
2025-11-21 14:15 ` Donglin Peng
2025-11-19 3:15 ` [RFC PATCH v7 2/7] selftests/bpf: Add test cases for btf__permute functionality Donglin Peng
2025-11-19 4:51 ` Donglin Peng
2025-11-20 23:39 ` Eduard Zingerman
2025-11-21 14:17 ` Donglin Peng
2025-11-21 0:20 ` Eduard Zingerman
2025-11-19 3:15 ` [RFC PATCH v7 3/7] tools/resolve_btfids: Add --btf_sort option for BTF name sorting Donglin Peng
2025-11-20 21:34 ` Ihor Solodrai
2025-11-20 23:53 ` Ihor Solodrai
2025-11-21 15:36 ` Donglin Peng
2025-11-24 19:35 ` Ihor Solodrai
2025-11-25 10:54 ` Donglin Peng
2025-11-21 0:18 ` Eduard Zingerman
2025-11-24 12:14 ` Donglin Peng
2025-11-19 3:15 ` [RFC PATCH v7 4/7] libbpf: Optimize type lookup with binary search for sorted BTF Donglin Peng
2025-11-19 4:11 ` bot+bpf-ci
2025-11-19 4:43 ` Donglin Peng
2025-11-19 19:47 ` Andrii Nakryiko
2025-11-20 7:41 ` Donglin Peng
2025-11-19 3:15 ` [RFC PATCH v7 5/7] libbpf: Implement BTF type sorting validation for binary search optimization Donglin Peng
2025-11-19 19:50 ` Andrii Nakryiko
2025-11-20 7:25 ` Donglin Peng
2025-11-21 19:07 ` Eduard Zingerman
2025-11-22 7:19 ` Donglin Peng
2025-11-22 8:50 ` Eduard Zingerman
2025-11-22 9:05 ` Eduard Zingerman
2025-11-22 15:45 ` Donglin Peng
2025-11-24 18:16 ` Eduard Zingerman
2025-11-25 10:53 ` Donglin Peng
2025-11-22 15:59 ` Donglin Peng
2025-11-21 19:42 ` Eduard Zingerman
2025-11-22 7:32 ` Donglin Peng
2025-11-22 8:38 ` Donglin Peng
2025-11-24 18:20 ` Eduard Zingerman
2025-11-25 10:52 ` Donglin Peng
2025-11-19 3:15 ` [RFC PATCH v7 6/7] btf: Optimize type lookup with binary search Donglin Peng
2025-11-19 3:15 ` [RFC PATCH v7 7/7] btf: Add sorting validation for " Donglin Peng
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=5315c03cd97af176065c86c0640461321c818887.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dolinux.peng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pengdonglin@xiaomi.com \
--cc=song@kernel.org \
--cc=zhangxiaoqin@xiaomi.com \
/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