From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DQBV8-000370-OO for qemu-devel@nongnu.org; Mon, 25 Apr 2005 17:52:23 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DQBV6-00036J-Qh for qemu-devel@nongnu.org; Mon, 25 Apr 2005 17:52:22 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DQBV6-00030w-IK for qemu-devel@nongnu.org; Mon, 25 Apr 2005 17:52:20 -0400 Received: from [213.21.189.59] (helo=mingus.dizzy.lan) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DQBUn-0006PV-Tq for qemu-devel@nongnu.org; Mon, 25 Apr 2005 17:52:02 -0400 Date: Mon, 25 Apr 2005 23:46:40 +0200 From: Massimo Dal Zotto Subject: Re: [Qemu-devel] [patch] option -no-tsc for i386 with speedstep (solved) Message-ID: <20050425214639.GA17803@dizzy.ath.cx> References: <20050425111532.GA2554@dizzy.ath.cx> <426D3DBE.9080307@bellard.org> <20050425201706.GA11602@dizzy.ath.cx> <380218305509284f15ded3ac17915cb1@elis.ugent.be> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="IS0zKkzwUGydFO0o" Content-Disposition: inline In-Reply-To: <380218305509284f15ded3ac17915cb1@elis.ugent.be> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --IS0zKkzwUGydFO0o Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Apr 25, 2005 at 10:24:45PM +0200, Jonas Maebe wrote: > > On 25 Apr 2005, at 22:17, Massimo Dal Zotto wrote: > > >In the meantime until we find a better solution could you give us some > >explanation on why using a microseconds clock from gettimeofday instead > >of rdtsc the guest os clock runs always 20% slower? > > Because a system call (which gettimeofday is) is very slow (two context > switches). > No, it has nothing to do with the speed of gettimeofday, which on my pc takes only a few microsecons to execute. The problem seems in (rounding?) errors in computations of ticks_per_sec and/or next_transition_time and was solved (om my 600/1800 laptop) by replacing the following instruction in my previous patch return get_clock(); with return get_clock()<<12; It seems that simply changing the scale of ticks values reduces the computation errors in the timer code, which must be somewhere even if I haven't been able to find them. The clock in the guest os is now running at the correct speed and the sleep(1) command takes the exact real time to execute at any cpu speed. The following patch should be then the correct one. -- Massimo Dal Zotto --IS0zKkzwUGydFO0o Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="qemu-notsc.patch" --- qemu-0.6.2cvs20050425.orig/vl.c 2005-04-08 00:20:28.000000000 +0200 +++ qemu-0.6.2cvs20050425/vl.c 2005-04-25 23:03:57.096969536 +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()<<12; + } asm volatile ("rdtsc" : "=A" (val)); return val; } @@ -590,6 +597,7 @@ usec = get_clock() - usec; ticks = cpu_get_real_ticks() - ticks; ticks_per_sec = (ticks * 1000000LL + (usec >> 1)) / usec; + //printf("ticks_per_sec=%lld\n",ticks_per_sec); } /* compute with 96 bit intermediate result: (a*b)/c */ @@ -2792,6 +2800,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 +2874,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 +2943,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 +3231,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) { --IS0zKkzwUGydFO0o--