From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id C87F53858CDA; Mon, 18 Jul 2022 03:34:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C87F53858CDA Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdbsupport] Add parallel_for_each_debug X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 38733fdc8c35aadb6dbea2bb655b1ced65e77ef0 X-Git-Newrev: 53944a3bf51cdff9ad30a0c3740b8124213fdab9 Message-Id: <20220718033404.C87F53858CDA@sourceware.org> Date: Mon, 18 Jul 2022 03:34:04 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jul 2022 03:34:04 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D53944a3bf51c= dff9ad30a0c3740b8124213fdab9 commit 53944a3bf51cdff9ad30a0c3740b8124213fdab9 Author: Tom de Vries Date: Mon Jul 18 05:34:01 2022 +0200 [gdbsupport] Add parallel_for_each_debug =20 Add a parallel_for_each_debug variable, set to false by default. =20 With an a.out compiled from hello world, we get with parallel_for_each_debug =3D=3D true: ... $ 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: elements on worker thread 0 : 1817 Parallel for: elements on worker thread 1 : 1817 Parallel for: elements on worker thread 2 : 1817 Parallel for: elements on worker thread 3 : 0 Parallel for: elements on main thread : 1820 =20 Temporary breakpoint 1, main () at /home/vries/hello.c:6 6 printf ("hello\n"); ... =20 Tested on x86_64-linux. Diff: --- gdbsupport/parallel-for.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h index a614fc35766..cfe8a6e4f09 100644 --- a/gdbsupport/parallel-for.h +++ b/gdbsupport/parallel-for.h @@ -139,7 +139,12 @@ parallel_for_each (unsigned n, RandomIt first, RandomI= t last, using result_type =3D typename std::result_of::type; =20 - size_t n_threads =3D thread_pool::g_thread_pool->thread_count (); + /* If enabled, print debug info about how the work is distributed across + the threads. */ + const int parallel_for_each_debug =3D false; + + size_t n_worker_threads =3D thread_pool::g_thread_pool->thread_count (); + size_t n_threads =3D n_worker_threads; size_t n_elements =3D last - first; size_t elts_per_thread =3D 0; if (n_threads > 1) @@ -155,9 +160,19 @@ parallel_for_each (unsigned n, RandomIt first, RandomI= t last, size_t count =3D n_threads =3D=3D 0 ? 0 : n_threads - 1; gdb::detail::par_for_accumulator results (count); =20 + if (parallel_for_each_debug) + { + debug_printf (_("Parallel for: n_elements: %zu\n"), n_elements); + debug_printf (_("Parallel for: minimum elements per thread: %u\n"), = n); + debug_printf (_("Parallel for: elts_per_thread: %zu\n"), elts_per_th= read); + } + for (int i =3D 0; i < count; ++i) { RandomIt end =3D first + elts_per_thread; + if (parallel_for_each_debug) + debug_printf (_("Parallel for: elements on worker thread %i\t: %zu\n"), + i, (size_t)(end - first)); results.post (i, [=3D] () { return callback (first, end); @@ -165,7 +180,14 @@ parallel_for_each (unsigned n, RandomIt first, RandomI= t last, first =3D end; } =20 + for (int i =3D count; i < n_worker_threads; ++i) + if (parallel_for_each_debug) + debug_printf (_("Parallel for: elements on worker thread %i\t: 0\n")= , i); + /* Process all the remaining elements in the main thread. */ + if (parallel_for_each_debug) + debug_printf (_("Parallel for: elements on main thread\t\t: %zu\n"), + (size_t)(last - first)); return results.finish ([=3D] () { return callback (first, last);