From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway32.websitewelcome.com (gateway32.websitewelcome.com [192.185.145.101]) by sourceware.org (Postfix) with ESMTPS id 29928385841D for ; Thu, 26 Aug 2021 02:19:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 29928385841D 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 cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway32.websitewelcome.com (Postfix) with ESMTP id CCB3D988BCC for ; Wed, 25 Aug 2021 21:19:41 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id J4zVmP0a7BvjyJ4zVmzisB; Wed, 25 Aug 2021 21:19:41 -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=zRwJOn09xXYwZWJ6oEedsb+7CxJiUh+NV6Ib62qtmoA=; b=OHU2SVTFm3crMEWWlWxfG84ult n4lD+sU8DqbYelOfma8ijM4wvVn9RaPlJiel86R3up9ew2eMyrLDhtyBUQhHe/6TUL2IRBurEOYOW +8RQrJHpS5Iasaha1aGhrcWTF; 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 1mJ4zV-003LSg-Hn; Wed, 25 Aug 2021 20:19:41 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 10/30] Add batching parameter to parallel_for_each Date: Wed, 25 Aug 2021 20:19:17 -0600 Message-Id: <20210826021937.1490292-11-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: 1mJ4zV-003LSg-Hn 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: 11 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_H3, RCVD_IN_MSPIKE_WL, 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:01 -0000 parallel_for_each currently requires each thread to process at least 10 elements. However, when indexing, it's fine for a thread to handle just a single CU. This patch parameterizes this, and updates the one user. --- gdb/minsyms.c | 4 ++-- gdbsupport/parallel-for.h | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 33560e3c41c..1c124848c28 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -1462,8 +1462,8 @@ minimal_symbol_reader::install () std::vector hash_values (mcount); msymbols = m_objfile->per_bfd->msymbols.get (); - gdb::parallel_for_each - (&msymbols[0], &msymbols[mcount], + /* Arbitrarily require at least 10 elements in a thread. */ + gdb::parallel_for_each (10, &msymbols[0], &msymbols[mcount], [&] (minimal_symbol *start, minimal_symbol *end) { for (minimal_symbol *msym = start; msym < end; ++msym) diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h index e4fcb4053b2..54027e69402 100644 --- a/gdbsupport/parallel-for.h +++ b/gdbsupport/parallel-for.h @@ -35,11 +35,16 @@ namespace gdb This approach was chosen over having the callback work on single items because it makes it simple for the caller to do - once-per-subrange initialization and destruction. */ + once-per-subrange initialization and destruction. + + The parameter N says how batching ought to be done -- there will be + at least N elements processed per thread. Setting N to 0 is not + allowed. */ template void -parallel_for_each (RandomIt first, RandomIt last, RangeFunction callback) +parallel_for_each (unsigned n, RandomIt first, RandomIt last, + RangeFunction callback) { #if CXX_STD_THREAD /* So we can use a local array below. */ @@ -52,10 +57,11 @@ parallel_for_each (RandomIt first, RandomIt last, RangeFunction callback) size_t n_elements = last - first; if (n_threads > 1) { - /* Arbitrarily require that there should be at least 10 elements - in a thread. */ - if (n_elements / n_threads < 10) - n_threads = std::max (n_elements / 10, (size_t) 1); + /* Require that there should be at least N elements in a + thread. */ + gdb_assert (n > 0); + if (n_elements / n_threads < n) + n_threads = std::max (n_elements / n, (size_t) 1); size_t elts_per_thread = n_elements / n_threads; n_actual_threads = n_threads - 1; for (int i = 0; i < n_actual_threads; ++i) -- 2.31.1