summaryrefslogtreecommitdiffstats
path: root/tapset/scheduler.stp
blob: 55e230c25d4cb380c3fd45fe29e605cf163887b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// scheduler tapset
// Copyright (C) 2006 Intel Corporation.
// Copyright (C) 2005, 2006 IBM Corp.
//
// This file is part of systemtap, and is free software.  You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.


function __is_idle:long()
%{ /* pure */
    /* Ways to detect idle-ness:
     * - pid() or tid() == 0
     * - current == current->parent
     * - current == this_rq()->idle
     * - others?
     */
    THIS->__retvalue = (current->pid == 0);
%}


/* probe scheduler.cpu_off
 *
 *  Fires when a process is about to stop running on a cpu.
 *
 * Context:
 *  The process leaving the cpu.
 *
 * Arguments:
 *  task_prev - the process leaving the cpu (same as current)
 *  task_next - the process replacing current
 *  idle - boolean indicating whether current is the idle process
 */
probe scheduler.cpu_off
    = kernel.function("context_switch")
{
    task_prev = $prev
    task_next = $next
    idle = __is_idle()
}


/* probe scheduler.cpu_on
 *
 *  Fires when a process is beginning execution on a cpu.
 *
 * Context:
 *  The resuming process.
 *
 * Arguments:
 *  task_prev - the process that was previously running on this cpu.
 *  idle - boolean indicating whether current is the idle process
 */
probe scheduler.cpu_on
    = kernel.function("finish_task_switch")?
{
    task_prev = $prev
    idle = __is_idle()
}


/* probe scheduler.tick
 *
 *  Fires on the schedulers internal tick, when a processes timeslice
 *  accounting is updated.
 *
 * Context:
 *  The process whose accounting will be updated.
 *
 * Arguments:
 *  idle - boolean indicating whether current is the idle process
 */
probe scheduler.tick = kernel.function("scheduler_tick")
{
    idle = __is_idle()
}


/* probe scheduler.migrate
 *
 *  Fires whenever a task is moved to a different cpu's runqueue.
 *
 * Context:
 *  Unknown (sometimes migration thread, sometimes cpu_to)
 *
 * Arguments:
 *  task - the process that is being migrated
 *  cpu_from - the cpu that is losing the task
 *  cpu_to - the cpu that is claiming the task
 */
probe scheduler.migrate = kernel.function("pull_task")? {
    task = $p
    cpu_from = task_cpu($p) /*thread_info renamed to stack since 2.6.22*/
    cpu_to = $this_cpu
}


/* probe scheduler.balance
 *
 *  Fires when a cpu attempts to find more work.
 *  Only applicable to SMP systems
 *
 * Context:
 *  The cpu looking for more work.
 */
probe scheduler.balance = kernel.function("idle_balance")? {}


/* probe scheduler.ctxswitch 
 * 
 *  Fires when there is a context switch

 *  Currently systemTap can't access arguments of inline
 *  functions. So we choose to probe __switch_to instead
 *  of context_switch()       

 *  Arguments:
 *    prev_pid: The pid of the process to be switched out
 *    next_pid: The pid of the process to be switched in
 *    prevtsk_state: the state of the process to be switched out
 */
probe scheduler.ctxswitch =
%( arch != "x86_64" %?
 %( arch != "ia64" %?
	kernel.function("__switch_to")
 %:
	kernel.function("context_switch")
 %)
%:
	kernel.function("context_switch")
%)
{
%( arch == "ppc64" %?
        prev_pid = $prev->pid
        next_pid =  $new->pid
        prev_task = $prev
        next_task = $new
        prevtsk_state = $prev->state
%: %( arch == "x86_64" %?
        prev_pid = $prev->pid
        next_pid =  $next->pid
        prev_task = $prev
        next_task = $next
        prevtsk_state = $prev->state
%: %( arch == "ia64" %?
        prev_pid = $prev->pid
        next_pid =  $next->pid
        prev_task = $prev
        next_task = $next
        prevtsk_state = $prev->state
%:
        prev_pid = $prev_p->pid
        next_pid = $next_p->pid
        prev_task = $prev_p
        next_task = $next_p
        prevtsk_state = $prev_p->state
%) %) %)
}