From: Pedro Alves <pedro@palves.net>
To: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
Subject: Re: [PATCH 07/11] gdb: maintain per-process-target list of resumed threads with pending wait status
Date: Wed, 7 Jul 2021 13:01:37 +0100 [thread overview]
Message-ID: <25ce9332-1145-6cfa-1520-540fe17debd6@palves.net> (raw)
In-Reply-To: <252f2a84-c7b4-d07a-fecc-c57685a89ee1@polymtl.ca>
On 2021-07-06 10:25 p.m., Simon Marchi wrote:
>>> + we don't leave any threads of this inferior in the target's "resumed with
>>> + pending wait status" list. */
>>> + if (t->stratum () == process_stratum)
>>> + {
>>> + process_stratum_target *proc_target = as_process_stratum_target (t);
>>> +
>>> + for (thread_info *thread : this->non_exited_threads ())
>>> + proc_target->maybe_remove_resumed_with_pending_wait_status (thread);
>>
>> Note the target_pid_to_str call inside maybe_remove_resumed_with_pending_wait_status
>> adds back a dependency on current_inferior.
>
> Arggg, we don't want that. Since that is in a process_stratum_target
> method, I'll change the message to call the pid_to_str method of the
> current object instead:
>
> infrun_debug_printf ("removing from resumed threads with event list: %s",
> this->pid_to_str (thread->ptid).c_str ());
>
> Does that sound good?
It does not. That would mean a target higher on the stack wouldn't have a chance
at printing the thread.
>>
>>> + m_resumed_with_pending_wait_status.push_back (*thread);
>>> + }
>>> +}
>>> +
>>> +/* See process-stratum-target.h. */
>>> +
>>
>>> +
>>> +private:
>>> + /* List of threads managed by this target which simultaneously are resumed
>>> + and have a pending wait status. */
>>
>> I'd suggest expanding this comment a little to mention this
>> is done for optimization reasons, to avoid walking
>> thread lists, something like that. Or maybe say that in
>> the thread_info node. Or both places.
>
> Done:
>
> /* List of threads managed by this target which simultaneously are resumed
> and have a pending wait status.
>
> This is done for optimization reasons, it would be possible to walk the
> inferior thread lists to find these threads. But since this is something
> we need to do quite frequently in the hot path, maintaining this list
> avoids walking the thread lists repeatedly. */
>
> I would prefer to avoid repeating the same thing at two places, because
> it's a recipe for the two places getting out of sync. Since the node
> comment in thread_info now points to here (says the list head is in
> process_stratum_target), people looking for more information about this
> list should have no problem finding the comment here.
>
Looks good.
>>
>>> + thread_info_resumed_with_pending_wait_status_list
>>> + m_resumed_with_pending_wait_status;
>>> };
>>>
>>> /* Downcast TARGET to process_stratum_target. */
>>> diff --git a/gdb/thread.c b/gdb/thread.c
>>> index 289d33c74c3b..26974e1b8cbc 100644
>>> --- a/gdb/thread.c
>>> +++ b/gdb/thread.c
>>> @@ -188,6 +188,10 @@ set_thread_exited (thread_info *tp, bool silent)
>>>
>>> if (tp->state != THREAD_EXITED)
>>> {
>>> + process_stratum_target *proc_target = tp->inf->process_target ();
>>> + if (proc_target != nullptr)
>>
>> I think this check needs a comment.
>
> Done:
>
> /* Some targets unpush themselves from the inferior's target stack before
> clearing the inferior's thread list (which marks all threads as exited,
> and therefore leads to this function). In this case, the inferior's
> process target will be nullptr when we arrive here.
>
> See also the comment in inferior::unpush_target. */
>
> And I also added a cross-reference to here from the comment in
> inferior::unpush_target.
Great.
>
>>> + /* If we transition from not resumed to resumed, we might need to add
>>> + the thread to the resumed threads with pending statuses list. */
>>> + if (resumed)
>>> + proc_target->maybe_add_resumed_with_pending_wait_status (this);
>>
>> Longest function name award goes to... ;-)
>
> Indeed! If you have a name that is shorter but just as clear, I'm open
> for suggestion. But I prefer names that are non-ambiguous and use the
> right terminology over names that are short just for convenience's sake.
Sure, as a preference, though that shouldn't be a too-strict rule IMO, otherwise
with very long function names we can end up with awkward looking code as soon as we
need to indent a caller a couple levels. In this case, luckily that didn't happen,
so I'm not really objecting.
"add_resumed_pending_status" or "add_resumed_pending_ws" would work as well for
me, for example.
next prev parent reply other threads:[~2021-07-07 12:02 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-22 16:56 [PATCH 00/11] Various thread lists optimizations Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 01/11] gdb: introduce iterator_range, remove next_adapter Simon Marchi via Gdb-patches
2021-07-05 15:41 ` Pedro Alves
2021-07-06 19:16 ` Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 02/11] gdb: introduce intrusive_list, make thread_info use it Simon Marchi via Gdb-patches
2021-06-22 23:13 ` Lancelot SIX via Gdb-patches
2021-06-23 0:48 ` Simon Marchi via Gdb-patches
2021-07-05 15:44 ` Pedro Alves
2021-07-06 19:38 ` Simon Marchi via Gdb-patches
2021-07-06 20:45 ` Simon Marchi via Gdb-patches
2021-07-06 21:04 ` Pedro Alves
2021-07-06 21:38 ` Simon Marchi via Gdb-patches
2021-07-06 21:02 ` Pedro Alves
2021-07-06 21:45 ` Simon Marchi via Gdb-patches
2021-07-07 11:46 ` Pedro Alves
2021-07-07 13:52 ` Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 03/11] gdb: make inferior_list use intrusive_list Simon Marchi via Gdb-patches
2021-07-05 15:44 ` Pedro Alves
2021-07-14 6:34 ` Tom de Vries
2021-07-14 16:11 ` Simon Marchi via Gdb-patches
2021-07-14 20:15 ` [PATCH] gdb: make all_inferiors_safe actually work Simon Marchi via Gdb-patches
2021-07-15 10:15 ` Tom de Vries
2021-07-17 12:54 ` Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 04/11] gdb: use intrusive list for step-over chain Simon Marchi via Gdb-patches
2021-07-05 15:45 ` Pedro Alves
2021-07-06 20:59 ` Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 05/11] gdb: add setter / getter for thread_info resumed state Simon Marchi via Gdb-patches
2021-07-05 15:45 ` Pedro Alves
2021-06-22 16:56 ` [PATCH 06/11] gdb: make thread_info::suspend private, add getters / setters Simon Marchi via Gdb-patches
2021-07-05 15:45 ` Pedro Alves
2021-06-22 16:57 ` [PATCH 07/11] gdb: maintain per-process-target list of resumed threads with pending wait status Simon Marchi via Gdb-patches
2021-07-05 15:51 ` Pedro Alves
2021-07-06 21:25 ` Simon Marchi via Gdb-patches
2021-07-07 12:01 ` Pedro Alves [this message]
2021-07-12 22:28 ` Simon Marchi via Gdb-patches
2021-07-12 22:34 ` Simon Marchi via Gdb-patches
2021-07-13 12:21 ` Pedro Alves
2021-06-22 16:57 ` [PATCH 08/11] gdb: optimize check for resumed threads with pending wait status in maybe_set_commit_resumed_all_targets Simon Marchi via Gdb-patches
2021-07-05 15:51 ` Pedro Alves
2021-06-22 16:57 ` [PATCH 09/11] gdb: optimize selection of resumed thread with pending event Simon Marchi via Gdb-patches
2021-07-05 15:51 ` Pedro Alves
2021-06-22 16:57 ` [PATCH 10/11] gdb: maintain ptid -> thread map, optimize find_thread_ptid Simon Marchi via Gdb-patches
2021-07-05 15:52 ` Pedro Alves
2021-07-06 21:31 ` Simon Marchi via Gdb-patches
2021-07-07 12:13 ` Pedro Alves
2021-06-22 16:57 ` [PATCH 11/11] gdb: optimize all_matching_threads_iterator Simon Marchi via Gdb-patches
2021-07-05 15:52 ` Pedro Alves
2021-07-14 9:40 ` Tom de Vries
2021-07-13 0:47 ` [PATCH 00/11] Various thread lists optimizations 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=25ce9332-1145-6cfa-1520-540fe17debd6@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@sourceware.org \
--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