| 1 | /* $NetBSD: iostat.h,v 1.10 2009/04/04 07:30:09 ad 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 | |
| 71 | /* |
| 72 | * Structure for keeping the in-kernel drive stats - these are linked |
| 73 | * together in drivelist. |
| 74 | */ |
| 75 | |
| 76 | struct io_stats { |
| 77 | char io_name[IOSTATNAMELEN]; /* device name */ |
| 78 | void *io_parent; /* pointer to what we are attached to */ |
| 79 | int io_type; /* type of device the state belong to */ |
| 80 | int io_busy; /* busy counter */ |
| 81 | u_int64_t io_rxfer; /* total number of read transfers */ |
| 82 | u_int64_t io_wxfer; /* total number of write transfers */ |
| 83 | u_int64_t io_seek; /* total independent seek operations */ |
| 84 | u_int64_t io_rbytes; /* total bytes read */ |
| 85 | u_int64_t io_wbytes; /* total bytes written */ |
| 86 | struct timeval io_attachtime; /* time disk was attached */ |
| 87 | struct timeval io_timestamp; /* timestamp of last unbusy */ |
| 88 | struct timeval io_time; /* total time spent busy */ |
| 89 | TAILQ_ENTRY(io_stats) io_link; |
| 90 | }; |
| 91 | |
| 92 | /* |
| 93 | * drivelist_head is defined here so that user-land has access to it. |
| 94 | */ |
| 95 | TAILQ_HEAD(iostatlist_head, io_stats); /* the iostatlist is a TAILQ */ |
| 96 | |
| 97 | #ifdef _KERNEL |
| 98 | void iostat_init(void); |
| 99 | void iostat_busy(struct io_stats *); |
| 100 | void iostat_unbusy(struct io_stats *, long, int); |
| 101 | bool iostat_isbusy(struct io_stats *); |
| 102 | struct io_stats *iostat_find(const char *); |
| 103 | struct io_stats *iostat_alloc(int32_t, void *, const char *); |
| 104 | void iostat_free(struct io_stats *); |
| 105 | void iostat_seek(struct io_stats *); |
| 106 | #endif |
| 107 | |
| 108 | #endif /* _SYS_IOSTAT_H_ */ |
| 109 | |