devicestat.h revision 139825
189857Sobrien/*- 289857Sobrien * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry. 389857Sobrien * All rights reserved. 489857Sobrien * 589857Sobrien * Redistribution and use in source and binary forms, with or without 689857Sobrien * modification, are permitted provided that the following conditions 789857Sobrien * are met: 889857Sobrien * 1. Redistributions of source code must retain the above copyright 9218822Sdim * notice, this list of conditions and the following disclaimer. 1089857Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1189857Sobrien * notice, this list of conditions and the following disclaimer in the 1289857Sobrien * documentation and/or other materials provided with the distribution. 1389857Sobrien * 3. The name of the author may not be used to endorse or promote products 1489857Sobrien * derived from this software without specific prior written permission. 1589857Sobrien * 1689857Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1789857Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1889857Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1989857Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2089857Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2189857Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2289857Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2389857Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2489857Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2589857Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2689857Sobrien * SUCH DAMAGE. 2789857Sobrien * 2889857Sobrien * $FreeBSD: head/sys/sys/devicestat.h 139825 2005-01-07 02:29:27Z imp $ 2989857Sobrien */ 3089857Sobrien 3189857Sobrien#ifndef _DEVICESTAT_H 3289857Sobrien#define _DEVICESTAT_H 3389857Sobrien 3489857Sobrien#include <sys/queue.h> 3589857Sobrien#include <sys/time.h> 3689857Sobrien 3789857Sobrien/* 3889857Sobrien * XXX: Should really be SPECNAMELEN 3989857Sobrien */ 4089857Sobrien#define DEVSTAT_NAME_LEN 16 4189857Sobrien 4289857Sobrien/* 4389857Sobrien * device name for the mmap device 4489857Sobrien */ 4589857Sobrien#define DEVSTAT_DEVICE_NAME "devstat" 4689857Sobrien 4789857Sobrien/* 4889857Sobrien * ATTENTION: The devstat version below should be incremented any time a 4989857Sobrien * change is made in struct devstat, or any time a change is made in the 5089857Sobrien * enumerated types that struct devstat uses. (Only if those changes 5189857Sobrien * would require a recompile -- i.e. re-arranging the order of an 5289857Sobrien * enumerated type or something like that.) This version number is used by 5389857Sobrien * userland utilities to determine whether or not they are in sync with the 5489857Sobrien * kernel. 5589857Sobrien */ 5689857Sobrien#define DEVSTAT_VERSION 6 5789857Sobrien 5889857Sobrien/* 5989857Sobrien * These flags specify which statistics features are supported or not 6089857Sobrien * supported by a particular device. The default is all statistics are 6189857Sobrien * supported. 6289857Sobrien */ 6389857Sobrientypedef enum { 6489857Sobrien DEVSTAT_ALL_SUPPORTED = 0x00, 6589857Sobrien DEVSTAT_NO_BLOCKSIZE = 0x01, 6689857Sobrien DEVSTAT_NO_ORDERED_TAGS = 0x02, 6789857Sobrien DEVSTAT_BS_UNAVAILABLE = 0x04 6889857Sobrien} devstat_support_flags; 6989857Sobrien 7089857Sobrientypedef enum { 7189857Sobrien DEVSTAT_NO_DATA = 0x00, 7289857Sobrien DEVSTAT_READ = 0x01, 7389857Sobrien DEVSTAT_WRITE = 0x02, 7489857Sobrien DEVSTAT_FREE = 0x03 7589857Sobrien} devstat_trans_flags; 7689857Sobrien#define DEVSTAT_N_TRANS_FLAGS 4 7789857Sobrien 7889857Sobrientypedef enum { 7989857Sobrien DEVSTAT_TAG_SIMPLE = 0x00, 8089857Sobrien DEVSTAT_TAG_HEAD = 0x01, 8189857Sobrien DEVSTAT_TAG_ORDERED = 0x02, 8289857Sobrien DEVSTAT_TAG_NONE = 0x03 8389857Sobrien} devstat_tag_type; 8489857Sobrien 8589857Sobrientypedef enum { 8689857Sobrien DEVSTAT_PRIORITY_MIN = 0x000, 8789857Sobrien DEVSTAT_PRIORITY_OTHER = 0x020, 8889857Sobrien DEVSTAT_PRIORITY_PASS = 0x030, 8989857Sobrien DEVSTAT_PRIORITY_FD = 0x040, 9089857Sobrien DEVSTAT_PRIORITY_WFD = 0x050, 9189857Sobrien DEVSTAT_PRIORITY_TAPE = 0x060, 9289857Sobrien DEVSTAT_PRIORITY_CD = 0x090, 9389857Sobrien DEVSTAT_PRIORITY_DISK = 0x110, 9489857Sobrien DEVSTAT_PRIORITY_ARRAY = 0x120, 9589857Sobrien DEVSTAT_PRIORITY_MAX = 0xfff 9689857Sobrien} devstat_priority; 9789857Sobrien 9889857Sobrien/* 9989857Sobrien * These types are intended to aid statistics gathering/display programs. 10089857Sobrien * The first 13 types (up to the 'target' flag) are identical numerically 10189857Sobrien * to the SCSI device type numbers. The next 3 types designate the device 10289857Sobrien * interface. Currently the choices are IDE, SCSI, and 'other'. The last 10389857Sobrien * flag specifies whether or not the given device is a passthrough device 10489857Sobrien * or not. If it is a passthrough device, the lower 4 bits specify which 10589857Sobrien * type of physical device lies under the passthrough device, and the next 10689857Sobrien * 4 bits specify the interface. 10789857Sobrien */ 10889857Sobrientypedef enum { 10989857Sobrien DEVSTAT_TYPE_DIRECT = 0x000, 11089857Sobrien DEVSTAT_TYPE_SEQUENTIAL = 0x001, 11189857Sobrien DEVSTAT_TYPE_PRINTER = 0x002, 11289857Sobrien DEVSTAT_TYPE_PROCESSOR = 0x003, 11389857Sobrien DEVSTAT_TYPE_WORM = 0x004, 11489857Sobrien DEVSTAT_TYPE_CDROM = 0x005, 11589857Sobrien DEVSTAT_TYPE_SCANNER = 0x006, 11689857Sobrien DEVSTAT_TYPE_OPTICAL = 0x007, 11789857Sobrien DEVSTAT_TYPE_CHANGER = 0x008, 11889857Sobrien DEVSTAT_TYPE_COMM = 0x009, 11989857Sobrien DEVSTAT_TYPE_ASC0 = 0x00a, 12089857Sobrien DEVSTAT_TYPE_ASC1 = 0x00b, 12189857Sobrien DEVSTAT_TYPE_STORARRAY = 0x00c, 12289857Sobrien DEVSTAT_TYPE_ENCLOSURE = 0x00d, 12389857Sobrien DEVSTAT_TYPE_FLOPPY = 0x00e, 12489857Sobrien DEVSTAT_TYPE_MASK = 0x00f, 12589857Sobrien DEVSTAT_TYPE_IF_SCSI = 0x010, 12689857Sobrien DEVSTAT_TYPE_IF_IDE = 0x020, 12789857Sobrien DEVSTAT_TYPE_IF_OTHER = 0x030, 12889857Sobrien DEVSTAT_TYPE_IF_MASK = 0x0f0, 12989857Sobrien DEVSTAT_TYPE_PASS = 0x100 13089857Sobrien} devstat_type_flags; 13189857Sobrien 13289857Sobrien/* 13389857Sobrien * XXX: Next revision should add 13489857Sobrien * off_t offset[DEVSTAT_N_TRANS_FLAGS]; 13589857Sobrien * XXX: which should contain the offset of the last completed transfer. 13689857Sobrien */ 13789857Sobrienstruct devstat { 13889857Sobrien /* Internal house-keeping fields */ 13989857Sobrien u_int sequence0; /* Update sequence# */ 14089857Sobrien int allocated; /* Allocated entry */ 14189857Sobrien u_int start_count; /* started ops */ 14289857Sobrien u_int end_count; /* completed ops */ 14389857Sobrien struct bintime busy_from; /* 14489857Sobrien * busy time unaccounted 14589857Sobrien * for since this time 14689857Sobrien */ 14789857Sobrien STAILQ_ENTRY(devstat) dev_links; 14889857Sobrien u_int32_t device_number; /* 14989857Sobrien * Devstat device 15089857Sobrien * number. 15189857Sobrien */ 15289857Sobrien char device_name[DEVSTAT_NAME_LEN]; 15389857Sobrien int unit_number; 15489857Sobrien u_int64_t bytes[DEVSTAT_N_TRANS_FLAGS]; 15589857Sobrien u_int64_t operations[DEVSTAT_N_TRANS_FLAGS]; 15689857Sobrien struct bintime duration[DEVSTAT_N_TRANS_FLAGS]; 15789857Sobrien struct bintime busy_time; 15889857Sobrien struct bintime creation_time; /* 15989857Sobrien * Time the device was 16089857Sobrien * created. 16189857Sobrien */ 16289857Sobrien u_int32_t block_size; /* Block size, bytes */ 16389857Sobrien u_int64_t tag_types[3]; /* 16489857Sobrien * The number of 16589857Sobrien * simple, ordered, 16689857Sobrien * and head of queue 16789857Sobrien * tags sent. 16889857Sobrien */ 16989857Sobrien devstat_support_flags flags; /* 17089857Sobrien * Which statistics 17189857Sobrien * are supported by a 17289857Sobrien * given device. 17389857Sobrien */ 17489857Sobrien devstat_type_flags device_type; /* Device type */ 17589857Sobrien devstat_priority priority; /* Controls list pos. */ 17689857Sobrien const void *id; /* 17789857Sobrien * Identification for 17889857Sobrien * GEOM nodes 17989857Sobrien */ 18089857Sobrien u_int sequence1; /* Update sequence# */ 18189857Sobrien}; 18289857Sobrien 18389857SobrienSTAILQ_HEAD(devstatlist, devstat); 18489857Sobrien 18589857Sobrien#ifdef _KERNEL 18689857Sobrienstruct bio; 18789857Sobrien 18889857Sobrienstruct devstat *devstat_new_entry(const void *dev_name, int unit_number, 18989857Sobrien u_int32_t block_size, 19089857Sobrien devstat_support_flags flags, 19189857Sobrien devstat_type_flags device_type, 19289857Sobrien devstat_priority priority); 19389857Sobrien 19489857Sobrienvoid devstat_remove_entry(struct devstat *ds); 19589857Sobrienvoid devstat_start_transaction(struct devstat *ds, struct bintime *now); 19689857Sobrienvoid devstat_start_transaction_bio(struct devstat *ds, struct bio *bp); 19789857Sobrienvoid devstat_end_transaction(struct devstat *ds, u_int32_t bytes, 19889857Sobrien devstat_tag_type tag_type, 19989857Sobrien devstat_trans_flags flags, 20089857Sobrien struct bintime *now, struct bintime *then); 20189857Sobrienvoid devstat_end_transaction_bio(struct devstat *ds, struct bio *bp); 20289857Sobrien#endif 20389857Sobrien 20489857Sobrien#endif /* _DEVICESTAT_H */ 20589857Sobrien