diff options
author | Mike Frysinger <vapier@gentoo.org> | 2011-02-14 04:58:12 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2011-02-14 04:58:12 +0000 |
commit | 891e7fb179daec94b56e4a740f645e8685dee8e5 (patch) | |
tree | 6847e66a779276a450585d6c7edfb23bf82bf667 | |
parent | 911684cfb7583a7b2405f65b1300146f54be26d5 (diff) | |
download | gdb-891e7fb179daec94b56e4a740f645e8685dee8e5.zip gdb-891e7fb179daec94b56e4a740f645e8685dee8e5.tar.gz gdb-891e7fb179daec94b56e4a740f645e8685dee8e5.tar.bz2 |
sim: change to 64bit time keeping to avoid 32bit overflows
The sim-events code jumps through some hoops to avoid using 64bit math
to manage the current time. One fundamental assumption here is that by
constantly scheduling the sim poll event a short time into the future,
the 64bit difference will always fall into a signed 32bit value. This
does work most of the time, except for when processing the sim poll event
itself.
Normally, sim_events_process() will dequeue the sim poll event, update
the current time (time_from_event) according to the next pending event,
process the sim poll event (which will then requeue the sim poll event),
and then continue on.
The problem here of course is that the current time is updated in that
small window before the sim poll event gets a chance to reschedule itself.
So if the 64bit difference between the current time and the next event
does not fit into the signed 32bit value, time_from_event overflows, and
the internal assert at the end of update_time_from_event() triggers.
Since attempts at tweaking sim_events_process() logic introduced other
subtle bugs (due to tangled assumptions between most pieces of the sim
time keeping code), change the time_from_event to a real 64bit value.
Tests on my system between a 32bit ELF and a 64bit ELF show no practical
difference (it's all lost in the system noise). Basically, I booted a
Linux kernel to userspace and then paniced it; this gave me a constant
sample size of about 18 million insns.
This was noticed when simulating Blackfin Das U-Boot. The simulated core
timer is given the max unsigned timeout value possible on a 32bit processor
(0xffffffff). This timeout value is used directly to schedule a hw event
in the sim future (the IRQ firing). Once the sim poll event is kicked off,
the next pending event is the core timer event which is more than 2^31
ticks in the future, and the sim aborts with:
sim-events.c:435: assertion failed - current_time == sim_events_time (sd)
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r-- | sim/common/ChangeLog | 4 | ||||
-rw-r--r-- | sim/common/sim-events.h | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 7add3c4..a253937 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,7 @@ +2011-02-13 Mike Frysinger <vapier@gentoo.org> + + * sim-events.h (_sim_events.time_from_event): Change type to signed64. + 2011-01-12 Mike Frysinger <vapier@gentoo.org> * sim-hw.c (sim_hw_uninstall): Uncomment hw_tree_delete. diff --git a/sim/common/sim-events.h b/sim/common/sim-events.h index 7303a8e..d3eefb7 100644 --- a/sim/common/sim-events.h +++ b/sim/common/sim-events.h @@ -93,7 +93,7 @@ struct _sim_events { unsigned long elapsed_wallclock; SIM_ELAPSED_TIME resume_wallclock; signed64 time_of_event; - int time_from_event; + signed64 time_from_event; int trace; }; |