xref: /freebsd/share/man/man9/devstat.9 (revision d282baddb0b029ca8466d23ac51e95c918442535)
1c61d88e0SJustin T. Gibbs.\"
22a888f93SKenneth D. Merry.\" Copyright (c) 1998, 1999 Kenneth D. Merry.
3c61d88e0SJustin T. Gibbs.\" All rights reserved.
4c61d88e0SJustin T. Gibbs.\"
5c61d88e0SJustin T. Gibbs.\" Redistribution and use in source and binary forms, with or without
6c61d88e0SJustin T. Gibbs.\" modification, are permitted provided that the following conditions
7c61d88e0SJustin T. Gibbs.\" are met:
8c61d88e0SJustin T. Gibbs.\" 1. Redistributions of source code must retain the above copyright
9c61d88e0SJustin T. Gibbs.\"    notice, this list of conditions and the following disclaimer.
10c61d88e0SJustin T. Gibbs.\" 2. Redistributions in binary form must reproduce the above copyright
11c61d88e0SJustin T. Gibbs.\"    notice, this list of conditions and the following disclaimer in the
12c61d88e0SJustin T. Gibbs.\"    documentation and/or other materials provided with the distribution.
13c61d88e0SJustin T. Gibbs.\" 3. The name of the author may not be used to endorse or promote products
14c61d88e0SJustin T. Gibbs.\"    derived from this software without specific prior written permission.
15c61d88e0SJustin T. Gibbs.\"
16c61d88e0SJustin T. Gibbs.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17c61d88e0SJustin T. Gibbs.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18c61d88e0SJustin T. Gibbs.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19c61d88e0SJustin T. Gibbs.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20c61d88e0SJustin T. Gibbs.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21c61d88e0SJustin T. Gibbs.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22c61d88e0SJustin T. Gibbs.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23c61d88e0SJustin T. Gibbs.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24c61d88e0SJustin T. Gibbs.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25c61d88e0SJustin T. Gibbs.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26c61d88e0SJustin T. Gibbs.\" SUCH DAMAGE.
27c61d88e0SJustin T. Gibbs.\"
28d8fd37e1SGordon Bergling.Dd July 15, 2020
29c61d88e0SJustin T. Gibbs.Dt DEVSTAT 9
303d45e180SRuslan Ermilov.Os
31c61d88e0SJustin T. Gibbs.Sh NAME
32fe27e01fSAlexey Zelkin.Nm devstat ,
330dc03e01SAlexey Zelkin.Nm devstat_end_transaction ,
34b1f2329cSBruce Evans.Nm devstat_end_transaction_bio ,
35b6c7d9c3SConrad Meyer.Nm devstat_end_transaction_bio_bt ,
36d8fd37e1SGordon Bergling.Nm devstat_new_entry ,
37fe27e01fSAlexey Zelkin.Nm devstat_remove_entry ,
38b6c7d9c3SConrad Meyer.Nm devstat_start_transaction ,
39b6c7d9c3SConrad Meyer.Nm devstat_start_transaction_bio
40c61d88e0SJustin T. Gibbs.Nd kernel interface for keeping device statistics
41c61d88e0SJustin T. Gibbs.Sh SYNOPSIS
4232eef9aeSRuslan Ermilov.In sys/devicestat.h
43d8fd37e1SGordon Bergling.Ft struct devstat *
44d8fd37e1SGordon Bergling.Fo devstat_new_entry
45d8fd37e1SGordon Bergling.Fa "const void *dev_name"
46c61d88e0SJustin T. Gibbs.Fa "int unit_number"
476b99842aSEd Schouten.Fa "uint32_t block_size"
48c61d88e0SJustin T. Gibbs.Fa "devstat_support_flags flags"
49c61d88e0SJustin T. Gibbs.Fa "devstat_type_flags device_type"
502a888f93SKenneth D. Merry.Fa "devstat_priority priority"
51c61d88e0SJustin T. Gibbs.Fc
52c61d88e0SJustin T. Gibbs.Ft void
53c61d88e0SJustin T. Gibbs.Fn devstat_remove_entry "struct devstat *ds"
54c61d88e0SJustin T. Gibbs.Ft void
55b6c7d9c3SConrad Meyer.Fo devstat_start_transaction
56b6c7d9c3SConrad Meyer.Fa "struct devstat *ds"
57b6c7d9c3SConrad Meyer.Fa "const struct bintime *now"
58b6c7d9c3SConrad Meyer.Fc
59b6c7d9c3SConrad Meyer.Ft void
60b6c7d9c3SConrad Meyer.Fo devstat_start_transaction_bio
61b6c7d9c3SConrad Meyer.Fa "struct devstat *ds"
62b6c7d9c3SConrad Meyer.Fa "struct bio *bp"
63b6c7d9c3SConrad Meyer.Fc
64c61d88e0SJustin T. Gibbs.Ft void
65c61d88e0SJustin T. Gibbs.Fo devstat_end_transaction
66c61d88e0SJustin T. Gibbs.Fa "struct devstat *ds"
676b99842aSEd Schouten.Fa "uint32_t bytes"
68c61d88e0SJustin T. Gibbs.Fa "devstat_tag_type tag_type"
69c61d88e0SJustin T. Gibbs.Fa "devstat_trans_flags flags"
70b6c7d9c3SConrad Meyer.Fa "const struct bintime *now"
71b6c7d9c3SConrad Meyer.Fa "const struct bintime *then"
72c61d88e0SJustin T. Gibbs.Fc
73bd9e52dcSPoul-Henning Kamp.Ft void
74b1f2329cSBruce Evans.Fo devstat_end_transaction_bio
75bd9e52dcSPoul-Henning Kamp.Fa "struct devstat *ds"
76b6c7d9c3SConrad Meyer.Fa "const struct bio *bp"
77b6c7d9c3SConrad Meyer.Fc
78b6c7d9c3SConrad Meyer.Ft void
79b6c7d9c3SConrad Meyer.Fo devstat_end_transaction_bio_bt
80b6c7d9c3SConrad Meyer.Fa "struct devstat *ds"
81b6c7d9c3SConrad Meyer.Fa "const struct bio *bp"
82b6c7d9c3SConrad Meyer.Fa "const struct bintime *now"
83bd9e52dcSPoul-Henning Kamp.Fc
84c61d88e0SJustin T. Gibbs.Sh DESCRIPTION
852a888f93SKenneth D. MerryThe devstat subsystem is an interface for recording device
86a0942a60SHiten Pandyastatistics, as its name implies.
87a0942a60SHiten PandyaThe idea is to keep reasonably detailed
88c61d88e0SJustin T. Gibbsstatistics while utilizing a minimum amount of CPU time to record them.
89c61d88e0SJustin T. GibbsThus, no statistical calculations are actually performed in the kernel
90c61d88e0SJustin T. Gibbsportion of the
914b66483fSRuslan Ermilov.Nm
925203edcdSRuslan Ermilovcode.
935203edcdSRuslan ErmilovInstead, that is left for user programs to handle.
94c61d88e0SJustin T. Gibbs.Pp
95b6c7d9c3SConrad MeyerThe historical and antiquated
96b6c7d9c3SConrad Meyer.Nm
97b6c7d9c3SConrad Meyermodel assumed a single active IO operation per device, which is not accurate
98b6c7d9c3SConrad Meyerfor most disk-like drivers in the 2000s and beyond.
99b6c7d9c3SConrad MeyerNew consumers of the interface should almost certainly use only the "bio"
100b6c7d9c3SConrad Meyervariants of the start and end transacation routines.
101b6c7d9c3SConrad Meyer.Pp
102d8fd37e1SGordon Bergling.Fn devstat_new_entry
103d8fd37e1SGordon Berglingallocates and initializes
104d8fd37e1SGordon Bergling.Va devstat
105d8fd37e1SGordon Berglingstructure and returns a pointer to it.
106d8fd37e1SGordon Bergling.Fn devstat_new_entry
107c61d88e0SJustin T. Gibbstakes several arguments:
108c61d88e0SJustin T. Gibbs.Bl -tag -width device_type
109c61d88e0SJustin T. Gibbs.It dev_name
110b6c7d9c3SConrad MeyerThe device name, e.g., da, cd, sa.
111c61d88e0SJustin T. Gibbs.It unit_number
112c61d88e0SJustin T. GibbsDevice unit number.
113c61d88e0SJustin T. Gibbs.It block_size
114a0942a60SHiten PandyaBlock size of the device, if supported.
115a0942a60SHiten PandyaIf the device does not support a
116c61d88e0SJustin T. Gibbsblock size, or if the blocksize is unknown at the time the device is added
117c61d88e0SJustin T. Gibbsto the
118c61d88e0SJustin T. Gibbs.Nm
119c61d88e0SJustin T. Gibbslist, it should be set to 0.
120c61d88e0SJustin T. Gibbs.It flags
121a0942a60SHiten PandyaFlags indicating operations supported or not supported by the device.
122a0942a60SHiten PandyaSee below for details.
123c61d88e0SJustin T. Gibbs.It device_type
124a0942a60SHiten PandyaThe device type.
125a0942a60SHiten PandyaThis is broken into three sections: base device type
126b6c7d9c3SConrad Meyer(e.g., direct access, CDROM, sequential access), interface type (IDE, SCSI
127a0942a60SHiten Pandyaor other) and a pass-through flag to indicate pas-through devices.
128a0942a60SHiten PandyaSee below for a complete list of types.
1292a888f93SKenneth D. Merry.It priority
130a0942a60SHiten PandyaThe device priority.
131a0942a60SHiten PandyaThe priority is used to determine how devices are
1322a888f93SKenneth D. Merrysorted within
1334b66483fSRuslan Ermilov.Nm devstat Ns 's
134a0942a60SHiten Pandyalist of devices.
135a0942a60SHiten PandyaDevices are sorted first by priority (highest to lowest),
136a0942a60SHiten Pandyaand then by attach order.
137a0942a60SHiten PandyaSee below for a complete list of available
1382a888f93SKenneth D. Merrypriorities.
139c61d88e0SJustin T. Gibbs.El
140c61d88e0SJustin T. Gibbs.Pp
141c61d88e0SJustin T. Gibbs.Fn devstat_remove_entry
142c61d88e0SJustin T. Gibbsremoves a device from the
143c61d88e0SJustin T. Gibbs.Nm
144a0942a60SHiten Pandyasubsystem.
145a0942a60SHiten PandyaIt takes the devstat structure for the device in question as
146a0942a60SHiten Pandyaan argument.
147a0942a60SHiten PandyaThe
148c61d88e0SJustin T. Gibbs.Nm
149c61d88e0SJustin T. Gibbsgeneration number is incremented and the number of devices is decremented.
150c61d88e0SJustin T. Gibbs.Pp
151c61d88e0SJustin T. Gibbs.Fn devstat_start_transaction
152c61d88e0SJustin T. Gibbsregisters the start of a transaction with the
153c61d88e0SJustin T. Gibbs.Nm
154a0942a60SHiten Pandyasubsystem.
155b6c7d9c3SConrad MeyerOptionally, if the caller already has a
156b6c7d9c3SConrad Meyer.Fn binuptime
157b6c7d9c3SConrad Meyervalue available, it may be passed in
158b6c7d9c3SConrad Meyer.Fa *now .
159b6c7d9c3SConrad MeyerUsually the caller can just pass
160b6c7d9c3SConrad Meyer.Dv NULL
161b6c7d9c3SConrad Meyerfor
162b6c7d9c3SConrad Meyer.Fa now ,
163b6c7d9c3SConrad Meyerand the routine will gather the current
164b6c7d9c3SConrad Meyer.Fn binuptime
165b6c7d9c3SConrad Meyeritself.
166a0942a60SHiten PandyaThe busy count is incremented with each transaction start.
167c61d88e0SJustin T. GibbsWhen a device goes from idle to busy, the system uptime is recorded in the
168b6c7d9c3SConrad Meyer.Va busy_from
169c61d88e0SJustin T. Gibbsfield of the
170c61d88e0SJustin T. Gibbs.Va devstat
171c61d88e0SJustin T. Gibbsstructure.
172c61d88e0SJustin T. Gibbs.Pp
173b6c7d9c3SConrad Meyer.Fn devstat_start_transaction_bio
174b6c7d9c3SConrad Meyerrecords the
175b6c7d9c3SConrad Meyer.Fn binuptime
176b6c7d9c3SConrad Meyerin the provided bio's
177b6c7d9c3SConrad Meyer.Fa bio_t0
178b6c7d9c3SConrad Meyerand then invokes
179b6c7d9c3SConrad Meyer.Fn devstat_start_transaction .
180b6c7d9c3SConrad Meyer.Pp
181c61d88e0SJustin T. Gibbs.Fn devstat_end_transaction
182c61d88e0SJustin T. Gibbsregisters the end of a transaction with the
183c61d88e0SJustin T. Gibbs.Nm
184a0942a60SHiten Pandyasubsystem.
185b6c7d9c3SConrad MeyerIt takes six arguments:
186c61d88e0SJustin T. Gibbs.Bl -tag -width tag_type
187c61d88e0SJustin T. Gibbs.It ds
188c61d88e0SJustin T. GibbsThe
189c61d88e0SJustin T. Gibbs.Va devstat
190c61d88e0SJustin T. Gibbsstructure for the device in question.
191c61d88e0SJustin T. Gibbs.It bytes
192c61d88e0SJustin T. GibbsThe number of bytes transferred in this transaction.
193c61d88e0SJustin T. Gibbs.It tag_type
194a0942a60SHiten PandyaTransaction tag type.
195a0942a60SHiten PandyaSee below for tag types.
196c61d88e0SJustin T. Gibbs.It flags
197c61d88e0SJustin T. GibbsTransaction flags indicating whether the transaction was a read, write, or
198c61d88e0SJustin T. Gibbswhether no data was transferred.
199b6c7d9c3SConrad Meyer.It now
200b6c7d9c3SConrad MeyerThe
201b6c7d9c3SConrad Meyer.Fn binuptime
202b6c7d9c3SConrad Meyerat the end of the transaction, or
203b6c7d9c3SConrad Meyer.Dv NULL .
204b6c7d9c3SConrad Meyer.It then
205b6c7d9c3SConrad MeyerThe
206b6c7d9c3SConrad Meyer.Fn binuptime
207b6c7d9c3SConrad Meyerat the beginning of the transaction, or
208b6c7d9c3SConrad Meyer.Dv NULL .
209c61d88e0SJustin T. Gibbs.El
210c61d88e0SJustin T. Gibbs.Pp
211b6c7d9c3SConrad MeyerIf
212b6c7d9c3SConrad Meyer.Fa now
213b6c7d9c3SConrad Meyeris
214b6c7d9c3SConrad Meyer.Dv NULL ,
215b6c7d9c3SConrad Meyerit collects the current time from
216b6c7d9c3SConrad Meyer.Fn binuptime .
217b6c7d9c3SConrad MeyerIf
218b6c7d9c3SConrad Meyer.Fa then
219b6c7d9c3SConrad Meyeris
220b6c7d9c3SConrad Meyer.Dv NULL ,
221b6c7d9c3SConrad Meyerthe operation is not tracked in the
222b6c7d9c3SConrad Meyer.Va devstat
223b6c7d9c3SConrad Meyer.Fa duration
224b6c7d9c3SConrad Meyertable.
225b6c7d9c3SConrad Meyer.Pp
226b1f2329cSBruce Evans.Fn devstat_end_transaction_bio
227b6c7d9c3SConrad Meyeris a thin wrapper for
228b6c7d9c3SConrad Meyer.Fn devstat_end_transaction_bio_bt
229b6c7d9c3SConrad Meyerwith a
230b6c7d9c3SConrad Meyer.Dv NULL
231b6c7d9c3SConrad Meyer.Fa now
232b6c7d9c3SConrad Meyerparameter.
233b6c7d9c3SConrad Meyer.Pp
234b6c7d9c3SConrad Meyer.Fn devstat_end_transaction_bio_bt
235bd9e52dcSPoul-Henning Kampis a wrapper for
236bd9e52dcSPoul-Henning Kamp.Fn devstat_end_transaction
237b6c7d9c3SConrad Meyerwhich pulls all needed information from a
238b1f2329cSBruce Evans.Va "struct bio"
239b6c7d9c3SConrad Meyerprepared by
240b6c7d9c3SConrad Meyer.Fn devstat_start_transaction_bio .
241b6c7d9c3SConrad MeyerThe bio must be ready for
242b6c7d9c3SConrad Meyer.Fn biodone
243b6c7d9c3SConrad Meyer(i.e.,
244b6c7d9c3SConrad Meyer.Fa bio_bcount
245b6c7d9c3SConrad Meyerand
246b6c7d9c3SConrad Meyer.Fa bio_resid
247b6c7d9c3SConrad Meyermust be correctly initialized).
248bd9e52dcSPoul-Henning Kamp.Pp
249c61d88e0SJustin T. GibbsThe
250c61d88e0SJustin T. Gibbs.Va devstat
251c61d88e0SJustin T. Gibbsstructure is composed of the following fields:
252c61d88e0SJustin T. Gibbs.Bl -tag -width dev_creation_time
253b6c7d9c3SConrad Meyer.It sequence0 ,
254b6c7d9c3SConrad Meyer.It sequence1
255b6c7d9c3SConrad MeyerAn implementation detail used to gather consistent snapshots of device
256b6c7d9c3SConrad Meyerstatistics.
257b6c7d9c3SConrad Meyer.It start_count
258b6c7d9c3SConrad MeyerNumber of operations started.
259b6c7d9c3SConrad Meyer.It end_count
260b6c7d9c3SConrad MeyerNumber of operations completed.
261b6c7d9c3SConrad MeyerThe
262b6c7d9c3SConrad Meyer.Dq busy_count
263b6c7d9c3SConrad Meyercan be calculated by subtracting
264b6c7d9c3SConrad Meyer.Fa end_count
265b6c7d9c3SConrad Meyerfrom
266b6c7d9c3SConrad Meyer.Fa start_count .
267b6c7d9c3SConrad Meyer.Fa ( sequence0
268b6c7d9c3SConrad Meyerand
269b6c7d9c3SConrad Meyer.Fa sequence1
270b6c7d9c3SConrad Meyerare used to get a consistent snapshot.)
271b6c7d9c3SConrad MeyerThis is the current number of outstanding transactions for the device.
272b6c7d9c3SConrad MeyerThis should never go below zero, and on an idle device it should be zero.
273b6c7d9c3SConrad MeyerIf either one of these conditions is not true, it indicates a problem.
274b6c7d9c3SConrad Meyer.Pp
275b6c7d9c3SConrad MeyerThere should be one and only one
276b6c7d9c3SConrad Meyertransaction start event and one transaction end event for each transaction.
277c61d88e0SJustin T. Gibbs.It dev_links
278c61d88e0SJustin T. GibbsEach
279c61d88e0SJustin T. Gibbs.Va devstat
280a0942a60SHiten Pandyastructure is placed in a linked list when it is registered.
281a0942a60SHiten PandyaThe
282c61d88e0SJustin T. Gibbs.Va dev_links
283c61d88e0SJustin T. Gibbsfield contains a pointer to the next entry in the list of
284c61d88e0SJustin T. Gibbs.Va devstat
285c61d88e0SJustin T. Gibbsstructures.
286c61d88e0SJustin T. Gibbs.It device_number
287a0942a60SHiten PandyaThe device number is a unique identifier for each device.
288a0942a60SHiten PandyaThe device
289a0942a60SHiten Pandyanumber is incremented for each new device that is registered.
290a0942a60SHiten PandyaThe device
291c61d88e0SJustin T. Gibbsnumber is currently only a 32-bit integer, but it could be enlarged if
292c61d88e0SJustin T. Gibbssomeone has a system with more than four billion device arrival events.
293c61d88e0SJustin T. Gibbs.It device_name
294c61d88e0SJustin T. GibbsThe device name is a text string given by the registering driver to
295a0942a60SHiten Pandyaidentify itself.
296b6c7d9c3SConrad Meyer(e.g.,
297c61d88e0SJustin T. Gibbs.Dq da ,
298c61d88e0SJustin T. Gibbs.Dq cd ,
299c61d88e0SJustin T. Gibbs.Dq sa ,
300c61d88e0SJustin T. Gibbsetc.)
301c61d88e0SJustin T. Gibbs.It unit_number
302c61d88e0SJustin T. GibbsThe unit number identifies the particular instance of the peripheral driver
303c61d88e0SJustin T. Gibbsin question.
304b6c7d9c3SConrad Meyer.It bytes[4]
305b6c7d9c3SConrad MeyerThis array contains the number of bytes that have been read (index
306b6c7d9c3SConrad Meyer.Dv DEVSTAT_READ ) ,
307b6c7d9c3SConrad Meyerwritten (index
308b6c7d9c3SConrad Meyer.Dv DEVSTAT_WRITE ) ,
309b6c7d9c3SConrad Meyerfreed or erased (index
310b6c7d9c3SConrad Meyer.Dv DEVSTAT_FREE ) ,
311b6c7d9c3SConrad Meyeror other (index
312b6c7d9c3SConrad Meyer.Dv DEVSTAT_NO_DATA ) .
313b6c7d9c3SConrad MeyerAll values are unsigned 64-bit integers.
314b6c7d9c3SConrad Meyer.It operations[4]
315b6c7d9c3SConrad MeyerThis array contains the number of operations of a given type that have been
316b6c7d9c3SConrad Meyerperformed.
317b6c7d9c3SConrad MeyerThe indices are identical to those for
318b6c7d9c3SConrad Meyer.Fa bytes
319b6c7d9c3SConrad Meyerabove.
320b6c7d9c3SConrad Meyer.Dv DEVSTAT_NO_DATA
321b6c7d9c3SConrad Meyeror "other" represents the number of transactions to the device which are
322b6c7d9c3SConrad Meyerneither reads, writes, nor frees.
323a0942a60SHiten PandyaFor instance,
324c61d88e0SJustin T. Gibbs.Tn SCSI
325c61d88e0SJustin T. Gibbsdrivers often send a test unit ready command to
326c61d88e0SJustin T. Gibbs.Tn SCSI
327a0942a60SHiten Pandyadevices.
328a0942a60SHiten PandyaThe test unit ready command does not read or write any data.
329a0942a60SHiten PandyaIt merely causes the device to return its status.
330b6c7d9c3SConrad Meyer.It duration[4]
331b6c7d9c3SConrad MeyerThis array contains the total bintime corresponding to completed operations of
332b6c7d9c3SConrad Meyera given type.
333b6c7d9c3SConrad MeyerThe indices are identical to those for
334b6c7d9c3SConrad Meyer.Fa bytes
335b6c7d9c3SConrad Meyerabove.
336b6c7d9c3SConrad Meyer(Operations that complete using the historical
337c61d88e0SJustin T. Gibbs.Fn devstat_end_transaction
338b6c7d9c3SConrad MeyerAPI and do not provide a non-NULL
339b6c7d9c3SConrad Meyer.Fa then
340b6c7d9c3SConrad Meyerare not accounted for.)
341b6c7d9c3SConrad Meyer.It busy_time
342b6c7d9c3SConrad MeyerThis is the amount of time that the device busy count has been greater than
343b6c7d9c3SConrad Meyerzero.
344b6c7d9c3SConrad MeyerThis is only updated when the busy count returns to zero.
345b6c7d9c3SConrad Meyer.It creation_time
346b6c7d9c3SConrad MeyerThis is the time, as reported by
347b6c7d9c3SConrad Meyer.Fn getmicrotime
348b6c7d9c3SConrad Meyerthat the device was registered.
349c61d88e0SJustin T. Gibbs.It block_size
350c61d88e0SJustin T. GibbsThis is the block size of the device, if the device has a block size.
351c61d88e0SJustin T. Gibbs.It tag_types
352c61d88e0SJustin T. GibbsThis is an array of counters to record the number of various tag types that
353a0942a60SHiten Pandyaare sent to a device.
354a0942a60SHiten PandyaSee below for a list of tag types.
355b6c7d9c3SConrad Meyer.It busy_from
356b6c7d9c3SConrad MeyerIf the device is not busy, this was the time that a transaction last completed.
357b6c7d9c3SConrad MeyerIf the device is busy, this the most recent of either the time that the device
358b6c7d9c3SConrad Meyerbecame busy, or the time that the last transaction completed.
359c61d88e0SJustin T. Gibbs.It flags
360c61d88e0SJustin T. GibbsThese flags indicate which statistics measurements are supported by a
361a0942a60SHiten Pandyaparticular device.
362a0942a60SHiten PandyaThese flags are primarily intended to serve as an aid
363c61d88e0SJustin T. Gibbsto userland programs that decipher the statistics.
364c61d88e0SJustin T. Gibbs.It device_type
365a0942a60SHiten PandyaThis is the device type.
366a0942a60SHiten PandyaIt consists of three parts: the device type
367b6c7d9c3SConrad Meyer(e.g., direct access, CDROM, sequential access, etc.), the interface (IDE,
368b82af3f5SMike PritchardSCSI or other) and whether or not the device in question is a pass-through
369a0942a60SHiten Pandyadriver.
370a0942a60SHiten PandyaSee below for a complete list of device types.
3712a888f93SKenneth D. Merry.It priority
372a0942a60SHiten PandyaThis is the priority.
373a0942a60SHiten PandyaThis is the first parameter used to determine where
3742a888f93SKenneth D. Merryto insert a device in the
3754b66483fSRuslan Ermilov.Nm
376a0942a60SHiten Pandyalist.
377a0942a60SHiten PandyaThe second parameter is attach order.
378b6c7d9c3SConrad MeyerSee below for a list of available priorities.
379d8fd37e1SGordon Bergling.It id
380d8fd37e1SGordon BerglingIdentification for GEOM nodes.
381c61d88e0SJustin T. Gibbs.El
382c61d88e0SJustin T. Gibbs.Pp
383a0942a60SHiten PandyaEach device is given a device type.
384b6c7d9c3SConrad MeyerPass-through devices have the same underlying device type and interface as the
385b6c7d9c3SConrad Meyerdevice they provide an interface for, but they also have the pass-through flag
386b6c7d9c3SConrad Meyerset.
387b6c7d9c3SConrad MeyerThe base device types are identical to the
388c61d88e0SJustin T. Gibbs.Tn SCSI
389c61d88e0SJustin T. Gibbsdevice type numbers, so with
390c61d88e0SJustin T. Gibbs.Tn SCSI
391b6c7d9c3SConrad Meyerperipherals, the device type returned from an inquiry is usually ORed with the
392c61d88e0SJustin T. Gibbs.Tn SCSI
393a0942a60SHiten Pandyainterface type and the pass-through flag if appropriate.
394a0942a60SHiten PandyaThe device type
395c61d88e0SJustin T. Gibbsflags are as follows:
396c61d88e0SJustin T. Gibbs.Bd -literal -offset indent
397c61d88e0SJustin T. Gibbstypedef enum {
398c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_DIRECT	= 0x000,
399c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_SEQUENTIAL	= 0x001,
400c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_PRINTER	= 0x002,
401c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_PROCESSOR	= 0x003,
402c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_WORM	= 0x004,
403c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_CDROM	= 0x005,
404c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_SCANNER	= 0x006,
405c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_OPTICAL	= 0x007,
406c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_CHANGER	= 0x008,
407c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_COMM	= 0x009,
408c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_ASC0	= 0x00a,
409c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_ASC1	= 0x00b,
410c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_STORARRAY	= 0x00c,
411c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_ENCLOSURE	= 0x00d,
412c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_FLOPPY	= 0x00e,
413c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_MASK	= 0x00f,
414c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_IF_SCSI	= 0x010,
415c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_IF_IDE	= 0x020,
416c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_IF_OTHER	= 0x030,
417*d282baddSAlexander Motin	DEVSTAT_TYPE_IF_NVME	= 0x040,
418c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_IF_MASK	= 0x0f0,
419c61d88e0SJustin T. Gibbs	DEVSTAT_TYPE_PASS	= 0x100
420c61d88e0SJustin T. Gibbs} devstat_type_flags;
421c61d88e0SJustin T. Gibbs.Ed
422c61d88e0SJustin T. Gibbs.Pp
4232a888f93SKenneth D. MerryDevices have a priority associated with them, which controls roughly where
4242a888f93SKenneth D. Merrythey are placed in the
4254b66483fSRuslan Ermilov.Nm
426a0942a60SHiten Pandyalist.
427a0942a60SHiten PandyaThe priorities are as follows:
4282a888f93SKenneth D. Merry.Bd -literal -offset indent
4292a888f93SKenneth D. Merrytypedef enum {
4302a888f93SKenneth D. Merry	DEVSTAT_PRIORITY_MIN	= 0x000,
4312a888f93SKenneth D. Merry	DEVSTAT_PRIORITY_OTHER	= 0x020,
4322a888f93SKenneth D. Merry	DEVSTAT_PRIORITY_PASS	= 0x030,
4332a888f93SKenneth D. Merry	DEVSTAT_PRIORITY_FD	= 0x040,
4342a888f93SKenneth D. Merry	DEVSTAT_PRIORITY_WFD	= 0x050,
43586b2c846SKenneth D. Merry	DEVSTAT_PRIORITY_TAPE	= 0x060,
4362a888f93SKenneth D. Merry	DEVSTAT_PRIORITY_CD	= 0x090,
43786b2c846SKenneth D. Merry	DEVSTAT_PRIORITY_DISK	= 0x110,
43886b2c846SKenneth D. Merry	DEVSTAT_PRIORITY_ARRAY	= 0x120,
4392a888f93SKenneth D. Merry	DEVSTAT_PRIORITY_MAX	= 0xfff
4402a888f93SKenneth D. Merry} devstat_priority;
4412a888f93SKenneth D. Merry.Ed
4422a888f93SKenneth D. Merry.Pp
443c61d88e0SJustin T. GibbsEach device has associated with it flags to indicate what operations are
444a0942a60SHiten Pandyasupported or not supported.
445a0942a60SHiten PandyaThe
446c61d88e0SJustin T. Gibbs.Va devstat_support_flags
447c61d88e0SJustin T. Gibbsvalues are as follows:
448c61d88e0SJustin T. Gibbs.Bl -tag -width DEVSTAT_NO_ORDERED_TAGS
449c61d88e0SJustin T. Gibbs.It DEVSTAT_ALL_SUPPORTED
450c61d88e0SJustin T. GibbsEvery statistic type is supported by the device.
451c61d88e0SJustin T. Gibbs.It DEVSTAT_NO_BLOCKSIZE
452c61d88e0SJustin T. GibbsThis device does not have a blocksize.
453c61d88e0SJustin T. Gibbs.It DEVSTAT_NO_ORDERED_TAGS
454c61d88e0SJustin T. GibbsThis device does not support ordered tags.
455c61d88e0SJustin T. Gibbs.It DEVSTAT_BS_UNAVAILABLE
456a0942a60SHiten PandyaThis device supports a blocksize, but it is currently unavailable.
457a0942a60SHiten PandyaThis
458c61d88e0SJustin T. Gibbsflag is most often used with removable media drives.
459c61d88e0SJustin T. Gibbs.El
460c61d88e0SJustin T. Gibbs.Pp
461c61d88e0SJustin T. GibbsTransactions to a device fall into one of three categories, which are
462c61d88e0SJustin T. Gibbsrepresented in the
463c61d88e0SJustin T. Gibbs.Va flags
464c61d88e0SJustin T. Gibbspassed into
465c61d88e0SJustin T. Gibbs.Fn devstat_end_transaction .
466c61d88e0SJustin T. GibbsThe transaction types are as follows:
467c61d88e0SJustin T. Gibbs.Bd -literal -offset indent
468c61d88e0SJustin T. Gibbstypedef enum {
469c61d88e0SJustin T. Gibbs	DEVSTAT_NO_DATA	= 0x00,
470c61d88e0SJustin T. Gibbs	DEVSTAT_READ	= 0x01,
47104a22538SPoul-Henning Kamp	DEVSTAT_WRITE	= 0x02,
47204a22538SPoul-Henning Kamp	DEVSTAT_FREE	= 0x03
473c61d88e0SJustin T. Gibbs} devstat_trans_flags;
474d8fd37e1SGordon Bergling#define DEVSTAT_N_TRANS_FLAGS   4
475c61d88e0SJustin T. Gibbs.Ed
476c61d88e0SJustin T. Gibbs.Pp
477d8fd37e1SGordon BerglingDEVSTAT_NO_DATA is a type of transactions to the device which are neither
478d8fd37e1SGordon Berglingreads or writes.
479d8fd37e1SGordon BerglingFor instance,
480d8fd37e1SGordon Bergling.Tn SCSI
481d8fd37e1SGordon Berglingdrivers often send a test unit ready command to
482d8fd37e1SGordon Bergling.Tn SCSI
483d8fd37e1SGordon Berglingdevices.
484d8fd37e1SGordon BerglingThe test unit ready command does not read or write any data.
485d8fd37e1SGordon BerglingIt merely causes the device to return its status.
486d8fd37e1SGordon Bergling.Pp
487c61d88e0SJustin T. GibbsThere are four possible values for the
488c61d88e0SJustin T. Gibbs.Va tag_type
489c61d88e0SJustin T. Gibbsargument to
490c61d88e0SJustin T. Gibbs.Fn devstat_end_transaction :
491c61d88e0SJustin T. Gibbs.Bl -tag -width DEVSTAT_TAG_ORDERED
492c61d88e0SJustin T. Gibbs.It DEVSTAT_TAG_SIMPLE
493c61d88e0SJustin T. GibbsThe transaction had a simple tag.
494c61d88e0SJustin T. Gibbs.It DEVSTAT_TAG_HEAD
495c61d88e0SJustin T. GibbsThe transaction had a head of queue tag.
496c61d88e0SJustin T. Gibbs.It DEVSTAT_TAG_ORDERED
497c61d88e0SJustin T. GibbsThe transaction had an ordered tag.
498c61d88e0SJustin T. Gibbs.It DEVSTAT_TAG_NONE
4990227791bSRuslan ErmilovThe device does not support tags.
500c61d88e0SJustin T. Gibbs.El
501c61d88e0SJustin T. Gibbs.Pp
502c61d88e0SJustin T. GibbsThe tag type values correspond to the lower four bits of the
503c61d88e0SJustin T. Gibbs.Tn SCSI
504a0942a60SHiten Pandyatag definitions.
505a0942a60SHiten PandyaIn CAM, for instance, the
506c61d88e0SJustin T. Gibbs.Va tag_action
507c61d88e0SJustin T. Gibbsfrom the CCB is ORed with 0xf to determine the tag type to pass in to
508c61d88e0SJustin T. Gibbs.Fn devstat_end_transaction .
509c61d88e0SJustin T. Gibbs.Pp
510c61d88e0SJustin T. GibbsThere is a macro,
511c61d88e0SJustin T. Gibbs.Dv DEVSTAT_VERSION
512c61d88e0SJustin T. Gibbsthat is defined in
513743d5d51SRuslan Ermilov.In sys/devicestat.h .
514c61d88e0SJustin T. GibbsThis is the current version of the
515c61d88e0SJustin T. Gibbs.Nm
516c61d88e0SJustin T. Gibbssubsystem, and it should be incremented each time a change is made that
517c61d88e0SJustin T. Gibbswould require recompilation of userland programs that access
518c61d88e0SJustin T. Gibbs.Nm
519a0942a60SHiten Pandyastatistics.
520a0942a60SHiten PandyaUserland programs use this version, via the
521c61d88e0SJustin T. Gibbs.Va kern.devstat.version
522c61d88e0SJustin T. Gibbs.Nm sysctl
523c61d88e0SJustin T. Gibbsvariable to determine whether they are in sync with the kernel
524c61d88e0SJustin T. Gibbs.Nm
525c61d88e0SJustin T. Gibbsstructures.
526c61d88e0SJustin T. Gibbs.Sh SEE ALSO
527c61d88e0SJustin T. Gibbs.Xr systat 1 ,
528c61d88e0SJustin T. Gibbs.Xr devstat 3 ,
529c61d88e0SJustin T. Gibbs.Xr iostat 8 ,
530c61d88e0SJustin T. Gibbs.Xr rpc.rstatd 8 ,
531c61d88e0SJustin T. Gibbs.Xr vmstat 8
532c61d88e0SJustin T. Gibbs.Sh HISTORY
533c61d88e0SJustin T. GibbsThe
534c61d88e0SJustin T. Gibbs.Nm
535c61d88e0SJustin T. Gibbsstatistics system appeared in
536c61d88e0SJustin T. Gibbs.Fx 3.0 .
537c61d88e0SJustin T. Gibbs.Sh AUTHORS
5388a7314fcSBaptiste Daroussin.An Kenneth Merry Aq Mt ken@FreeBSD.org
539c61d88e0SJustin T. Gibbs.Sh BUGS
540c61d88e0SJustin T. GibbsThere may be a need for
541c61d88e0SJustin T. Gibbs.Fn spl
542c61d88e0SJustin T. Gibbsprotection around some of the
543c61d88e0SJustin T. Gibbs.Nm
544e7f8dd75SRebecca Cranlist manipulation code to ensure, for example, that the list of devices
545c61d88e0SJustin T. Gibbsis not changed while someone is fetching the
546c61d88e0SJustin T. Gibbs.Va kern.devstat.all
547c61d88e0SJustin T. Gibbs.Nm sysctl
548c61d88e0SJustin T. Gibbsvariable.
549