BPF List
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Daniel Xu <dxu@dxuuu.xyz>
Cc: Viktor Malik <vmalik@redhat.com>,
	bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Manu Bretelle <chantr4@gmail.com>
Subject: Re: [PATCH bpf-next v3 1/2] tools/resolve_btfids: Refactor set sorting with types from btf_ids.h
Date: Tue, 6 Feb 2024 12:33:56 +0100	[thread overview]
Message-ID: <ZcIZJEXOByuZLFsC@krava> (raw)
In-Reply-To: <uk5wsboc2rfloizsah5d4vb3tid55diiejkutfgsvr6qn7u5vn@ka3u4e7usa3z>

On Mon, Feb 05, 2024 at 12:45:30PM -0700, Daniel Xu wrote:

SNIP

> > @@ -654,10 +655,10 @@ static int sets_patch(struct object *obj)
> >  
> >  	next = rb_first(&obj->sets);
> >  	while (next) {
> > +		struct btf_id_set8 *set8;
> > +		struct btf_id_set *set;
> >  		unsigned long addr, idx;
> >  		struct btf_id *id;
> > -		int *base;
> > -		int cnt;
> >  
> >  		id   = rb_entry(next, struct btf_id, rb_node);
> >  		addr = id->addr[0];
> > @@ -671,13 +672,21 @@ static int sets_patch(struct object *obj)
> >  		}
> >  
> >  		idx = idx / sizeof(int);
> > -		base = &ptr[idx] + (id->is_set8 ? 2 : 1);
> > -		cnt = ptr[idx];
> > +		if (id->is_set) {
> > +			set = (struct btf_id_set *)&ptr[idx];
> 
> Nit: should be able to simplify logic a bit like this:
> 
>         int off = addr - obj->efile.idlist_addr;
>         set8 = data->d_buf + off;
> 
> Don't think that `idx`, `ptr` or casts are necessary anymore.

+1 , otherwise it looks good to me

jirka

> 
> > +			qsort(set->ids, set->cnt, sizeof(set->ids[0]), cmp_id);
> > +		} else {
> > +			set8 = (struct btf_id_set8 *)&ptr[idx];
> > +			/*
> > +			 * Make sure id is at the beginning of the pairs
> > +			 * struct, otherwise the below qsort would not work.
> > +			 */
> > +			BUILD_BUG_ON(set8->pairs != &set8->pairs[0].id);
> > +			qsort(set8->pairs, set8->cnt, sizeof(set8->pairs[0]), cmp_id);
> > +		}
> >  
> >  		pr_debug("sorting  addr %5lu: cnt %6d [%s]\n",
> > -			 (idx + 1) * sizeof(int), cnt, id->name);
> > -
> > -		qsort(base, cnt, id->is_set8 ? sizeof(uint64_t) : sizeof(int), cmp_id);
> > +			 (idx + 1) * sizeof(int), id->is_set ? set->cnt : set8->cnt, id->name);
> >  
> >  		next = rb_next(next);
> >  	}
> > diff --git a/tools/include/linux/btf_ids.h b/tools/include/linux/btf_ids.h
> > index 2f882d5cb30f..72535f00572f 100644
> > --- a/tools/include/linux/btf_ids.h
> > +++ b/tools/include/linux/btf_ids.h
> > @@ -8,6 +8,15 @@ struct btf_id_set {
> >  	u32 ids[];
> >  };
> >  
> > +struct btf_id_set8 {
> > +	u32 cnt;
> > +	u32 flags;
> > +	struct {
> > +		u32 id;
> > +		u32 flags;
> > +	} pairs[];
> > +};
> > +
> >  #ifdef CONFIG_DEBUG_INFO_BTF
> >  
> >  #include <linux/compiler.h> /* for __PASTE */
> > -- 
> > 2.43.0
> > 

  reply	other threads:[~2024-02-06 11:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-05 18:39 [PATCH bpf-next v3 0/2] tools/resolve_btfids: fix cross-compilation to non-host endianness Viktor Malik
2024-02-05 18:39 ` [PATCH bpf-next v3 1/2] tools/resolve_btfids: Refactor set sorting with types from btf_ids.h Viktor Malik
2024-02-05 19:45   ` Daniel Xu
2024-02-06 11:33     ` Jiri Olsa [this message]
2024-02-05 18:39 ` [PATCH bpf-next v3 2/2] tools/resolve_btfids: fix cross-compilation to non-host endianness Viktor Malik

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=ZcIZJEXOByuZLFsC@krava \
    --to=olsajiri@gmail.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chantr4@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=dxu@dxuuu.xyz \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=vmalik@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox