]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Add IO delay option
authorPrasad Joshi <prasadjoshi124@gmail.com>
Fri, 10 Jun 2011 10:35:20 +0000 (11:35 +0100)
committerPekka Enberg <penberg@kernel.org>
Wed, 15 Jun 2011 13:59:37 +0000 (16:59 +0300)
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 <mingo@elte.hu>
Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/disk/core.c
tools/kvm/include/kvm/util.h
tools/kvm/kvm-run.c

index f2b482a570c9e05106bb61bb8560fe4d22314af1..965bbe5baac672b5cd49d8188d9d1e393555038e 100644 (file)
@@ -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
index a9425cc6d3e308838a2484db30f180c9af52b9c6..dc2e0b9f77908bdc7da448105934f9c65dd57604 100644 (file)
@@ -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 */
index 201019a23d8e461f40c5883db0e4e5e3d90003e1..f121a2b81756f5c9236845418427ee393a506051 100644 (file)
@@ -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()
 };