1*5e5a94b6SBenoît Canet /* 2*5e5a94b6SBenoît Canet * QEMU System Emulator block accounting 3*5e5a94b6SBenoît Canet * 4*5e5a94b6SBenoît Canet * Copyright (c) 2011 Christoph Hellwig 5*5e5a94b6SBenoît Canet * 6*5e5a94b6SBenoît Canet * Permission is hereby granted, free of charge, to any person obtaining a copy 7*5e5a94b6SBenoît Canet * of this software and associated documentation files (the "Software"), to deal 8*5e5a94b6SBenoît Canet * in the Software without restriction, including without limitation the rights 9*5e5a94b6SBenoît Canet * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10*5e5a94b6SBenoît Canet * copies of the Software, and to permit persons to whom the Software is 11*5e5a94b6SBenoît Canet * furnished to do so, subject to the following conditions: 12*5e5a94b6SBenoît Canet * 13*5e5a94b6SBenoît Canet * The above copyright notice and this permission notice shall be included in 14*5e5a94b6SBenoît Canet * all copies or substantial portions of the Software. 15*5e5a94b6SBenoît Canet * 16*5e5a94b6SBenoît Canet * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17*5e5a94b6SBenoît Canet * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18*5e5a94b6SBenoît Canet * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19*5e5a94b6SBenoît Canet * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20*5e5a94b6SBenoît Canet * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21*5e5a94b6SBenoît Canet * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22*5e5a94b6SBenoît Canet * THE SOFTWARE. 23*5e5a94b6SBenoît Canet */ 24*5e5a94b6SBenoît Canet #ifndef BLOCK_ACCOUNTING_H 25*5e5a94b6SBenoît Canet #define BLOCK_ACCOUNTING_H 26*5e5a94b6SBenoît Canet 27*5e5a94b6SBenoît Canet #include <stdint.h> 28*5e5a94b6SBenoît Canet 29*5e5a94b6SBenoît Canet #include "qemu/typedefs.h" 30*5e5a94b6SBenoît Canet 31*5e5a94b6SBenoît Canet enum BlockAcctType { 32*5e5a94b6SBenoît Canet BDRV_ACCT_READ, 33*5e5a94b6SBenoît Canet BDRV_ACCT_WRITE, 34*5e5a94b6SBenoît Canet BDRV_ACCT_FLUSH, 35*5e5a94b6SBenoît Canet BDRV_MAX_IOTYPE, 36*5e5a94b6SBenoît Canet }; 37*5e5a94b6SBenoît Canet 38*5e5a94b6SBenoît Canet typedef struct BlockAcctStats { 39*5e5a94b6SBenoît Canet uint64_t nr_bytes[BDRV_MAX_IOTYPE]; 40*5e5a94b6SBenoît Canet uint64_t nr_ops[BDRV_MAX_IOTYPE]; 41*5e5a94b6SBenoît Canet uint64_t total_time_ns[BDRV_MAX_IOTYPE]; 42*5e5a94b6SBenoît Canet uint64_t wr_highest_sector; 43*5e5a94b6SBenoît Canet } BlockAcctStats; 44*5e5a94b6SBenoît Canet 45*5e5a94b6SBenoît Canet typedef struct BlockAcctCookie { 46*5e5a94b6SBenoît Canet int64_t bytes; 47*5e5a94b6SBenoît Canet int64_t start_time_ns; 48*5e5a94b6SBenoît Canet enum BlockAcctType type; 49*5e5a94b6SBenoît Canet } BlockAcctCookie; 50*5e5a94b6SBenoît Canet 51*5e5a94b6SBenoît Canet void bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie, 52*5e5a94b6SBenoît Canet int64_t bytes, enum BlockAcctType type); 53*5e5a94b6SBenoît Canet void bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie); 54*5e5a94b6SBenoît Canet void bdrv_acct_highest_sector(BlockDriverState *bs, int64_t sector_num, 55*5e5a94b6SBenoît Canet unsigned int nb_sectors); 56*5e5a94b6SBenoît Canet 57*5e5a94b6SBenoît Canet #endif 58