devicestat.h revision 51375
139229Sgibbs/*
243819Sken * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
339229Sgibbs * All rights reserved.
439229Sgibbs *
539229Sgibbs * Redistribution and use in source and binary forms, with or without
639229Sgibbs * modification, are permitted provided that the following conditions
739229Sgibbs * are met:
839229Sgibbs * 1. Redistributions of source code must retain the above copyright
939229Sgibbs *    notice, this list of conditions and the following disclaimer.
1039229Sgibbs * 2. Redistributions in binary form must reproduce the above copyright
1139229Sgibbs *    notice, this list of conditions and the following disclaimer in the
1239229Sgibbs *    documentation and/or other materials provided with the distribution.
1339229Sgibbs * 3. The name of the author may not be used to endorse or promote products
1439229Sgibbs *    derived from this software without specific prior written permission.
1539229Sgibbs *
1639229Sgibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1739229Sgibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1839229Sgibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1939229Sgibbs * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2039229Sgibbs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2139229Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2239229Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2339229Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2439229Sgibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2539229Sgibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2639229Sgibbs * SUCH DAMAGE.
2739229Sgibbs *
2850477Speter * $FreeBSD: head/sys/sys/devicestat.h 51375 1999-09-18 21:28:09Z phk $
2939229Sgibbs */
3039229Sgibbs
3139229Sgibbs#ifndef _DEVICESTAT_H
3239229Sgibbs#define _DEVICESTAT_H
3339229Sgibbs
3439229Sgibbs#include <sys/queue.h>
3539229Sgibbs#include <sys/time.h>
3639229Sgibbs
3739229Sgibbs#define DEVSTAT_NAME_LEN  16
3839229Sgibbs
3939229Sgibbs/*
4039229Sgibbs * ATTENTION:  The devstat version below should be incremented any time a
4139229Sgibbs * change is made in struct devstat, or any time a change is made in the
4239229Sgibbs * enumerated types that struct devstat uses.  (Only if those changes
4339229Sgibbs * would require a recompile -- i.e. re-arranging the order of an
4439229Sgibbs * enumerated type or something like that.)  This version number is used by
4539229Sgibbs * userland utilities to determine whether or not they are in sync with the
4639229Sgibbs * kernel.
4739229Sgibbs */
4843819Sken#define DEVSTAT_VERSION	   3
4939229Sgibbs
5039229Sgibbs/*
5139229Sgibbs * These flags specify which statistics features are supported or not
5239229Sgibbs * supported by a particular device.  The default is all statistics are
5339229Sgibbs * supported.
5439229Sgibbs */
5539229Sgibbstypedef enum {
5639229Sgibbs	DEVSTAT_ALL_SUPPORTED	= 0x00,
5739229Sgibbs	DEVSTAT_NO_BLOCKSIZE	= 0x01,
5839229Sgibbs	DEVSTAT_NO_ORDERED_TAGS	= 0x02,
5939229Sgibbs	DEVSTAT_BS_UNAVAILABLE	= 0x04
6039229Sgibbs} devstat_support_flags;
6139229Sgibbs
6239229Sgibbstypedef enum {
6339229Sgibbs	DEVSTAT_NO_DATA	= 0x00,
6439229Sgibbs	DEVSTAT_READ	= 0x01,
6551375Sphk	DEVSTAT_WRITE	= 0x02,
6651375Sphk	DEVSTAT_FREE	= 0x03
6739229Sgibbs} devstat_trans_flags;
6839229Sgibbs
6939229Sgibbstypedef enum {
7039229Sgibbs	DEVSTAT_TAG_SIMPLE	= 0x00,
7139229Sgibbs	DEVSTAT_TAG_HEAD	= 0x01,
7239229Sgibbs	DEVSTAT_TAG_ORDERED	= 0x02,
7339229Sgibbs	DEVSTAT_TAG_NONE	= 0x03
7439229Sgibbs} devstat_tag_type;
7539229Sgibbs
7643819Skentypedef enum {
7743819Sken	DEVSTAT_PRIORITY_MIN	= 0x000,
7843819Sken	DEVSTAT_PRIORITY_OTHER	= 0x020,
7943819Sken	DEVSTAT_PRIORITY_PASS	= 0x030,
8043819Sken	DEVSTAT_PRIORITY_FD	= 0x040,
8143819Sken	DEVSTAT_PRIORITY_WFD	= 0x050,
8243819Sken	DEVSTAT_PRIORITY_SA	= 0x060,
8343819Sken	DEVSTAT_PRIORITY_OCD	= 0x070,
8443819Sken	DEVSTAT_PRIORITY_WCD	= 0x080,
8543819Sken	DEVSTAT_PRIORITY_CD	= 0x090,
8643819Sken	DEVSTAT_PRIORITY_WD	= 0x100,
8743819Sken	DEVSTAT_PRIORITY_DA	= 0x110,
8843819Sken	DEVSTAT_PRIORITY_CCD	= 0x120,
8943819Sken	DEVSTAT_PRIORITY_MAX	= 0xfff
9043819Sken} devstat_priority;
9143819Sken
9239229Sgibbs/*
9339229Sgibbs * These types are intended to aid statistics gathering/display programs.
9439229Sgibbs * The first 13 types (up to the 'target' flag) are identical numerically
9539229Sgibbs * to the SCSI device type numbers.  The next 3 types designate the device
9639229Sgibbs * interface.  Currently the choices are IDE, SCSI, and 'other'.  The last
9739229Sgibbs * flag specifies whether or not the given device is a passthrough device
9839229Sgibbs * or not.  If it is a passthrough device, the lower 4 bits specify which
9939229Sgibbs * type of physical device lies under the passthrough device, and the next
10039229Sgibbs * 4 bits specify the interface.
10139229Sgibbs */
10239229Sgibbstypedef enum {
10339229Sgibbs	DEVSTAT_TYPE_DIRECT	= 0x000,
10439229Sgibbs	DEVSTAT_TYPE_SEQUENTIAL	= 0x001,
10539229Sgibbs	DEVSTAT_TYPE_PRINTER	= 0x002,
10639229Sgibbs	DEVSTAT_TYPE_PROCESSOR	= 0x003,
10739229Sgibbs	DEVSTAT_TYPE_WORM	= 0x004,
10839229Sgibbs	DEVSTAT_TYPE_CDROM	= 0x005,
10939229Sgibbs	DEVSTAT_TYPE_SCANNER	= 0x006,
11039229Sgibbs	DEVSTAT_TYPE_OPTICAL	= 0x007,
11139229Sgibbs	DEVSTAT_TYPE_CHANGER	= 0x008,
11239229Sgibbs	DEVSTAT_TYPE_COMM	= 0x009,
11339229Sgibbs	DEVSTAT_TYPE_ASC0	= 0x00a,
11439229Sgibbs	DEVSTAT_TYPE_ASC1	= 0x00b,
11539229Sgibbs	DEVSTAT_TYPE_STORARRAY	= 0x00c,
11639229Sgibbs	DEVSTAT_TYPE_ENCLOSURE	= 0x00d,
11739229Sgibbs	DEVSTAT_TYPE_FLOPPY	= 0x00e,
11839229Sgibbs	DEVSTAT_TYPE_MASK	= 0x00f,
11939229Sgibbs	DEVSTAT_TYPE_IF_SCSI	= 0x010,
12039229Sgibbs	DEVSTAT_TYPE_IF_IDE	= 0x020,
12139229Sgibbs	DEVSTAT_TYPE_IF_OTHER	= 0x030,
12239229Sgibbs	DEVSTAT_TYPE_IF_MASK	= 0x0f0,
12339229Sgibbs	DEVSTAT_TYPE_PASS	= 0x100
12439229Sgibbs} devstat_type_flags;
12539229Sgibbs
12639229Sgibbsstruct devstat {
12739229Sgibbs	STAILQ_ENTRY(devstat) 	dev_links;
12839229Sgibbs	u_int32_t		device_number;	     /*
12939229Sgibbs						      * Devstat device
13039229Sgibbs						      * number.
13139229Sgibbs						      */
13239229Sgibbs	char			device_name[DEVSTAT_NAME_LEN];
13339229Sgibbs	int			unit_number;
13451375Sphk	u_int64_t		bytes_read;	     /*
13551375Sphk						      * Total bytes read
13651375Sphk						      * from a device.
13751375Sphk						      */
13839229Sgibbs	u_int64_t		bytes_written;	     /*
13939229Sgibbs						      * Total bytes written
14039229Sgibbs						      * to a device.
14139229Sgibbs						      */
14251375Sphk	u_int64_t		bytes_freed;	     /*
14351375Sphk						      * Total bytes freed
14439229Sgibbs						      * from a device.
14539229Sgibbs						      */
14639229Sgibbs	u_int64_t		num_reads;	     /*
14739229Sgibbs						      * Total number of
14839229Sgibbs						      * read requests to
14939229Sgibbs						      * the device.
15039229Sgibbs						      */
15139229Sgibbs	u_int64_t		num_writes;	     /*
15239229Sgibbs						      * Total number of
15339229Sgibbs						      * write requests to
15439229Sgibbs						      * the device.
15539229Sgibbs						      */
15651375Sphk	u_int64_t		num_frees;	     /*
15751375Sphk						      * Total number of
15851375Sphk						      * free requests to
15951375Sphk						      * the device.
16051375Sphk						      */
16139229Sgibbs	u_int64_t		num_other;	     /*
16239229Sgibbs						      * Total number of
16339229Sgibbs						      * transactions that
16439229Sgibbs						      * don't read or write
16539229Sgibbs						      * data.
16639229Sgibbs						      */
16739229Sgibbs	int32_t			busy_count;	     /*
16839229Sgibbs						      * Total number of
16939229Sgibbs						      * transactions
17039229Sgibbs						      * outstanding for
17139229Sgibbs						      * the device.
17239229Sgibbs						      */
17339229Sgibbs	u_int32_t		block_size;	     /* Block size, bytes */
17439229Sgibbs	u_int64_t		tag_types[3];	     /*
17539229Sgibbs						      * The number of
17639229Sgibbs						      * simple, ordered,
17739229Sgibbs						      * and head of queue
17839229Sgibbs						      * tags sent.
17939229Sgibbs						      */
18039229Sgibbs	struct timeval		dev_creation_time;   /*
18139229Sgibbs						      * Time the device was
18239229Sgibbs						      * created.
18339229Sgibbs						      */
18439229Sgibbs	struct timeval 		busy_time;	     /*
18539229Sgibbs						      * Total amount of
18639229Sgibbs						      * time drive has spent
18739229Sgibbs						      * processing requests.
18839229Sgibbs						      */
18939229Sgibbs	struct timeval		start_time;	     /*
19039229Sgibbs						      * The time when
19139229Sgibbs						      * busy_count was
19239229Sgibbs						      * last == 0.  Or, the
19339229Sgibbs						      * start of the latest
19439229Sgibbs						      * busy period.
19539229Sgibbs						      */
19639229Sgibbs	struct timeval		last_comp_time;	     /*
19739229Sgibbs						      * Last time a
19839229Sgibbs						      * transaction was
19939229Sgibbs						      * completed.
20039229Sgibbs						      */
20139229Sgibbs
20239229Sgibbs	devstat_support_flags	flags;		     /*
20339229Sgibbs						      * Which statistics
20439229Sgibbs						      * are supported by a
20539229Sgibbs						      * given device.
20639229Sgibbs						      */
20739229Sgibbs	devstat_type_flags	device_type;	     /* Device type */
20843819Sken	devstat_priority	priority;	     /* Controls list pos. */
20939229Sgibbs};
21039229Sgibbs
21139229Sgibbs#ifdef KERNEL
21251375Sphkstruct buf;
21341153Swollmanvoid devstat_add_entry(struct devstat *ds, const char *dev_name,
21439229Sgibbs		       int unit_number, u_int32_t block_size,
21539229Sgibbs		       devstat_support_flags flags,
21643819Sken		       devstat_type_flags device_type,
21743819Sken		       devstat_priority priority);
21839229Sgibbsvoid devstat_remove_entry(struct devstat *ds);
21939229Sgibbsvoid devstat_start_transaction(struct devstat *ds);
22039229Sgibbsvoid devstat_end_transaction(struct devstat *ds, u_int32_t bytes,
22139229Sgibbs			     devstat_tag_type tag_type,
22239229Sgibbs			     devstat_trans_flags flags);
22351375Sphkvoid devstat_end_transaction_buf(struct devstat *ds, struct buf *);
22439229Sgibbs#endif
22539229Sgibbs
22639229Sgibbs#endif /* _DEVICESTAT_H */
227