xref: /freebsd/share/man/man4/dtrace_sched.4 (revision 5e3190f700637fcfc1a52daeaa4a031fdd2557c7)
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.Dd April 18, 2015
26.Dt DTRACE_SCHED 4
27.Os
28.Sh NAME
29.Nm dtrace_sched
30.Nd a DTrace provider for tracing CPU scheduling events
31.Sh SYNOPSIS
32.Fn sched:::change-pri "struct thread *" "struct proc *" "uint8_t"
33.Fn sched:::dequeue "struct thread *" "struct proc *" "void *"
34.Fn sched:::enqueue "struct thread *" "struct proc *" "void *" "int"
35.Fn sched:::lend-pri "struct thread *" "struct proc *" "uint8_t" "struct thread *"
36.Fn sched:::load-change "int" "int"
37.Fn sched:::off-cpu "struct thread *" "struct proc *"
38.Fn sched:::on-cpu
39.Fn sched:::preempt
40.Fn sched:::remain-cpu
41.Fn sched:::surrender "struct thread *" "struct proc *"
42.Fn sched:::sleep
43.Fn sched:::tick "struct thread *" "struct proc *"
44.Fn sched:::wakeup "struct thread *" "struct proc *"
45.Sh DESCRIPTION
46The DTrace
47.Nm sched
48provider allows the tracing of events related to CPU scheduling in the 4BSD and
49ULE schedulers.
50.Pp
51The
52.Fn sched:::change-pri
53probe fires when a thread's active scheduling priority is about to be updated.
54The first two arguments are the thread whose priority is about to be changed,
55and the corresponding process.
56The third argument is the new absolute priority for the thread, while the
57current value is given by
58.Dv args[0]->td_priority .
59The
60.Fn sched:::lend-pri
61probe fires when the currently-running thread elevates the priority of another
62thread via priority lending.
63The first two arguments are the thread whose priority is about to be changed,
64and the corresponding process.
65The third argument is the new absolute priority for the thread.
66The fourth argument is the currently-running thread.
67.Pp
68The
69.Fn sched:::dequeue
70probe fires immediately before a runnable thread is removed from a scheduler
71run queue.
72This may occur when the thread is about to begin execution on a CPU, or because
73the thread is being migrated to a different run queue.
74The latter event may occur in several circumstances: the scheduler may be
75attempting to rebalance load between multiple CPUs, the thread's scheduling
76priority may have changed, or the thread's CPU affinity settings may have
77changed.
78The first two arguments to
79.Fn sched:::dequeue
80are the thread and corresponding process.
81The third argument is currently always
82.Dv NULL .
83The
84.Fn sched:::enqueue
85probe fires when a runnable thread is about to be added to a scheduler run
86queue.
87Its first two arguments are the thread and corresponding process.
88The third argument is currently always
89.Dv NULL .
90The fourth argument is a boolean value that is non-zero if the thread is
91enqueued at the beginning of its run queue slot, and zero if the thread is
92instead enqueued at the end.
93.Pp
94The
95.Fn sched:::load-change
96probe fires after the load of a thread queue is adjusted.
97The first argument is the cpuid for the CPU associated with the thread queue,
98and the second argument is the adjusted load of the thread queue, i.e., the
99number of elements in the queue.
100.Pp
101The
102.Fn sched:::off-cpu
103probe is triggered by the scheduler suspending execution of the
104currently-running thread, and the
105.Fn sched:::on-cpu
106probe fires when the current thread has been selected to run on a CPU and is
107about to begin or resume execution.
108The arguments to
109.Fn sched:::off-cpu
110are the thread and corresponding process selected to run following the
111currently-running thread.
112If these two threads are the same, the
113.Fn sched:::remain-cpu
114probe will fire instead.
115.Pp
116The
117.Fn sched:::surrender
118probe fires when the scheduler is called upon to make a scheduling decision by
119a thread running on a different CPU, via an interprocessor interrupt.
120The arguments to this probe are the interrupted thread and its corresponding
121process.
122This probe currently always fires in the context of the interrupted thread.
123.Pp
124The
125.Fn sched:::preempt
126probe will fire immediately before the currently-running thread is preempted.
127When this occurs, the scheduler will select a new thread to run, and one of the
128.Fn sched:::off-cpu
129or
130.Fn sched:::remain-cpu
131probes will subsequently fire, depending on whether or not the scheduler selects
132the preempted thread.
133.Pp
134The
135.Fn sched:::sleep
136probe fires immediately before the currently-running thread is about to suspend
137execution and begin waiting for a condition to be met.
138The
139.Fn sched:::wakeup
140probe fires when a thread is set up to resume execution after having gone to
141sleep.
142Its arguments are the thread being awoken, and the corresponding process.
143.Pp
144The
145.Fn sched:::tick
146fires before each scheduler clock tick.
147Its arguments are the currently-running thread and its corresponding process.
148.Sh ARGUMENTS
149The
150.Nm sched
151provider probes use the kernel types
152.Vt "struct proc"
153and
154.Vt "struct thread"
155to represent processes and threads, respectively.
156These structures have many fields and are defined in
157.Pa sys/proc.h .
158In a probe body, the currently-running thread can always be obtained with the
159.Va curthread
160global variable, which has type
161.Vt "struct thread *" .
162For example, when a running thread is about to sleep, the
163.Fn sched:::sleep
164probe fires in the context of that thread, which can be accessed using
165.Va curthread .
166The
167.Va curcpu
168global variable contains the cpuid of the CPU on which the currently-running
169thread is executing.
170.Sh EXAMPLES
171The following script gives a breakdown of CPU utilization by process name:
172.Bd -literal -offset indent
173sched:::on-cpu
174{
175        self->ts = timestamp;
176}
177
178sched:::off-cpu
179/self->ts != 0/
180{
181        @[execname] = sum((timestamp - self->ts) / 1000);
182        self->ts = 0;
183}
184.Ed
185.Pp
186Here, DTrace stores a timestamp each time a thread is scheduled to run, and
187computes the time elapsed in microseconds when it is descheduled.
188The results are summed by process name.
189.Sh COMPATIBILITY
190This provider is not compatible with the
191.Nm sched
192provider found in Solaris.
193In particular, the probe argument types are native
194.Fx
195types, and the
196.Fn sched:::cpucaps-sleep ,
197.Fn sched:::cpucaps-wakeup ,
198.Fn sched:::schedctl-nopreempt ,
199.Fn sched:::schedctl-preempt ,
200and
201.Fn sched:::schedctl-yield
202probes are not available in
203.Fx .
204.Pp
205The
206.Fn sched:::lend-pri
207and
208.Fn sched:::load-change
209probes are specific to
210.Fx .
211.Sh SEE ALSO
212.Xr dtrace 1 ,
213.Xr sched_4bsd 4 ,
214.Xr sched_ule 4 ,
215.Xr SDT 9 ,
216.Xr sleepqueue 9
217.Sh HISTORY
218The
219.Nm sched
220provider first appeared in
221.Fx
2228.4 and 9.1.
223.Sh AUTHORS
224This manual page was written by
225.An Mark Johnston Aq Mt markj@FreeBSD.org .
226