]> git.proxmox.com Git - mirror_qemu.git/blame - include/block/accounting.h
bitops.h: Implement half-shuffle and half-unshuffle ops
[mirror_qemu.git] / include / block / accounting.h
CommitLineData
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
30typedef struct BlockAcctTimedStats BlockAcctTimedStats;
5e5a94b6
BC
31
32enum 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
39struct BlockAcctTimedStats {
40 TimedAverage latency[BLOCK_MAX_IOTYPE];
41 unsigned interval_length; /* in seconds */
42 QSLIST_ENTRY(BlockAcctTimedStats) entries;
43};
44
5e5a94b6 45typedef 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
58typedef struct BlockAcctCookie {
59 int64_t bytes;
60 int64_t start_time_ns;
61 enum BlockAcctType type;
62} BlockAcctCookie;
63
362e9299
AG
64void block_acct_init(BlockAcctStats *stats, bool account_invalid,
65 bool account_failed);
979e9b03
AG
66void block_acct_cleanup(BlockAcctStats *stats);
67void block_acct_add_interval(BlockAcctStats *stats, unsigned interval_length);
68BlockAcctTimedStats *block_acct_interval_next(BlockAcctStats *stats,
69 BlockAcctTimedStats *s);
5366d0c8
BC
70void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie,
71 int64_t bytes, enum BlockAcctType type);
72void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie);
7ee12daf
AG
73void block_acct_failed(BlockAcctStats *stats, BlockAcctCookie *cookie);
74void block_acct_invalid(BlockAcctStats *stats, enum BlockAcctType type);
f4564d53
PL
75void block_acct_merge_done(BlockAcctStats *stats, enum BlockAcctType type,
76 int num_requests);
cb38fffb 77int64_t block_acct_idle_time_ns(BlockAcctStats *stats);
96e4deda
AG
78double block_acct_queue_depth(BlockAcctTimedStats *stats,
79 enum BlockAcctType type);
5e5a94b6
BC
80
81#endif