From: Tom Tromey <tom@tromey.com>
To: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [RFC][gdbsupport] Improve thread scheduling in parallel_for_each
Date: Fri, 15 Jul 2022 13:05:48 -0600 [thread overview]
Message-ID: <87y1wumc1f.fsf@tromey.com> (raw)
In-Reply-To: <20220715094034.GA10751@delia.home> (Tom de Vries via Gdb-patches's message of "Fri, 15 Jul 2022 11:40:35 +0200")
>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:
Tom> This introduces a performance regression on a particular test-case I happened
Tom> to use:
Tom> ...
Tom> $ for n in $(seq 1 10); do \
Tom> time gdb -q -batch libxul.so.debug 2>&1 | grep real:; \
Tom> done
Tom> ...
Tom> so revert to the original schedule by reducing the worker threads:
Tom> ...
This seems like making a change and then undoing it somewhere else?
Tom> Still, the performance experiment yields a slight performance loss.
Sounds bad.
Tom> if (n_threads < 0)
Tom> - n_threads = std::thread::hardware_concurrency ();
Tom> + {
Tom> + n_threads = std::thread::hardware_concurrency ();
Tom> + if (n_threads > 0)
Tom> + /* Account for main thread. */
Tom> + n_threads--;
Tom> + }
I think it's better if the setting just directly controls how many
threads there are. Then elsewhere we can decide what that means -- like
if it performs better with the defaults to not do any work in the main
thread, then parallel_for_each can be modified to just send tasks to the
workers and do nothing in the main thread except wait for results.
Tom> size_t elts_per_thread = 0;
[...]
Tom> + elts_per_thread = n_elements / n_threads;
The initial declaration can be removed and then this latter line can
declare the variable as well.
Tom> for (int i = 0; i < count; ++i)
Tom> {
Tom> RandomIt end = first + elts_per_thread;
Tom> + if (i < left_over)
Tom> + end++;
It may be nice to mention the distribution of leftovers in a comment
somewhere.
Tom
next prev parent reply other threads:[~2022-07-15 19:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-15 9:40 Tom de Vries
2022-07-15 19:05 ` Tom Tromey [this message]
2022-07-18 7:30 ` Tom de Vries
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=87y1wumc1f.fsf@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/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).