From: "Marc Lörner" <marc.loerner@hob.de>
To: balrogg@gmail.com
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Patch: cpu-all.h for better cycle counter
Date: Tue, 27 Mar 2007 07:33:48 +0100 [thread overview]
Message-ID: <200703270833.48027.marc.loerner@hob.de> (raw)
In-Reply-To: <fb249edb0703261337v7c24b45u9c2e4a2ad0173379@mail.gmail.com>
On Monday 26 March 2007 22:37, andrzej zaborowski wrote:
> On 26/03/07, Marc Lörner <marc.loerner@hob.de> wrote:
> > On Monday 26 March 2007 00:08, andrzej zaborowski wrote:
> > > On 26/03/07, andrzej zaborowski <balrog@zabor.org> 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.
>
> 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.
>
> <snip>
>
> 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,
so the call of gettimeofday should be in the loop (i think).
--
Freundliche Gruesse,
Marc Lörner
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ü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
prev parent reply other threads:[~2007-03-27 6:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-21 2:37 [Qemu-devel] Patch: cpu-all.h for better cycle counter Todd T. Fries
2007-03-25 22:07 ` andrzej zaborowski
2007-03-25 22:08 ` andrzej zaborowski
2007-03-26 12:52 ` Marc Lörner
2007-03-26 20:37 ` andrzej zaborowski
2007-03-27 6:33 ` Marc Lörner [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200703270833.48027.marc.loerner@hob.de \
--to=marc.loerner@hob.de \
--cc=balrogg@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).