From 66f7a41dfbf02a000ef3fb2a2b84c89f5dd53177 Mon Sep 17 00:00:00 2001 From: simonmar Date: Thu, 3 Aug 2000 11:28:35 +0000 Subject: [PATCH] [project @ 2000-08-03 11:28:35 by simonmar] Implement +RTS -C, 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. --- ghc/includes/Constants.h | 9 +-------- ghc/rts/Itimer.c | 13 +++++++++++-- ghc/rts/Itimer.h | 7 ++++++- ghc/rts/RtsFlags.c | 8 ++++---- ghc/rts/RtsFlags.h | 6 +++--- ghc/rts/Schedule.c | 17 ++++++++++++++--- 6 files changed, 39 insertions(+), 21 deletions(-) diff --git a/ghc/includes/Constants.h b/ghc/includes/Constants.h index d0640f7..bc6b162 100644 --- a/ghc/includes/Constants.h +++ b/ghc/includes/Constants.h @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- - * $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 * @@ -194,13 +194,6 @@ #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. -------------------------------------------------------------------------- */ diff --git a/ghc/rts/Itimer.c b/ghc/rts/Itimer.c index 9117157..c327528 100644 --- a/ghc/rts/Itimer.c +++ b/ghc/rts/Itimer.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $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; } diff --git a/ghc/rts/Itimer.h b/ghc/rts/Itimer.h index 58f4152..257d274 100644 --- a/ghc/rts/Itimer.h +++ b/ghc/rts/Itimer.h @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $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 ); diff --git a/ghc/rts/RtsFlags.c b/ghc/rts/RtsFlags.c index a341fca..c86690f 100644 --- a/ghc/rts/RtsFlags.c +++ b/ghc/rts/RtsFlags.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $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 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 Use 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; diff --git a/ghc/rts/RtsFlags.h b/ghc/rts/RtsFlags.h index 61d0a9a..12fceb2 100644 --- a/ghc/rts/RtsFlags.h +++ b/ghc/rts/RtsFlags.h @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $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 diff --git a/ghc/rts/Schedule.c b/ghc/rts/Schedule.c index 05d44df..ed0389f 100644 --- a/ghc/rts/Schedule.c +++ b/ghc/rts/Schedule.c @@ -1,5 +1,5 @@ /* --------------------------------------------------------------------------- - * $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(); -- 1.7.10.4