[PATCH dwarves v3 8/8] btf_encoder: clean up global encoders list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxx>
---
 btf_encoder.c | 106 ++++++++------------------------------------------
 btf_encoder.h |   4 --
 2 files changed, 17 insertions(+), 93 deletions(-)

diff --git a/btf_encoder.c b/btf_encoder.c
index 7e03ba4..88e32e4 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,27 +1260,29 @@ 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, *s;
-	struct btf_encoder *e = NULL;
-	int i = 0, j, nr_saved_fns = 0;
+	int err = 0, i = 0, j, nr_saved_fns = 0;
 
-	/* 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)
-		return 0;
+		goto out;
 
 	saved_fns = calloc(nr_saved_fns, sizeof(*saved_fns));
-	btf_encoders__for_each_encoder(e) {
-		list_for_each_entry(s, &e->func_states, node)
-			saved_fns[i++] = s;
+	if (!saved_fns) {
+		err = -ENOMEM;
+		goto out;
+	}
+
+	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);
 
@@ -1377,11 +1313,10 @@ static int btf_encoder__add_saved_funcs(bool skip_encoding_inconsistent_proto)
 
 	/* Now that we are done with function states, free them. */
 	free(saved_fns);
-	btf_encoders__for_each_encoder(e) {
-		btf_encoder__delete_saved_funcs(e);
-	}
+	btf_encoder__delete_saved_funcs(encoder);
 
-	return 0;
+out:
+	return err;
 }
 
 static void elf_functions__collect_function(struct elf_functions *functions, GElf_Sym *sym)
@@ -2134,7 +2069,7 @@ int btf_encoder__encode(struct btf_encoder *encoder, struct conf_load *conf)
 	int err;
 	size_t shndx;
 
-	btf_encoder__add_saved_funcs(conf->skip_encoding_btf_inconsistent_proto);
+	btf_encoder__add_saved_funcs(encoder, conf->skip_encoding_btf_inconsistent_proto);
 
 	for (shndx = 1; shndx < encoder->seccnt; shndx++)
 		if (gobuffer__size(&encoder->secinfo[shndx].secinfo))
@@ -2541,7 +2476,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;
@@ -2558,7 +2492,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);
@@ -2727,8 +2660,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







[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux