From: Ihor Solodrai <ihor.solodrai@pm.me>
To: dwarves@vger.kernel.org
Cc: bpf@vger.kernel.org, acme@kernel.org, alan.maguire@oracle.com,
eddyz87@gmail.com, andrii@kernel.org, mykolal@fb.com,
olsajiri@gmail.com
Subject: [PATCH dwarves v4 09/10] btf_encoder: clean up global encoders list
Date: Tue, 07 Jan 2025 19:09:48 +0000 [thread overview]
Message-ID: <20250107190855.2312210-10-ihor.solodrai@pm.me> (raw)
In-Reply-To: <20250107190855.2312210-1-ihor.solodrai@pm.me>
With multithreading moved entirely to the dwarf_loader, now there is
only one btf_encoder. Hence there is no need to maintain a global list
of encoders anymore.
Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>
---
btf_encoder.c | 94 +++++----------------------------------------------
btf_encoder.h | 4 ---
2 files changed, 8 insertions(+), 90 deletions(-)
diff --git a/btf_encoder.c b/btf_encoder.c
index 7fc04cb..4b6e4b7 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -218,39 +218,6 @@ static struct elf_functions *elf_functions__find(const Elf *elf, const struct li
return NULL;
}
-
-static LIST_HEAD(encoders);
-static pthread_mutex_t encoders__lock = PTHREAD_MUTEX_INITIALIZER;
-
-/* mutex only needed for add/delete, as this can happen in multiple encoding
- * threads. Traversal of the list is currently confined to thread collection.
- */
-
-#define btf_encoders__for_each_encoder(encoder) \
- list_for_each_entry(encoder, &encoders, node)
-
-static void btf_encoders__add(struct btf_encoder *encoder)
-{
- pthread_mutex_lock(&encoders__lock);
- list_add_tail(&encoder->node, &encoders);
- pthread_mutex_unlock(&encoders__lock);
-}
-
-static void btf_encoders__delete(struct btf_encoder *encoder)
-{
- struct btf_encoder *existing = NULL;
-
- pthread_mutex_lock(&encoders__lock);
- /* encoder may not have been added to list yet; check. */
- btf_encoders__for_each_encoder(existing) {
- if (encoder == existing)
- break;
- }
- if (encoder == existing)
- list_del(&encoder->node);
- pthread_mutex_unlock(&encoders__lock);
-}
-
#define PERCPU_SECTION ".data..percpu"
/*
@@ -868,39 +835,6 @@ static int32_t btf_encoder__add_var_secinfo(struct btf_encoder *encoder, size_t
return gobuffer__add(&encoder->secinfo[shndx].secinfo, &si, sizeof(si));
}
-int32_t btf_encoder__add_encoder(struct btf_encoder *encoder, struct btf_encoder *other)
-{
- size_t shndx;
- if (encoder == other)
- return 0;
-
- for (shndx = 1; shndx < other->seccnt; shndx++) {
- struct gobuffer *var_secinfo_buf = &other->secinfo[shndx].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;
-
- if (strcmp(encoder->secinfo[shndx].name, other->secinfo[shndx].name)) {
- fprintf(stderr, "mismatched ELF sections at index %zu: \"%s\", \"%s\"\n",
- shndx, encoder->secinfo[shndx].name, other->secinfo[shndx].name);
- return -1;
- }
-
- 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, shndx, 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, size_t shndx)
{
struct gobuffer *var_secinfo_buf = &encoder->secinfo[shndx].secinfo;
@@ -1326,18 +1260,16 @@ static void btf_encoder__delete_saved_funcs(struct btf_encoder *encoder)
}
}
-static int btf_encoder__add_saved_funcs(bool skip_encoding_inconsistent_proto)
+static int btf_encoder__add_saved_funcs(struct btf_encoder *encoder, bool skip_encoding_inconsistent_proto)
{
struct btf_encoder_func_state **saved_fns = NULL, *s;
int err = 0, i = 0, j, nr_saved_fns = 0;
- struct btf_encoder *e = NULL;
- /* Retrieve function states from each encoder, combine them
+ /* Retrieve function states from the encoder, combine them
* and sort by name, addr.
*/
- btf_encoders__for_each_encoder(e) {
- list_for_each_entry(s, &e->func_states, node)
- nr_saved_fns++;
+ list_for_each_entry(s, &encoder->func_states, node) {
+ nr_saved_fns++;
}
if (nr_saved_fns == 0)
@@ -1349,9 +1281,8 @@ static int btf_encoder__add_saved_funcs(bool skip_encoding_inconsistent_proto)
goto out;
}
- btf_encoders__for_each_encoder(e) {
- list_for_each_entry(s, &e->func_states, node)
- saved_fns[i++] = s;
+ list_for_each_entry(s, &encoder->func_states, node) {
+ saved_fns[i++] = s;
}
qsort(saved_fns, nr_saved_fns, sizeof(*saved_fns), saved_functions_cmp);
@@ -1383,9 +1314,7 @@ static int btf_encoder__add_saved_funcs(bool skip_encoding_inconsistent_proto)
out:
free(saved_fns);
- btf_encoders__for_each_encoder(e) {
- btf_encoder__delete_saved_funcs(e);
- }
+ btf_encoder__delete_saved_funcs(encoder);
return err;
}
@@ -2147,7 +2076,7 @@ int btf_encoder__encode(struct btf_encoder *encoder, struct conf_load *conf)
int err;
size_t shndx;
- err = btf_encoder__add_saved_funcs(conf->skip_encoding_btf_inconsistent_proto);
+ err = btf_encoder__add_saved_funcs(encoder, conf->skip_encoding_btf_inconsistent_proto);
if (err < 0)
return err;
@@ -2553,7 +2482,6 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
if (encoder->verbose)
printf("File %s:\n", cu->filename);
- btf_encoders__add(encoder);
}
return encoder;
@@ -2570,7 +2498,6 @@ void btf_encoder__delete(struct btf_encoder *encoder)
if (encoder == NULL)
return;
- btf_encoders__delete(encoder);
for (shndx = 0; shndx < encoder->seccnt; shndx++)
__gobuffer__delete(&encoder->secinfo[shndx].secinfo);
free(encoder->secinfo);
@@ -2740,8 +2667,3 @@ out:
encoder->cu = NULL;
return err;
}
-
-struct btf *btf_encoder__btf(struct btf_encoder *encoder)
-{
- return encoder->btf;
-}
diff --git a/btf_encoder.h b/btf_encoder.h
index 0081a99..0f345e2 100644
--- a/btf_encoder.h
+++ b/btf_encoder.h
@@ -27,10 +27,6 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
void btf_encoder__delete(struct btf_encoder *encoder);
int btf_encoder__encode(struct btf_encoder *encoder, struct conf_load *conf);
-
int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu, struct conf_load *conf_load);
-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_ */
--
2.47.1
next prev parent reply other threads:[~2025-01-07 19:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-07 19:08 [PATCH dwarves v4 00/10] pahole: faster reproducible BTF encoding Ihor Solodrai
2025-01-07 19:09 ` [PATCH dwarves v4 01/10] btf_encoder: simplify function encoding Ihor Solodrai
2025-01-07 19:09 ` [PATCH dwarves v4 02/10] btf_encoder: free encoder->secinfo in btf_encoder__delete Ihor Solodrai
2025-01-09 16:54 ` Alan Maguire
2025-01-09 21:36 ` Arnaldo Carvalho de Melo
2025-01-07 19:09 ` [PATCH dwarves v4 03/10] btf_encoder: separate elf function, saved function representations Ihor Solodrai
2025-01-07 19:09 ` [PATCH dwarves v4 04/10] btf_encoder: introduce elf_functions struct type Ihor Solodrai
2025-01-07 19:09 ` [PATCH dwarves v4 05/10] btf_encoder: introduce elf_functions_list Ihor Solodrai
2025-01-07 19:09 ` [PATCH dwarves v4 06/10] btf_encoder: remove skip_encoding_inconsistent_proto Ihor Solodrai
2025-01-07 19:09 ` [PATCH dwarves v4 07/10] dwarf_loader: introduce cu->id Ihor Solodrai
2025-01-07 19:09 ` [PATCH dwarves v4] dwarf_loader: multithreading with a job/worker model Ihor Solodrai
2025-01-07 19:09 ` Ihor Solodrai [this message]
2025-01-07 19:09 ` [PATCH dwarves v4] btf_encoder: switch func_states from a list to an array Ihor Solodrai
2025-01-07 20:35 ` [PATCH dwarves v4 00/10] pahole: faster reproducible BTF encoding Ihor Solodrai
2025-01-09 18:32 ` Arnaldo Carvalho de Melo
2025-01-09 18:38 ` Ihor Solodrai
2025-01-09 21:21 ` Arnaldo Carvalho de Melo
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=20250107190855.2312210-10-ihor.solodrai@pm.me \
--to=ihor.solodrai@pm.me \
--cc=acme@kernel.org \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=mykolal@fb.com \
--cc=olsajiri@gmail.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