[tip:tools/kvm] kvm tools: Add IO delay option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  b7dbead4e06a6b9a7f74a7bd65e9e2f0770158b5
Gitweb:     http://git.kernel.org/tip/b7dbead4e06a6b9a7f74a7bd65e9e2f0770158b5
Author:     Prasad Joshi <prasadjoshi124@xxxxxxxxx>
AuthorDate: Fri, 10 Jun 2011 11:35:20 +0100
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Wed, 15 Jun 2011 16:59:37 +0300

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 <mingo@xxxxxxx>
Signed-off-by: Prasad Joshi <prasadjoshi124@xxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 tools/kvm/disk/core.c        |    8 ++++++++
 tools/kvm/include/kvm/util.h |    7 +++++++
 tools/kvm/kvm-run.c          |    3 +++
 3 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/disk/core.c b/tools/kvm/disk/core.c
index f2b482a..965bbe5 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 a9425cc..dc2e0b9 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 201019a..f121a2b 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()
 };
 
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux