devicestat.h revision 115567
161515Sobrien/* 261515Sobrien * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry. 359243Sobrien * All rights reserved. 459243Sobrien * 559243Sobrien * Redistribution and use in source and binary forms, with or without 659243Sobrien * modification, are permitted provided that the following conditions 759243Sobrien * are met: 859243Sobrien * 1. Redistributions of source code must retain the above copyright 959243Sobrien * notice, this list of conditions and the following disclaimer. 1059243Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1159243Sobrien * notice, this list of conditions and the following disclaimer in the 1259243Sobrien * documentation and/or other materials provided with the distribution. 1359243Sobrien * 3. The name of the author may not be used to endorse or promote products 1459243Sobrien * derived from this software without specific prior written permission. 1559243Sobrien * 1659243Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1759243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1859243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1959243Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2059243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2159243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2259243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2359243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2459243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2561515Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2661515Sobrien * SUCH DAMAGE. 2759243Sobrien * 2859243Sobrien * $FreeBSD: head/sys/sys/devicestat.h 115567 2003-05-31 21:10:01Z phk $ 2959243Sobrien */ 3059243Sobrien 3159243Sobrien#ifndef _DEVICESTAT_H 3259243Sobrien#define _DEVICESTAT_H 3359243Sobrien 3459243Sobrien#include <sys/queue.h> 3559243Sobrien#include <sys/time.h> 3659243Sobrien 3759243Sobrien/* 3859243Sobrien * XXX: Should really be SPECNAMELEN 3959243Sobrien */ 4059243Sobrien#define DEVSTAT_NAME_LEN 16 4159243Sobrien 4259243Sobrien/* 4359243Sobrien * device name for the mmap device 4459243Sobrien */ 4559243Sobrien#define DEVSTAT_DEVICE_NAME "devstat" 4659243Sobrien 4759243Sobrien/* 4859243Sobrien * ATTENTION: The devstat version below should be incremented any time a 4959243Sobrien * change is made in struct devstat, or any time a change is made in the 5059243Sobrien * enumerated types that struct devstat uses. (Only if those changes 5159243Sobrien * would require a recompile -- i.e. re-arranging the order of an 5259243Sobrien * enumerated type or something like that.) This version number is used by 5359243Sobrien * userland utilities to determine whether or not they are in sync with the 5459243Sobrien * kernel. 5559243Sobrien */ 5659243Sobrien#define DEVSTAT_VERSION 6 5759243Sobrien 5859243Sobrien/* 5959243Sobrien * These flags specify which statistics features are supported or not 6059243Sobrien * supported by a particular device. The default is all statistics are 6159243Sobrien * supported. 6259243Sobrien */ 6359243Sobrientypedef enum { 6459243Sobrien DEVSTAT_ALL_SUPPORTED = 0x00, 6559243Sobrien DEVSTAT_NO_BLOCKSIZE = 0x01, 6659243Sobrien DEVSTAT_NO_ORDERED_TAGS = 0x02, 6759243Sobrien DEVSTAT_BS_UNAVAILABLE = 0x04 6859243Sobrien} devstat_support_flags; 6959243Sobrien 7059243Sobrientypedef enum { 7159243Sobrien DEVSTAT_NO_DATA = 0x00, 7259243Sobrien DEVSTAT_READ = 0x01, 7359243Sobrien DEVSTAT_WRITE = 0x02, 7459243Sobrien DEVSTAT_FREE = 0x03 7559243Sobrien} devstat_trans_flags; 7659243Sobrien#define DEVSTAT_N_TRANS_FLAGS 4 7759243Sobrien 7859243Sobrientypedef enum { 7959243Sobrien DEVSTAT_TAG_SIMPLE = 0x00, 8059243Sobrien DEVSTAT_TAG_HEAD = 0x01, 8159243Sobrien DEVSTAT_TAG_ORDERED = 0x02, 8259243Sobrien DEVSTAT_TAG_NONE = 0x03 8359243Sobrien} devstat_tag_type; 8459243Sobrien 8559243Sobrientypedef enum { 8659243Sobrien DEVSTAT_PRIORITY_MIN = 0x000, 8759243Sobrien DEVSTAT_PRIORITY_OTHER = 0x020, 8859243Sobrien DEVSTAT_PRIORITY_PASS = 0x030, 8959243Sobrien DEVSTAT_PRIORITY_FD = 0x040, 9059243Sobrien DEVSTAT_PRIORITY_WFD = 0x050, 9159243Sobrien DEVSTAT_PRIORITY_TAPE = 0x060, 9259243Sobrien DEVSTAT_PRIORITY_CD = 0x090, 9359243Sobrien DEVSTAT_PRIORITY_DISK = 0x110, 9459243Sobrien DEVSTAT_PRIORITY_ARRAY = 0x120, 9559243Sobrien DEVSTAT_PRIORITY_MAX = 0xfff 9659243Sobrien} devstat_priority; 9759243Sobrien 9859243Sobrien/* 9959243Sobrien * These types are intended to aid statistics gathering/display programs. 10059243Sobrien * The first 13 types (up to the 'target' flag) are identical numerically 10159243Sobrien * to the SCSI device type numbers. The next 3 types designate the device 10259243Sobrien * interface. Currently the choices are IDE, SCSI, and 'other'. The last 10359243Sobrien * flag specifies whether or not the given device is a passthrough device 10459243Sobrien * or not. If it is a passthrough device, the lower 4 bits specify which 10559243Sobrien * type of physical device lies under the passthrough device, and the next 10659243Sobrien * 4 bits specify the interface. 10759243Sobrien */ 10859243Sobrientypedef enum { 10959243Sobrien DEVSTAT_TYPE_DIRECT = 0x000, 11059243Sobrien DEVSTAT_TYPE_SEQUENTIAL = 0x001, 11159243Sobrien DEVSTAT_TYPE_PRINTER = 0x002, 11259243Sobrien DEVSTAT_TYPE_PROCESSOR = 0x003, 11359243Sobrien DEVSTAT_TYPE_WORM = 0x004, 11459243Sobrien DEVSTAT_TYPE_CDROM = 0x005, 11559243Sobrien DEVSTAT_TYPE_SCANNER = 0x006, 11659243Sobrien DEVSTAT_TYPE_OPTICAL = 0x007, 11759243Sobrien DEVSTAT_TYPE_CHANGER = 0x008, 11859243Sobrien DEVSTAT_TYPE_COMM = 0x009, 11959243Sobrien DEVSTAT_TYPE_ASC0 = 0x00a, 12059243Sobrien DEVSTAT_TYPE_ASC1 = 0x00b, 12159243Sobrien DEVSTAT_TYPE_STORARRAY = 0x00c, 12259243Sobrien DEVSTAT_TYPE_ENCLOSURE = 0x00d, 12359243Sobrien DEVSTAT_TYPE_FLOPPY = 0x00e, 12459243Sobrien DEVSTAT_TYPE_MASK = 0x00f, 12559243Sobrien DEVSTAT_TYPE_IF_SCSI = 0x010, 12659243Sobrien DEVSTAT_TYPE_IF_IDE = 0x020, 12759243Sobrien DEVSTAT_TYPE_IF_OTHER = 0x030, 12859243Sobrien DEVSTAT_TYPE_IF_MASK = 0x0f0, 12959243Sobrien DEVSTAT_TYPE_PASS = 0x100 13059243Sobrien} devstat_type_flags; 13159243Sobrien 13259243Sobrien/* 13359243Sobrien * XXX: Next revision should add 13459243Sobrien * off_t offset[DEVSTAT_N_TRANS_FLAGS]; 13559243Sobrien * XXX: which should contain the offset of the last completed transfer. 13659243Sobrien */ 13759243Sobrienstruct devstat { 13859243Sobrien /* Internal house-keeping fields */ 13959243Sobrien u_int sequence0; /* Update sequence# */ 14059243Sobrien int allocated; /* Allocated entry */ 14159243Sobrien u_int start_count; /* started ops */ 14259243Sobrien u_int end_count; /* completed ops */ 14359243Sobrien struct bintime busy_from; /* 14459243Sobrien * busy time unaccounted 14559243Sobrien * for since this time 14659243Sobrien */ 14759243Sobrien STAILQ_ENTRY(devstat) dev_links; 14859243Sobrien u_int32_t device_number; /* 14959243Sobrien * Devstat device 15059243Sobrien * number. 15159243Sobrien */ 15259243Sobrien char device_name[DEVSTAT_NAME_LEN]; 15359243Sobrien int unit_number; 15459243Sobrien u_int64_t bytes[DEVSTAT_N_TRANS_FLAGS]; 15559243Sobrien u_int64_t operations[DEVSTAT_N_TRANS_FLAGS]; 15659243Sobrien struct bintime duration[DEVSTAT_N_TRANS_FLAGS]; 15759243Sobrien struct bintime busy_time; 15859243Sobrien struct bintime creation_time; /* 15959243Sobrien * Time the device was 16059243Sobrien * created. 16159243Sobrien */ 16259243Sobrien u_int32_t block_size; /* Block size, bytes */ 16359243Sobrien u_int64_t tag_types[3]; /* 16459243Sobrien * The number of 16559243Sobrien * simple, ordered, 16659243Sobrien * and head of queue 16759243Sobrien * tags sent. 16859243Sobrien */ 16959243Sobrien devstat_support_flags flags; /* 17059243Sobrien * Which statistics 17159243Sobrien * are supported by a 17259243Sobrien * given device. 17359243Sobrien */ 17459243Sobrien devstat_type_flags device_type; /* Device type */ 17559243Sobrien devstat_priority priority; /* Controls list pos. */ 17659243Sobrien const void *id; /* 17759243Sobrien * Identification for 17859243Sobrien * GEOM nodes 17959243Sobrien */ 18059243Sobrien u_int sequence1; /* Update sequence# */ 18159243Sobrien}; 18259243Sobrien 18359243SobrienSTAILQ_HEAD(devstatlist, devstat); 18459243Sobrien 18559243Sobrien#ifdef _KERNEL 18659243Sobrienstruct bio; 18759243Sobrien 18859243Sobrienstruct devstat *devstat_new_entry(const void *dev_name, int unit_number, 18959243Sobrien u_int32_t block_size, 19059243Sobrien devstat_support_flags flags, 19159243Sobrien devstat_type_flags device_type, 19259243Sobrien devstat_priority priority); 19359243Sobrien 19459243Sobrienvoid devstat_remove_entry(struct devstat *ds); 19559243Sobrienvoid devstat_start_transaction(struct devstat *ds, struct bintime *now); 19659243Sobrienvoid devstat_start_transaction_bio(struct devstat *ds, struct bio *bp); 19759243Sobrienvoid devstat_end_transaction(struct devstat *ds, u_int32_t bytes, 19859243Sobrien devstat_tag_type tag_type, 19959243Sobrien devstat_trans_flags flags, 20059243Sobrien struct bintime *now, struct bintime *then); 20159243Sobrienvoid devstat_end_transaction_bio(struct devstat *ds, struct bio *bp); 20259243Sobrien#endif 20359243Sobrien 20459243Sobrien#endif /* _DEVICESTAT_H */ 20559243Sobrien