From b7dbead4e06a6b9a7f74a7bd65e9e2f0770158b5 Mon Sep 17 00:00:00 2001 From: Prasad Joshi Date: Fri, 10 Jun 2011 11:35:20 +0100 Subject: [PATCH] kvm tools: Add IO delay option Add a command line debug option to add a fix amount of delay in read and write operation. From Ingo "the delays are *constant* [make sure you use a high-res timers kernel], so they do not result in nearly as much measurement noise as real block IO does. [...] This way you are basically 'emulating' a real disk drive but you will emulate uniform latencies, which makes measurements a lot more reliable - while still relevant to the end result." Suggested-by: Ingo Molnar Signed-off-by: Prasad Joshi Signed-off-by: Pekka Enberg --- tools/kvm/disk/core.c | 8 ++++++++ tools/kvm/include/kvm/util.h | 7 +++++++ tools/kvm/kvm-run.c | 3 +++ 3 files changed, 18 insertions(+) diff --git a/tools/kvm/disk/core.c b/tools/kvm/disk/core.c index f2b482a570c9..965bbe5baac6 100644 --- a/tools/kvm/disk/core.c +++ b/tools/kvm/disk/core.c @@ -1,6 +1,8 @@ #include "kvm/disk-image.h" #include "kvm/qcow.h" +int debug_iodelay; + struct disk_image *disk_image__new(int fd, u64 size, struct disk_image_operations *ops, int use_mmap) { struct disk_image *disk; @@ -132,6 +134,9 @@ ssize_t disk_image__read(struct disk_image *disk, u64 sector, const struct iovec ssize_t total = 0; ssize_t nr; + if (debug_iodelay) + msleep(debug_iodelay); + if (disk->ops->read_sector_iov) { /* * Try mulitple buffer based operation first @@ -170,6 +175,9 @@ ssize_t disk_image__write(struct disk_image *disk, u64 sector, const struct iove ssize_t total = 0; ssize_t nr; + if (debug_iodelay) + msleep(debug_iodelay); + if (disk->ops->write_sector_iov) { /* * Try writev based operation first diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h index a9425cc6d3e3..dc2e0b9f7790 100644 --- a/tools/kvm/include/kvm/util.h +++ b/tools/kvm/include/kvm/util.h @@ -68,4 +68,11 @@ static inline const char *skip_prefix(const char *str, const char *prefix) return strncmp(str, prefix, len) ? NULL : str + len; } +#define MSECS_TO_USECS(s) ((s) * 1000) + +/* Millisecond sleep */ +static inline void msleep(unsigned int msecs) +{ + usleep(MSECS_TO_USECS(msecs)); +} #endif /* KVM__UTIL_H */ diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index 201019a23d8e..f121a2b81756 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -76,6 +76,7 @@ static bool vnc; static bool sdl; extern bool ioport_debug; extern int active_console; +extern int debug_iodelay; bool do_debug_print = false; @@ -151,6 +152,8 @@ static const struct option options[] = { "Enable single stepping"), OPT_BOOLEAN('\0', "debug-ioport-debug", &ioport_debug, "Enable ioport debugging"), + OPT_INTEGER('\0', "debug_iodelay", &debug_iodelay, + "Delay IO by millisecond"), OPT_END() }; -- 2.39.5