From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway20.websitewelcome.com (gateway20.websitewelcome.com [192.185.47.18]) by sourceware.org (Postfix) with ESMTPS id 941BA385803B for ; Thu, 4 Nov 2021 18:10:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 941BA385803B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tromey.com Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 37FC24012EF5F for ; Thu, 4 Nov 2021 13:09:15 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id ihApmjE7ftL6eihApmwuNE; Thu, 04 Nov 2021 13:09:15 -0500 X-Authority-Reason: nr=8 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=PJRX0LFYXi+CVDT7Q7F0IqSBLY0SKokCtyH7jY8N6d0=; b=pYfty/v2nXE1CpBlte7p/JfcWT 18JeNSYshQQGj+BlETRXT1sxqtlbm/uvAFUcl5mFmZh28jsy6DmwmfU8AgghEkciaGl4fzd3FixVi 8Umdd6lsi2Oxk2e3Nmw4G/dxU; Received: from 75-166-134-234.hlrn.qwest.net ([75.166.134.234]:51960 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mihAo-003H6y-Rk; Thu, 04 Nov 2021 12:09:14 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 23/32] "Finalize" the DWARF index in the background Date: Thu, 4 Nov 2021 12:08:58 -0600 Message-Id: <20211104180907.2360627-24-tom@tromey.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211104180907.2360627-1-tom@tromey.com> References: <20211104180907.2360627-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: 75.166.134.234 X-Source-L: No X-Exim-ID: 1mihAo-003H6y-Rk X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-134-234.hlrn.qwest.net (localhost.localdomain) [75.166.134.234]:51960 X-Source-Auth: tom+tromey.com X-Email-Count: 28 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.1 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_PASS, SPF_NEUTRAL, TXREP 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: Thu, 04 Nov 2021 18:10:18 -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 bb10b884a43..7e114c4edd2 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -117,9 +117,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. */ @@ -152,6 +156,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 a4bfc3eb183..365150b8692 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.31.1