Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Sebastian Huber <sebastian.huber@embedded-brains.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/4] sim: Allow an overdue event to be descheduled
Date: Mon, 17 Aug 2026 01:43:53 +0200	[thread overview]
Message-ID: <20260816234357.278358-2-sebastian.huber@embedded-brains.de> (raw)
In-Reply-To: <20260816234357.278358-1-sebastian.huber@embedded-brains.de>

sim_events_deschedule() asserted that a non-empty event queue implies a
non-negative time from event.  That is not an invariant.
sim_events_slip() decrements the time from event unconditionally, so the
time can pass an event which is still queued.  update_time_from_event()
then computes a negative time from event for the head of the queue,
which is overdue rather than pending.  The next tick raises the pending
work flag and sim_events_process() consumes it, so nothing is lost.

An event handler which deschedules another overdue event triggers the
assertion.  The MIPS jmr3904 board reaches this with two timers running:
they queue events for the same time, a branch delay slot slips the time
past both, and the handler of the first deschedules the second.

Assert only the direction which holds: an empty queue gives a negative
time from event.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
---
 sim/common/sim-events.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sim/common/sim-events.c b/sim/common/sim-events.c
index f87f133efc3..e908c40f764 100644
--- a/sim/common/sim-events.c
+++ b/sim/common/sim-events.c
@@ -852,7 +852,11 @@ sim_events_deschedule (SIM_DESC sd,
 		       (dead->trace != NULL) ? dead->trace : ""));
 	      sim_events_free (sd, dead);
 	      update_time_from_event (sd);
-	      SIM_ASSERT ((events->time_from_event >= 0) == (events->queue != NULL));
+	      /* sim_events_slip() advances the time past an event
+		 which is still queued. The head of the queue is then
+		 overdue rather than pending.  */
+	      SIM_ASSERT (events->queue != NULL
+			  || events->time_from_event < 0);
 	      return;
 	    }
 	}
-- 
2.51.0


  reply	other threads:[~2026-08-16 23:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-16 23:43 [PATCH 0/4] Fix some MIPS GDB simulator issues Sebastian Huber
2026-08-16 23:43 ` Sebastian Huber [this message]
2026-08-18  9:59   ` [PATCH 1/4] sim: Allow an overdue event to be descheduled Andrew Burgess
2026-08-16 23:43 ` [PATCH 2/4] sim/mips: Do not abort on a HI/LO hazard Sebastian Huber
2026-08-18 10:04   ` Andrew Burgess
2026-08-16 23:43 ` [PATCH 3/4] sim/mips: Deliver the reserved instruction exception Sebastian Huber
2026-08-18 10:18   ` Andrew Burgess
2026-08-16 23:43 ` [PATCH 4/4] sim/mips: Recognise a software interrupt request Sebastian Huber
2026-08-18 10:42   ` Andrew Burgess
2026-08-18 11:45     ` Sebastian Huber
2026-08-19  0:03     ` Maciej W. Rozycki
2026-08-19  0:27       ` Sebastian Huber
2026-08-19 13:17         ` Maciej W. Rozycki

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=20260816234357.278358-2-sebastian.huber@embedded-brains.de \
    --to=sebastian.huber@embedded-brains.de \
    --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