Debian Codegraph @

tapset/linux/scheduler.stp

raw
1 // scheduler tapset
2 // Copyright (C) 2006 Intel Corporation.
3 // Copyright (C) 2005, 2006 IBM Corp.
4 // Copyright (C) 2010 Red Hat Inc.
5 //
6 // This file is part of systemtap, and is free software. You can
7 // redistribute it and/or modify it under the terms of the GNU General
8 // Public License (GPL); either version 2, or (at your option) any
9 // later version.
10
11
12 @__private30 function __is_idle:long()
13 %{ /* pure */ /* stable */
14 /* Ways to detect idle-ness:
15 * - pid() or tid() == 0
16 * - current == current->parent
17 * - current == this_rq()->idle
18 * - others?
19 */
20 STAP_RETVALUE = (current->pid == 0);
21 %}
22
23
24 /**
25 * probe scheduler.cpu_off - Process is about to stop running on a cpu
26 *
27 * @name: name of the probe point
28 * @task_prev: the process leaving the cpu (same as current)
29 * @task_next: the process replacing current
30 * @idle: boolean indicating whether current is the idle process
31 *
32 * Context: The process leaving the cpu.
33 *
34 */
35 probe scheduler.cpu_off =
36 kernel.trace("sched_switch") !,
37 kernel.function("context_switch")
38 {
39 name = "cpu_off"
40 task_prev = $prev
41 task_next = $next
42 idle = __is_idle()
43 }
44
45
46 /**
47 * probe scheduler.cpu_on - Process is beginning execution on a cpu
48 *
49 * @name: name of the probe point
50 * @task_prev: the process that was previously running on this cpu
51 * @idle:- boolean indicating whether current is the idle process
52 *
53 * Context: The resuming process.
54 */
55 probe scheduler.cpu_on = kernel.function("finish_task_switch") ?
56 {
57 name = "cpu_on"
58 task_prev = $prev
59 idle = __is_idle()
60 }
61
62
63 /**
64 * probe scheduler.tick - Schedulers internal tick, a processes timeslice accounting is updated
65 *
66 * @name: name of the probe point
67 * @idle: boolean indicating whether current is the idle process
68 *
69 * Context: The process whose accounting will be updated.
70 */
71 probe scheduler.tick = kernel.function("sched_tick")!,
72 kernel.function("scheduler_tick")
73 {
74 name = "tick"
75 idle = __is_idle()
76 }
77
78 /**
79 * probe scheduler.balance - A cpu attempting to find more work.
80 *
81 * @name: name of the probe point
82 *
83 * Context: The cpu looking for more work.
84 */
85 probe scheduler.balance = kernel.function("idle_balance") ?
86 {
87 name = "balance"
88 }
89
90
91 /**
92 * probe scheduler.ctxswitch - A context switch is occuring.
93 *
94 * @name: name of the probe point
95 * @prev_pid: The PID of the process to be switched out
96 * @next_pid: The PID of the process to be switched in
97 * @prev_tid: The TID of the process to be switched out
98 * @next_tid: The TID of the process to be switched in
99 * @prev_task_name: The name of the process to be switched out
100 * @next_task_name: The name of the process to be switched in
101 * @prev_priority: The priority of the process to be switched out
102 * @next_priority: The priority of the process to be switched in
103 * @prevtsk_state: the state of the process to be switched out
104 * @nexttsk_state: the state of the process to be switched in
105 */
106
107 /*
108 * We prefer the "sched_switch" tracepoint here, since we can reliably
109 * access the tracepoint's arguments. If we don't have the
110 * tracepoint, we try function probing. But these are typically
111 * inlined, and SystemTap can't access arguments of inline functions
112 * consistently. So we choose to probe __switch_to() instead of
113 * context_switch() on some platforms.
114 *
115 * Since the argument names for the tracepoint ("$prev" and "$next")
116 * match up with the function argument names, handling either the
117 * tracepoint or function here was made easier.
118 */
119
120 probe scheduler.ctxswitch = kernel.trace("sched_switch") !,
121 %( arch != "x86_64" && arch != "ia64" && arch != "arm" && arch != "mips" %?
122 kernel.function("__switch_to")
123 %:
124 kernel.function("context_switch")
125 %)
126 {
127 name = "ctxswitch"
128
129 /*
130 * Note that we prefer '$prev_p' here because on RHEL5
131 * (2.6.18-238.1.1.el5) the '__switch_to()' function has both
132 * a '$prev_p' and a '$prev' argument. Since '$prev_p' is of
133 * the correct type (struct task_struct *), we need to look
134 * for it first.
135 */
136 if (@defined($prev_p)) {
137 prev_priority = $prev_p->prio
138 prev_pid = $prev_p->tgid
139 prev_tid = $prev_p->pid
140 prev_task = $prev_p
141 prev_task_name = task_execname($prev_p)
142 prevtsk_state = task_state($prev_p)
143 }
144 else {
145 prev_priority = $prev->prio
146 prev_pid = $prev->tgid
147 prev_tid = $prev->pid
148 prev_task = $prev
149 prev_task_name = task_execname($prev)
150 prevtsk_state = task_state($prev)
151 }
152
153 if (@defined($next)) {
154 next_priority = $next->prio
155 next_pid = $next->tgid
156 next_tid = $next->pid
157 next_task = $next
158 next_task_name = task_execname($next)
159 nexttsk_state = task_state($next)
160 }
161 else if (@defined($next_p)) {
162 next_priority = $next_p->prio
163 next_pid = $next_p->tgid
164 next_tid = $next_p->pid
165 next_task = $next_p
166 next_task_name = task_execname($next_p)
167 nexttsk_state = task_state($next_p)
168 }
169 else {
170 next_priority = $new->prio
171 next_pid = $new->tgid
172 next_tid = $new->pid
173 next_task = $new
174 next_task_name = task_execname($new)
175 nexttsk_state = task_state($new)
176 }
177 }
178
179
180 /**
181 * probe scheduler.kthread_stop - A thread created by kthread_create is being stopped
182 * @thread_pid: PID of the thread being stopped
183 * @thread_priority: priority of the thread
184 */
185 probe __scheduler.kthread_stop.kp = kernel.function("kthread_stop")
186 {
187 thread_pid = $k->tgid
188 thread_priority = $k->prio
189 }
190 probe __scheduler.kthread_stop.tp = kernel.trace("sched_kthread_stop")
191 {
192 thread_pid = $t->tgid
193 thread_priority = $t->prio
194 }
195 probe scheduler.kthread_stop =
196 __scheduler.kthread_stop.tp !,
197 __scheduler.kthread_stop.kp
198 {
199 name = "kthread_stop"
200 }
201
202
203 /**
204 * probe scheduler.kthread_stop.return - A kthread is stopped and gets the return value
205 * @name: name of the probe point
206 * @return_value: return value after stopping the thread
207 */
208
209 probe __scheduler.kthread_stop.return.kp =
210 kernel.function("kthread_stop").return
211 {
212 return_value = @entry($k->exit_code)
213 }
214 probe __scheduler.kthread_stop.return.tp =
215 kernel.trace("sched_kthread_stop_ret")
216 {
217 return_value = $ret
218 }
219
220 probe scheduler.kthread_stop.return =
221 __scheduler.kthread_stop.return.tp !,
222 __scheduler.kthread_stop.return.kp
223 {
224 name = "kthread_stop"
225 }
226
227 /**
228 * probe scheduler.wait_task - Waiting on a task to unschedule (become inactive)
229 * @name: name of the probe point
230 * @task_pid: PID of the task the scheduler is waiting on
231 * @task_priority: priority of the task
232 */
233
234 probe scheduler.wait_task =
235 kernel.trace("sched_wait_task") !,
236 kernel.function("wait_task_inactive") ?
237 {
238 name = "wait_task"
239 task_pid = $p->tgid
240 task_priority = $p->prio
241 }
242
243 /**
244 * probe scheduler.wakeup - Task is woken up
245 * @name: name of the probe point
246 * @task_pid: PID of the task being woken up
247 * @task_priority: priority of the task being woken up
248 * @task_cpu: cpu of the task being woken up
249 * @task_state: state of the task being woken up
250 * @task_tid: tid of the task being woken up
251 */
252
253 probe scheduler.wakeup =
254 kernel.trace("sched_wakeup") !,
255 kernel.function("try_to_wake_up")
256 {
257 name = "wakeup"
258 task = $p
259 task_pid = $p->tgid
260 task_tid = $p->pid
261 task_priority = $p->prio
262 task_cpu = task_cpu($p)
263 task_state = task_state($p)
264 }
265
266 /**
267 * probe scheduler.wakeup_new - Newly created task is woken up for the first time
268 * @name: name of the probe point
269 * @task_pid: PID of the new task woken up
270 * @task_priority: priority of the new task
271 * @task_tid: TID of the new task woken up
272 * @task_state: state of the task woken up
273 * @task_cpu: cpu of the task woken up
274 */
275 probe scheduler.wakeup_new =
276 kernel.trace("sched_wakeup_new") !,
277 kernel.function("wake_up_new_task")
278 {
279 name = "wakeup_new"
280 task_pid = $p->tgid
281 task_priority = $p->prio
282 task_cpu = task_cpu($p)
283 task_state = task_state($p)
284 task = $p
285 task_tid = $p->pid
286 }
287
288 /**
289 * probe scheduler.migrate - Task migrating across cpus
290 * @name: name of the probe point
291 * @task: the process that is being migrated
292 * @pid: PID of the task being migrated
293 * @priority: priority of the task being migrated
294 * @cpu_from: the original cpu
295 * @cpu_to: the destination cpu
296 */
297 probe __scheduler.migrate.kp =
298 kernel.function("set_task_cpu") !,
299 kernel.function("pull_task") ?
300 {
301 cpu_to = @choose_defined($new_cpu,
302 @choose_defined($cpu, $this_cpu))
303 }
304 probe __scheduler.migrate.tp = kernel.trace("sched_migrate_task")
305 {
306 cpu_to = $dest_cpu
307 }
308 probe scheduler.migrate =
309 __scheduler.migrate.tp !,
310 __scheduler.migrate.kp ?
311 {
312 name = "migrate"
313 task = $p
314 pid = $p->tgid
315 priority = $p->prio
316 cpu_from = task_cpu($p)
317 }
318
319 function container_of_task_rcu:long(rcu_ptr:long)
320 {
321 if (@defined(&@task(0)->rcu)) {
322 /* Like @container_of, but taking care not to wrap */
323 offset = & @task(0)->rcu
324 if (rcu_ptr > offset)
325 return &@task(rcu_ptr - offset)
326 }
327 return 0
328 }
329
330 /**
331 * probe scheduler.process_free - Scheduler freeing a data structure for a process
332 * @name: name of the probe point
333 * @pid: PID of the process getting freed
334 * @priority: priority of the process getting freed
335 */
336 probe __scheduler.process_free.kp =
337 kernel.function("delayed_put_task_struct") !,
338 kernel.function("__put_task_struct")
339 {
340 if (@defined($rhp)) {
341 __tsk = container_of_task_rcu($rhp)
342 pid = __tsk->tgid
343 priority = __tsk->prio
344 }
345 else {
346 pid = $tsk->tgid
347 priority = $tsk->prio
348 }
349 }
350 probe __scheduler.process_free.tp = kernel.trace("sched_process_free")
351 {
352 pid = $p->tgid
353 priority = $p->prio
354 }
355 probe scheduler.process_free =
356 __scheduler.process_free.tp !,
357 __scheduler.process_free.kp
358 {
359 name = "process_free"
360 }
361
362 /**
363 * probe scheduler.process_exit - Process exiting
364 * @name: name of the probe point
365 * @pid: PID of the process exiting
366 * @priority: priority of the process exiting
367 */
368 probe __scheduler.process_exit.kp = kernel.function("do_exit")
369 {
370 if (@defined($tsk)) {
371 __tsk = $tsk
372 pid = $tsk->tgid
373 priority = $tsk->prio
374 }
375 else {
376 __tsk = task_current()
377 pid = __tsk->tgid
378 priority = __tsk->prio
379 }
380 }
381 probe __scheduler.process_exit.tp = kernel.trace("sched_process_exit")
382 {
383 pid = $p->tgid
384 priority = $p->prio
385 }
386
387 probe scheduler.process_exit =
388 __scheduler.process_exit.tp !,
389 __scheduler.process_exit.kp
390 {
391 name = "process_exit"
392 }
393
394 /**
395 * probe scheduler.process_wait - Scheduler starting to wait on a process
396 * @name: name of the probe point
397 * @pid: PID of the process scheduler is waiting on
398 */
399 probe __scheduler.process_wait.kp = kernel.function("do_wait")
400 {
401 if (@defined($wo)) {
402 pid = $wo->wo_pid
403 }
404 else {
405 pid = $pid
406 }
407 }
408 probe __scheduler.process_wait.tp = kernel.trace("sched_process_wait")
409 {
410 pid = $pid
411 }
412 probe scheduler.process_wait =
413 __scheduler.process_wait.tp !,
414 __scheduler.process_wait.kp
415 {
416 name = "process_wait"
417 }
418
419 /**
420 * probe scheduler.process_fork - Process forked
421 * @name: name of the probe point
422 * @parent_pid: PID of the parent process
423 * @child_pid: PID of the child process
424 */
425 probe __scheduler.process_fork.kp =
426 kernel.function("kernel_clone").return !,
427 kernel.function("_do_fork").return !,
428 kernel.function("do_fork").return
429 {
430 parent_pid = task_current()->tgid
431 child_pid = $return
432 }
433 probe __scheduler.process_fork.tp = kernel.trace("sched_process_fork")
434 {
435 parent_pid = $parent->tgid
436 child_pid = $child->tgid
437 }
438
439 probe scheduler.process_fork =
440 __scheduler.process_fork.tp !,
441 __scheduler.process_fork.kp
442 {
443 name = "process_fork"
444 }
445
446 /**
447 * probe scheduler.signal_send - Sending a signal
448 * @name: name of the probe point
449 * @pid: pid of the process sending signal
450 * @signal_number: signal number
451 */
452 probe __scheduler.signal_send.kp =
453 kernel.function("send_signal_locked")!,
454 kernel.function("__send_signal") !,
455 kernel.function("send_signal")
456 {
457 pid = $t->tgid
458 }
459 probe __scheduler.signal_send.tp =
460 kernel.trace("signal_generate")!,
461 kernel.trace("sched_signal_send")
462 {
463 if (@defined($task)) {
464 pid = $task->tgid
465 } else {
466 pid = $p->tgid
467 }
468 }
469 probe scheduler.signal_send =
470 __scheduler.signal_send.tp !,
471 __scheduler.signal_send.kp
472 {
473 name = "signal_send"
474 signal_number = $sig
475 }