From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy3-pub.mail.unifiedlayer.com (gproxy3-pub.mail.unifiedlayer.com [69.89.30.42]) by sourceware.org (Postfix) with ESMTPS id E1CD73857C48 for ; Mon, 4 Apr 2022 19:53:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E1CD73857C48 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway5.mail.pro1.eigbox.com (Postfix) with ESMTP id 54AE910047F37 for ; Mon, 4 Apr 2022 19:53:46 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id bSllnJMaMQs3CbSlmnPKQ3; Mon, 04 Apr 2022 19:53:46 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=A+Opg4aG c=1 sm=1 tr=0 ts=624b4cca a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=z0gMJWrwH1QA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=j-TL0r5iQPrGpVUNc_QA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=z3/0eHmNbG0qp/Wv7hxpfotZXniIY18AijLZBm8hQGc=; b=FFsEX/lfukaz4J19EPR3xLPKim lu2SlId6yVO3RWYaQKeMkzeP9pGHmnadv5qVUozNwLRtIefsPQA3mtL2ClKj9CjovFT9PWdHe2652 Pmg99q6U00upeX51/mLHvq+l4; Received: from 71-211-176-135.hlrn.qwest.net ([71.211.176.135]:34802 helo=prentzel.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nbSll-003uHX-LM; Mon, 04 Apr 2022 13:53:45 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v4 25/34] "Finalize" the DWARF index in the background Date: Mon, 4 Apr 2022 13:53:26 -0600 Message-Id: <20220404195335.2111906-26-tom@tromey.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220404195335.2111906-1-tom@tromey.com> References: <20220404195335.2111906-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.176.135 X-Source-L: No X-Exim-ID: 1nbSll-003uHX-LM X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-176-135.hlrn.qwest.net (prentzel.Home) [71.211.176.135]:34802 X-Source-Auth: tom+tromey.com X-Email-Count: 33 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3030.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Apr 2022 19:53:48 -0000 After scanning the CUs, the DWARF indexer merges all the data into a single vector, canonicalizing C++ names as it proceeds. While not necessarily single-threaded, this process is currently done in just one thread, to keep memory costs lower. However, this work is all done without reference to any data outside of the indexes. This patch improves the apparent performance of GDB by moving it to the background. All uses of the index are then made to wait for this process to complete. In our ongoing example, this reduces the scanning time on gdb itself to 0.173937 (wall). Recall that before this patch, the time was 0.668923; and psymbol reader does this in 1.598869. That is, at the end of this series, we see about a 10x speedup. --- gdb/dwarf2/cooked-index.c | 10 ++++++++-- gdb/dwarf2/cooked-index.h | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 1a2f044091b..9d11376147c 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -118,9 +118,13 @@ cooked_index::add (sect_offset die_offset, enum dwarf_tag tag, } cooked_index_vector::cooked_index_vector (vec_type &&vec) - : m_vector (std::move (vec)) + : m_vector (std::move (vec)), + m_future (gdb::thread_pool::g_thread_pool->post_task + ([this] () + { + finalize (); + })) { - finalize (); } /* See cooked-index.h. */ @@ -153,6 +157,8 @@ cooked_index_vector::get_addrmaps () cooked_index_vector::range cooked_index_vector::find (gdb::string_view name, bool completing) { + m_future.wait (); + auto lower = std::lower_bound (m_entries.begin (), m_entries.end (), name, [=] (const cooked_index_entry *entry, diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 188155190ec..661664d9f84 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -254,6 +254,17 @@ class cooked_index_vector explicit cooked_index_vector (vec_type &&vec); DISABLE_COPY_AND_ASSIGN (cooked_index_vector); + ~cooked_index_vector () + { + /* The 'finalize' method may be run in a different thread. If + this object is destroyed before this completes, then the method + will end up writing to freed memory. Waiting for this to + complete avoids this problem; and the cost seems ignorable + because creating and immediately destroying the debug info is a + relatively rare thing to do. */ + m_future.wait (); + } + /* A simple range over part of m_entries. */ typedef iterator_range::iterator> range; @@ -265,6 +276,7 @@ class cooked_index_vector /* Return a range of all the entries. */ range all_entries () { + m_future.wait (); return { m_entries.begin (), m_entries.end () }; } @@ -305,6 +317,11 @@ class cooked_index_vector /* Storage for canonical names. */ std::vector> m_names; + + /* A future that tracks when the 'finalize' method is done. Note + that the 'get' method is never called on this future, only + 'wait'. */ + std::future m_future; }; #endif /* GDB_DWARF2_COOKED_INDEX_H */ -- 2.34.1