xref: /freebsd/share/man/man4/dtrace_sched.4 (revision cd0d51baaa4509a1db83251a601d34404d20c990)
1.\" Copyright (c) 2015 Mark Johnston <markj@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd April 18, 2015
28.Dt DTRACE_SCHED 4
29.Os
30.Sh NAME
31.Nm dtrace_sched
32.Nd a DTrace provider for tracing CPU scheduling events
33.Sh SYNOPSIS
34.Fn sched:::change-pri "struct thread *" "struct proc *" "uint8_t"
35.Fn sched:::dequeue "struct thread *" "struct proc *" "void *"
36.Fn sched:::enqueue "struct thread *" "struct proc *" "void *" "int"
37.Fn sched:::lend-pri "struct thread *" "struct proc *" "uint8_t" "struct thread *"
38.Fn sched:::load-change "int" "int"
39.Fn sched:::off-cpu "struct thread *" "struct proc *"
40.Fn sched:::on-cpu
41.Fn sched:::preempt
42.Fn sched:::remain-cpu
43.Fn sched:::surrender "struct thread *" "struct proc *"
44.Fn sched:::sleep
45.Fn sched:::tick "struct thread *" "struct proc *"
46.Fn sched:::wakeup "struct thread *" "struct proc *"
47.Sh DESCRIPTION
48The DTrace
49.Nm sched
50provider allows the tracing of events related to CPU scheduling in the 4BSD and
51ULE schedulers.
52.Pp
53The
54.Fn sched:::change-pri
55probe fires when a thread's active scheduling priority is about to be updated.
56The first two arguments are the thread whose priority is about to be changed,
57and the corresponding process.
58The third argument is the new absolute priority for the thread, while the
59current value is given by
60.Dv args[0]->td_priority .
61The
62.Fn sched:::lend-pri
63probe fires when the currently-running thread elevates the priority of another
64thread via priority lending.
65The first two arguments are the thread whose priority is about to be changed,
66and the corresponding process.
67The third argument is the new absolute priority for the thread.
68The fourth argument is the currently-running thread.
69.Pp
70The
71.Fn sched:::dequeue
72probe fires immediately before a runnable thread is removed from a scheduler
73run queue.
74This may occur when the thread is about to begin execution on a CPU, or because
75the thread is being migrated to a different run queue.
76The latter event may occur in several circumstances: the scheduler may be
77attempting to rebalance load between multiple CPUs, the thread's scheduling
78priority may have changed, or the thread's CPU affinity settings may have
79changed.
80The first two arguments to
81.Fn sched:::dequeue
82are the thread and corresponding process.
83The third argument is currently always
84.Dv NULL .
85The
86.Fn sched:::enqueue
87probe fires when a runnable thread is about to be added to a scheduler run
88queue.
89Its first two arguments are the thread and corresponding process.
90The third argument is currently always
91.Dv NULL .
92The fourth argument is a boolean value that is non-zero if the thread is
93enqueued at the beginning of its run queue slot, and zero if the thread is
94instead enqueued at the end.
95.Pp
96The
97.Fn sched:::load-change
98probe fires after the load of a thread queue is adjusted.
99The first argument is the cpuid for the CPU associated with the thread queue,
100and the second argument is the adjusted load of the thread queue, i.e., the
101number of elements in the queue.
102.Pp
103The
104.Fn sched:::off-cpu
105probe is triggered by the scheduler suspending execution of the
106currently-running thread, and the
107.Fn sched:::on-cpu
108probe fires when the current thread has been selected to run on a CPU and is
109about to begin or resume execution.
110The arguments to
111.Fn sched:::off-cpu
112are the thread and corresponding process selected to run following the
113currently-running thread.
114If these two threads are the same, the
115.Fn sched:::remain-cpu
116probe will fire instead.
117.Pp
118The
119.Fn sched:::surrender
120probe fires when the scheduler is called upon to make a scheduling decision by
121a thread running on a different CPU, via an interprocessor interrupt.
122The arguments to this probe are the interrupted thread and its corresponding
123process.
124This probe currently always fires in the context of the interrupted thread.
125.Pp
126The
127.Fn sched:::preempt
128probe will fire immediately before the currently-running thread is preempted.
129When this occurs, the scheduler will select a new thread to run, and one of the
130.Fn sched:::off-cpu
131or
132.Fn sched:::remain-cpu
133probes will subsequently fire, depending on whether or not the scheduler selects
134the preempted thread.
135.Pp
136The
137.Fn sched:::sleep
138probe fires immediately before the currently-running thread is about to suspend
139execution and begin waiting for a condition to be met.
140The
141.Fn sched:::wakeup
142probe fires when a thread is set up to resume execution after having gone to
143sleep.
144Its arguments are the thread being awoken, and the corresponding process.
145.Pp
146The
147.Fn sched:::tick
148fires before each scheduler clock tick.
149Its arguments are the currently-running thread and its corresponding process.
150.Sh ARGUMENTS
151The
152.Nm sched
153provider probes use the kernel types
154.Vt "struct proc"
155and
156.Vt "struct thread"
157to represent processes and threads, respectively.
158These structures have many fields and are defined in
159.Pa sys/proc.h .
160In a probe body, the currently-running thread can always be obtained with the
161.Va curthread
162global variable, which has type
163.Vt "struct thread *" .
164For example, when a running thread is about to sleep, the
165.Fn sched:::sleep
166probe fires in the context of that thread, which can be accessed using
167.Va curthread .
168The
169.Va curcpu
170global variable contains the cpuid of the CPU on which the currently-running
171thread is executing.
172.Sh EXAMPLES
173The following script gives a breakdown of CPU utilization by process name:
174.Bd -literal -offset indent
175sched:::on-cpu
176{
177        self->ts = timestamp;
178}
179
180sched:::off-cpu
181/self->ts != 0/
182{
183        @[execname] = sum((timestamp - self->ts) / 1000);
184        self->ts = 0;
185}
186.Ed
187.Pp
188Here, DTrace stores a timestamp each time a thread is scheduled to run, and
189computes the time elapsed in microseconds when it is descheduled.
190The results are summed by process name.
191.Sh COMPATIBILITY
192This provider is not compatible with the
193.Nm sched
194provider found in Solaris.
195In particular, the probe argument types are native
196.Fx
197types, and the
198.Fn sched:::cpucaps-sleep ,
199.Fn sched:::cpucaps-wakeup ,
200.Fn sched:::schedctl-nopreempt ,
201.Fn sched:::schedctl-preempt ,
202and
203.Fn sched:::schedctl-yield
204probes are not available in
205.Fx .
206.Pp
207The
208.Fn sched:::lend-pri
209and
210.Fn sched:::load-change
211probes are specific to
212.Fx .
213.Sh SEE ALSO
214.Xr dtrace 1 ,
215.Xr sched_4bsd 4 ,
216.Xr sched_ule 4 ,
217.Xr SDT 9 ,
218.Xr sleepqueue 9
219.Sh HISTORY
220The
221.Nm sched
222provider first appeared in
223.Fx
2248.4 and 9.1.
225.Sh AUTHORS
226This manual page was written by
227.An Mark Johnston Aq Mt markj@FreeBSD.org .
228