From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: dwarves@vger.kernel.org, alan.maguire@oracle.com,
acme@kernel.org, eddyz87@gmail.com
Cc: bpf@vger.kernel.org, andrii@kernel.org, ast@kernel.org,
kernel-team@meta.com
Subject: [PATCH dwarves v3 1/3] btf_encoder: Remove encoder pointer from btf_encoder_func_state
Date: Wed, 5 Nov 2025 10:59:24 -0800 [thread overview]
Message-ID: <20251105185926.296539-2-ihor.solodrai@linux.dev> (raw)
In-Reply-To: <20251105185926.296539-1-ihor.solodrai@linux.dev>
Since multithreading was moved to dwarf_loader [1], pahole maintains a
single global btf_encoder instance. However parts of btf_encoder.c
exist to manage mulitple encoders, which is not necessary anymore.
This patch removes encoder pointer from struct btf_encoder_func_state.
We create a state for every encountered instance of a function in
DWARF, and currently they carry around the encoder unnecessarily.
[1] https://lore.kernel.org/all/20250109185950.653110-9-ihor.solodrai@pm.me/
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
---
btf_encoder.c | 34 +++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)
diff --git a/btf_encoder.c b/btf_encoder.c
index 03bc3c7..a6fdc58 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -79,7 +79,6 @@ struct btf_encoder_func_annot {
/* state used to do later encoding of saved functions */
struct btf_encoder_func_state {
- struct btf_encoder *encoder;
struct elf_function *elf;
uint32_t type_id_off;
uint16_t nr_parms;
@@ -819,7 +818,7 @@ static int32_t btf_encoder__add_func_proto(struct btf_encoder *encoder, struct f
struct btf_encoder_func_state *state)
{
const struct btf_type *t;
- struct btf *btf;
+ struct btf *btf = encoder->btf;
struct parameter *param;
uint16_t nr_params, param_idx;
int32_t id, type_id;
@@ -834,12 +833,9 @@ static int32_t btf_encoder__add_func_proto(struct btf_encoder *encoder, struct f
/* add btf_type for func_proto */
if (ftype) {
- btf = encoder->btf;
nr_params = ftype->nr_parms + (ftype->unspec_parms ? 1 : 0);
type_id = btf_encoder__tag_type(encoder, ftype->tag.type);
} else if (state) {
- encoder = state->encoder;
- btf = state->encoder->btf;
nr_params = state->nr_parms;
type_id = state->ret_type_id;
} else {
@@ -1123,13 +1119,12 @@ static bool types__match(struct btf_encoder *encoder,
return false;
}
-static bool funcs__match(struct btf_encoder_func_state *s1,
+static bool funcs__match(struct btf_encoder *encoder,
+ struct btf_encoder_func_state *s1,
struct btf_encoder_func_state *s2)
{
- struct btf_encoder *encoder = s1->encoder;
struct elf_function *func = s1->elf;
- struct btf *btf1 = s1->encoder->btf;
- struct btf *btf2 = s2->encoder->btf;
+ struct btf *btf = encoder->btf;
uint8_t i;
if (s1->nr_parms != s2->nr_parms) {
@@ -1138,7 +1133,7 @@ static bool funcs__match(struct btf_encoder_func_state *s1,
s1->nr_parms, s2->nr_parms);
return false;
}
- if (!types__match(encoder, btf1, s1->ret_type_id, btf2, s2->ret_type_id)) {
+ if (!types__match(encoder, btf, s1->ret_type_id, btf, s2->ret_type_id)) {
btf_encoder__log_func_skip(encoder, func, "return type mismatch\n");
return false;
}
@@ -1146,11 +1141,11 @@ static bool funcs__match(struct btf_encoder_func_state *s1,
return true;
for (i = 0; i < s1->nr_parms; i++) {
- if (!types__match(encoder, btf1, s1->parms[i].type_id,
- btf2, s2->parms[i].type_id)) {
+ if (!types__match(encoder, btf, s1->parms[i].type_id,
+ btf, s2->parms[i].type_id)) {
if (encoder->verbose) {
- const char *p1 = btf__name_by_offset(btf1, s1->parms[i].name_off);
- const char *p2 = btf__name_by_offset(btf2, s2->parms[i].name_off);
+ const char *p1 = btf__name_by_offset(btf, s1->parms[i].name_off);
+ const char *p2 = btf__name_by_offset(btf, s2->parms[i].name_off);
btf_encoder__log_func_skip(encoder, func,
"param type mismatch for param#%d %s %s %s\n",
@@ -1244,7 +1239,6 @@ static int32_t btf_encoder__save_func(struct btf_encoder *encoder, struct functi
if (!state)
return -ENOMEM;
- state->encoder = encoder;
state->elf = func;
state->nr_parms = ftype->nr_parms + (ftype->unspec_parms ? 1 : 0);
state->ret_type_id = ftype->tag.type == 0 ? 0 : encoder->type_id_off + ftype->tag.type;
@@ -1410,7 +1404,9 @@ static int saved_functions_cmp(const void *_a, const void *_b)
return elf_function__name_cmp(a->elf, b->elf);
}
-static int saved_functions_combine(struct btf_encoder_func_state *a, struct btf_encoder_func_state *b)
+static int saved_functions_combine(struct btf_encoder *encoder,
+ struct btf_encoder_func_state *a,
+ struct btf_encoder_func_state *b)
{
uint8_t optimized, unexpected, inconsistent, uncertain_parm_loc;
@@ -1421,7 +1417,7 @@ static int saved_functions_combine(struct btf_encoder_func_state *a, struct btf_
unexpected = a->unexpected_reg | b->unexpected_reg;
inconsistent = a->inconsistent_proto | b->inconsistent_proto;
uncertain_parm_loc = a->uncertain_parm_loc | b->uncertain_parm_loc;
- if (!unexpected && !inconsistent && !funcs__match(a, b))
+ if (!unexpected && !inconsistent && !funcs__match(encoder, a, b))
inconsistent = 1;
a->optimized_parms = b->optimized_parms = optimized;
a->unexpected_reg = b->unexpected_reg = unexpected;
@@ -1471,7 +1467,7 @@ static int btf_encoder__add_saved_funcs(struct btf_encoder *encoder, bool skip_e
*/
j = i + 1;
- while (j < nr_saved_fns && saved_functions_combine(&saved_fns[i], &saved_fns[j]) == 0)
+ while (j < nr_saved_fns && saved_functions_combine(encoder, &saved_fns[i], &saved_fns[j]) == 0)
j++;
/* do not exclude functions with optimized-out parameters; they
@@ -1488,7 +1484,7 @@ static int btf_encoder__add_saved_funcs(struct btf_encoder *encoder, bool skip_e
0, 0);
if (add_to_btf) {
- err = btf_encoder__add_func(state->encoder, state);
+ err = btf_encoder__add_func(encoder, state);
if (err < 0)
goto out;
}
--
2.51.1
next prev parent reply other threads:[~2025-11-05 18:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-05 18:59 [PATCH dwarves v3 0/3] btf_encoder: refactor emission of BTF funcs Ihor Solodrai
2025-11-05 18:59 ` Ihor Solodrai [this message]
2025-11-05 18:59 ` [PATCH dwarves v3 2/3] btf_encoder: Refactor btf_encoder__add_func_proto Ihor Solodrai
2025-11-05 18:59 ` [PATCH dwarves v3 3/3] btf_encoder: Factor out BPF kfunc emission Ihor Solodrai
2025-11-05 22:07 ` Eduard Zingerman
2025-11-05 22:08 ` [PATCH dwarves v3 0/3] btf_encoder: refactor emission of BTF funcs 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=20251105185926.296539-2-ihor.solodrai@linux.dev \
--to=ihor.solodrai@linux.dev \
--cc=acme@kernel.org \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=kernel-team@meta.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;
as well as URLs for NNTP newsgroup(s).