From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway30.websitewelcome.com (gateway30.websitewelcome.com [192.185.179.30]) by sourceware.org (Postfix) with ESMTPS id 1AA803857C7B for ; Thu, 4 Nov 2021 18:09:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1AA803857C7B 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 cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway30.websitewelcome.com (Postfix) with ESMTP id B887AEBBD for ; Thu, 4 Nov 2021 13:09:11 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id ihAlm4cbZIWzGihAlmB83K; Thu, 04 Nov 2021 13:09:11 -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=mXD5ceXxvDZHLLh44s+uUAAHO5z/M6W2nE+lm9e3o4M=; b=U09ZxEggJ7bSux+C1v2FtnT1W5 SEf8duFS30RNOehvyxRDcdkK6wN6JRU7tt9MxWEjl7r9kID+XtadWEnJ+bPyMus/FXie4pxNticu1 AMwZ08xI5VRt8/nxrelCTvpcB; Received: from 75-166-134-234.hlrn.qwest.net ([75.166.134.234]:51958 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 1mihAl-003Gzb-F3; Thu, 04 Nov 2021 12:09:11 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 10/32] Add batching parameter to parallel_for_each Date: Thu, 4 Nov 2021 12:08:45 -0600 Message-Id: <20211104180907.2360627-11-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: 1mihAl-003Gzb-F3 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-134-234.hlrn.qwest.net (localhost.localdomain) [75.166.134.234]:51958 X-Source-Auth: tom+tromey.com X-Email-Count: 15 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.0 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, 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:09:14 -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 ++-- gdb/unittests/parallel-for-selftests.c | 2 +- gdbsupport/parallel-for.h | 18 ++++++++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 5f4cf54c663..7f2f23dd789 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/gdb/unittests/parallel-for-selftests.c b/gdb/unittests/parallel-for-selftests.c index f149e72f0c7..c7a3780c743 100644 --- a/gdb/unittests/parallel-for-selftests.c +++ b/gdb/unittests/parallel-for-selftests.c @@ -52,7 +52,7 @@ test (int n_threads) #define NUMBER 10000 std::atomic counter (0); - gdb::parallel_for_each (0, NUMBER, + gdb::parallel_for_each (1, 0, NUMBER, [&] (int start, int end) { counter += end - start; 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