From patchwork Tue Jan 7 19:09:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ihor Solodrai X-Patchwork-Id: 13929534 Received: from mail-10628.protonmail.ch (mail-10628.protonmail.ch [79.135.106.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0CC01F470C for ; Tue, 7 Jan 2025 19:09:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.28 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736276998; cv=none; b=UYcjEpj19D19nJGclaaIVMINf1yX2+mUSqy9WNiDabxBVdPsw0Hh08qMQATMvyjjNR6tjVdb24duuV5fku3F+qNK8ZRlTc8voXL43MsX4RAdlcOhtbeN4iCxHsZuGVjn3seixsKIs3rext4h41NCrixsQsIRPaaJHWGNk32tGek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736276998; c=relaxed/simple; bh=9IeFZzMnVRUUbyUt7fLv61oIiHiC1M36VosCjsne8Cs=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fM8PYhgbsrXObaGH5tp4ZiZgIOm0iUy1feT9JZ94XYl0o73Jd3aK69MzpJycGgVybbFtIbf5n+HRdFkapi+BBd8JSrxu/7VPn202KjMttnr02IfAPpH5cEa0GPINeyp1wgND/40Opl+WytJrJ6hBxIdrMmo/V8GhjCtx2J51Nw8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=Jf6RQghi; arc=none smtp.client-ip=79.135.106.28 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="Jf6RQghi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1736276992; x=1736536192; bh=VeQTSyx/mjaHmdLYSH5yxPaGXWhYyevT098OP7Y4JnA=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=Jf6RQghi1Ux8zy9GqVZXvpYvijaM7gehiT1TLpuhZeLiJ7bIHoe9Kl7fZj9YXZuzz rLAGchitP1g9nC5XMOC5g7hfBBfp6yCofNscZ7LTXPwQ2s/rdsOK/tKUaT5WBXZhgv 0DyaH27e1oOsmScAKUIH5JiPtHDAqlU8O7zbItfRne2kgC0nSNOTIUGtqLuMHZ8g34 edPzsPcTea/C5rt1VcZhipMI6H6LQ6eCY06ly4oWrOHAmXR4SW9P8TZJyFecY+iZ9N HgeY1Y9JJn/v657G7V8AD+VZxm2ImXqqv6xQ0grdX8NUjoFW2+cXttfu0w7ifpNf6u ZpNYZy8XtJdYA== Date: Tue, 07 Jan 2025 19:09:48 +0000 To: dwarves@vger.kernel.org From: Ihor Solodrai 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 Message-ID: <20250107190855.2312210-10-ihor.solodrai@pm.me> In-Reply-To: <20250107190855.2312210-1-ihor.solodrai@pm.me> References: <20250107190855.2312210-1-ihor.solodrai@pm.me> Feedback-ID: 27520582:user:proton X-Pm-Message-ID: 6f70ca2a186137f3dca0e61bdde6a5bfcd51ef32 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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_ */