From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway31.websitewelcome.com (gateway31.websitewelcome.com [192.185.143.40]) by sourceware.org (Postfix) with ESMTPS id 9447B3858006 for ; Thu, 26 Aug 2021 02:19:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9447B3858006 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 cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 4492B29121 for ; Wed, 25 Aug 2021 21:19:44 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id J4zYmDkIHK61iJ4zYmEqMH; Wed, 25 Aug 2021 21:19:44 -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=Ur6iDnJlmPChoQsSQzIuHxKy9q/ZwTKknzmGiwXddyw=; b=kT8JNi1RmCRpy2Imz6mY2tC2ZB QuRAu7GimxlLDAs5PEqxqGsnBVvxX4T3IRVmMdFI24/H/GpFEXb8H1aWQ/D05iJiZ5mKZq8eKezKO Bj9VVqrscNoXEaFD7IU5/LSpx; Received: from 97-122-86-84.hlrn.qwest.net ([97.122.86.84]:46876 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 1mJ4zY-003LSg-1X; Wed, 25 Aug 2021 20:19:44 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 21/30] "Finalize" the DWARF index in the background Date: Wed, 25 Aug 2021 20:19:28 -0600 Message-Id: <20210826021937.1490292-22-tom@tromey.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210826021937.1490292-1-tom@tromey.com> References: <20210826021937.1490292-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: 97.122.86.84 X-Source-L: No X-Exim-ID: 1mJ4zY-003LSg-1X X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-84.hlrn.qwest.net (localhost.localdomain) [97.122.86.84]:46876 X-Source-Auth: tom+tromey.com X-Email-Count: 22 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3030.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, URIBL_CSS_A 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, 26 Aug 2021 02:20:13 -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 513c461b0f2..37a78f126d6 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