All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH dwarves] pahole, btf_encoder: Collect info of per-cpu varaibles from threads.
@ 2022-03-21 23:08 Kui-Feng Lee
  2022-03-25 23:02 ` Andrii Nakryiko
  0 siblings, 1 reply; 3+ messages in thread
From: Kui-Feng Lee @ 2022-03-21 23:08 UTC (permalink / raw)
  To: arnaldo.melo, dwarves, ast, andrii, daniel; +Cc: Kui-Feng Lee

Collect the information of per-cpu variables from encoders of worker
threads to the primary encoder.

btf_encoder store per-cpu info separately, not in btf.  Previously, it
merged only btf types generated by worker threads.  So, some of the
per-cpu info was missing.

Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
---
 btf_encoder.c | 21 +++++++++++++++++++++
 btf_encoder.h |  2 ++
 pahole.c      |  2 +-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/btf_encoder.c b/btf_encoder.c
index fa29824..1a42094 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -606,6 +606,27 @@ static int32_t btf_encoder__add_var_secinfo(struct btf_encoder *encoder, uint32_
 	return gobuffer__add(&encoder->percpu_secinfo, &si, sizeof(si));
 }
 
+int32_t btf_encoder__add_encoder(struct btf_encoder *encoder, struct btf_encoder *other)
+{
+	struct gobuffer *var_secinfo_buf = &other->percpu_secinfo;
+	size_t sz = gobuffer__size(var_secinfo_buf);
+	uint16_t nr_var_secinfo = sz / sizeof(struct btf_var_secinfo);
+	uint32_t type_id;
+	uint32_t next_type_id = btf__type_cnt(encoder->btf);
+	int32_t i, id;
+	struct btf_var_secinfo *vsi;
+
+	for (i = 0; i < nr_var_secinfo; i++) {
+		vsi = (struct btf_var_secinfo *)var_secinfo_buf->entries + i;
+		type_id = next_type_id + vsi->type - 1; /* Type ID starts from 1 */
+		id = btf_encoder__add_var_secinfo(encoder, type_id, vsi->offset, vsi->size);
+		if (id < 0)
+			return id;
+	}
+
+	return btf__add_btf(encoder->btf, other->btf);
+}
+
 static int32_t btf_encoder__add_datasec(struct btf_encoder *encoder, const char *section_name)
 {
 	struct gobuffer *var_secinfo_buf = &encoder->percpu_secinfo;
diff --git a/btf_encoder.h b/btf_encoder.h
index 0f0eee8..339fae2 100644
--- a/btf_encoder.h
+++ b/btf_encoder.h
@@ -31,4 +31,6 @@ struct btf_encoder *btf_encoders__next(struct btf_encoder *encoder);
 
 struct btf *btf_encoder__btf(struct btf_encoder *encoder);
 
+int btf_encoder__add_encoder(struct btf_encoder *encoder, struct btf_encoder *other);
+
 #endif /* _BTF_ENCODER_H_ */
diff --git a/pahole.c b/pahole.c
index f7c7966..a909b22 100644
--- a/pahole.c
+++ b/pahole.c
@@ -2867,7 +2867,7 @@ static int pahole_threads_collect(struct conf_load *conf, int nr_threads, void *
                 */
 		if (!threads[i]->btf || threads[i]->encoder == btf_encoder)
 			continue; /* The primary btf_encoder */
-		err = btf__add_btf(btf_encoder__btf(btf_encoder), threads[i]->btf);
+		err = btf_encoder__add_encoder(btf_encoder, threads[i]->encoder);
 		if (err < 0)
 			goto out;
 		btf_encoder__delete(threads[i]->encoder);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH dwarves] pahole, btf_encoder: Collect info of per-cpu varaibles from threads.
  2022-03-21 23:08 [PATCH dwarves] pahole, btf_encoder: Collect info of per-cpu varaibles from threads Kui-Feng Lee
@ 2022-03-25 23:02 ` Andrii Nakryiko
  2022-03-26 14:51   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2022-03-25 23:02 UTC (permalink / raw)
  To: Kui-Feng Lee
  Cc: Arnaldo Carvalho de Melo, dwarves, Alexei Starovoitov,
	Andrii Nakryiko, Daniel Borkmann

On Mon, Mar 21, 2022 at 4:08 PM Kui-Feng Lee <kuifeng@fb.com> wrote:
>
> Collect the information of per-cpu variables from encoders of worker
> threads to the primary encoder.
>
> btf_encoder store per-cpu info separately, not in btf.  Previously, it
> merged only btf types generated by worker threads.  So, some of the
> per-cpu info was missing.
>
> Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
> ---

I've applied this locally and tested, it all looks good, thanks! I'm
keeping this applied locally until Arnaldo pushes this to master :)

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Andrii Nakryiko <andrii@kernel.org>

>  btf_encoder.c | 21 +++++++++++++++++++++
>  btf_encoder.h |  2 ++
>  pahole.c      |  2 +-
>  3 files changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/btf_encoder.c b/btf_encoder.c
> index fa29824..1a42094 100644
> --- a/btf_encoder.c
> +++ b/btf_encoder.c
> @@ -606,6 +606,27 @@ static int32_t btf_encoder__add_var_secinfo(struct btf_encoder *encoder, uint32_
>         return gobuffer__add(&encoder->percpu_secinfo, &si, sizeof(si));
>  }
>
> +int32_t btf_encoder__add_encoder(struct btf_encoder *encoder, struct btf_encoder *other)
> +{
> +       struct gobuffer *var_secinfo_buf = &other->percpu_secinfo;
> +       size_t sz = gobuffer__size(var_secinfo_buf);
> +       uint16_t nr_var_secinfo = sz / sizeof(struct btf_var_secinfo);
> +       uint32_t type_id;
> +       uint32_t next_type_id = btf__type_cnt(encoder->btf);
> +       int32_t i, id;
> +       struct btf_var_secinfo *vsi;
> +
> +       for (i = 0; i < nr_var_secinfo; i++) {
> +               vsi = (struct btf_var_secinfo *)var_secinfo_buf->entries + i;
> +               type_id = next_type_id + vsi->type - 1; /* Type ID starts from 1 */
> +               id = btf_encoder__add_var_secinfo(encoder, type_id, vsi->offset, vsi->size);
> +               if (id < 0)
> +                       return id;
> +       }
> +
> +       return btf__add_btf(encoder->btf, other->btf);
> +}
> +
>  static int32_t btf_encoder__add_datasec(struct btf_encoder *encoder, const char *section_name)
>  {
>         struct gobuffer *var_secinfo_buf = &encoder->percpu_secinfo;
> diff --git a/btf_encoder.h b/btf_encoder.h
> index 0f0eee8..339fae2 100644
> --- a/btf_encoder.h
> +++ b/btf_encoder.h
> @@ -31,4 +31,6 @@ struct btf_encoder *btf_encoders__next(struct btf_encoder *encoder);
>
>  struct btf *btf_encoder__btf(struct btf_encoder *encoder);
>
> +int btf_encoder__add_encoder(struct btf_encoder *encoder, struct btf_encoder *other);
> +
>  #endif /* _BTF_ENCODER_H_ */
> diff --git a/pahole.c b/pahole.c
> index f7c7966..a909b22 100644
> --- a/pahole.c
> +++ b/pahole.c
> @@ -2867,7 +2867,7 @@ static int pahole_threads_collect(struct conf_load *conf, int nr_threads, void *
>                  */
>                 if (!threads[i]->btf || threads[i]->encoder == btf_encoder)
>                         continue; /* The primary btf_encoder */
> -               err = btf__add_btf(btf_encoder__btf(btf_encoder), threads[i]->btf);
> +               err = btf_encoder__add_encoder(btf_encoder, threads[i]->encoder);
>                 if (err < 0)
>                         goto out;
>                 btf_encoder__delete(threads[i]->encoder);
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH dwarves] pahole, btf_encoder: Collect info of per-cpu varaibles from threads.
  2022-03-25 23:02 ` Andrii Nakryiko
@ 2022-03-26 14:51   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-03-26 14:51 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Kui-Feng Lee, Arnaldo Carvalho de Melo, dwarves,
	Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann

Em Fri, Mar 25, 2022 at 04:02:13PM -0700, Andrii Nakryiko escreveu:
> On Mon, Mar 21, 2022 at 4:08 PM Kui-Feng Lee <kuifeng@fb.com> wrote:
> >
> > Collect the information of per-cpu variables from encoders of worker
> > threads to the primary encoder.
> >
> > btf_encoder store per-cpu info separately, not in btf.  Previously, it
> > merged only btf types generated by worker threads.  So, some of the
> > per-cpu info was missing.
> >
> > Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
> > ---
> 
> I've applied this locally and tested, it all looks good, thanks! I'm
> keeping this applied locally until Arnaldo pushes this to master :)
> 
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
> Tested-by: Andrii Nakryiko <andrii@kernel.org>

And from a quick look the code is really elegant, well done!

Applied and will push to the next branch, later today/tomorrow I'll push
it out to master after it passes the libbpf CI tests.
 
Thanks!

- Arnaldo

> >  btf_encoder.c | 21 +++++++++++++++++++++
> >  btf_encoder.h |  2 ++
> >  pahole.c      |  2 +-
> >  3 files changed, 24 insertions(+), 1 deletion(-)
> >
> > diff --git a/btf_encoder.c b/btf_encoder.c
> > index fa29824..1a42094 100644
> > --- a/btf_encoder.c
> > +++ b/btf_encoder.c
> > @@ -606,6 +606,27 @@ static int32_t btf_encoder__add_var_secinfo(struct btf_encoder *encoder, uint32_
> >         return gobuffer__add(&encoder->percpu_secinfo, &si, sizeof(si));
> >  }
> >
> > +int32_t btf_encoder__add_encoder(struct btf_encoder *encoder, struct btf_encoder *other)
> > +{
> > +       struct gobuffer *var_secinfo_buf = &other->percpu_secinfo;
> > +       size_t sz = gobuffer__size(var_secinfo_buf);
> > +       uint16_t nr_var_secinfo = sz / sizeof(struct btf_var_secinfo);
> > +       uint32_t type_id;
> > +       uint32_t next_type_id = btf__type_cnt(encoder->btf);
> > +       int32_t i, id;
> > +       struct btf_var_secinfo *vsi;
> > +
> > +       for (i = 0; i < nr_var_secinfo; i++) {
> > +               vsi = (struct btf_var_secinfo *)var_secinfo_buf->entries + i;
> > +               type_id = next_type_id + vsi->type - 1; /* Type ID starts from 1 */
> > +               id = btf_encoder__add_var_secinfo(encoder, type_id, vsi->offset, vsi->size);
> > +               if (id < 0)
> > +                       return id;
> > +       }
> > +
> > +       return btf__add_btf(encoder->btf, other->btf);
> > +}
> > +
> >  static int32_t btf_encoder__add_datasec(struct btf_encoder *encoder, const char *section_name)
> >  {
> >         struct gobuffer *var_secinfo_buf = &encoder->percpu_secinfo;
> > diff --git a/btf_encoder.h b/btf_encoder.h
> > index 0f0eee8..339fae2 100644
> > --- a/btf_encoder.h
> > +++ b/btf_encoder.h
> > @@ -31,4 +31,6 @@ struct btf_encoder *btf_encoders__next(struct btf_encoder *encoder);
> >
> >  struct btf *btf_encoder__btf(struct btf_encoder *encoder);
> >
> > +int btf_encoder__add_encoder(struct btf_encoder *encoder, struct btf_encoder *other);
> > +
> >  #endif /* _BTF_ENCODER_H_ */
> > diff --git a/pahole.c b/pahole.c
> > index f7c7966..a909b22 100644
> > --- a/pahole.c
> > +++ b/pahole.c
> > @@ -2867,7 +2867,7 @@ static int pahole_threads_collect(struct conf_load *conf, int nr_threads, void *
> >                  */
> >                 if (!threads[i]->btf || threads[i]->encoder == btf_encoder)
> >                         continue; /* The primary btf_encoder */
> > -               err = btf__add_btf(btf_encoder__btf(btf_encoder), threads[i]->btf);
> > +               err = btf_encoder__add_encoder(btf_encoder, threads[i]->encoder);
> >                 if (err < 0)
> >                         goto out;
> >                 btf_encoder__delete(threads[i]->encoder);
> > --
> > 2.30.2
> >

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-26 14:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-21 23:08 [PATCH dwarves] pahole, btf_encoder: Collect info of per-cpu varaibles from threads Kui-Feng Lee
2022-03-25 23:02 ` Andrii Nakryiko
2022-03-26 14:51   ` Arnaldo Carvalho de Melo

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.