]>
Commit | Line | Data |
---|---|---|
5e5a94b6 BC |
1 | /* |
2 | * QEMU System Emulator block accounting | |
3 | * | |
4 | * Copyright (c) 2011 Christoph Hellwig | |
aece5edc | 5 | * Copyright (c) 2015 Igalia, S.L. |
5e5a94b6 BC |
6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
23 | * THE SOFTWARE. | |
24 | */ | |
25 | #ifndef BLOCK_ACCOUNTING_H | |
26 | #define BLOCK_ACCOUNTING_H | |
27 | ||
979e9b03 AG |
28 | #include "qemu/timed-average.h" |
29 | ||
30 | typedef struct BlockAcctTimedStats BlockAcctTimedStats; | |
5e5a94b6 BC |
31 | |
32 | enum BlockAcctType { | |
28298fd3 BC |
33 | BLOCK_ACCT_READ, |
34 | BLOCK_ACCT_WRITE, | |
35 | BLOCK_ACCT_FLUSH, | |
36 | BLOCK_MAX_IOTYPE, | |
5e5a94b6 BC |
37 | }; |
38 | ||
979e9b03 AG |
39 | struct BlockAcctTimedStats { |
40 | TimedAverage latency[BLOCK_MAX_IOTYPE]; | |
41 | unsigned interval_length; /* in seconds */ | |
42 | QSLIST_ENTRY(BlockAcctTimedStats) entries; | |
43 | }; | |
44 | ||
5e5a94b6 | 45 | typedef struct BlockAcctStats { |
28298fd3 BC |
46 | uint64_t nr_bytes[BLOCK_MAX_IOTYPE]; |
47 | uint64_t nr_ops[BLOCK_MAX_IOTYPE]; | |
7ee12daf AG |
48 | uint64_t invalid_ops[BLOCK_MAX_IOTYPE]; |
49 | uint64_t failed_ops[BLOCK_MAX_IOTYPE]; | |
28298fd3 | 50 | uint64_t total_time_ns[BLOCK_MAX_IOTYPE]; |
f4564d53 | 51 | uint64_t merged[BLOCK_MAX_IOTYPE]; |
cb38fffb | 52 | int64_t last_access_time_ns; |
979e9b03 | 53 | QSLIST_HEAD(, BlockAcctTimedStats) intervals; |
362e9299 AG |
54 | bool account_invalid; |
55 | bool account_failed; | |
5e5a94b6 BC |
56 | } BlockAcctStats; |
57 | ||
58 | typedef struct BlockAcctCookie { | |
59 | int64_t bytes; | |
60 | int64_t start_time_ns; | |
61 | enum BlockAcctType type; | |
62 | } BlockAcctCookie; | |
63 | ||
362e9299 AG |
64 | void block_acct_init(BlockAcctStats *stats, bool account_invalid, |
65 | bool account_failed); | |
979e9b03 AG |
66 | void block_acct_cleanup(BlockAcctStats *stats); |
67 | void block_acct_add_interval(BlockAcctStats *stats, unsigned interval_length); | |
68 | BlockAcctTimedStats *block_acct_interval_next(BlockAcctStats *stats, | |
69 | BlockAcctTimedStats *s); | |
5366d0c8 BC |
70 | void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie, |
71 | int64_t bytes, enum BlockAcctType type); | |
72 | void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie); | |
7ee12daf AG |
73 | void block_acct_failed(BlockAcctStats *stats, BlockAcctCookie *cookie); |
74 | void block_acct_invalid(BlockAcctStats *stats, enum BlockAcctType type); | |
f4564d53 PL |
75 | void block_acct_merge_done(BlockAcctStats *stats, enum BlockAcctType type, |
76 | int num_requests); | |
cb38fffb | 77 | int64_t block_acct_idle_time_ns(BlockAcctStats *stats); |
96e4deda AG |
78 | double block_acct_queue_depth(BlockAcctTimedStats *stats, |
79 | enum BlockAcctType type); | |
5e5a94b6 BC |
80 | |
81 | #endif |