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.
18 #include "PosixSource.h"
22 #include "Proftimer.h"
25 #include "Capability.h"
26 #include "RtsSignals.h"
28 /* ticks left before next pre-emptive context switch */
29 static int ticks_to_ctxt_switch = 0;
31 #if defined(THREADED_RTS)
32 /* idle ticks left before we perform a GC */
33 static int ticks_to_gc = 0;
37 * Function: handle_tick()
39 * At each occurrence of a tick, the OS timer will invoke
44 handle_tick(int unused STG_UNUSED)
47 if (RtsFlags.ConcFlags.ctxtSwitchTicks > 0) {
48 ticks_to_ctxt_switch--;
49 if (ticks_to_ctxt_switch <= 0) {
50 ticks_to_ctxt_switch = RtsFlags.ConcFlags.ctxtSwitchTicks;
51 setContextSwitches(); /* schedule a context switch */
55 #if defined(THREADED_RTS)
57 * If we've been inactive for idleGCDelayTime (set by +RTS
58 * -I), tell the scheduler to wake up and do a GC, to check
59 * for threads that are deadlocked.
61 switch (recent_activity) {
63 recent_activity = ACTIVITY_MAYBE_NO;
64 ticks_to_gc = RtsFlags.GcFlags.idleGCDelayTime /
65 RtsFlags.MiscFlags.tickInterval;
67 case ACTIVITY_MAYBE_NO:
68 if (ticks_to_gc == 0) {
69 /* 0 ==> no idle GC */
70 recent_activity = ACTIVITY_DONE_GC;
71 // disable timer signals (see #1623)
75 if (ticks_to_gc == 0) {
76 ticks_to_gc = RtsFlags.GcFlags.idleGCDelayTime /
77 RtsFlags.MiscFlags.tickInterval;
78 recent_activity = ACTIVITY_INACTIVE;
79 blackholes_need_checking = rtsTrue;
80 /* hack: re-use the blackholes_need_checking flag */
95 if (RtsFlags.MiscFlags.tickInterval != 0) {
96 initTicker(RtsFlags.MiscFlags.tickInterval, handle_tick);
103 if (RtsFlags.MiscFlags.tickInterval != 0) {
111 if (RtsFlags.MiscFlags.tickInterval != 0) {
119 if (RtsFlags.MiscFlags.tickInterval != 0) {