| 1 | /*- |
| 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * |
| 4 | * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. The name of the author may not be used to endorse or promote products |
| 16 | * derived from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 | * SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #ifndef _DEVICESTAT_H |
| 32 | #define _DEVICESTAT_H |
| 33 | |
| 34 | #include <sys/queue.h> |
| 35 | #include <sys/time.h> |
| 36 | |
| 37 | /* |
| 38 | * XXX: Should really be SPECNAMELEN |
| 39 | */ |
| 40 | #define DEVSTAT_NAME_LEN 16 |
| 41 | |
| 42 | /* |
| 43 | * device name for the mmap device |
| 44 | */ |
| 45 | #define DEVSTAT_DEVICE_NAME "devstat" |
| 46 | |
| 47 | /* |
| 48 | * ATTENTION: The devstat version below should be incremented any time a |
| 49 | * change is made in struct devstat, or any time a change is made in the |
| 50 | * enumerated types that struct devstat uses. (Only if those changes |
| 51 | * would require a recompile -- i.e. re-arranging the order of an |
| 52 | * enumerated type or something like that.) This version number is used by |
| 53 | * userland utilities to determine whether or not they are in sync with the |
| 54 | * kernel. |
| 55 | */ |
| 56 | #define DEVSTAT_VERSION	 6 |
| 57 | |
| 58 | /* |
| 59 | * These flags specify which statistics features are supported or not |
| 60 | * supported by a particular device. The default is all statistics are |
| 61 | * supported. |
| 62 | */ |
| 63 | typedef enum { |
| 64 | 	DEVSTAT_ALL_SUPPORTED	= 0x00, |
| 65 | 	DEVSTAT_NO_BLOCKSIZE	= 0x01, |
| 66 | 	DEVSTAT_NO_ORDERED_TAGS	= 0x02, |
| 67 | 	DEVSTAT_BS_UNAVAILABLE	= 0x04 |
| 68 | } devstat_support_flags; |
| 69 | |
| 70 | typedef enum { |
| 71 | 	DEVSTAT_NO_DATA	= 0x00, |
| 72 | 	DEVSTAT_READ	= 0x01, |
| 73 | 	DEVSTAT_WRITE	= 0x02, |
| 74 | 	DEVSTAT_FREE	= 0x03 |
| 75 | } devstat_trans_flags; |
| 76 | #define DEVSTAT_N_TRANS_FLAGS	4 |
| 77 | |
| 78 | typedef enum { |
| 79 | 	DEVSTAT_TAG_SIMPLE	= 0x00, |
| 80 | 	DEVSTAT_TAG_HEAD	= 0x01, |
| 81 | 	DEVSTAT_TAG_ORDERED	= 0x02, |
| 82 | 	DEVSTAT_TAG_NONE	= 0x03 |
| 83 | } devstat_tag_type; |
| 84 | |
| 85 | typedef enum { |
| 86 | 	DEVSTAT_PRIORITY_MIN	= 0x000, |
| 87 | 	DEVSTAT_PRIORITY_OTHER	= 0x020, |
| 88 | 	DEVSTAT_PRIORITY_PASS	= 0x030, |
| 89 | 	DEVSTAT_PRIORITY_FD	= 0x040, |
| 90 | 	DEVSTAT_PRIORITY_WFD	= 0x050, |
| 91 | 	DEVSTAT_PRIORITY_TAPE	= 0x060, |
| 92 | 	DEVSTAT_PRIORITY_CD	= 0x090, |
| 93 | 	DEVSTAT_PRIORITY_DISK	= 0x110, |
| 94 | 	DEVSTAT_PRIORITY_ARRAY	= 0x120, |
| 95 | 	DEVSTAT_PRIORITY_MAX	= 0xfff |
| 96 | } devstat_priority; |
| 97 | |
| 98 | /* |
| 99 | * These types are intended to aid statistics gathering/display programs. |
| 100 | * The first 13 types (up to the 'target' flag) are identical numerically |
| 101 | * to the SCSI device type numbers. The next 3 types designate the device |
| 102 | * interface. Currently the choices are IDE, SCSI, and 'other'. The last |
| 103 | * flag specifies whether or not the given device is a passthrough device |
| 104 | * or not. If it is a passthrough device, the lower 4 bits specify which |
| 105 | * type of physical device lies under the passthrough device, and the next |
| 106 | * 4 bits specify the interface. |
| 107 | */ |
| 108 | typedef enum { |
| 109 | 	DEVSTAT_TYPE_DIRECT	= 0x000, |
| 110 | 	DEVSTAT_TYPE_SEQUENTIAL	= 0x001, |
| 111 | 	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_NVME	= 0x040, |
| 129 | 	DEVSTAT_TYPE_IF_MASK	= 0x0f0, |
| 130 | 	DEVSTAT_TYPE_PASS	= 0x100 |
| 131 | } devstat_type_flags; |
| 132 | |
| 133 | /* |
| 134 | * XXX: Next revision should add |
| 135 | *	off_t		offset[DEVSTAT_N_TRANS_FLAGS]; |
| 136 | * XXX: which should contain the offset of the last completed transfer. |
| 137 | */ |
| 138 | struct devstat { |
| 139 | 	/* Internal house-keeping fields */ |
| 140 | 	u_int			sequence0;	 /* Update sequence# */ |
| 141 | 	int			allocated;	 /* Allocated entry */ |
| 142 | 	u_int			start_count;	 /* started ops */ |
| 143 | 	u_int			end_count;	 /* completed ops */ |
| 144 | 	struct bintime		busy_from;	 /* |
| 145 | 						 * busy time unaccounted |
| 146 | 						 * for since this time |
| 147 | 						 */ |
| 148 | 	STAILQ_ENTRY(devstat) 	dev_links; |
| 149 | 	u_int32_t		device_number;	 /* |
| 150 | 						 * Devstat device |
| 151 | 						 * number. |
| 152 | 						 */ |
| 153 | 	char			device_name[DEVSTAT_NAME_LEN]; |
| 154 | 	int			unit_number; |
| 155 | 	u_int64_t		bytes[DEVSTAT_N_TRANS_FLAGS]; |
| 156 | 	u_int64_t		operations[DEVSTAT_N_TRANS_FLAGS]; |
| 157 | 	struct bintime		duration[DEVSTAT_N_TRANS_FLAGS]; |
| 158 | 	struct bintime		busy_time; |
| 159 | 	struct bintime creation_time; /* |
| 160 | 						 * Time the device was |
| 161 | 						 * created. |
| 162 | 						 */ |
| 163 | 	u_int32_t		block_size;	 /* Block size, bytes */ |
| 164 | 	u_int64_t		tag_types[3];	 /* |
| 165 | 						 * The number of |
| 166 | 						 * simple, ordered, |
| 167 | 						 * and head of queue |
| 168 | 						 * tags sent. |
| 169 | 						 */ |
| 170 | 	devstat_support_flags	flags;		 /* |
| 171 | 						 * Which statistics |
| 172 | 						 * are supported by a |
| 173 | 						 * given device. |
| 174 | 						 */ |
| 175 | 	devstat_type_flags	device_type;	 /* Device type */ |
| 176 | 	devstat_priority	priority;	 /* Controls list pos. */ |
| 177 | 	const void		*id;		 /* |
| 178 | 						 * Identification for |
| 179 | 						 * GEOM nodes |
| 180 | 						 */ |
| 181 | 	u_int			sequence1;	 /* Update sequence# */ |
| 182 | }; |
| 183 | |
| 184 | STAILQ_HEAD(devstatlist, devstat); |
| 185 | |
| 186 | #ifdef _KERNEL |
| 187 | struct bio; |
| 188 | |
| 189 | struct devstat *devstat_new_entry(const void *dev_name, int unit_number, |
| 190 | 				 u_int32_t block_size, |
| 191 | 				 devstat_support_flags flags, |
| 192 | 				 devstat_type_flags device_type, |
| 193 | 				 devstat_priority priority); |
| 194 | |
| 195 | void devstat_remove_entry(struct devstat *ds); |
| 196 | void devstat_start_transaction(struct devstat *ds, const struct bintime *now); |
| 197 | void devstat_start_transaction_bio(struct devstat *ds, struct bio *bp); |
| 198 | void devstat_start_transaction_bio_t0(struct devstat *ds, struct bio *bp); |
| 199 | void devstat_end_transaction(struct devstat *ds, u_int32_t bytes, |
| 200 | 			 devstat_tag_type tag_type, |
| 201 | 			 devstat_trans_flags flags, |
| 202 | 			 const struct bintime *now, |
| 203 | 			 const struct bintime *then); |
| 204 | void devstat_end_transaction_bio(struct devstat *ds, const struct bio *bp); |
| 205 | void devstat_end_transaction_bio_bt(struct devstat *ds, const struct bio *bp, |
| 206 | 			 const struct bintime *now); |
| 207 | #endif |
| 208 | |
| 209 | #endif /* _DEVICESTAT_H */ |