Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HVojM-0004hs-4c for qemu-devel@nongnu.org; Mon, 26 Mar 2007 08:55:24 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HVojI-0004cE-Ga for qemu-devel@nongnu.org; Mon, 26 Mar 2007 08:55:23 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HVojI-0004bs-2i for qemu-devel@nongnu.org; Mon, 26 Mar 2007 07:55:20 -0500 Received: from mailgate.hob.de ([212.185.199.3]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HVoh2-0001sI-9s for qemu-devel@nongnu.org; Mon, 26 Mar 2007 08:53:00 -0400 From: Marc =?utf-8?q?L=C3=B6rner?= Subject: Re: [Qemu-devel] Patch: cpu-all.h for better cycle counter Date: Mon, 26 Mar 2007 13:52:54 +0100 References: <20070321023726.GA11696@fries.net> In-Reply-To: MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="utf-8" Message-Id: <200703261452.54872.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, qemu-devel@nongnu.org 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 loop. > > > > How about "return j + (ticks++)" instead of the loop? If I understand > > 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=3D= i", so unless "(tv.tv_sec * (uint64_t) 1000000) + tv.tv_usec" always computes= the=20 same value the do-while block gets only executed once. > --=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