/* ----------------------------------------------------------------------------
- * $Id: Constants.h,v 1.12 2000/07/26 13:27:54 simonmar Exp $
+ * $Id: Constants.h,v 1.13 2000/08/03 11:28:35 simonmar Exp $
*
* (c) The GHC Team, 1998-1999
*
#define INFO_FIRST_TAG 0
/* -----------------------------------------------------------------------------
- Context switch timing constants.
- -------------------------------------------------------------------------- */
-
-#define CS_MAX_FREQUENCY 100 /* context switches per second */
-#define CS_MIN_MILLISECS (1000/CS_MAX_FREQUENCY)/* milliseconds per slice */
-
-/* -----------------------------------------------------------------------------
How much C stack to reserve for local temporaries when in the STG
world. Used in StgRun.S and StgCRun.c.
-------------------------------------------------------------------------- */
/* -----------------------------------------------------------------------------
- * $Id: Itimer.c,v 1.15 2000/07/17 15:09:35 rrt Exp $
+ * $Id: Itimer.c,v 1.16 2000/08/03 11:28:35 simonmar Exp $
*
* (c) The GHC Team, 1995-1999
*
#endif
#include "Rts.h"
+#include "RtsFlags.h"
#include "Itimer.h"
#include "Proftimer.h"
#include "Schedule.h"
lnat total_ticks = 0;
+/* ticks left before next pre-emptive context switch */
+int ticks_to_ctxt_switch = 0;
+
static
void
#if defined(mingw32_TARGET_OS) || (defined(cygwin32_TARGET_OS) && !defined(HAVE_SETITIMER))
/* For threadDelay etc., see Select.c */
ticks_since_select++;
- context_switch = 1;
+ ticks_to_ctxt_switch--;
+ if (ticks_to_ctxt_switch <= 0) {
+ ticks_to_ctxt_switch = RtsFlags.ConcFlags.ctxtSwitchTicks;
+ context_switch = 1; /* schedule a context switch */
+ }
}
0,
TIME_PERIODIC);
# endif
+
return 0;
}
/* -----------------------------------------------------------------------------
- * $Id: Itimer.h,v 1.5 2000/03/20 09:42:49 andy Exp $
+ * $Id: Itimer.h,v 1.6 2000/08/03 11:28:35 simonmar Exp $
*
* (c) The GHC Team 1998-1999
*
# define TICK_FREQUENCY 50 /* ticks per second */
# define TICK_MILLISECS (1000/TICK_FREQUENCY) /* ms per tick */
+/* Context switch timing constants. Context switches happen after a
+ * whole number of ticks, the default being every tick.
+ */
+#define CS_MIN_MILLISECS TICK_MILLISECS /* milliseconds per slice */
+
extern rtsBool do_prof_ticks; /* profiling ticks on/off */
nat initialize_virtual_timer ( nat ms );
/* -----------------------------------------------------------------------------
- * $Id: RtsFlags.c,v 1.30 2000/04/19 12:42:48 simonmar Exp $
+ * $Id: RtsFlags.c,v 1.31 2000/08/03 11:28:35 simonmar Exp $
*
* (c) The AQUA Project, Glasgow University, 1994-1997
* (c) The GHC Team, 1998-1999
#include "RtsFlags.h"
#include "RtsUtils.h"
#include "BlockAlloc.h"
+#include "Itimer.h" /* CS_MIN_MILLISECS */
#include "Profiling.h"
#if defined(PROFILING)
#if defined(GRAN)
/* ToDo: check defaults for GranSim and GUM */
- RtsFlags.ConcFlags.ctxtSwitchTime = CS_MIN_MILLISECS; /* In milliseconds */
RtsFlags.GcFlags.maxStkSize = (1024 * 1024) / sizeof(W_);
RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
#endif
" -C<secs> Context-switch interval in seconds",
" (0 or no argument means switch as often as possible)",
-" the default is .01 sec; resolution is .01 sec",
+" the default is .02 sec; resolution is .02 sec",
#if defined(SMP)
" -N<n> Use <n> OS threads (default: 1)",
#endif
/* Convert to milliseconds */
cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
cst = (cst / CS_MIN_MILLISECS) * CS_MIN_MILLISECS;
- if (cst < CS_MIN_MILLISECS)
+ if (cst != 0 && cst < CS_MIN_MILLISECS)
cst = CS_MIN_MILLISECS;
RtsFlags.ConcFlags.ctxtSwitchTime = cst;
/* -----------------------------------------------------------------------------
- * $Id: RtsFlags.h,v 1.25 2000/04/19 12:42:48 simonmar Exp $
+ * $Id: RtsFlags.h,v 1.26 2000/08/03 11:28:35 simonmar Exp $
*
* (c) The GHC Team, 1998-1999
*
# define COST_CENTRES_ALL 3
# define COST_CENTRES_XML 4
- int ctxtSwitchTicks; /* derived */
int profilerTicks; /* derived */
int msecsPerTick; /* derived */
};
#endif /* DEBUG || PROFILING */
struct CONCURRENT_FLAGS {
- int ctxtSwitchTime; /* in milliseconds */
+ int ctxtSwitchTime; /* in milliseconds */
+ int ctxtSwitchTicks; /* derived */
};
#ifdef PAR
/* ---------------------------------------------------------------------------
- * $Id: Schedule.c,v 1.73 2000/07/17 15:15:40 rrt Exp $
+ * $Id: Schedule.c,v 1.74 2000/08/03 11:28:35 simonmar Exp $
*
* (c) The GHC Team, 1998-2000
*
cap->rCurrentTSO = t;
- /* context switches are now initiated by the timer signal */
- context_switch = 0;
+ /* context switches are now initiated by the timer signal, unless
+ * the user specified "context switch as often as possible", with
+ * +RTS -C0
+ */
+ if (RtsFlags.ConcFlags.ctxtSwitchTicks == 0
+ && (run_queue_hd != END_TSO_QUEUE
+ || blocked_queue_hd != END_TSO_QUEUE))
+ context_switch = 1;
+ else
+ context_switch = 0;
RELEASE_LOCK(&sched_mutex);
context_switch = 0;
interrupted = 0;
+ RtsFlags.ConcFlags.ctxtSwitchTicks =
+ RtsFlags.ConcFlags.ctxtSwitchTime / TICK_MILLISECS;
+
#ifdef INTERPRETER
ecafList = END_ECAF_LIST;
clearECafTable();