qemu/include/block/accounting.h
<<
>>
Prefs
   1/*
   2 * QEMU System Emulator block accounting
   3 *
   4 * Copyright (c) 2011 Christoph Hellwig
   5 * Copyright (c) 2015 Igalia, S.L.
   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
  28#include "qemu/timed-average.h"
  29
  30typedef struct BlockAcctTimedStats BlockAcctTimedStats;
  31
  32enum BlockAcctType {
  33    BLOCK_ACCT_READ,
  34    BLOCK_ACCT_WRITE,
  35    BLOCK_ACCT_FLUSH,
  36    BLOCK_MAX_IOTYPE,
  37};
  38
  39struct BlockAcctTimedStats {
  40    TimedAverage latency[BLOCK_MAX_IOTYPE];
  41    unsigned interval_length; /* in seconds */
  42    QSLIST_ENTRY(BlockAcctTimedStats) entries;
  43};
  44
  45typedef struct BlockAcctStats {
  46    uint64_t nr_bytes[BLOCK_MAX_IOTYPE];
  47    uint64_t nr_ops[BLOCK_MAX_IOTYPE];
  48    uint64_t invalid_ops[BLOCK_MAX_IOTYPE];
  49    uint64_t failed_ops[BLOCK_MAX_IOTYPE];
  50    uint64_t total_time_ns[BLOCK_MAX_IOTYPE];
  51    uint64_t merged[BLOCK_MAX_IOTYPE];
  52    int64_t last_access_time_ns;
  53    QSLIST_HEAD(, BlockAcctTimedStats) intervals;
  54    bool account_invalid;
  55    bool account_failed;
  56} BlockAcctStats;
  57
  58typedef struct BlockAcctCookie {
  59    int64_t bytes;
  60    int64_t start_time_ns;
  61    enum BlockAcctType type;
  62} BlockAcctCookie;
  63
  64void block_acct_init(BlockAcctStats *stats, bool account_invalid,
  65                     bool account_failed);
  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);
  70void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie,
  71                      int64_t bytes, enum BlockAcctType type);
  72void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie);
  73void block_acct_failed(BlockAcctStats *stats, BlockAcctCookie *cookie);
  74void block_acct_invalid(BlockAcctStats *stats, enum BlockAcctType type);
  75void block_acct_merge_done(BlockAcctStats *stats, enum BlockAcctType type,
  76                           int num_requests);
  77int64_t block_acct_idle_time_ns(BlockAcctStats *stats);
  78double block_acct_queue_depth(BlockAcctTimedStats *stats,
  79                              enum BlockAcctType type);
  80
  81#endif
  82