From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id D08083858D37 for ; Thu, 14 Jul 2022 22:18:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D08083858D37 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8B2CA33FCB; Thu, 14 Jul 2022 22:18:37 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 729F913A61; Thu, 14 Jul 2022 22:18:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id zw/IGj2W0GILWwAAMHmgww (envelope-from ); Thu, 14 Jul 2022 22:18:37 +0000 Date: Fri, 15 Jul 2022 00:18:31 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC][gdbsupport] Add PARALLEL_FOR_EACH_DEBUG Message-ID: <20220714221829.GA31924@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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, 14 Jul 2022 22:18:53 -0000 Hi, Add a PARALLEL_FOR_EACH_DEBUG macro, set to 0 by default. With an a.out compiled from hello world, we get with PARALLEL_FOR_EACH_DEBUG == 1: ... $ gdb -q -batch a.out -ex start ... Parallel for: n_elements: 7271 Parallel for: minimum elements per thread: 10 Parallel for: elts_per_thread: 1817 Parallel for: worker threads: 4 Parallel for: worker threads used: 3 Parallel for: elements 0-1816 on thread 0: 1817 Parallel for: elements 1817-3633 on thread 1: 1817 Parallel for: elements 3634-5450 on thread 2: 1817 Parallel for: elements 5451-7270 on main thread: 1820 Temporary breakpoint 1, main () at /home/vries/hello.c:6 6 printf ("hello\n"); ... Note that thread usage isn't ideal. We end up using only three out of four worker threads here. Any comments? Thanks, - Tom [gdbsupport] Add PARALLEL_FOR_EACH_DEBUG --- gdbsupport/parallel-for.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h index a614fc35766..358ed9e8f7f 100644 --- a/gdbsupport/parallel-for.h +++ b/gdbsupport/parallel-for.h @@ -113,6 +113,8 @@ struct par_for_accumulator } +#define PARALLEL_FOR_EACH_DEBUG 0 + /* A very simple "parallel for". This splits the range of iterators into subranges, and then passes each subrange to the callback. The work may or may not be done in separate threads. @@ -139,6 +141,10 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last, using result_type = typename std::result_of::type; +#if PARALLEL_FOR_EACH_DEBUG + RandomIt orig_first = first; +#endif + size_t n_threads = thread_pool::g_thread_pool->thread_count (); size_t n_elements = last - first; size_t elts_per_thread = 0; @@ -155,9 +161,25 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last, size_t count = n_threads == 0 ? 0 : n_threads - 1; gdb::detail::par_for_accumulator results (count); +#if PARALLEL_FOR_EACH_DEBUG + fprintf (stderr, "Parallel for: n_elements: %zu\n", n_elements); + fprintf (stderr, "Parallel for: minimum elements per thread: %u\n", n); + fprintf (stderr, "Parallel for: elts_per_thread: %zu\n", elts_per_thread); + fprintf (stderr, "Parallel for: worker threads: %zu\n", + thread_pool::g_thread_pool->thread_count ()); + fprintf (stderr, "Parallel for: worker threads used: %zu\n", count); +#endif + for (int i = 0; i < count; ++i) { RandomIt end = first + elts_per_thread; +#if PARALLEL_FOR_EACH_DEBUG + fprintf (stderr, "Parallel for: elements %u-%u on thread %d: %u\n", + (unsigned)(first - orig_first), + (unsigned)(end - 1 - orig_first), + i, + (unsigned)(end - first)); +#endif results.post (i, [=] () { return callback (first, end); @@ -166,6 +188,12 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last, } /* Process all the remaining elements in the main thread. */ +#if PARALLEL_FOR_EACH_DEBUG + fprintf (stderr, "Parallel for: elements %u-%u on main thread: %u\n", + (unsigned)(first - orig_first), + (unsigned)(last - 1 - orig_first), + (unsigned)(last - first)); +#endif return results.finish ([=] () { return callback (first, last);