xref: /openbmc/qemu/include/block/accounting.h (revision 28298fd3d9df6685c069fa0d03398c8c585a83ea)
15e5a94b6SBenoît Canet /*
25e5a94b6SBenoît Canet  * QEMU System Emulator block accounting
35e5a94b6SBenoît Canet  *
45e5a94b6SBenoît Canet  * Copyright (c) 2011 Christoph Hellwig
55e5a94b6SBenoît Canet  *
65e5a94b6SBenoît Canet  * Permission is hereby granted, free of charge, to any person obtaining a copy
75e5a94b6SBenoît Canet  * of this software and associated documentation files (the "Software"), to deal
85e5a94b6SBenoît Canet  * in the Software without restriction, including without limitation the rights
95e5a94b6SBenoît Canet  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
105e5a94b6SBenoît Canet  * copies of the Software, and to permit persons to whom the Software is
115e5a94b6SBenoît Canet  * furnished to do so, subject to the following conditions:
125e5a94b6SBenoît Canet  *
135e5a94b6SBenoît Canet  * The above copyright notice and this permission notice shall be included in
145e5a94b6SBenoît Canet  * all copies or substantial portions of the Software.
155e5a94b6SBenoît Canet  *
165e5a94b6SBenoît Canet  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
175e5a94b6SBenoît Canet  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
185e5a94b6SBenoît Canet  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
195e5a94b6SBenoît Canet  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
205e5a94b6SBenoît Canet  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
215e5a94b6SBenoît Canet  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
225e5a94b6SBenoît Canet  * THE SOFTWARE.
235e5a94b6SBenoît Canet  */
245e5a94b6SBenoît Canet #ifndef BLOCK_ACCOUNTING_H
255e5a94b6SBenoît Canet #define BLOCK_ACCOUNTING_H
265e5a94b6SBenoît Canet 
275e5a94b6SBenoît Canet #include <stdint.h>
285e5a94b6SBenoît Canet 
295e5a94b6SBenoît Canet #include "qemu/typedefs.h"
305e5a94b6SBenoît Canet 
315e5a94b6SBenoît Canet enum BlockAcctType {
32*28298fd3SBenoît Canet     BLOCK_ACCT_READ,
33*28298fd3SBenoît Canet     BLOCK_ACCT_WRITE,
34*28298fd3SBenoît Canet     BLOCK_ACCT_FLUSH,
35*28298fd3SBenoît Canet     BLOCK_MAX_IOTYPE,
365e5a94b6SBenoît Canet };
375e5a94b6SBenoît Canet 
385e5a94b6SBenoît Canet typedef struct BlockAcctStats {
39*28298fd3SBenoît Canet     uint64_t nr_bytes[BLOCK_MAX_IOTYPE];
40*28298fd3SBenoît Canet     uint64_t nr_ops[BLOCK_MAX_IOTYPE];
41*28298fd3SBenoît Canet     uint64_t total_time_ns[BLOCK_MAX_IOTYPE];
425e5a94b6SBenoît Canet     uint64_t wr_highest_sector;
435e5a94b6SBenoît Canet } BlockAcctStats;
445e5a94b6SBenoît Canet 
455e5a94b6SBenoît Canet typedef struct BlockAcctCookie {
465e5a94b6SBenoît Canet     int64_t bytes;
475e5a94b6SBenoît Canet     int64_t start_time_ns;
485e5a94b6SBenoît Canet     enum BlockAcctType type;
495e5a94b6SBenoît Canet } BlockAcctCookie;
505e5a94b6SBenoît Canet 
515e5a94b6SBenoît Canet void bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie,
525e5a94b6SBenoît Canet         int64_t bytes, enum BlockAcctType type);
535e5a94b6SBenoît Canet void bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie);
545e5a94b6SBenoît Canet void bdrv_acct_highest_sector(BlockDriverState *bs, int64_t sector_num,
555e5a94b6SBenoît Canet                               unsigned int nb_sectors);
565e5a94b6SBenoît Canet 
575e5a94b6SBenoît Canet #endif
58