btf_encoder: Collect info of per-cpu variables from threads

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>
Tested-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: dwarves@vger.kernel.org
Link: https://lore.kernel.org/r/20220321230837.855572-1-kuifeng@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Kui-Feng Lee 2022-03-21 16:08:37 -07:00 committed by Arnaldo Carvalho de Melo
parent 31df013b70
commit 1bc98ed290
3 changed files with 24 additions and 1 deletions

View File

@ -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;

View File

@ -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_ */

View File

@ -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);