[PATCH dwarves] pahole, btf_encoder: Collect info of per-cpu varaibles from threads.

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

 



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





[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux