devicestat.h revision 39229
139229Sgibbs/*
239229Sgibbs * Copyright (c) 1997, 1998 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 *
2839229Sgibbs *	$Id$
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 */
4839229Sgibbs#define DEVSTAT_VERSION	   1
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,
6539229Sgibbs	DEVSTAT_WRITE	= 0x02
6639229Sgibbs} devstat_trans_flags;
6739229Sgibbs
6839229Sgibbstypedef enum {
6939229Sgibbs	DEVSTAT_TAG_SIMPLE	= 0x00,
7039229Sgibbs	DEVSTAT_TAG_HEAD	= 0x01,
7139229Sgibbs	DEVSTAT_TAG_ORDERED	= 0x02,
7239229Sgibbs	DEVSTAT_TAG_NONE	= 0x03
7339229Sgibbs} devstat_tag_type;
7439229Sgibbs
7539229Sgibbs/*
7639229Sgibbs * These types are intended to aid statistics gathering/display programs.
7739229Sgibbs * The first 13 types (up to the 'target' flag) are identical numerically
7839229Sgibbs * to the SCSI device type numbers.  The next 3 types designate the device
7939229Sgibbs * interface.  Currently the choices are IDE, SCSI, and 'other'.  The last
8039229Sgibbs * flag specifies whether or not the given device is a passthrough device
8139229Sgibbs * or not.  If it is a passthrough device, the lower 4 bits specify which
8239229Sgibbs * type of physical device lies under the passthrough device, and the next
8339229Sgibbs * 4 bits specify the interface.
8439229Sgibbs */
8539229Sgibbstypedef enum {
8639229Sgibbs	DEVSTAT_TYPE_DIRECT	= 0x000,
8739229Sgibbs	DEVSTAT_TYPE_SEQUENTIAL	= 0x001,
8839229Sgibbs	DEVSTAT_TYPE_PRINTER	= 0x002,
8939229Sgibbs	DEVSTAT_TYPE_PROCESSOR	= 0x003,
9039229Sgibbs	DEVSTAT_TYPE_WORM	= 0x004,
9139229Sgibbs	DEVSTAT_TYPE_CDROM	= 0x005,
9239229Sgibbs	DEVSTAT_TYPE_SCANNER	= 0x006,
9339229Sgibbs	DEVSTAT_TYPE_OPTICAL	= 0x007,
9439229Sgibbs	DEVSTAT_TYPE_CHANGER	= 0x008,
9539229Sgibbs	DEVSTAT_TYPE_COMM	= 0x009,
9639229Sgibbs	DEVSTAT_TYPE_ASC0	= 0x00a,
9739229Sgibbs	DEVSTAT_TYPE_ASC1	= 0x00b,
9839229Sgibbs	DEVSTAT_TYPE_STORARRAY	= 0x00c,
9939229Sgibbs	DEVSTAT_TYPE_ENCLOSURE	= 0x00d,
10039229Sgibbs	DEVSTAT_TYPE_FLOPPY	= 0x00e,
10139229Sgibbs	DEVSTAT_TYPE_MASK	= 0x00f,
10239229Sgibbs	DEVSTAT_TYPE_IF_SCSI	= 0x010,
10339229Sgibbs	DEVSTAT_TYPE_IF_IDE	= 0x020,
10439229Sgibbs	DEVSTAT_TYPE_IF_OTHER	= 0x030,
10539229Sgibbs	DEVSTAT_TYPE_IF_MASK	= 0x0f0,
10639229Sgibbs	DEVSTAT_TYPE_PASS	= 0x100
10739229Sgibbs} devstat_type_flags;
10839229Sgibbs
10939229Sgibbsstruct devstat {
11039229Sgibbs	STAILQ_ENTRY(devstat) 	dev_links;
11139229Sgibbs	u_int32_t		device_number;	     /*
11239229Sgibbs						      * Devstat device
11339229Sgibbs						      * number.
11439229Sgibbs						      */
11539229Sgibbs	char			device_name[DEVSTAT_NAME_LEN];
11639229Sgibbs	int			unit_number;
11739229Sgibbs	u_int64_t		bytes_written;	     /*
11839229Sgibbs						      * Total bytes written
11939229Sgibbs						      * to a device.
12039229Sgibbs						      */
12139229Sgibbs	u_int64_t		bytes_read;	     /*
12239229Sgibbs						      * Total bytes read
12339229Sgibbs						      * from a device.
12439229Sgibbs						      */
12539229Sgibbs	u_int64_t		num_reads;	     /*
12639229Sgibbs						      * Total number of
12739229Sgibbs						      * read requests to
12839229Sgibbs						      * the device.
12939229Sgibbs						      */
13039229Sgibbs	u_int64_t		num_writes;	     /*
13139229Sgibbs						      * Total number of
13239229Sgibbs						      * write requests to
13339229Sgibbs						      * the device.
13439229Sgibbs						      */
13539229Sgibbs	u_int64_t		num_other;	     /*
13639229Sgibbs						      * Total number of
13739229Sgibbs						      * transactions that
13839229Sgibbs						      * don't read or write
13939229Sgibbs						      * data.
14039229Sgibbs						      */
14139229Sgibbs	int32_t			busy_count;	     /*
14239229Sgibbs						      * Total number of
14339229Sgibbs						      * transactions
14439229Sgibbs						      * outstanding for
14539229Sgibbs						      * the device.
14639229Sgibbs						      */
14739229Sgibbs	u_int32_t		block_size;	     /* Block size, bytes */
14839229Sgibbs	u_int64_t		tag_types[3];	     /*
14939229Sgibbs						      * The number of
15039229Sgibbs						      * simple, ordered,
15139229Sgibbs						      * and head of queue
15239229Sgibbs						      * tags sent.
15339229Sgibbs						      */
15439229Sgibbs	struct timeval		dev_creation_time;   /*
15539229Sgibbs						      * Time the device was
15639229Sgibbs						      * created.
15739229Sgibbs						      */
15839229Sgibbs	struct timeval 		busy_time;	     /*
15939229Sgibbs						      * Total amount of
16039229Sgibbs						      * time drive has spent
16139229Sgibbs						      * processing requests.
16239229Sgibbs						      */
16339229Sgibbs	struct timeval		start_time;	     /*
16439229Sgibbs						      * The time when
16539229Sgibbs						      * busy_count was
16639229Sgibbs						      * last == 0.  Or, the
16739229Sgibbs						      * start of the latest
16839229Sgibbs						      * busy period.
16939229Sgibbs						      */
17039229Sgibbs	struct timeval		last_comp_time;	     /*
17139229Sgibbs						      * Last time a
17239229Sgibbs						      * transaction was
17339229Sgibbs						      * completed.
17439229Sgibbs						      */
17539229Sgibbs
17639229Sgibbs	devstat_support_flags	flags;		     /*
17739229Sgibbs						      * Which statistics
17839229Sgibbs						      * are supported by a
17939229Sgibbs						      * given device.
18039229Sgibbs						      */
18139229Sgibbs	devstat_type_flags	device_type;	     /* Device type */
18239229Sgibbs};
18339229Sgibbs
18439229Sgibbs#ifdef KERNEL
18539229Sgibbsvoid devstat_add_entry(struct devstat *ds, char *dev_name,
18639229Sgibbs		       int unit_number, u_int32_t block_size,
18739229Sgibbs		       devstat_support_flags flags,
18839229Sgibbs		       devstat_type_flags device_type);
18939229Sgibbsvoid devstat_remove_entry(struct devstat *ds);
19039229Sgibbsvoid devstat_start_transaction(struct devstat *ds);
19139229Sgibbsvoid devstat_end_transaction(struct devstat *ds, u_int32_t bytes,
19239229Sgibbs			     devstat_tag_type tag_type,
19339229Sgibbs			     devstat_trans_flags flags);
19439229Sgibbs#endif
19539229Sgibbs
19639229Sgibbs#endif /* _DEVICESTAT_H */
197