devicestat.h revision 112000
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 112000 2003-03-08 19:55:59Z phk $
2939229Sgibbs */
3039229Sgibbs
3139229Sgibbs#ifndef _DEVICESTAT_H
3239229Sgibbs#define _DEVICESTAT_H
3339229Sgibbs
3439229Sgibbs#include <sys/queue.h>
3539229Sgibbs#include <sys/time.h>
3639229Sgibbs
37112000Sphk/*
38112000Sphk * XXX: Should really be SPECNAMELEN
39112000Sphk */
4039229Sgibbs#define DEVSTAT_NAME_LEN  16
4139229Sgibbs
4239229Sgibbs/*
4339229Sgibbs * ATTENTION:  The devstat version below should be incremented any time a
4439229Sgibbs * change is made in struct devstat, or any time a change is made in the
4539229Sgibbs * enumerated types that struct devstat uses.  (Only if those changes
4639229Sgibbs * would require a recompile -- i.e. re-arranging the order of an
4739229Sgibbs * enumerated type or something like that.)  This version number is used by
4839229Sgibbs * userland utilities to determine whether or not they are in sync with the
4939229Sgibbs * kernel.
5039229Sgibbs */
51112000Sphk#define DEVSTAT_VERSION	   5
5239229Sgibbs
5339229Sgibbs/*
5439229Sgibbs * These flags specify which statistics features are supported or not
5539229Sgibbs * supported by a particular device.  The default is all statistics are
5639229Sgibbs * supported.
5739229Sgibbs */
5839229Sgibbstypedef enum {
5939229Sgibbs	DEVSTAT_ALL_SUPPORTED	= 0x00,
6039229Sgibbs	DEVSTAT_NO_BLOCKSIZE	= 0x01,
6139229Sgibbs	DEVSTAT_NO_ORDERED_TAGS	= 0x02,
6239229Sgibbs	DEVSTAT_BS_UNAVAILABLE	= 0x04
6339229Sgibbs} devstat_support_flags;
6439229Sgibbs
6539229Sgibbstypedef enum {
6639229Sgibbs	DEVSTAT_NO_DATA	= 0x00,
6739229Sgibbs	DEVSTAT_READ	= 0x01,
6851375Sphk	DEVSTAT_WRITE	= 0x02,
6951375Sphk	DEVSTAT_FREE	= 0x03
7039229Sgibbs} devstat_trans_flags;
7139229Sgibbs
7239229Sgibbstypedef enum {
7339229Sgibbs	DEVSTAT_TAG_SIMPLE	= 0x00,
7439229Sgibbs	DEVSTAT_TAG_HEAD	= 0x01,
7539229Sgibbs	DEVSTAT_TAG_ORDERED	= 0x02,
7639229Sgibbs	DEVSTAT_TAG_NONE	= 0x03
7739229Sgibbs} devstat_tag_type;
7839229Sgibbs
7943819Skentypedef enum {
8043819Sken	DEVSTAT_PRIORITY_MIN	= 0x000,
8143819Sken	DEVSTAT_PRIORITY_OTHER	= 0x020,
8243819Sken	DEVSTAT_PRIORITY_PASS	= 0x030,
8343819Sken	DEVSTAT_PRIORITY_FD	= 0x040,
8443819Sken	DEVSTAT_PRIORITY_WFD	= 0x050,
8554279Sken	DEVSTAT_PRIORITY_TAPE	= 0x060,
8643819Sken	DEVSTAT_PRIORITY_CD	= 0x090,
8754279Sken	DEVSTAT_PRIORITY_DISK	= 0x110,
8854279Sken	DEVSTAT_PRIORITY_ARRAY	= 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 {
127112000Sphk	int			sequence0;	     /* Update sequence# */
128112000Sphk	int			allocated;	     /* Allocated entry */
12960938Sjake	STAILQ_ENTRY(devstat) 	dev_links;
13039229Sgibbs	u_int32_t		device_number;	     /*
13139229Sgibbs						      * Devstat device
13239229Sgibbs						      * number.
13339229Sgibbs						      */
13439229Sgibbs	char			device_name[DEVSTAT_NAME_LEN];
13539229Sgibbs	int			unit_number;
13651375Sphk	u_int64_t		bytes_read;	     /*
13751375Sphk						      * Total bytes read
13851375Sphk						      * from a device.
13951375Sphk						      */
14039229Sgibbs	u_int64_t		bytes_written;	     /*
14139229Sgibbs						      * Total bytes written
14239229Sgibbs						      * to a device.
14339229Sgibbs						      */
14451375Sphk	u_int64_t		bytes_freed;	     /*
14551375Sphk						      * Total bytes freed
14639229Sgibbs						      * from a device.
14739229Sgibbs						      */
14839229Sgibbs	u_int64_t		num_reads;	     /*
14939229Sgibbs						      * Total number of
15039229Sgibbs						      * read requests to
15139229Sgibbs						      * the device.
15239229Sgibbs						      */
15339229Sgibbs	u_int64_t		num_writes;	     /*
15439229Sgibbs						      * Total number of
15539229Sgibbs						      * write requests to
15639229Sgibbs						      * the device.
15739229Sgibbs						      */
15851375Sphk	u_int64_t		num_frees;	     /*
15951375Sphk						      * Total number of
16051375Sphk						      * free requests to
16151375Sphk						      * the device.
16251375Sphk						      */
16339229Sgibbs	u_int64_t		num_other;	     /*
16439229Sgibbs						      * Total number of
16539229Sgibbs						      * transactions that
16639229Sgibbs						      * don't read or write
16739229Sgibbs						      * data.
16839229Sgibbs						      */
16939229Sgibbs	int32_t			busy_count;	     /*
17039229Sgibbs						      * Total number of
17139229Sgibbs						      * transactions
17239229Sgibbs						      * outstanding for
17339229Sgibbs						      * the device.
17439229Sgibbs						      */
17539229Sgibbs	u_int32_t		block_size;	     /* Block size, bytes */
17639229Sgibbs	u_int64_t		tag_types[3];	     /*
17739229Sgibbs						      * The number of
17839229Sgibbs						      * simple, ordered,
17939229Sgibbs						      * and head of queue
18039229Sgibbs						      * tags sent.
18139229Sgibbs						      */
18239229Sgibbs	struct timeval		dev_creation_time;   /*
18339229Sgibbs						      * Time the device was
18439229Sgibbs						      * created.
18539229Sgibbs						      */
18639229Sgibbs	struct timeval 		busy_time;	     /*
18739229Sgibbs						      * Total amount of
18839229Sgibbs						      * time drive has spent
18939229Sgibbs						      * processing requests.
19039229Sgibbs						      */
19139229Sgibbs	struct timeval		start_time;	     /*
19239229Sgibbs						      * The time when
19339229Sgibbs						      * busy_count was
19439229Sgibbs						      * last == 0.  Or, the
19539229Sgibbs						      * start of the latest
19639229Sgibbs						      * busy period.
19739229Sgibbs						      */
19839229Sgibbs	struct timeval		last_comp_time;	     /*
19939229Sgibbs						      * Last time a
20039229Sgibbs						      * transaction was
20139229Sgibbs						      * completed.
20239229Sgibbs						      */
20339229Sgibbs
20439229Sgibbs	devstat_support_flags	flags;		     /*
20539229Sgibbs						      * Which statistics
20639229Sgibbs						      * are supported by a
20739229Sgibbs						      * given device.
20839229Sgibbs						      */
20939229Sgibbs	devstat_type_flags	device_type;	     /* Device type */
21043819Sken	devstat_priority	priority;	     /* Controls list pos. */
211112000Sphk
212112000Sphk	int			sequence1;	     /* Update sequence# */
21339229Sgibbs};
21439229Sgibbs
21581129StmmSTAILQ_HEAD(devstatlist, devstat);
21681129Stmm
21755205Speter#ifdef _KERNEL
21858969Sphkstruct bio;
21960395Sbde
220112000Sphkstruct devstat *devstat_new_entry(const char *dev_name,
221112000Sphk		       int unit_number, u_int32_t block_size,
222112000Sphk		       devstat_support_flags flags,
223112000Sphk		       devstat_type_flags device_type,
224112000Sphk		       devstat_priority priority);
225112000Sphk
22641153Swollmanvoid devstat_add_entry(struct devstat *ds, const char *dev_name,
22739229Sgibbs		       int unit_number, u_int32_t block_size,
22839229Sgibbs		       devstat_support_flags flags,
22943819Sken		       devstat_type_flags device_type,
23043819Sken		       devstat_priority priority);
23139229Sgibbsvoid devstat_remove_entry(struct devstat *ds);
23239229Sgibbsvoid devstat_start_transaction(struct devstat *ds);
23339229Sgibbsvoid devstat_end_transaction(struct devstat *ds, u_int32_t bytes,
23439229Sgibbs			     devstat_tag_type tag_type,
23539229Sgibbs			     devstat_trans_flags flags);
23660395Sbdevoid devstat_end_transaction_bio(struct devstat *ds, struct bio *bp);
23739229Sgibbs#endif
23839229Sgibbs
23939229Sgibbs#endif /* _DEVICESTAT_H */
240