Commit 90a6918a authored by andy's avatar andy

[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)
parent b32b2d43
/* -----------------------------------------------------------------------------
* $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
......
......@@ -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);
......
/* -----------------------------------------------------------------------------
* $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);
}
/* -----------------------------------------------------------------------------
* $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 );
/* -----------------------------------------------------------------------------
* $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);
......
/* ---------------------------------------------------------------------------
* $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
......
/* -----------------------------------------------------------------------------
* $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");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment