1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1995-2005
5 * Interval timer service for profiling and pre-emptive scheduling.
7 * ---------------------------------------------------------------------------*/
10 * The interval timer is used for profiling and for context switching in the
13 * This file defines the platform-independent view of interval timing, relying
14 * on platform-specific services to install and run the timers.
19 #include "Proftimer.h"
24 #include "Capability.h"
25 #include "RtsSignals.h"
27 /* ticks left before next pre-emptive context switch */
28 static int ticks_to_ctxt_switch = 0;
30 #if defined(THREADED_RTS)
31 /* idle ticks left before we perform a GC */
32 static int ticks_to_gc = 0;
36 * Function: handle_tick()
38 * At each occurrence of a tick, the OS timer will invoke
43 handle_tick(int unused STG_UNUSED)
48 if (RtsFlags.ConcFlags.ctxtSwitchTicks > 0) {
49 ticks_to_ctxt_switch--;
50 if (ticks_to_ctxt_switch <= 0) {
51 ticks_to_ctxt_switch = RtsFlags.ConcFlags.ctxtSwitchTicks;
52 context_switch = 1; /* schedule a context switch */
56 #if defined(THREADED_RTS)
58 * If we've been inactive for idleGCDelayTime (set by +RTS
59 * -I), tell the scheduler to wake up and do a GC, to check
60 * for threads that are deadlocked.
62 switch (recent_activity) {
64 recent_activity = ACTIVITY_MAYBE_NO;
65 ticks_to_gc = RtsFlags.GcFlags.idleGCDelayTime /
66 RtsFlags.MiscFlags.tickInterval;
68 case ACTIVITY_MAYBE_NO:
69 if (ticks_to_gc == 0) break; /* 0 ==> no idle GC */
71 if (ticks_to_gc == 0) {
72 ticks_to_gc = RtsFlags.GcFlags.idleGCDelayTime /
73 RtsFlags.MiscFlags.tickInterval;
74 recent_activity = ACTIVITY_INACTIVE;
75 blackholes_need_checking = rtsTrue;
76 /* hack: re-use the blackholes_need_checking flag */
93 return startTicker(RtsFlags.MiscFlags.tickInterval, handle_tick);