xref: /dragonfly/sys/sys/devicestat.h (revision f8f04fe3)
1 /*
2  * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD: src/sys/sys/devicestat.h,v 1.9 1999/12/29 04:24:39 peter Exp $
29  * $DragonFly: src/sys/sys/devicestat.h,v 1.2 2003/06/17 04:28:58 dillon Exp $
30  */
31 
32 #ifndef _DEVICESTAT_H
33 #define _DEVICESTAT_H
34 
35 #include <sys/queue.h>
36 #include <sys/time.h>
37 
38 #define DEVSTAT_NAME_LEN  16
39 
40 /*
41  * ATTENTION:  The devstat version below should be incremented any time a
42  * change is made in struct devstat, or any time a change is made in the
43  * enumerated types that struct devstat uses.  (Only if those changes
44  * would require a recompile -- i.e. re-arranging the order of an
45  * enumerated type or something like that.)  This version number is used by
46  * userland utilities to determine whether or not they are in sync with the
47  * kernel.
48  */
49 #define DEVSTAT_VERSION	   4
50 
51 /*
52  * These flags specify which statistics features are supported or not
53  * supported by a particular device.  The default is all statistics are
54  * supported.
55  */
56 typedef enum {
57 	DEVSTAT_ALL_SUPPORTED	= 0x00,
58 	DEVSTAT_NO_BLOCKSIZE	= 0x01,
59 	DEVSTAT_NO_ORDERED_TAGS	= 0x02,
60 	DEVSTAT_BS_UNAVAILABLE	= 0x04
61 } devstat_support_flags;
62 
63 typedef enum {
64 	DEVSTAT_NO_DATA	= 0x00,
65 	DEVSTAT_READ	= 0x01,
66 	DEVSTAT_WRITE	= 0x02,
67 	DEVSTAT_FREE	= 0x03
68 } devstat_trans_flags;
69 
70 typedef enum {
71 	DEVSTAT_TAG_SIMPLE	= 0x00,
72 	DEVSTAT_TAG_HEAD	= 0x01,
73 	DEVSTAT_TAG_ORDERED	= 0x02,
74 	DEVSTAT_TAG_NONE	= 0x03
75 } devstat_tag_type;
76 
77 typedef enum {
78 	DEVSTAT_PRIORITY_MIN	= 0x000,
79 	DEVSTAT_PRIORITY_OTHER	= 0x020,
80 	DEVSTAT_PRIORITY_PASS	= 0x030,
81 	DEVSTAT_PRIORITY_FD	= 0x040,
82 	DEVSTAT_PRIORITY_WFD	= 0x050,
83 	DEVSTAT_PRIORITY_TAPE	= 0x060,
84 	DEVSTAT_PRIORITY_CD	= 0x090,
85 	DEVSTAT_PRIORITY_DISK	= 0x110,
86 	DEVSTAT_PRIORITY_ARRAY	= 0x120,
87 	DEVSTAT_PRIORITY_MAX	= 0xfff
88 } devstat_priority;
89 
90 /*
91  * These types are intended to aid statistics gathering/display programs.
92  * The first 13 types (up to the 'target' flag) are identical numerically
93  * to the SCSI device type numbers.  The next 3 types designate the device
94  * interface.  Currently the choices are IDE, SCSI, and 'other'.  The last
95  * flag specifies whether or not the given device is a passthrough device
96  * or not.  If it is a passthrough device, the lower 4 bits specify which
97  * type of physical device lies under the passthrough device, and the next
98  * 4 bits specify the interface.
99  */
100 typedef enum {
101 	DEVSTAT_TYPE_DIRECT	= 0x000,
102 	DEVSTAT_TYPE_SEQUENTIAL	= 0x001,
103 	DEVSTAT_TYPE_PRINTER	= 0x002,
104 	DEVSTAT_TYPE_PROCESSOR	= 0x003,
105 	DEVSTAT_TYPE_WORM	= 0x004,
106 	DEVSTAT_TYPE_CDROM	= 0x005,
107 	DEVSTAT_TYPE_SCANNER	= 0x006,
108 	DEVSTAT_TYPE_OPTICAL	= 0x007,
109 	DEVSTAT_TYPE_CHANGER	= 0x008,
110 	DEVSTAT_TYPE_COMM	= 0x009,
111 	DEVSTAT_TYPE_ASC0	= 0x00a,
112 	DEVSTAT_TYPE_ASC1	= 0x00b,
113 	DEVSTAT_TYPE_STORARRAY	= 0x00c,
114 	DEVSTAT_TYPE_ENCLOSURE	= 0x00d,
115 	DEVSTAT_TYPE_FLOPPY	= 0x00e,
116 	DEVSTAT_TYPE_MASK	= 0x00f,
117 	DEVSTAT_TYPE_IF_SCSI	= 0x010,
118 	DEVSTAT_TYPE_IF_IDE	= 0x020,
119 	DEVSTAT_TYPE_IF_OTHER	= 0x030,
120 	DEVSTAT_TYPE_IF_MASK	= 0x0f0,
121 	DEVSTAT_TYPE_PASS	= 0x100
122 } devstat_type_flags;
123 
124 struct devstat {
125 	STAILQ_ENTRY(devstat) 	dev_links;
126 	u_int32_t		device_number;	     /*
127 						      * Devstat device
128 						      * number.
129 						      */
130 	char			device_name[DEVSTAT_NAME_LEN];
131 	int			unit_number;
132 	u_int64_t		bytes_read;	     /*
133 						      * Total bytes read
134 						      * from a device.
135 						      */
136 	u_int64_t		bytes_written;	     /*
137 						      * Total bytes written
138 						      * to a device.
139 						      */
140 	u_int64_t		bytes_freed;	     /*
141 						      * Total bytes freed
142 						      * from a device.
143 						      */
144 	u_int64_t		num_reads;	     /*
145 						      * Total number of
146 						      * read requests to
147 						      * the device.
148 						      */
149 	u_int64_t		num_writes;	     /*
150 						      * Total number of
151 						      * write requests to
152 						      * the device.
153 						      */
154 	u_int64_t		num_frees;	     /*
155 						      * Total number of
156 						      * free requests to
157 						      * the device.
158 						      */
159 	u_int64_t		num_other;	     /*
160 						      * Total number of
161 						      * transactions that
162 						      * don't read or write
163 						      * data.
164 						      */
165 	int32_t			busy_count;	     /*
166 						      * Total number of
167 						      * transactions
168 						      * outstanding for
169 						      * the device.
170 						      */
171 	u_int32_t		block_size;	     /* Block size, bytes */
172 	u_int64_t		tag_types[3];	     /*
173 						      * The number of
174 						      * simple, ordered,
175 						      * and head of queue
176 						      * tags sent.
177 						      */
178 	struct timeval		dev_creation_time;   /*
179 						      * Time the device was
180 						      * created.
181 						      */
182 	struct timeval 		busy_time;	     /*
183 						      * Total amount of
184 						      * time drive has spent
185 						      * processing requests.
186 						      */
187 	struct timeval		start_time;	     /*
188 						      * The time when
189 						      * busy_count was
190 						      * last == 0.  Or, the
191 						      * start of the latest
192 						      * busy period.
193 						      */
194 	struct timeval		last_comp_time;	     /*
195 						      * Last time a
196 						      * transaction was
197 						      * completed.
198 						      */
199 
200 	devstat_support_flags	flags;		     /*
201 						      * Which statistics
202 						      * are supported by a
203 						      * given device.
204 						      */
205 	devstat_type_flags	device_type;	     /* Device type */
206 	devstat_priority	priority;	     /* Controls list pos. */
207 };
208 
209 #ifdef _KERNEL
210 struct buf;
211 void devstat_add_entry(struct devstat *ds, const char *dev_name,
212 		       int unit_number, u_int32_t block_size,
213 		       devstat_support_flags flags,
214 		       devstat_type_flags device_type,
215 		       devstat_priority priority);
216 void devstat_remove_entry(struct devstat *ds);
217 void devstat_start_transaction(struct devstat *ds);
218 void devstat_end_transaction(struct devstat *ds, u_int32_t bytes,
219 			     devstat_tag_type tag_type,
220 			     devstat_trans_flags flags);
221 void devstat_end_transaction_buf(struct devstat *ds, struct buf *);
222 #endif
223 
224 #endif /* _DEVICESTAT_H */
225