From: Joel Brobecker <brobecker@adacore.com>
To: Tom Tromey via Gdb-patches <gdb-patches@sourceware.org>
Cc: Tom Tromey <tromey@adacore.com>, Joel Brobecker <brobecker@adacore.com>
Subject: Re: [PATCH 1/4] Avoid submitting empty tasks in parallel_for_each
Date: Sat, 7 Jan 2023 15:19:41 +0400 [thread overview]
Message-ID: <Y7lVTazKcEUTvLN+@adacore.com> (raw)
In-Reply-To: <20221215190759.2494095-2-tromey@adacore.com>
Hi Tom,
On Thu, Dec 15, 2022 at 12:07:56PM -0700, Tom Tromey via Gdb-patches wrote:
> I found that parallel_for_each would submit empty tasks to the thread
> pool. For example, this can happen if the number of tasks is smaller
> than the number of available threads. In the DWARF reader, this
> resulted in the cooked index containing empty sub-indices. This patch
> arranges to instead shrink the result vector and process the trailing
> entries in the calling thread.
This patch looks good to me.
If I'm allowed to nitpick...
> ---
> gdbsupport/parallel-for.h | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h
> index acd9137efbd..ed460f31f63 100644
> --- a/gdbsupport/parallel-for.h
> +++ b/gdbsupport/parallel-for.h
> @@ -70,6 +70,12 @@ struct par_for_accumulator
> return result;
> }
>
> + /* Resize the results to N. */
> + void resize (size_t n)
> + {
> + m_futures.resize (n);
> + }
> +
> private:
>
> /* A vector of futures coming from the tasks run in the
> @@ -108,6 +114,12 @@ struct par_for_accumulator<void>
> }
> }
>
> + /* Resize the results to N. */
> + void resize (size_t n)
> + {
> + m_futures.resize (n);
> + }
> +
> private:
>
> std::vector<gdb::future<void>> m_futures;
> @@ -232,6 +244,17 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last,
> end = j;
> remaining_size -= chunk_size;
> }
> +
> + if (end == last)
> + {
> + /* We're about to dispatch the last batch of elements, which
> + we normally process in the main thread. So just truncate
> + the result list here. */
... I'd expand the last sentence to explain that this is to avoid
submitting empty tasks to the thread pool.
But I'll leave it up to you do decide whether that's a useful suggestion
or not ;-).
Thanks for that patch!
> + count = i;
> + results.resize (count);
> + break;
> + }
> +
> if (parallel_for_each_debug)
> {
> debug_printf (_("Parallel for: elements on worker thread %i\t: %zu"),
> --
> 2.34.3
>
--
Joel
next prev parent reply other threads:[~2023-01-07 11:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-15 19:07 [PATCH 0/4] Fix regression in new DWARF reader Tom Tromey
2022-12-15 19:07 ` [PATCH 1/4] Avoid submitting empty tasks in parallel_for_each Tom Tromey
2023-01-07 11:19 ` Joel Brobecker [this message]
2023-01-09 16:20 ` Tom Tromey
2022-12-15 19:07 ` [PATCH 2/4] Don't erase empty indices in DWARF reader Tom Tromey
2022-12-19 14:51 ` Andrew Burgess
2022-12-19 17:09 ` Tom Tromey
2023-01-07 11:24 ` Joel Brobecker
2023-01-09 16:45 ` Tom Tromey
2023-01-09 18:18 ` Tom Tromey
2023-01-10 10:07 ` Andrew Burgess
2023-01-10 18:24 ` Tom Tromey
2022-12-15 19:07 ` [PATCH 3/4] Move hash_entry and eq_entry into cooked_index::do_finalize Tom Tromey
2023-01-07 11:26 ` Joel Brobecker
2022-12-15 19:07 ` [PATCH 4/4] Fix parameter-less template regression in new DWARF reader Tom Tromey
2023-01-07 11:37 ` Joel Brobecker
2023-01-07 11:45 ` Joel Brobecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y7lVTazKcEUTvLN+@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=tromey@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).