Commit 66f7a41d authored by simonmar's avatar simonmar

[project @ 2000-08-03 11:28:35 by simonmar]

Implement +RTS -C<n>, the context switch interval flag.  This was
previously advertised in the usage message, but there was a note in
the Users' Guide stating that it didn't work.  Anwyay, I'm going to
consider it a bug and backport to 4.08.1.
parent f151e6c0
/* ----------------------------------------------------------------------------
* $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
*
......@@ -193,13 +193,6 @@
#define INFO_IND_TAG (-2)
#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
*
......@@ -23,6 +23,7 @@
#endif
#include "Rts.h"
#include "RtsFlags.h"
#include "Itimer.h"
#include "Proftimer.h"
#include "Schedule.h"
......@@ -45,6 +46,9 @@
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))
......@@ -79,7 +83,11 @@ handle_tick(int unused STG_UNUSED)
/* 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 */
}
}
......@@ -133,6 +141,7 @@ initialize_virtual_timer(nat ms)
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
*
......@@ -10,6 +10,11 @@
# 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
......@@ -25,6 +25,7 @@
#include "RtsFlags.h"
#include "RtsUtils.h"
#include "BlockAlloc.h"
#include "Itimer.h" /* CS_MIN_MILLISECS */
#include "Profiling.h"
#if defined(PROFILING)
......@@ -266,7 +267,6 @@ void initRtsFlagsDefaults(void)
#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_);
......@@ -402,7 +402,7 @@ usage_text[] = {
#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
......@@ -742,7 +742,7 @@ error = rtsTrue;
/* 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
*
......@@ -76,7 +76,6 @@ struct COST_CENTRE_FLAGS {
# define COST_CENTRES_ALL 3
# define COST_CENTRES_XML 4
int ctxtSwitchTicks; /* derived */
int profilerTicks; /* derived */
int msecsPerTick; /* derived */
};
......@@ -111,7 +110,8 @@ struct PROFILING_FLAGS {
#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
*
......@@ -850,8 +850,16 @@ schedule( void )
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);
......@@ -1589,6 +1597,9 @@ initScheduler(void)
context_switch = 0;
interrupted = 0;
RtsFlags.ConcFlags.ctxtSwitchTicks =
RtsFlags.ConcFlags.ctxtSwitchTime / TICK_MILLISECS;
#ifdef INTERPRETER
ecafList = END_ECAF_LIST;
clearECafTable();
......
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