Skip to contentSkip to conversation

kvm tools: Emulate RTC to fix system time in guests

PATCH In review Pekka Enberg 2 participants 2 messages Apr 28, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm tools: Emulate RTC to fix system time in guests

This patch fixes system time in guests by implementing proper CMOS RTC clock support.

# Before:

sh-2.05b# date
Fri Aug 7 04:02:01 UTC 2009

# After:

sh-2.05b# date
Thu Apr 28 19:12:21 UTC 2011

Cc Asias He <[email protected]>
Cc Cyrill Gorcunov <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Prasad Joshi <[email protected]>
Cc Sasha Levin <[email protected]>
---
 tools/kvm/Makefile          |    3 +-
 tools/kvm/include/kvm/rtc.h |    6 +++
 tools/kvm/ioport.c          |   26 -------------
 tools/kvm/kvm-run.c         |    3 +
 tools/kvm/rtc.c             |   87 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 98 insertions(+), 27 deletions(-)
 create mode 100644 tools/kvm/include/kvm/rtc.h
 create mode 100644 tools/kvm/rtc.c
tools/kvm/Makefile +2 -1
index fbce14d..659bc35 100644
@@ -26,8 +26,9 @@ OBJS	+= kvm-cpu.o
 OBJS	+= main.o
 OBJS	+= mmio.o
 OBJS	+= pci.o
-OBJS	+= util.o
+OBJS	+= rtc.o
 OBJS	+= term.o
+OBJS	+= util.o
 OBJS	+= virtio.o
 OBJS    += util/parse-options.o
 OBJS    += util/strbuf.o
tools/kvm/include/kvm/rtc.h new file +6 -0
new file mode 100644
index 0000000..0b8d9f9
@@ -0,0 +1,6 @@
+#ifndef KVM__RTC_H
+#define KVM__RTC_H
+
+void rtc__init(void);
+
+#endif /* KVM__RTC_H */
tools/kvm/ioport.c +0 -26
index e3f67fc..a38d2d1 100644
@@ -12,28 +12,6 @@
 
 bool ioport_debug;
 
-static uint8_t ioport_to_uint8(void *data)
-{
-	uint8_t *p = data;
-
-	return *p;
-}
-
-static bool cmos_ram_rtc_io_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
-{
-	uint8_t value;
-
-	value	= ioport_to_uint8(data);
-
-	self->nmi_disabled	= value & (1UL << 7);
-
-	return true;
-}
-
-static struct ioport_operations cmos_ram_rtc_ops = {
-	.io_out		= cmos_ram_rtc_io_out,
-};
-
 static bool debug_io_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
 {
 	exit(EXIT_SUCCESS);
@@ -128,10 +106,6 @@ void ioport__setup_legacy(void)
 	ioport__register(0x0060, &dummy_read_write_ioport_ops, 2);
 	ioport__register(0x0064, &dummy_read_write_ioport_ops, 1);
 
-	/* PORT 0070-007F - CMOS RAM/RTC (REAL TIME CLOCK) */
-	ioport__register(0x0070, &cmos_ram_rtc_ops, 1);
-	ioport__register(0x0071, &dummy_read_write_ioport_ops, 1);
-
 	/* 0x00A0 - 0x00AF - 8259A PIC 2 */
 	ioport__register(0x00A0, &dummy_read_write_ioport_ops, 2);
 
tools/kvm/kvm-run.c +3 -0
index b21b4a2..64f3409 100644
@@ -22,6 +22,7 @@
 #include <kvm/disk-image.h>
 #include <kvm/util.h>
 #include <kvm/pci.h>
+#include <kvm/rtc.h>
 #include <kvm/term.h>
 #include <kvm/ioport.h>
 #include <kvm/threadpool.h>
@@ -416,6 +417,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 
 	ioport__setup_legacy();
 
+	rtc__init();
+
 	kvm__setup_bios(kvm);
 
 	serial8250__init(kvm);
tools/kvm/rtc.c new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 5 lines · Pekka Enberg

This patch fixes system time in guests by implementing proper CMOS RTC clock support.

# Before:

Quoted 7 lines

sh-2.05b# date
Fri Aug 7 04:02:01 UTC 2009

# After:

sh-2.05b# date
Thu Apr 28 19:12:21 UTC 2011

Very nice!

Ingo