Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: Simon Marchi <simon.marchi@efficios.com>,
	Pedro Alves <pedro@palves.net>,
	 gdb-patches@sourceware.org
Subject: Re: [PATCH v3 4/5] gdb: generalize commit_resume, avoid commit-resuming when threads have pending statuses
Date: Thu, 21 Jan 2021 21:46:39 -0500	[thread overview]
Message-ID: <c1217a3f-f22f-96bf-8206-ceba0c858b3f@polymtl.ca> (raw)
In-Reply-To: <617137d0-d740-c495-b7c1-9ad400ae617b@efficios.com>

On 2021-01-11 3:28 p.m., Simon Marchi wrote:
> I see more of ~1.33 % slowdown, but it's consistent too.
> 
> It could be the std::set allocation.  I changed all_process_targets to make it
> return an array of 1 element, just to see what happens, it didn't seem to help.
> See attached patch "0001-Test-returning-something-else-than-std-set-in-all_pr.patch"
> if you want to try it.
> 
> It's maybe due to the fact that we now iterate on all threads at every handled
> event? fetch_inferior_event calls ~scoped_disable_commit_resumed, which calls
> maybe_commit_resumed_all_process_targets, which iterates on all threads.  The
> loop actually breaks when it finds a thread with a pending status, but that
> still makes this function O(number of threads).

I did some more testing regarding this.

I am testing the following scenarios:

- baseline: up to the previous patch ("gdb: move commit_resume to
  process_stratum_target") applied.
- original patch: baseline + this patch applied
- always commit resume: I take the original patch, and I remove the loop over
  all threads to check if there are resumed threads with a pending status.
  Instead, I just let it do the commit-resume all the time.
- all no-op: I make these no-ops:

    - maybe_commit_resumed_all_process_targets
    - scoped_disable_commit_resumed::scoped_disable_commit_resumed
    - scoped_disable_commit_resumed::~scoped_disable_commit_resumed

  This essentially gets rid of all calls to all_process_targets and its std::set
  allocation.  It wouldn't be a correct patch, but the native target doesn't care,
  it's just to see the impact of these functions.

The results are:

baseline: 81,534
original patch: 78,926
always commit resume: 80,416
all no-op: 80,890

I don't really understand why "all no-op" would be slower than the baseline, there
isn't much left at this point.

Still, we see, with the difference between "original patch" and "always commit
resume", that iterating on all threads to see if there's one resumed with a
pending status has a non-negligible cost.  To speed this up, we could maintain
a per target or per inferior count of "number of resumed threads with a pending
status".  I think it would be a bit tricky to get completely right, to make sure
this count never gets out of sync with the reality.

Another similar idea would be to keep a per inferior list / queue of resumed
threads with pending statuses.  That would serve the same purpose as the count
from above (checking quickly if there exists a resumed thread with pending status)
but could also make random_pending_event_thread more efficient.
random_pending_event_thread would just return the first thread in that list that
matches waiton_ptid (most of the time, that will be the first in the list because
we are looking for any thread).  It would no longer be random, but it would be
FIFO, but I think it would achieve the same goal of ensuring no thread starves
because it is never the chosen one.  There would be the same difficulty as with
the counter though, to make sure that this list gets in sync with the reality.

Simon

  reply	other threads:[~2021-01-22  2:46 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-08  4:17 [PATCH v3 0/5] Reduce back and forth with target when threads have pending statuses + better handling of 'S' packets Simon Marchi via Gdb-patches
2021-01-08  4:17 ` [PATCH v3 1/5] gdb: make the remote target track its own thread resume state Simon Marchi via Gdb-patches
2021-01-08 15:41   ` Pedro Alves
2021-01-08 18:56     ` Simon Marchi via Gdb-patches
2021-01-18  5:16   ` Sebastian Huber
2021-01-18  6:04     ` Simon Marchi via Gdb-patches
2021-01-18 10:36       ` Sebastian Huber
2021-01-18 13:53         ` Simon Marchi via Gdb-patches
2021-01-08  4:17 ` [PATCH v3 2/5] gdb: remove target_ops::commit_resume implementation in record-{btrace, full}.c Simon Marchi via Gdb-patches
2021-01-08 15:43   ` [PATCH v3 2/5] gdb: remove target_ops::commit_resume implementation in record-{btrace,full}.c Pedro Alves
2021-01-08 19:00     ` Simon Marchi via Gdb-patches
2021-01-08  4:17 ` [PATCH v3 3/5] gdb: move commit_resume to process_stratum_target Simon Marchi via Gdb-patches
2021-01-08 18:12   ` Andrew Burgess
2021-01-08 19:01     ` Simon Marchi via Gdb-patches
2021-01-09 20:29   ` Pedro Alves
2021-01-08  4:17 ` [PATCH v3 4/5] gdb: generalize commit_resume, avoid commit-resuming when threads have pending statuses Simon Marchi via Gdb-patches
2021-01-08 18:34   ` Andrew Burgess
2021-01-08 19:04     ` Simon Marchi via Gdb-patches
2021-01-09 20:34   ` Pedro Alves
2021-01-11 20:28     ` Simon Marchi via Gdb-patches
2021-01-22  2:46       ` Simon Marchi via Gdb-patches [this message]
2021-01-22 22:07       ` Simon Marchi via Gdb-patches
2021-01-12 17:14   ` Simon Marchi via Gdb-patches
2021-01-12 18:04     ` Simon Marchi via Gdb-patches
2021-01-15 19:17   ` Simon Marchi via Gdb-patches
2021-01-08  4:17 ` [PATCH v3 5/5] gdb: better handling of 'S' packets Simon Marchi via Gdb-patches
2021-01-08 18:19   ` Andrew Burgess
2021-01-08 19:11     ` Simon Marchi via Gdb-patches
2021-01-09 21:26   ` Pedro Alves
2021-01-11 20:36     ` Simon Marchi via Gdb-patches
2021-01-12  3:07       ` Simon Marchi via Gdb-patches
2021-01-13 20:17         ` Pedro Alves
2021-01-14  1:28           ` Simon Marchi via Gdb-patches

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=c1217a3f-f22f-96bf-8206-ceba0c858b3f@polymtl.ca \
    --to=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    --cc=simon.marchi@efficios.com \
    --cc=simon.marchi@polymtl.ca \
    /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