From: Pedro Alves <pedro@palves.net>
To: Simon Marchi <simon.marchi@efficios.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 1/4] gdb: make async event handlers clear themselves
Date: Thu, 4 Feb 2021 17:42:06 +0000 [thread overview]
Message-ID: <0fe68d72-6530-cb97-a40a-e68a8f230702@palves.net> (raw)
In-Reply-To: <20201130165251.830482-2-simon.marchi@efficios.com>
On 30/11/20 16:52, Simon Marchi via Gdb-patches wrote:
> The `ready` flag of async event handlers is cleared by the async event
> handler system right before invoking the associated callback, in
> check_async_event_handlers.
>
> This is not ideal with how the infrun subsystem consumes events: all
> targets' async event handler callbacks essentially just invoke
> `inferior_event_handler`, which eventually calls `fetch_inferior_event`
> and `do_target_wait`. `do_target_wait` picks an inferior at random,
> and thus a target at random (it could be the target whose `ready` flag
> was cleared, or not), and pulls one event from it.
>
> So it's possible that:
>
> - the async event handler for a target A is called
> - we end up consuming an event for target B
> - all threads of target B are stopped, target_async(0) is called on it,
> so its async event handler is cleared (e.g.
> record_btrace_target::async)
>
> As a result, target A still has events to report while its async event
> handler is left unmarked, so these events are not consumed. To counter
> this, at the end of their async event handler callbacks, targets check
> if they still have something to report and re-mark their async event
> handler (e.g. remote_async_inferior_event_handler).
>
> The linux_nat target does not suffer from this because it doesn't use an
> async event handler at the moment. It only uses a pipe registered with
> the event loop. It is written to in the SIGCHLD handler (and in other
> spots that want to get target wait method called) and read from in
> the target's wait method. So if linux_nat happened to be target A in
> the example above, the pipe would just stay readable, and the event loop
> would wake up again, until linux_nat's wait method is finally called and
> consumes the contents of the pipe.
>
> I think it would be nicer if targets using async_event_handler worked in
> a similar way, where the flag would stay set until the target's wait
> method is actually called. As a first step towards that, this patch
> moves the responsibility of clearing the ready flags of async event
> handlers to the invoked callback.
>
> All async event handler callbacks are modified to clear their ready flag
> before doing anything else. So in practice, nothing changes with this
> patch. It's only the responsibility of clearing the flag that is
> shifted toward the callee.
>
> gdb/ChangeLog:
>
> * async-event.h (async_event_handler_func): Add documentation.
> * async-event.c (check_async_event_handlers): Don't clear
> async_event_handler ready flag.
> * infrun.c (infrun_async_inferior_event_handler): Clear ready
> flag.
> * record-btrace.c (record_btrace_handle_async_inferior_event):
> Likewise.
> * record-full.c (record_full_async_inferior_event_handler):
> Likewise.
> * remote-notif.c (remote_async_get_pending_events_handler):
> Likewise.
> * remote.c (remote_async_inferior_event_handler): Likewise.
(Watch out for spaces/tabs in the ChangeLog.)
I like this. OK.
next prev parent reply other threads:[~2021-02-04 17:42 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-30 16:52 [PATCH 0/4] Clear target async event handlers in wait method Simon Marchi
2020-11-30 16:52 ` [PATCH 1/4] gdb: make async event handlers clear themselves Simon Marchi
2020-12-24 17:26 ` Andrew Burgess
2021-02-04 17:42 ` Pedro Alves [this message]
2021-02-04 18:15 ` Simon Marchi
2020-11-30 16:52 ` [PATCH 2/4] gdb: make remote target clear its async event handler in wait Simon Marchi
2020-12-24 17:23 ` Andrew Burgess
2020-12-24 17:44 ` Simon Marchi
2021-02-04 18:00 ` Pedro Alves
2021-02-04 18:34 ` Simon Marchi
2020-11-30 16:52 ` [PATCH 3/4] gdb: make record-btrace " Simon Marchi
2021-01-06 9:50 ` Andrew Burgess
2020-11-30 16:52 ` [PATCH 4/4] gdb: make record-full " Simon Marchi
2021-01-06 9:51 ` Andrew Burgess
2020-12-23 21:31 ` [PATCH 0/4] Clear target async event handlers in wait method Simon Marchi
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=0fe68d72-6530-cb97-a40a-e68a8f230702@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.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).