aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2018-10-03 16:03:04 -0700
committerH. Peter Anvin <hpa@zytor.com>2018-10-03 16:03:04 -0700
commit3b1400407d962c26313966f9ef780a2bdcbc36e2 (patch)
tree47a211307e9634105609c4ce9d557e5fb24c626f
parent5a3418107515e7c041a393e6b9787d9d45c25f19 (diff)
downloadabc80sim-3b1400407d962c26313966f9ef780a2bdcbc36e2.tar.gz
abc80sim-3b1400407d962c26313966f9ef780a2bdcbc36e2.tar.xz
abc80sim-3b1400407d962c26313966f9ef780a2bdcbc36e2.zip
Allow the simulated CPU to run all the way to the next event
Allow the simulated CPU to keep free-running until it has caught up to the next timer event. This maximizes the time we can sleep as well as the amount of slack we can take up for slow I/O models.
-rw-r--r--clock.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/clock.c b/clock.c
index a2ece22..bf9e9a5 100644
--- a/clock.c
+++ b/clock.c
@@ -77,26 +77,23 @@ static inline bool trigger(uint64_t now, struct abctimer *tmr)
static void consider_napping(uint64_t now, uint64_t next)
{
uint64_t when;
- int64_t ahead;
+ int64_t ahead, behind;
static uint64_t ref_time, ref_tstate;
if (unlikely(now <= ref_time || TSTATE <= ref_tstate))
goto weird;
when = ref_time + (TSTATE - ref_tstate) * ns_per_tstate;
- ahead = when - now;
-
- if (unlikely(ahead <= MS(-250) || ahead >= MS(100)))
- goto weird; /* 250 ms or more behind or 100 ms ahead of schedule */
-
- /*
- * If we are more than 2 ms ahead, sleep a bit.
- */
- if (unlikely(ahead >= MS(2))) {
- if (next < when)
- when = next; /* Don't sleep past the next event */
- mynssleep(when, now);
- }
+ behind = now - when;
+ ahead = when - next;
+
+ /* Sanity range check: 250 ms behind or 100 ms ahead of schedule */
+ if (unlikely(behind >= MS(250) || ahead >= MS(100)))
+ goto weird;
+
+ /* If we are ahead of the next event, hold off and wait for it */
+ if (ahead >= 0)
+ mynssleep(next, now);
return;
weird: