devicestat.h revision 256603
1272234Sgjb/*-
2272234Sgjb * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
3278505Sgjb * All rights reserved.
4272234Sgjb *
5272234Sgjb * Redistribution and use in source and binary forms, with or without
6272234Sgjb * modification, are permitted provided that the following conditions
7272234Sgjb * are met:
8272234Sgjb * 1. Redistributions of source code must retain the above copyright
9272234Sgjb *    notice, this list of conditions and the following disclaimer.
10272234Sgjb * 2. Redistributions in binary form must reproduce the above copyright
11272234Sgjb *    notice, this list of conditions and the following disclaimer in the
12272234Sgjb *    documentation and/or other materials provided with the distribution.
13272234Sgjb * 3. The name of the author may not be used to endorse or promote products
14272234Sgjb *    derived from this software without specific prior written permission.
15272234Sgjb *
16272234Sgjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17272234Sgjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18272234Sgjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19272234Sgjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20272234Sgjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21272234Sgjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22272234Sgjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23272234Sgjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24272234Sgjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25272234Sgjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26272234Sgjb * SUCH DAMAGE.
27272234Sgjb *
28272234Sgjb * $FreeBSD: head/sys/sys/devicestat.h 256603 2013-10-16 09:12:40Z mav $
29272234Sgjb */
30272234Sgjb
31272234Sgjb#ifndef _DEVICESTAT_H
32272234Sgjb#define _DEVICESTAT_H
33272234Sgjb
34272234Sgjb#include <sys/queue.h>
35277458Sgjb#include <sys/time.h>
36277458Sgjb
37277458Sgjb/*
38277458Sgjb * XXX: Should really be SPECNAMELEN
39277458Sgjb */
40277458Sgjb#define DEVSTAT_NAME_LEN  16
41274134Sgjb
42274134Sgjb/*
43278502Sgjb * device name for the mmap device
44274134Sgjb */
45274134Sgjb#define DEVSTAT_DEVICE_NAME "devstat"
46274134Sgjb
47274134Sgjb/*
48274134Sgjb * ATTENTION:  The devstat version below should be incremented any time a
49274134Sgjb * change is made in struct devstat, or any time a change is made in the
50274134Sgjb * enumerated types that struct devstat uses.  (Only if those changes
51274134Sgjb * would require a recompile -- i.e. re-arranging the order of an
52274134Sgjb * enumerated type or something like that.)  This version number is used by
53274134Sgjb * userland utilities to determine whether or not they are in sync with the
54274134Sgjb * kernel.
55274134Sgjb */
56274134Sgjb#define DEVSTAT_VERSION	   6
57274134Sgjb
58274134Sgjb/*
59277458Sgjb * These flags specify which statistics features are supported or not
60274134Sgjb * supported by a particular device.  The default is all statistics are
61274134Sgjb * supported.
62274134Sgjb */
63274134Sgjbtypedef enum {
64274134Sgjb	DEVSTAT_ALL_SUPPORTED	= 0x00,
65274134Sgjb	DEVSTAT_NO_BLOCKSIZE	= 0x01,
66274134Sgjb	DEVSTAT_NO_ORDERED_TAGS	= 0x02,
67274134Sgjb	DEVSTAT_BS_UNAVAILABLE	= 0x04
68274134Sgjb} devstat_support_flags;
69274134Sgjb
70274134Sgjbtypedef enum {
71274134Sgjb	DEVSTAT_NO_DATA	= 0x00,
72274134Sgjb	DEVSTAT_READ	= 0x01,
73272234Sgjb	DEVSTAT_WRITE	= 0x02,
74274134Sgjb	DEVSTAT_FREE	= 0x03
75272234Sgjb} devstat_trans_flags;
76274134Sgjb#define DEVSTAT_N_TRANS_FLAGS	4
77274134Sgjb
78274134Sgjbtypedef enum {
79274134Sgjb	DEVSTAT_TAG_SIMPLE	= 0x00,
80278502Sgjb	DEVSTAT_TAG_HEAD	= 0x01,
81274134Sgjb	DEVSTAT_TAG_ORDERED	= 0x02,
82278502Sgjb	DEVSTAT_TAG_NONE	= 0x03
83272380Sgjb} devstat_tag_type;
84272380Sgjb
85274134Sgjbtypedef enum {
86274134Sgjb	DEVSTAT_PRIORITY_MIN	= 0x000,
87274134Sgjb	DEVSTAT_PRIORITY_OTHER	= 0x020,
88272234Sgjb	DEVSTAT_PRIORITY_PASS	= 0x030,
89272234Sgjb	DEVSTAT_PRIORITY_FD	= 0x040,
90274134Sgjb	DEVSTAT_PRIORITY_WFD	= 0x050,
91274134Sgjb	DEVSTAT_PRIORITY_TAPE	= 0x060,
92278502Sgjb	DEVSTAT_PRIORITY_CD	= 0x090,
93274134Sgjb	DEVSTAT_PRIORITY_DISK	= 0x110,
94272234Sgjb	DEVSTAT_PRIORITY_ARRAY	= 0x120,
95272234Sgjb	DEVSTAT_PRIORITY_MAX	= 0xfff
96277458Sgjb} devstat_priority;
97274134Sgjb
98274134Sgjb/*
99274134Sgjb * These types are intended to aid statistics gathering/display programs.
100274134Sgjb * The first 13 types (up to the 'target' flag) are identical numerically
101274134Sgjb * to the SCSI device type numbers.  The next 3 types designate the device
102274134Sgjb * interface.  Currently the choices are IDE, SCSI, and 'other'.  The last
103277458Sgjb * flag specifies whether or not the given device is a passthrough device
104277458Sgjb * or not.  If it is a passthrough device, the lower 4 bits specify which
105277458Sgjb * type of physical device lies under the passthrough device, and the next
106274134Sgjb * 4 bits specify the interface.
107272234Sgjb */
108272234Sgjbtypedef enum {
109272234Sgjb	DEVSTAT_TYPE_DIRECT	= 0x000,
110272234Sgjb	DEVSTAT_TYPE_SEQUENTIAL	= 0x001,
111272234Sgjb	DEVSTAT_TYPE_PRINTER	= 0x002,
112	DEVSTAT_TYPE_PROCESSOR	= 0x003,
113	DEVSTAT_TYPE_WORM	= 0x004,
114	DEVSTAT_TYPE_CDROM	= 0x005,
115	DEVSTAT_TYPE_SCANNER	= 0x006,
116	DEVSTAT_TYPE_OPTICAL	= 0x007,
117	DEVSTAT_TYPE_CHANGER	= 0x008,
118	DEVSTAT_TYPE_COMM	= 0x009,
119	DEVSTAT_TYPE_ASC0	= 0x00a,
120	DEVSTAT_TYPE_ASC1	= 0x00b,
121	DEVSTAT_TYPE_STORARRAY	= 0x00c,
122	DEVSTAT_TYPE_ENCLOSURE	= 0x00d,
123	DEVSTAT_TYPE_FLOPPY	= 0x00e,
124	DEVSTAT_TYPE_MASK	= 0x00f,
125	DEVSTAT_TYPE_IF_SCSI	= 0x010,
126	DEVSTAT_TYPE_IF_IDE	= 0x020,
127	DEVSTAT_TYPE_IF_OTHER	= 0x030,
128	DEVSTAT_TYPE_IF_MASK	= 0x0f0,
129	DEVSTAT_TYPE_PASS	= 0x100
130} devstat_type_flags;
131
132/*
133 * XXX: Next revision should add
134 *	off_t		offset[DEVSTAT_N_TRANS_FLAGS];
135 * XXX: which should contain the offset of the last completed transfer.
136 */
137struct devstat {
138	/* Internal house-keeping fields */
139	u_int			sequence0;	     /* Update sequence# */
140	int			allocated;	     /* Allocated entry */
141	u_int			start_count;	     /* started ops */
142	u_int			end_count;	     /* completed ops */
143	struct bintime		busy_from;	     /*
144						      * busy time unaccounted
145						      * for since this time
146						      */
147	STAILQ_ENTRY(devstat) 	dev_links;
148	u_int32_t		device_number;	     /*
149						      * Devstat device
150						      * number.
151						      */
152	char			device_name[DEVSTAT_NAME_LEN];
153	int			unit_number;
154	u_int64_t		bytes[DEVSTAT_N_TRANS_FLAGS];
155	u_int64_t		operations[DEVSTAT_N_TRANS_FLAGS];
156	struct bintime		duration[DEVSTAT_N_TRANS_FLAGS];
157	struct bintime		busy_time;
158	struct bintime          creation_time;       /*
159						      * Time the device was
160						      * created.
161						      */
162	u_int32_t		block_size;	     /* Block size, bytes */
163	u_int64_t		tag_types[3];	     /*
164						      * The number of
165						      * simple, ordered,
166						      * and head of queue
167						      * tags sent.
168						      */
169	devstat_support_flags	flags;		     /*
170						      * Which statistics
171						      * are supported by a
172						      * given device.
173						      */
174	devstat_type_flags	device_type;	     /* Device type */
175	devstat_priority	priority;	     /* Controls list pos. */
176	const void		*id;		     /*
177						      * Identification for
178						      * GEOM nodes
179						      */
180	u_int			sequence1;	     /* Update sequence# */
181};
182
183STAILQ_HEAD(devstatlist, devstat);
184
185#ifdef _KERNEL
186struct bio;
187
188struct devstat *devstat_new_entry(const void *dev_name, int unit_number,
189				  u_int32_t block_size,
190				  devstat_support_flags flags,
191				  devstat_type_flags device_type,
192				  devstat_priority priority);
193
194void devstat_remove_entry(struct devstat *ds);
195void devstat_start_transaction(struct devstat *ds, struct bintime *now);
196void devstat_start_transaction_bio(struct devstat *ds, struct bio *bp);
197void devstat_end_transaction(struct devstat *ds, u_int32_t bytes,
198			     devstat_tag_type tag_type,
199			     devstat_trans_flags flags,
200			     struct bintime *now, struct bintime *then);
201void devstat_end_transaction_bio(struct devstat *ds, struct bio *bp);
202void devstat_end_transaction_bio_bt(struct devstat *ds, struct bio *bp,
203			     struct bintime *now);
204#endif
205
206#endif /* _DEVICESTAT_H */
207