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)
46 if (RtsFlags.ConcFlags.ctxtSwitchTicks > 0) {
47 ticks_to_ctxt_switch--;
48 if (ticks_to_ctxt_switch <= 0) {
49 ticks_to_ctxt_switch = RtsFlags.ConcFlags.ctxtSwitchTicks;
50 context_switch = 1; /* schedule a context switch */
54 #if defined(THREADED_RTS)
56 * If we've been inactive for idleGCDelayTime (set by +RTS
57 * -I), tell the scheduler to wake up and do a GC, to check
58 * for threads that are deadlocked.
60 switch (recent_activity) {
62 recent_activity = ACTIVITY_MAYBE_NO;
63 ticks_to_gc = RtsFlags.GcFlags.idleGCDelayTime /
64 RtsFlags.MiscFlags.tickInterval;
66 case ACTIVITY_MAYBE_NO:
67 if (ticks_to_gc == 0) break; /* 0 ==> no idle GC */
69 if (ticks_to_gc == 0) {
70 ticks_to_gc = RtsFlags.GcFlags.idleGCDelayTime /
71 RtsFlags.MiscFlags.tickInterval;
72 recent_activity = ACTIVITY_INACTIVE;
73 blackholes_need_checking = rtsTrue;
74 /* hack: re-use the blackholes_need_checking flag */
88 if (RtsFlags.MiscFlags.tickInterval != 0) {
89 startTicker(RtsFlags.MiscFlags.tickInterval, handle_tick);