This file is indexed.

/usr/share/systemtap/tapset/linux/scheduler.stp is in systemtap-common 2.6-0.2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
// scheduler tapset
// Copyright (C) 2006 Intel Corporation.
// Copyright (C) 2005, 2006 IBM Corp.
// Copyright (C) 2010 Red Hat Inc.
//
// 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?
     */
    STAP_RETVALUE = (current->pid == 0);
%}


/**
 * probe scheduler.cpu_off - Process is about to stop running on a cpu
 *
 * @name: name of the probe point
 * @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
 *
 * Context: The process leaving the cpu.
 *
 */
probe scheduler.cpu_off =
	kernel.trace("sched_switch") !,
	kernel.function("context_switch")
{
    name = "cpu_off"
    task_prev = $prev
    task_next = $next
    idle = __is_idle()
}


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


/**
 * probe scheduler.tick - Schedulers internal tick, a processes timeslice accounting is updated
 *
 *  @name: name of the probe point
 *  @idle: boolean indicating whether current is the idle process
 *
 * Context: The process whose accounting will be updated.
 */
probe scheduler.tick = kernel.function("scheduler_tick")
{
    name = "tick"
    idle = __is_idle()
}

/**
 * probe scheduler.balance - A cpu attempting to find more work.
 * 
 * @name: name of the probe point
 *
 * Context: The cpu looking for more work.
 */
probe scheduler.balance = kernel.function("idle_balance") ?
{
    name = "balance"
}


/** 
 * probe scheduler.ctxswitch - A context switch is occuring.
 *
 * @name: name of the probe point
 * @prev_pid: The PID of the process to be switched out
 * @next_pid: The PID of the process to be switched in
 * @prev_tid: The TID of the process to be switched out
 * @next_tid: The TID of the process to be switched in	 
 * @prev_task_name: The name of the process to be switched out
 * @next_task_name: The name of the process to be switched in
 * @prev_priority: The priority of the process to be switched out
 * @next_priority: The priority of the process to be switched in
 * @prevtsk_state: the state of the process to be switched out
 * @nexttsk_state: the state of the process to be switched in
 */

/*
 * We prefer the "sched_switch" tracepoint here, since we can reliably
 * access the tracepoint's arguments.  If we don't have the
 * tracepoint, we try function probing.  But these are typically
 * inlined, and SystemTap can't access arguments of inline functions
 * consistently. So we choose to probe __switch_to() instead of
 * context_switch() on some platforms.
 * 
 * Since the argument names for the tracepoint ("$prev" and "$next")
 * match up with the function argument names, handling either the
 * tracepoint or function here was made easier.
 */

probe scheduler.ctxswitch = kernel.trace("sched_switch") !,
%( arch != "x86_64" && arch != "ia64" && arch != "arm" %?
	kernel.function("__switch_to")
%:
	kernel.function("context_switch")
%)
{
	name = "ctxswitch"

	/*
	 * Note that we prefer '$prev_p' here because on RHEL5
	 * (2.6.18-238.1.1.el5) the '__switch_to()' function has both
	 * a '$prev_p' and a '$prev' argument.  Since '$prev_p' is of
	 * the correct type (struct task_struct *), we need to look
	 * for it first.
	 */
	if (@defined($prev_p)) {
		prev_priority = $prev_p->prio
		prev_pid = $prev_p->tgid
		prev_tid = $prev_p->pid
		prev_task = $prev_p
		prev_task_name = task_execname($prev_p)
		prevtsk_state = $prev_p->state
	}
	else {
		prev_priority = $prev->prio
		prev_pid = $prev->tgid
		prev_tid = $prev->pid
		prev_task = $prev
		prev_task_name = task_execname($prev)
		prevtsk_state = $prev->state
	}

	if (@defined($next)) {
		next_priority = $next->prio
		next_pid = $next->tgid
		next_tid = $next->pid
		next_task = $next
		next_task_name = task_execname($next)
		nexttsk_state = $next->state
	}
	else if (@defined($next_p)) {
		next_priority = $next_p->prio
		next_pid = $next_p->tgid
		next_tid = $next_p->pid
		next_task = $next_p
		next_task_name = task_execname($next_p)
		nexttsk_state = $next_p->state
	}
	else {
		next_priority = $new->prio
		next_pid = $new->tgid
		next_tid = $new->pid
		next_task = $new
		next_task_name = task_execname($new)
		nexttsk_state = $new->state
	}
}


/**
 * probe scheduler.kthread_stop - A thread created by kthread_create is being stopped
 * @thread_pid: PID of the thread being stopped
 * @thread_priority: priority of the thread
 */
probe __scheduler.kthread_stop.kp = kernel.function("kthread_stop")
{
	thread_pid = $k->tgid
	thread_priority = $k->prio
}
probe __scheduler.kthread_stop.tp = kernel.trace("sched_kthread_stop") 
{
	thread_pid = $t->tgid
	thread_priority = $t->prio
}
probe scheduler.kthread_stop =
	__scheduler.kthread_stop.tp !,
	__scheduler.kthread_stop.kp
{
	name = "kthread_stop"
}


/**
 * probe scheduler.kthread_stop.return - A kthread is stopped and gets the return value
 * @name: name of the probe point
 * @return_value: return value after stopping the thread
 */

probe __scheduler.kthread_stop.return.kp =
	kernel.function("kthread_stop").return
{
	return_value = $k->exit_code
}
probe __scheduler.kthread_stop.return.tp =
	kernel.trace("sched_kthread_stop_ret")
{
	return_value = $ret
}

probe scheduler.kthread_stop.return =
	__scheduler.kthread_stop.return.tp !,
	__scheduler.kthread_stop.return.kp
{
	name = "kthread_stop"
}

/**
 * probe scheduler.wait_task - Waiting on a task to unschedule (become inactive)
 * @name: name of the probe point
 * @task_pid: PID of the task the scheduler is waiting on
 * @task_priority: priority of the task
 */

probe scheduler.wait_task =
	kernel.trace("sched_wait_task") !,
	kernel.function("wait_task_inactive") ?
{
	name = "wait_task"
	task_pid = $p->tgid
	task_priority = $p->prio
}

/**
 * probe scheduler.wakeup - Task is woken up 
 * @name: name of the probe point
 * @task_pid: PID of the task being woken up
 * @task_priority: priority of the task being woken up
 * @task_cpu: cpu of the task being woken up
 * @task_state: state of the task being woken up
 * @task_tid: tid of the task being woken up
 */

probe scheduler.wakeup =
	kernel.trace("sched_wakeup") !,
	kernel.function("try_to_wake_up")
{
	name = "wakeup"
	task = $p
	task_pid = $p->tgid
	task_tid = $p->pid
	task_priority = $p->prio
	task_cpu = task_cpu($p)
	task_state = task_state($p)
}

/**
 * probe scheduler.wakeup_new - Newly created task is woken up for the first time
 * @name: name of the probe point
 * @task_pid: PID of the new task woken up
 * @task_priority: priority of the new task
 * @task_tid: TID of the new task woken up
 * @task_state: state of the task woken up
 * @task_cpu: cpu of the task woken up
 */
probe scheduler.wakeup_new =
	kernel.trace("sched_wakeup_new") !,
	kernel.function("wake_up_new_task")
{
	name = "wakeup_new"
	task_pid = $p->tgid
	task_priority = $p->prio
	task_cpu = task_cpu($p)
	task_state = task_state($p)
	task = $p
	task_tid = $p->pid
}

/**
 * probe scheduler.migrate - Task migrating across cpus
 * @name: name of the probe point
 * @task: the process that is being migrated
 * @pid: PID of the task being migrated
 * @priority: priority of the task being migrated
 * @cpu_from: the original cpu
 * @cpu_to: the destination cpu
 */
probe __scheduler.migrate.kp =
	kernel.function("set_task_cpu") !,
	kernel.function("pull_task") ?
{
	cpu_to = @choose_defined($new_cpu,
                @choose_defined($cpu, $this_cpu))
}
probe __scheduler.migrate.tp = kernel.trace("sched_migrate_task")
{
	cpu_to = $dest_cpu
}
probe scheduler.migrate =
	__scheduler.migrate.tp !,
	__scheduler.migrate.kp ?
{
	name = "migrate"
	task = $p
	pid = $p->tgid
	priority = $p->prio
	cpu_from = task_cpu($p)
}

function container_of_task_rcu:long(rcu_ptr:long)
{
	if (@defined(&@cast(0, "task_struct", "kernel<linux/sched.h>")->rcu)) {
		/*
		 * The following is the script language equivalent of:
		 *
		 *    return container_of(rcu_ptr, struct task_struct, rcu);
		 *
		 * More spelled out, that would look like:
		 *
		 *    return (rcu_ptr - offsetof(struct task_struct, rcu));
		 * 
		 * Notice we're casting 0 here on purpose to find the
		 * offset of the 'rcu' member of 'struct task_struct'.
		 */
		offset = &@cast(0, "task_struct",
				"kernel<linux/sched.h>")->rcu
		if (rcu_ptr > offset)
			return (rcu_ptr - offset)
	}
	return 0
}

/**
 * probe scheduler.process_free - Scheduler freeing a data structure for a process
 * @name: name of the probe point
 * @pid: PID of the process getting freed
 * @priority: priority of the process getting freed
 */
probe __scheduler.process_free.kp =
	kernel.function("delayed_put_task_struct") !,
	kernel.function("__put_task_struct")
{
	if (@defined($rhp)) {
		__tsk = container_of_task_rcu($rhp)
		pid = @cast(__tsk, "task_struct",
			    "kernel<linux/sched.h>")->tgid
		priority = @cast(__tsk, "task_struct",
				 "kernel<linux/sched.h>")->prio
	}
	else {
		pid = $tsk->tgid
		priority = $tsk->prio
	}
}
probe __scheduler.process_free.tp = kernel.trace("sched_process_free")
{
	pid = $p->tgid
	priority = $p->prio
}
probe scheduler.process_free =
	__scheduler.process_free.tp !,
	__scheduler.process_free.kp
{
	name = "process_free"
}

/**
 * probe scheduler.process_exit - Process exiting
 * @name: name of the probe point
 * @pid: PID of the process exiting
 * @priority: priority of the process exiting
 */
probe __scheduler.process_exit.kp = kernel.function("do_exit")
{
	if (@defined($tsk)) {
		__tsk = $tsk
		pid = $tsk->tgid
		priority = $tsk->prio
	}
	else {
		__tsk = task_current()
		pid = @cast(__tsk, "task_struct",
			    "kernel<linux/sched.h>")->tgid
		priority = @cast(__tsk, "task_struct",
				 "kernel<linux/sched.h>")->prio
	}
}
probe __scheduler.process_exit.tp = kernel.trace("sched_process_exit")
{
	pid = $p->tgid
	priority = $p->prio
}

probe scheduler.process_exit =
	__scheduler.process_exit.tp !,
	__scheduler.process_exit.kp
{
	name = "process_exit"
}

/**
 * probe scheduler.process_wait - Scheduler starting to wait on a process
 * @name: name of the probe point
 * @pid: PID of the process scheduler is waiting on
 */
probe __scheduler.process_wait.kp = kernel.function("do_wait")
{
	if (@defined($wo)) {
		pid = $wo->wo_pid
	}
	else {
		pid = $pid
	}
}
probe __scheduler.process_wait.tp = kernel.trace("sched_process_wait")
{
	pid = $pid
}
probe scheduler.process_wait =
	__scheduler.process_wait.tp !,
	__scheduler.process_wait.kp
{
	name = "process_wait"
}

/**
 * probe scheduler.process_fork - Process forked
 * @name: name of the probe point
 * @parent_pid: PID of the parent process
 * @child_pid: PID of the child process
 */
probe __scheduler.process_fork.kp = kernel.function("do_fork").return
{
	parent_pid = @cast(task_current(), "task_struct",
			   "kernel<linux/sched.h>")->tgid
	child_pid = $return
}
probe __scheduler.process_fork.tp = kernel.trace("sched_process_fork")
{
	parent_pid = $parent->tgid
	child_pid = $child->tgid
}

probe scheduler.process_fork =
	__scheduler.process_fork.tp !,
	__scheduler.process_fork.kp
{
	name = "process_fork"
}

/**
 * probe scheduler.signal_send - Sending a signal
 * @name: name of the probe point
 * @pid: pid of the process sending signal
 * @signal_number: signal number
 */
probe __scheduler.signal_send.kp =
	kernel.function("__send_signal") !,
	kernel.function("send_signal")
{
	pid = $t->tgid
}
probe __scheduler.signal_send.tp = kernel.trace("sched_signal_send")
{
	pid = $p->tgid
}
probe scheduler.signal_send =
	__scheduler.signal_send.tp !,
	__scheduler.signal_send.kp
{
	name = "signal_send"
	signal_number = $sig
}