From 90a6918a3cb4901ecc64d810a6a4eb54d572c0bf Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 20 Mar 2000 09:42:50 +0000 Subject: [PATCH] [project @ 2000-03-20 09:42:49 by andy] Adding an alternative to the "delay" system used for threads that are waiting for time to pass. This works on a target time basis, eliminating the need to use the ticky style counter. It is only enabled under: #if defined(INTERPRETER) && !defined(HAVE_SETITIMER) --- ghc/includes/TSO.h | 6 +++++- ghc/rts/Evaluator.c | 10 ++++++++-- ghc/rts/Itimer.c | 12 ++++++++++-- ghc/rts/Itimer.h | 3 ++- ghc/rts/PrimOps.hc | 7 ++++++- ghc/rts/Schedule.c | 9 ++++++++- ghc/rts/Select.c | 45 +++++++++++++++++++++++++++++++++++---------- 7 files changed, 74 insertions(+), 18 deletions(-) diff --git a/ghc/includes/TSO.h b/ghc/includes/TSO.h index d3a76ae..4de0562 100644 --- a/ghc/includes/TSO.h +++ b/ghc/includes/TSO.h @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: TSO.h,v 1.13 2000/03/17 13:30:23 simonmar Exp $ + * $Id: TSO.h,v 1.14 2000/03/20 09:42:49 andy Exp $ * * (c) The GHC Team, 1998-1999 * @@ -130,7 +130,11 @@ typedef union { StgClosure *closure; struct StgTSO_ *tso; int fd; +#if defined(INTERPRETER) && !defined(HAVE_SETITIMER) + unsigned int target; +#else unsigned int delay; +#endif #if defined(PAR) globalAddr ga; #endif diff --git a/ghc/rts/Evaluator.c b/ghc/rts/Evaluator.c index dba69d3..b33c10f 100644 --- a/ghc/rts/Evaluator.c +++ b/ghc/rts/Evaluator.c @@ -5,8 +5,8 @@ * Copyright (c) 1994-1998. * * $RCSfile: Evaluator.c,v $ - * $Revision: 1.43 $ - * $Date: 2000/03/20 04:26:24 $ + * $Revision: 1.44 $ + * $Date: 2000/03/20 09:42:49 $ * ---------------------------------------------------------------------------*/ #include "Rts.h" @@ -24,6 +24,7 @@ #include "ForeignCall.h" #include "PrimOps.h" /* for __{encode,decode}{Float,Double} */ #include "Prelude.h" +#include "ITimer.h" #include "Evaluator.h" #include "sainteger.h" @@ -529,8 +530,13 @@ StgThreadReturnCode enter( Capability* cap, StgClosure* obj0 ) cap->rCurrentTSO->why_blocked = BlockedOnDelay; ACQUIRE_LOCK(&sched_mutex); +#if defined(HAVE_SETITIMER) cap->rCurrentTSO->block_info.delay = hugsBlock.delay + ticks_since_select; +#else + cap->rCurrentTSO->block_info.target + = hugsBlock.delay + getourtimeofday(); +#endif APPEND_TO_BLOCKED_QUEUE(cap->rCurrentTSO); RELEASE_LOCK(&sched_mutex); diff --git a/ghc/rts/Itimer.c b/ghc/rts/Itimer.c index de95f1b..cb7df62 100644 --- a/ghc/rts/Itimer.c +++ b/ghc/rts/Itimer.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: Itimer.c,v 1.10 2000/03/14 01:43:27 sof Exp $ + * $Id: Itimer.c,v 1.11 2000/03/20 09:42:49 andy Exp $ * * (c) The GHC Team, 1995-1999 * @@ -158,7 +158,7 @@ nat initialize_virtual_timer(nat ms) { # ifndef HAVE_SETITIMER - fprintf(stderr, "No virtual timer on this system\n"); + /* fprintf(stderr, "No virtual timer on this system\n"); */ return -1; # else struct itimerval it; @@ -238,3 +238,11 @@ unblock_vtalrm_signal(void) (void) sigprocmask(SIG_UNBLOCK, &signals, NULL); } #endif + +unsigned int +getourtimeofday(void) +{ + struct timeval tv; + gettimeofday(&tv, (struct timezone *) NULL); + return (tv.tv_sec * 1000000 + tv.tv_usec); +} diff --git a/ghc/rts/Itimer.h b/ghc/rts/Itimer.h index fbdf795..58f4152 100644 --- a/ghc/rts/Itimer.h +++ b/ghc/rts/Itimer.h @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: Itimer.h,v 1.4 1999/08/25 16:11:48 simonmar Exp $ + * $Id: Itimer.h,v 1.5 2000/03/20 09:42:49 andy Exp $ * * (c) The GHC Team 1998-1999 * @@ -16,3 +16,4 @@ nat initialize_virtual_timer ( nat ms ); int install_vtalrm_handler ( void ); void block_vtalrm_signal ( void ); void unblock_vtalrm_signal ( void ); +unsigned int getourtimeofday ( void ); diff --git a/ghc/rts/PrimOps.hc b/ghc/rts/PrimOps.hc index 2322861..bf3d644 100644 --- a/ghc/rts/PrimOps.hc +++ b/ghc/rts/PrimOps.hc @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: PrimOps.hc,v 1.46 2000/03/14 09:55:05 simonmar Exp $ + * $Id: PrimOps.hc,v 1.47 2000/03/20 09:42:49 andy Exp $ * * (c) The GHC Team, 1998-2000 * @@ -19,6 +19,7 @@ #include "StablePriv.h" #include "HeapStackCheck.h" #include "StgRun.h" +#include "ITimer.h" #include "Prelude.h" /* ** temporary ** @@ -1016,7 +1017,11 @@ FN_(delayzh_fast) /* Add on ticks_since_select, since these will be subtracted at * the next awaitEvent call. */ +#if defined(HAVE_SETITIMER) CurrentTSO->block_info.delay = R1.i + ticks_since_select; +#else + CurrentTSO->block_info.target = R1.i + getourtimeofday(); +#endif APPEND_TO_BLOCKED_QUEUE(CurrentTSO); diff --git a/ghc/rts/Schedule.c b/ghc/rts/Schedule.c index 5ffd4b6..869b2ab 100644 --- a/ghc/rts/Schedule.c +++ b/ghc/rts/Schedule.c @@ -1,5 +1,5 @@ /* --------------------------------------------------------------------------- - * $Id: Schedule.c,v 1.56 2000/03/17 14:37:21 simonmar Exp $ + * $Id: Schedule.c,v 1.57 2000/03/20 09:42:50 andy Exp $ * * (c) The GHC Team, 1998-2000 * @@ -72,6 +72,7 @@ #include "Sanity.h" #include "Stats.h" #include "Sparks.h" +#include "Itimer.h" #include "Prelude.h" #if defined(GRAN) || defined(PAR) # include "GranSimRts.h" @@ -2393,7 +2394,12 @@ printThreadBlockage(StgTSO *tso) fprintf(stderr,"blocked on write to fd %d", tso->block_info.fd); break; case BlockedOnDelay: +#if defined(HAVE_SETITIMER) fprintf(stderr,"blocked on delay of %d ms", tso->block_info.delay); +#else + fprintf(stderr,"blocked on delay of %d ms", + tso->block_info.target - getourtimeofday()); +#endif break; case BlockedOnMVar: fprintf(stderr,"blocked on an MVar"); @@ -2615,6 +2621,7 @@ sched_belch(char *s, ...) #endif /* DEBUG */ + //@node Index, , Debugging Routines, Main scheduling code //@subsection Index diff --git a/ghc/rts/Select.c b/ghc/rts/Select.c index d973e3e..1666b49 100644 --- a/ghc/rts/Select.c +++ b/ghc/rts/Select.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: Select.c,v 1.9 2000/03/16 17:24:08 simonmar Exp $ + * $Id: Select.c,v 1.10 2000/03/20 09:42:50 andy Exp $ * * (c) The GHC Team 1995-1999 * @@ -105,8 +105,18 @@ awaitEvent(rtsBool wait) case BlockedOnDelay: { - if (tso->block_info.delay < min) - min = tso->block_info.delay; + int candidate; /* signed int is intentional */ +#if defined(HAVE_SETITIMER) + candidate = tso->block_info.delay; +#else + candidate = tso->block_info.target - getourtimeofday(); + if (candidate < 0) { + candidate = 0; + } +#endif + if ((nat)candidate < min) { + min = candidate; + } continue; } @@ -207,14 +217,29 @@ awaitEvent(rtsBool wait) break; case BlockedOnDelay: - if (tso->block_info.delay > delta) { - tso->block_info.delay -= delta; - ready = 0; - } else { - tso->block_info.delay = 0; - ready = 1; + { + int candidate; /* signed int is intentional */ +#if defined(HAVE_SETITIMER) + if (tso->block_info.delay > delta) { + tso->block_info.delay -= delta; + ready = 0; + } else { + tso->block_info.delay = 0; + ready = 1; + } +#else + candidate = tso->block_info.target - getourtimeofday(); + if (candidate < 0) { + candidate = 0; + } + if ((nat)candidate > delta) { + ready = 0; + } else { + ready = 1; + } +#endif + break; } - break; default: barf("awaitEvent"); -- 1.7.10.4