These device properties allow setting up I/O latency thresholds for when to report an I/O operation delay via QMP event (BLOCK_IO_DELAY) or when to stop the VM.
Signed-off-by: Hanna Czenczek <[email protected]> --- include/hw/block/block.h | 8 +++- blockdev.c | 16 ++++++++ hw/block/block.c | 7 ++++ tests/qemu-iotests/172.out | 76 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) diff --git a/include/hw/block/block.h b/include/hw/block/block.h index df941df19f2..3edc33a0339 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -36,6 +36,8 @@ typedef struct BlockConf { BlockdevOnError werror; uint32_t num_stats_intervals; uint32_t *stats_intervals; + uint64_t delay_report_ns; + uint64_t delay_stop_ns; } BlockConf; static inline unsigned int get_physical_block_exp(BlockConf *conf) @@ -83,7 +85,11 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) _conf.account_failed, ON_OFF_AUTO_AUTO), \ DEFINE_PROP_ARRAY("stats-intervals", _state, \ _conf.num_stats_intervals, _conf.stats_intervals, \ - qdev_prop_uint32, uint32_t) + qdev_prop_uint32, uint32_t), \ + DEFINE_PROP_UINT64("delay-report-ns", _state, _conf.delay_report_ns,\ + 0), \ + DEFINE_PROP_UINT64("delay-stop-ns", _state, _conf.delay_stop_ns, \ + 0) #define DEFINE_BLOCK_PROPERTIES(_state, _conf) \ DEFINE_PROP_DRIVE("drive", _state, _conf.blk), \ diff --git a/blockdev.c b/blockdev.c index 6e86c6262f9..90d94900645 100644 --- a/blockdev.c +++ b/blockdev.c @@ -496,6 +496,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, BlockdevDetectZeroesOptions detect_zeroes = BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF; const char *throttling_group = NULL; + uint64_t delay_report_ns, delay_stop_ns; /* Check common options by copying from bs_opts to opts, all other options * stay in bs_opts for processing by bdrv_open(). */ @@ -580,6 +581,9 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, read_only = qemu_opt_get_bool(opts, BDRV_OPT_READ_ONLY, false); + delay_report_ns = qemu_opt_get_number(opts, "delay-report-ns", 0); + delay_stop_ns = qemu_opt_get_number(opts, "delay-stop-ns", 0); + /* init */ if ((!file || !*file) && !qdict_size(bs_opts)) { BlockBackendRootState *blk_rs; @@ -615,6 +619,8 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, } bs = blk_bs(blk); + blk_set_delay_report_threshold(blk, delay_report_ns); + blk_set_delay_stop_threshold(blk, delay_stop_ns); bs->detect_zeroes = detect_zeroes; block_acct_setup(blk_get_stats(blk), account_invalid, account_failed, @@ -3753,6 +3759,16 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_BOOL, .help = "whether to account for failed I/O operations " "in the statistics", + },{ + .name = "delay-report-ns", + .type = QEMU_OPT_NUMBER, + .help = "threshold in ns when to report an I/O operation " + "delay via QMP event", + },{ + .name = "delay-stop-ns", + .type = QEMU_OPT_NUMBER, + .help = "threshold in ns when to pause the VM because " + "of an I/O operation delay", }, { /* end of list */ } }, diff --git a/hw/block/block.c b/hw/block/block.c index f187fa025d0..82d6f2e7980 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -249,6 +249,13 @@ bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, blk_set_enable_write_cache(blk, wce); blk_set_on_error(blk, rerror, werror); + if (conf->delay_report_ns) { + blk_set_delay_report_threshold(blk, conf->delay_report_ns); + } + if (conf->delay_stop_ns) { + blk_set_delay_stop_threshold(blk, conf->delay_stop_ns); + } + if (!block_acct_setup(blk_get_stats(blk), conf->account_invalid, conf->account_failed, conf->stats_intervals, conf->num_stats_intervals, errp)) { diff --git a/tests/qemu-iotests/172.out b/tests/qemu-iotests/172.out index a023cd407de..97ba78a8d53 100644 --- a/tests/qemu-iotests/172.out +++ b/tests/qemu-iotests/172.out @@ -31,6 +31,8 @@ Testing: account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "288" @@ -61,6 +63,8 @@ Testing: -fda TEST_DIR/t.qcow2 account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/unattached/device[N] @@ -98,6 +102,8 @@ Testing: -fdb TEST_DIR/t.qcow2 account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" dev: floppy, id "" unit = 0 (0x0) @@ -113,6 +119,8 @@ Testing: -fdb TEST_DIR/t.qcow2 account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "288" floppy1 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/unattached/device[N] @@ -154,6 +162,8 @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2 account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" dev: floppy, id "" unit = 0 (0x0) @@ -169,6 +179,8 @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2 account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/unattached/device[N] @@ -211,6 +223,8 @@ Testing: -fdb account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "288" dev: floppy, id "" unit = 0 (0x0) @@ -226,6 +240,8 @@ Testing: -fdb account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "288" @@ -256,6 +272,8 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/unattached/device[N] @@ -293,6 +311,8 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1 account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" dev: floppy, id "" unit = 0 (0x0) @@ -308,6 +328,8 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1 account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "288" floppy1 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/unattached/device[N] @@ -349,6 +371,8 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" dev: floppy, id "" unit = 0 (0x0) @@ -364,6 +388,8 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/unattached/device[N] @@ -409,6 +435,8 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0 account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/peripheral-anon/device[N] @@ -446,6 +474,8 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1 account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/peripheral-anon/device[N] @@ -483,6 +513,8 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" dev: floppy, id "" unit = 0 (0x0) @@ -498,6 +530,8 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/peripheral-anon/device[N] @@ -549,6 +583,8 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" dev: floppy, id "" unit = 0 (0x0) @@ -564,6 +600,8 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/unattached/device[N] @@ -606,6 +644,8 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" dev: floppy, id "" unit = 0 (0x0) @@ -621,6 +661,8 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/unattached/device[N] @@ -663,6 +705,8 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" dev: floppy, id "" unit = 1 (0x1) @@ -678,6 +722,8 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" floppy1 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/unattached/device[N] @@ -720,6 +766,8 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" dev: floppy, id "" unit = 1 (0x1) @@ -735,6 +783,8 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" floppy1 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/unattached/device[N] @@ -786,6 +836,8 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" dev: floppy, id "" unit = 0 (0x0) @@ -801,6 +853,8 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/unattached/device[N] @@ -843,6 +897,8 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" dev: floppy, id "" unit = 0 (0x0) @@ -858,6 +914,8 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/unattached/device[N] @@ -906,6 +964,8 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -global floppy.drive=none0 -device account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/peripheral-anon/device[N] @@ -973,6 +1033,8 @@ Testing: -device floppy account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "288" Testing: -device floppy,drive-type=120 @@ -1000,6 +1062,8 @@ Testing: -device floppy,drive-type=120 account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "120" Testing: -device floppy,drive-type=144 @@ -1027,6 +1091,8 @@ Testing: -device floppy,drive-type=144 account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" Testing: -device floppy,drive-type=288 @@ -1054,6 +1120,8 @@ Testing: -device floppy,drive-type=288 account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "288" @@ -1084,6 +1152,8 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "120" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/peripheral-anon/device[N] @@ -1121,6 +1191,8 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "288" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/peripheral-anon/device[N] @@ -1161,6 +1233,8 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,logical account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/peripheral-anon/device[N] @@ -1198,6 +1272,8 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,physica account-invalid = "auto" account-failed = "auto" stats-intervals = <null> + delay-report-ns = 0 (0x0) + delay-stop-ns = 0 (0x0) drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) Attached to: /machine/peripheral-anon/device[N] -- 2.55.0
