From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 63904 invoked by alias); 18 May 2019 21:00:34 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 60825 invoked by uid 89); 18 May 2019 21:00:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.45.250) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 18 May 2019 21:00:24 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 65BA0400DC999 for ; Sat, 18 May 2019 16:00:15 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id S6RDh3xOZYTGMS6RDh5Qz6; Sat, 18 May 2019 16:00:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: 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=CbLH5yT9gnhWbNSMmJoIOsu3JwRUWbyXSlFDhkRVA7M=; b=jHkiS7xs6kJNf1qrMAfXdyUNj4 7TvCLXOmA5MbcoESKVlvB6IkC2mwCxotWcq1qHylurI3SoNFmigTqCer5/hFlD+QxO8+Drcx38w8R 5GCX7kCW9XRXpu39RfOdaFoR0; Received: from 71-218-69-43.hlrn.qwest.net ([71.218.69.43]:38158 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hS6RD-0016Ya-4K; Sat, 18 May 2019 16:00:15 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 7/8] Demangle minsyms in parallel Date: Sat, 18 May 2019 21:00:00 -0000 Message-Id: <20190518210010.27697-8-tom@tromey.com> In-Reply-To: <20190518210010.27697-1-tom@tromey.com> References: <20190518210010.27697-1-tom@tromey.com> X-SW-Source: 2019-05/txt/msg00447.txt.bz2 This patch introduces a simple parallel for_each and changes the minimal symbol reader to use it when computing the demangled name for a minimal symbol. This yields a speedup when reading minimal symbols. gdb/ChangeLog 2019-05-18 Tom Tromey * minsyms.c (minimal_symbol_reader::install): Use parallel_for_each. * common/parallel-for.h: New file. * common/parallel-for.c: New file. * Makefile.in (HFILES_NO_SRCDIR): Add common/parallel-for.h. (COMMON_SFILES): Add common/parallel-for.c. --- gdb/ChangeLog | 9 +++++ gdb/Makefile.in | 2 + gdb/common/parallel-for.c | 27 +++++++++++++ gdb/common/parallel-for.h | 79 +++++++++++++++++++++++++++++++++++++++ gdb/minsyms.c | 23 +++++++----- 5 files changed, 130 insertions(+), 10 deletions(-) create mode 100644 gdb/common/parallel-for.c create mode 100644 gdb/common/parallel-for.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 2dd69f3f0ba..15c7a6e2536 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -971,6 +971,7 @@ COMMON_SFILES = \ common/gdb_vecs.c \ common/netstuff.c \ common/new-op.c \ + common/parallel-for.c \ common/pathstuff.c \ common/print-utils.c \ common/ptid.c \ @@ -1471,6 +1472,7 @@ HFILES_NO_SRCDIR = \ common/common-inferior.h \ common/netstuff.h \ common/host-defs.h \ + common/parallel-for.h \ common/pathstuff.h \ common/print-utils.h \ common/ptid.h \ diff --git a/gdb/common/parallel-for.c b/gdb/common/parallel-for.c new file mode 100644 index 00000000000..acec77c9fa4 --- /dev/null +++ b/gdb/common/parallel-for.c @@ -0,0 +1,27 @@ +/* Parallel for loops + + Copyright (C) 2019 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "common/common-defs.h" +#include "common/parallel-for.h" + +namespace gdb +{ +/* See parallel-for.h. */ +int enable_threads = 1; +} diff --git a/gdb/common/parallel-for.h b/gdb/common/parallel-for.h new file mode 100644 index 00000000000..db90137127d --- /dev/null +++ b/gdb/common/parallel-for.h @@ -0,0 +1,79 @@ +/* Parallel for loops + + Copyright (C) 2019 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef COMMON_PARALLEL_FOR_H +#define COMMON_PARALLEL_FOR_H + +#include +#if CXX_STD_THREAD +#include +#endif + +namespace gdb +{ + +/* True if threading should be enabled. */ + +extern int enable_threads; + +/* A very simple "parallel for". This iterates over the elements + given by the range of iterators, which must be random access + iterators. For each element, it calls the callback function. The + work may or may not be done by separate threads. */ + +template +void parallel_for_each (RandomIt first, RandomIt last, UnaryFunction f) +{ +#if CXX_STD_THREAD + unsigned n_threads = std::thread::hardware_concurrency (); + /* So we can use a local array below. */ + const unsigned max_threads = 16; + if (n_threads > max_threads) + n_threads = max_threads; + + if (!enable_threads || n_threads == 0 || last - first < 2 * n_threads) +#endif /* CXX_STD_THREAD */ + { + /* Don't bother. */ + std::for_each (first, last, f); + return; + } + +#if CXX_STD_THREAD + auto body = [&] (RandomIt start) + { + for (; start < last; start += n_threads) + f (*start); + }; + + std::thread threads[max_threads]; + for (unsigned i = 0; i < n_threads; ++i) + { + threads[i] = std::thread (body, first); + ++first; + } + + for (unsigned i = 0; i < n_threads; ++i) + threads[i].join (); +#endif /* CXX_STD_THREAD */ +} + +} + +#endif /* COMMON_PARALLEL_FOR_H */ diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 488201a1886..4c0ee11c47e 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -53,6 +53,7 @@ #include "common/symbol.h" #include #include "safe-ctype.h" +#include "common/parallel-for.h" /* See minsyms.h. */ @@ -1372,16 +1373,18 @@ minimal_symbol_reader::install () m_objfile->per_bfd->msymbols = std::move (msym_holder); msymbols = m_objfile->per_bfd->msymbols.get (); - for (int i = 0; i < mcount; ++i) - { - if (!msymbols[i].name_set) - { - symbol_set_names (&msymbols[i], msymbols[i].name, - strlen (msymbols[i].name), 0, - m_objfile->per_bfd); - msymbols[i].name_set = 1; - } - } + gdb::parallel_for_each + (&msymbols[0], &msymbols[mcount], + [&] (minimal_symbol &msym) + { + if (!msym.name_set) + { + symbol_set_names (&msym, msym.name, + strlen (msym.name), 0, + m_objfile->per_bfd); + msym.name_set = 1; + } + }); build_minimal_symbol_hash_tables (m_objfile); } -- 2.17.2