xref: /openbmc/qemu/include/block/accounting.h (revision 96e4deda)
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>
28362e9299SAlberto Garcia #include <stdbool.h>
295e5a94b6SBenoît Canet 
305e5a94b6SBenoît Canet #include "qemu/typedefs.h"
31979e9b03SAlberto Garcia #include "qemu/timed-average.h"
32979e9b03SAlberto Garcia 
33979e9b03SAlberto Garcia typedef struct BlockAcctTimedStats BlockAcctTimedStats;
345e5a94b6SBenoît Canet 
355e5a94b6SBenoît Canet enum BlockAcctType {
3628298fd3SBenoît Canet     BLOCK_ACCT_READ,
3728298fd3SBenoît Canet     BLOCK_ACCT_WRITE,
3828298fd3SBenoît Canet     BLOCK_ACCT_FLUSH,
3928298fd3SBenoît Canet     BLOCK_MAX_IOTYPE,
405e5a94b6SBenoît Canet };
415e5a94b6SBenoît Canet 
42979e9b03SAlberto Garcia struct BlockAcctTimedStats {
43979e9b03SAlberto Garcia     TimedAverage latency[BLOCK_MAX_IOTYPE];
44979e9b03SAlberto Garcia     unsigned interval_length; /* in seconds */
45979e9b03SAlberto Garcia     QSLIST_ENTRY(BlockAcctTimedStats) entries;
46979e9b03SAlberto Garcia };
47979e9b03SAlberto Garcia 
485e5a94b6SBenoît Canet typedef struct BlockAcctStats {
4928298fd3SBenoît Canet     uint64_t nr_bytes[BLOCK_MAX_IOTYPE];
5028298fd3SBenoît Canet     uint64_t nr_ops[BLOCK_MAX_IOTYPE];
517ee12dafSAlberto Garcia     uint64_t invalid_ops[BLOCK_MAX_IOTYPE];
527ee12dafSAlberto Garcia     uint64_t failed_ops[BLOCK_MAX_IOTYPE];
5328298fd3SBenoît Canet     uint64_t total_time_ns[BLOCK_MAX_IOTYPE];
54f4564d53SPeter Lieven     uint64_t merged[BLOCK_MAX_IOTYPE];
55cb38fffbSAlberto Garcia     int64_t last_access_time_ns;
56979e9b03SAlberto Garcia     QSLIST_HEAD(, BlockAcctTimedStats) intervals;
57362e9299SAlberto Garcia     bool account_invalid;
58362e9299SAlberto Garcia     bool account_failed;
595e5a94b6SBenoît Canet } BlockAcctStats;
605e5a94b6SBenoît Canet 
615e5a94b6SBenoît Canet typedef struct BlockAcctCookie {
625e5a94b6SBenoît Canet     int64_t bytes;
635e5a94b6SBenoît Canet     int64_t start_time_ns;
645e5a94b6SBenoît Canet     enum BlockAcctType type;
655e5a94b6SBenoît Canet } BlockAcctCookie;
665e5a94b6SBenoît Canet 
67362e9299SAlberto Garcia void block_acct_init(BlockAcctStats *stats, bool account_invalid,
68362e9299SAlberto Garcia                      bool account_failed);
69979e9b03SAlberto Garcia void block_acct_cleanup(BlockAcctStats *stats);
70979e9b03SAlberto Garcia void block_acct_add_interval(BlockAcctStats *stats, unsigned interval_length);
71979e9b03SAlberto Garcia BlockAcctTimedStats *block_acct_interval_next(BlockAcctStats *stats,
72979e9b03SAlberto Garcia                                               BlockAcctTimedStats *s);
735366d0c8SBenoît Canet void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie,
745e5a94b6SBenoît Canet                       int64_t bytes, enum BlockAcctType type);
755366d0c8SBenoît Canet void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie);
767ee12dafSAlberto Garcia void block_acct_failed(BlockAcctStats *stats, BlockAcctCookie *cookie);
777ee12dafSAlberto Garcia void block_acct_invalid(BlockAcctStats *stats, enum BlockAcctType type);
78f4564d53SPeter Lieven void block_acct_merge_done(BlockAcctStats *stats, enum BlockAcctType type,
79f4564d53SPeter Lieven                            int num_requests);
80cb38fffbSAlberto Garcia int64_t block_acct_idle_time_ns(BlockAcctStats *stats);
81*96e4dedaSAlberto Garcia double block_acct_queue_depth(BlockAcctTimedStats *stats,
82*96e4dedaSAlberto Garcia                               enum BlockAcctType type);
835e5a94b6SBenoît Canet 
845e5a94b6SBenoît Canet #endif
85