Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: iostat.h,v 1.12 2019/05/22 08:47:02 hannken Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1997, 2004, 2009 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #ifndef _SYS_IOSTAT_H_
     34 #define _SYS_IOSTAT_H_
     35 
     36 /*
     37  * Disk device structures.
     38  */
     39 
     40 #include <sys/time.h>
     41 #include <sys/queue.h>
     42 
     43 #define	IOSTATNAMELEN	16
     44 
     45 /* types of drives we can have */
     46 #define IOSTAT_DISK	0
     47 #define IOSTAT_TAPE	1
     48 #define IOSTAT_NFS	2
     49 
     50 /* The following structure is 64-bit alignment safe */
     51 struct io_sysctl {
     52 	char		name[IOSTATNAMELEN];
     53 	int32_t		busy;
     54 	int32_t		type;
     55 	u_int64_t	xfer;
     56 	u_int64_t	seek;
     57 	u_int64_t	bytes;
     58 	u_int32_t	attachtime_sec;
     59 	u_int32_t	attachtime_usec;
     60 	u_int32_t	timestamp_sec;
     61 	u_int32_t	timestamp_usec;
     62 	u_int32_t	time_sec;
     63 	u_int32_t	time_usec;
     64 	/* New separate read/write stats */
     65 	u_int64_t	rxfer;
     66 	u_int64_t	rbytes;
     67 	u_int64_t	wxfer;
     68 	u_int64_t	wbytes;
     69 	/*
     70 	 * New queue stats
     71 	 * accumulated wait time (iostat_wait .. iostat_busy)
     72 	 * accumulated wait sum (wait time * count)
     73 	 * accumulated busy sum (busy time * count)
     74 	 */
     75 	u_int32_t	wait_sec;
     76 	u_int32_t	wait_usec;
     77 	u_int32_t	waitsum_sec;
     78 	u_int32_t	waitsum_usec;
     79 	u_int32_t	busysum_sec;
     80 	u_int32_t	busysum_usec;
     81 };
     82 
     83 /*
     84  * Structure for keeping the in-kernel drive stats - these are linked
     85  * together in drivelist.
     86  */
     87 
     88 struct io_stats {
     89 	char		io_name[IOSTATNAMELEN];  /* device name */
     90 	void		*io_parent; /* pointer to what we are attached to */
     91 	int		io_type;   /* type of device the state belong to */
     92 	int		io_busy;	/* busy counter */
     93 	int		io_wait;	/* wait counter */
     94 	u_int64_t	io_rxfer;	/* total number of read transfers */
     95 	u_int64_t	io_wxfer;	/* total number of write transfers */
     96 	u_int64_t	io_seek;	/* total independent seek operations */
     97 	u_int64_t	io_rbytes;	/* total bytes read */
     98 	u_int64_t	io_wbytes;	/* total bytes written */
     99 	struct timeval	io_attachtime;	/* time disk was attached */
    100 	struct timeval	io_timestamp;	/* timestamp of last unbusy */
    101 	struct timeval	io_busystamp;	/* timestamp of last busy */
    102 	struct timeval	io_waitstamp;	/* timestamp of last wait */
    103 	struct timeval	io_busysum;	/* accumulated wait * time */
    104 	struct timeval	io_waitsum;	/* accumulated busy * time */
    105 	struct timeval	io_busytime;	/* accumlated time busy */
    106 	struct timeval	io_waittime;	/* accumlated time waiting */
    107 	TAILQ_ENTRY(io_stats) io_link;
    108 };
    109 
    110 /*
    111  * drivelist_head is defined here so that user-land has access to it.
    112  */
    113 TAILQ_HEAD(iostatlist_head, io_stats);	/* the iostatlist is a TAILQ */
    114 
    115 #ifdef _KERNEL
    116 void	iostat_init(void);
    117 void	iostat_wait(struct io_stats *);
    118 void	iostat_busy(struct io_stats *);
    119 void	iostat_unbusy(struct io_stats *, long, int);
    120 bool	iostat_isbusy(struct io_stats *);
    121 struct io_stats *iostat_find(const char *);
    122 struct io_stats *iostat_alloc(int32_t, void *, const char *);
    123 void	iostat_free(struct io_stats *);
    124 void	iostat_rename(struct io_stats *, const char *);
    125 void	iostat_seek(struct io_stats *);
    126 #endif
    127 
    128 #endif /* _SYS_IOSTAT_H_ */
    129