From patchwork Mon Sep 28 12:21:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 144782 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 96C724BAE7CC for ; Mon, 28 Sep 2026 12:22:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96C724BAE7CC X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by sourceware.org (Postfix) with ESMTPS id 69A8E4B9DB7B for ; Mon, 28 Sep 2026 12:22:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 69A8E4B9DB7B Authentication-Results: sourceware.org; dmarc=fail (p=quarantine dis=none) header.from=seketeli.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=seketeli.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 69A8E4B9DB7B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2001:4b98:dc4:8::226 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790598167; cv=none; b=ZtL0QVIQHLLETt0GNPAbBAZ4wGKEux3dQLPPesDiv5pQL4U3diBnv88r1weU1F/OeG0jtNVbUV1rnKVgv4FVFsrjqsIg4YHFHzcrV/nJiGrEURJ9jL0jono/S2FPqIlel7VfKR406l9Qk4/7cbJJs5V33kgj73BkOvXD2UPoLvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790598167; c=relaxed/simple; bh=yGtSz8vFYJHM3czNFMfwlofLqU1TdCVnoyrm1Hst4P4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=QKOvNBEvNEsC6/wnYBSO0VfJyE6KQw3eFEsF8q4gYtFqJMKtPKdbo/xDTFJEGFO6eGKTGxdie54pLj0OOt4xNTwhe1NIRxvetocG+CMYuy0ZXSZkgQsPHqL1IjZxwBqwmzx3YzcCZnNqcwSQbwfdpX/h8oOf6Pzvqj/STLnLQHk= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69A8E4B9DB7B Received: by mail.gandi.net (Postfix) with ESMTPSA id B9FF93EC01 for ; Mon, 28 Sep 2026 12:22:43 +0000 (UTC) Received: by localhost (Postfix, from userid 1000) id 4F5A46031647; Mon, 28 Sep 2026 14:22:43 +0200 (CEST) From: Dodji Seketeli To: libabigail@sourceware.org Subject: [PATCH 2/4] dwarf-reader: Store DIE -> pretty representation map in TLS Date: Mon, 28 Sep 2026 14:21:39 +0200 Message-ID: <20260928122243.3988357-2-dodji@seketeli.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260928122243.3988357-1-dodji@seketeli.org> References: <20260928122243.3988357-1-dodji@seketeli.org> MIME-Version: 1.0 X-GND-Sasl: dodj@seketeli.net X-GND-State: clean X-GND-Score: 0 X-GND-Cause: dmFkZTFkUemiU2CiUD9Ez2bqr9XMfxjsIqKXdurwpatONNUOVja2hwrn3uWZeTAXvZByUthvzcY9/UunZh7bog9eqklVvL+UvgQhpuyPEd4TGJhkuLSL0rUeXJ87V2PGomQ2flYDy5pRsIEHvhaWWkCFwBK2Oq7zsS4Xm+NLiy+9qSCxvFBs1s3CqrM8vTTJvkPXBVE19TAeE2bNY9qxU60gnVHPZBYNsODHDUQlBle2b/naRN45lr1IZzH3IQj37QBdU13zxUekFvzXzTwQFo51Thp/8VsAyR0Ulm951W1R18tfH5JRuvWhs9stKoWsOTccrVkeYMriu3gKc84z683nzvMFOb61X3IhZMdvPqyZEUcCIG5KqZYKfQ3iw3L5NsOkUeXhdFp50KAkkoJDKxeii1P+evtBKTNfAiC/uO8OPRM7eSvyvC4Ue3UlmGkTACJXV4uR/MyjeQGVN5g++tglG8HXWzuzvd38/exp0zpKBXw+7diEuCX3+8hp+Wr4vIz5VKh2LT6ZMxvZC2tcGeU0N2V31warLYkuaJCb/Ft3yjMBKQ9EpXGzfv1N3h7TikstCCCrKrN+86OOqh/bONvJeNPRAkAwhKIEB7AdUQ2glW/c4ToSSL0KuQCvWa4YnigCHHAlLP2I91IKl+n19g2s8OeeLylupECCeDBLu2EuI5KmUA X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, LOCAL_AUTHENTICATION_FAIL_DMARC, LOCAL_AUTHENTICATION_FAIL_SPF, SPF_HELO_PASS, TXREP, T_SPF_PERMERROR, URI_PHISH shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libabigail-bounces~patchwork=sourceware.org@sourceware.org Data members dwarf::reader::{die_qualified_name,die_pretty_repr}_maps_ are shared between the threads used for the Abigail IR (aka AIR) construction. They thus need synchronization to prevent data races. This patch stores these maps in thread-local storage to prevent the need for synchronization. This somewhat lowers the amount of context switches. Despite the increase of cache-miss, the patch does not slowdown the processing and seem to slightly increase speed overall. * src/abg-dwarf-reader.cc (reader::{die_qualified_name_maps_,die_pretty_repr_maps_}): Declare these data members as 'static thread_local'. (reader::{die_qualified_name_maps_mutex_,die_pretty_repr_maps_mutex_}): Remove these now useless data members. Signed-off-by: Dodji Seketeli --- src/abg-dwarf-reader.cc | 68 +++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index aebcaa2b..ebb8bebe 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -2146,11 +2146,9 @@ public: unsigned short dwarf_version_; scope_decl_sptr nil_scope_; - mutable die_istring_map_type die_qualified_name_maps_; - mutable mutex die_qualified_name_maps_mutex_; + static thread_local die_istring_map_type die_qualified_name_maps_; - mutable die_istring_map_type die_pretty_repr_maps_; - mutable recursive_mutex die_pretty_repr_maps_mutex_; + static thread_local die_istring_map_type die_pretty_repr_maps_; // A map that associates the address of a decl die to its // corresponding decl artifact, along with its mutex. @@ -2769,36 +2767,55 @@ public: clear_types_to_canonicalize(); } - const die_istring_map_type& - die_qualified_name_maps() const - {return die_qualified_name_maps_;} - - die_istring_map_type& + /// Getter for the map that associates a DIE to its qualified name. + /// + /// This map is stored in thread-local-storage to avoid locking. + /// Things are not slower when using this, even when analyzing the + /// Linux kernel. + /// + /// @return the map that associates a DIE to its qualified name. + static die_istring_map_type& die_qualified_name_maps() {return die_qualified_name_maps_;} + /// Set the qualified name of a given DIE in its thread-local storage. + /// + /// This does not involve any synchronization. + /// + /// @param die_addr the address of the DIE to consider. + /// + /// @param istr the new qualified name. void set_die_qualified_name(const void* die_addr, interned_string istr) const { ABG_ASSERT(die_addr && !istr.empty()); - std::lock_guard lock(die_qualified_name_maps_mutex_); - die_qualified_name_maps_[const_cast(die_addr)] = istr; + die_qualified_name_maps()[const_cast(die_addr)] = istr; } - const die_istring_map_type& - die_pretty_repr_maps() const - {return die_pretty_repr_maps_;} - - die_istring_map_type& + /// Getter of the map that associates a DIE to its pretty representation. + /// + /// This map is stored in thread-local-storage to avoid locking. + /// Things are not slower when using this, even when analyzing the + /// Linux kernel. + /// + /// @return the map that associates a DIE to its pretty representation. + static die_istring_map_type& die_pretty_repr_maps() {return die_pretty_repr_maps_;} - void - set_die_pretty_repr(const void* die_addr, interned_string istr) const + /// Set the pretty representation of a given DIE. + /// + /// This does not involve any synchronization as the DIE -> pretty + /// repr map is stored in thread-local storage. + /// + /// @param die_addr the address of the DIE to consider. + /// + /// @param istr the new pretty representation. + static void + set_die_pretty_repr(const void* die_addr, interned_string istr) { ABG_ASSERT(die_addr && !istr.empty()); - std::lock_guard lock(die_pretty_repr_maps_mutex_); - die_pretty_repr_maps_[const_cast(die_addr)] = istr; + die_pretty_repr_maps()[const_cast(die_addr)] = istr; } /// Getter for the current environment. @@ -5565,6 +5582,17 @@ public: } };// end class reader. +/// The thread-local storage of the reader::die_qualified_name_maps_ +/// data member. Using this avoids the need for locking. +thread_local die_istring_map_type +reader::die_qualified_name_maps_; + +/// The thread-local storage of the reader::die_pretty_repr_maps_ data +/// member. Using this avoids the need for locking. +/// Using this avoids the need for locking. +thread_local die_istring_map_type +reader::die_pretty_repr_maps_; + static bool do_handle_dwarf_die(reader& rdr, reader::tu_context_type_sptr tu_ctxt, Dwarf_Die& die, bool die_is_public);