Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HW5I6-0000Fb-Ib for qemu-devel@nongnu.org; Tue, 27 Mar 2007 02:36:22 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HW5I4-000086-Ne for qemu-devel@nongnu.org; Tue, 27 Mar 2007 02:36:22 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HW5I4-00007s-JZ for qemu-devel@nongnu.org; Tue, 27 Mar 2007 01:36:20 -0500 Received: from mailgate.hob.de ([212.185.199.3]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HW5Fi-0004fy-6v for qemu-devel@nongnu.org; Tue, 27 Mar 2007 02:33:55 -0400 From: Marc =?utf-8?q?L=C3=B6rner?= Subject: Re: [Qemu-devel] Patch: cpu-all.h for better cycle counter Date: Tue, 27 Mar 2007 07:33:48 +0100 References: <20070321023726.GA11696@fries.net> <200703261452.54872.marc.loerner@hob.de> In-Reply-To: MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="utf-8" Message-Id: <200703270833.48027.marc.loerner@hob.de> Content-Transfer-Encoding: quoted-printable Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: balrogg@gmail.com Cc: qemu-devel@nongnu.org On Monday 26 March 2007 22:37, andrzej zaborowski wrote: > On 26/03/07, Marc L=C3=B6rner wrote: > > On Monday 26 March 2007 00:08, andrzej zaborowski wrote: > > > On 26/03/07, andrzej zaborowski wrote: > > > > > > > > > > > +# warning non-optimized CPU > > > > > +#include > > > > > +#include > > > > > + > > > > > static inline int64_t cpu_get_real_ticks (void) > > > > > { > > > > > - static int64_t ticks =3D 0; > > > > > - return ticks++; > > > > > + struct timeval tv; > > > > > + static int64_t i =3D 0; > > > > > + int64_t j; > > > > > + > > > > > + gettimeofday(&tv, NULL); > > > > > + do { > > > > > + j =3D (tv.tv_sec * (uint64_t) 1000000) + tv.tv_usec; > > > > > + } while (i =3D=3D j); > > > > > + i =3D j; > > > > > + return j; > > > > > > > > Isn't this an infinite loop? gettimeofday() was left out of the l= oop. > > > > > > > > How about "return j + (ticks++)" instead of the loop? If I unders= tand > > > > correctly it may slow things down to below 1Hz. > > > > > > (I wanted to say MHz) > > > > I dont think so, in the loop "j" is set and the while-condition is > > "j=3D=3Di", so unless "(tv.tv_sec * (uint64_t) 1000000) + tv.tv_usec"= always > > computes the same value the do-while block gets only executed once. > > Well, it does always compute the same value - inside the loop. Doesn't > it? And across one microsecond also the same value in all calls to > cpu_get_real_ticks. > > > > Regards okay, sometimes one doesn't see the wood for the trees. The over and over computation of the same value doesn't make sense,=20 so the call of gettimeofday should be in the loop (i think). --=20 Freundliche Gruesse, Marc L=C3=B6rner Tel.: +49 (0)9103-715-30046 Fax.: +49 (0)9103-715-271 Internet: http://www.hob.de E-Mail: marc.loerner@hob.de HOB GmbH & Co. KG Schwaderm=C3=BChlstra=C3=9Fe 3 90556 Cadolzburg Geschaeftsfuehrer Klaus Brandstaetter - Franz Wiedenmann AG Fuerth HRA 5180 Steuer-Nr. 218/163/00107 USt-ID-Nr. DE 132747002 Komplementaerin HOB electronic BeteiligungsGmbH AG Fuerth HRB 3416