qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [patch] option -no-tsc for i386 with speedstep
@ 2005-04-25 11:15 Massimo Dal Zotto
  2005-04-25 15:44 ` [Qemu-devel] " Heike C. Zimmerer
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Massimo Dal Zotto @ 2005-04-25 11:15 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1036 bytes --]

When qemu runs on an i386 cpu with speedstep enabled the clock of the
guest os is not in sync with the clock on the host os because the
vm_timer used for irq 0 generates interrupts at wrong rate when
the host cpu frequency changes.

The problem is that the vm_timer uses the rdtsc instruction and the value
of ticks_per_sec, computed at start time, for calculating the expire time
of vm_timers. While ticks_per_sec is constant the values returned by
rdtsc are dependent on the current cpu clock, which is not constant if
speedstep is used.

The problem can be cleary observed by running "xclock -update 1" in the
guest os and observing how the clock speed varies with the cpu freqency.

The following patch fixes the problem by adding a new option -no-tsc for
the i386 architecture which can be used to disable rdtsc when running on
a cpu with speedstep enabled.

The patch works for me but I don't know if this is the best way of fixing
this bug. If anyone has a better suggestion it is welcome.

-- 
Massimo Dal Zotto <dz@debian.org>

[-- Attachment #2: qemu-notsc.patch --]
[-- Type: text/plain, Size: 1759 bytes --]

--- qemu-0.6.2cvs20050425.orig/vl.c	2005-04-08 00:20:28.000000000 +0200
+++ qemu-0.6.2cvs20050425/vl.c	2005-04-25 11:44:41.119819832 +0200
@@ -135,6 +135,10 @@
 int prep_enabled = 0;
 int rtc_utc = 1;
 int cirrus_vga_enabled = 1;
+#ifdef __i386__
+static int notsc = 0;
+extern int64_t get_clock(void);
+#endif
 #ifdef TARGET_SPARC
 int graphic_width = 1024;
 int graphic_height = 768;
@@ -502,6 +506,9 @@
 int64_t cpu_get_real_ticks(void)
 {
     int64_t val;
+    if (notsc) {
+	return get_clock();
+    }
     asm volatile ("rdtsc" : "=A" (val));
     return val;
 }
@@ -2792,6 +2799,9 @@
 #ifdef USE_CODE_COPY
            "-no-code-copy   disable code copy acceleration\n"
 #endif
+#ifdef __i386__
+           "-no-tsc         disable tsc as clock source\n"
+#endif
 #ifdef TARGET_I386
            "-isa            simulate an ISA-only system (default is PCI system)\n"
            "-std-vga        simulate a standard VGA card with VESA Bochs Extensions\n"
@@ -2863,6 +2873,7 @@
     QEMU_OPTION_hdachs,
     QEMU_OPTION_L,
     QEMU_OPTION_no_code_copy,
+    QEMU_OPTION_no_tsc,
     QEMU_OPTION_pci,
     QEMU_OPTION_isa,
     QEMU_OPTION_prep,
@@ -2931,6 +2942,9 @@
 #ifdef USE_KQEMU
     { "no-kqemu", 0, QEMU_OPTION_no_kqemu },
 #endif
+#ifdef __i386__
+    { "no-tsc", 0, QEMU_OPTION_no_tsc },
+#endif
 #ifdef TARGET_PPC
     { "prep", 0, QEMU_OPTION_prep },
 #endif
@@ -3216,6 +3230,11 @@
             case QEMU_OPTION_no_code_copy:
                 code_copy_enabled = 0;
                 break;
+#ifdef __i386__
+            case QEMU_OPTION_no_tsc:
+                notsc = 1;
+                break;
+#endif
             case QEMU_OPTION_nics:
                 nb_nics = atoi(optarg);
                 if (nb_nics < 0 || nb_nics > MAX_NICS) {

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2005-04-26  6:52 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-25 11:15 [Qemu-devel] [patch] option -no-tsc for i386 with speedstep Massimo Dal Zotto
2005-04-25 15:44 ` [Qemu-devel] " Heike C. Zimmerer
2005-04-25 17:07 ` [Qemu-devel] " Jim C. Brown
2005-04-25 17:28   ` Paul Brook
2005-04-25 17:44   ` Massimo Dal Zotto
2005-04-25 17:47   ` [Qemu-devel] " Heike C. Zimmerer
2005-04-25 18:58 ` [Qemu-devel] " Fabrice Bellard
2005-04-25 20:17   ` Massimo Dal Zotto
2005-04-25 20:24     ` Jonas Maebe
2005-04-25 20:38       ` Filip Navara
2005-04-25 21:03         ` Lionel Ulmer
2005-04-25 22:45         ` Taras Glek
2005-04-25 21:46       ` [Qemu-devel] [patch] option -no-tsc for i386 with speedstep (solved) Massimo Dal Zotto
2005-04-26  6:50         ` Jonas Maebe
2005-04-26  3:03 ` [Qemu-devel] [patch] option -no-tsc for i386 with speedstep Kyle Hayes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).