qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Patch: cpu-all.h for better cycle counter


From: Marc Lörner
Subject: Re: [Qemu-devel] Patch: cpu-all.h for better cycle counter
Date: Mon, 26 Mar 2007 13:52:54 +0100
User-agent: KMail/1.6.2

On Monday 26 March 2007 00:08, andrzej zaborowski wrote:
> On 26/03/07, andrzej zaborowski <address@hidden> wrote:
<snip>
> > > +# warning non-optimized CPU
> > > +#include <sys/time.h>
> > > +#include <time.h>
> > > +
> > >  static inline int64_t cpu_get_real_ticks (void)
> > >  {
> > > -    static int64_t ticks = 0;
> > > -    return ticks++;
> > > +       struct timeval tv;
> > > +       static int64_t i = 0;
> > > +       int64_t j;
> > > +
> > > +       gettimeofday(&tv, NULL);
> > > +       do {
> > > +          j = (tv.tv_sec * (uint64_t) 1000000) + tv.tv_usec;
> > > +       } while (i == j);
> > > +       i = 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==i",
so unless "(tv.tv_sec * (uint64_t) 1000000) + tv.tv_usec" always computes the 
same value the do-while block gets only executed once.
>
<snip>

-- 
Freundliche Gruesse,
Marc Lörner

Tel.: +49 (0)9103-715-30046
Fax.: +49 (0)9103-715-271
Internet: http://www.hob.de
E-Mail: address@hidden

HOB GmbH & Co. KG
Schwadermühlstraße 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]