qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Patch: cpu-all.h for better cycle counter
@ 2007-03-21  2:37 Todd T. Fries
  2007-03-25 22:07 ` andrzej zaborowski
  0 siblings, 1 reply; 6+ messages in thread
From: Todd T. Fries @ 2007-03-21  2:37 UTC (permalink / raw)
  To: qemu-devel

This is relative to the 20070319 snapshot.

--- cpu-all.h.orig	Fri Mar 16 18:58:11 2007
+++ cpu-all.h	Tue Mar 20 21:14:10 2007
@@ -1012,13 +1012,22 @@ static inline int64_t cpu_get_real_ticks
 #endif
 }
 #else
-/* The host CPU doesn't have an easily accessible cycle counter.
-   Just return a monotonically increasing vlue.  This will be totally wrong,
-   but hopefully better than nothing.  */
+# 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;
 }
 #endif
 
-- 
Todd Fries .. todd@fries.net

 _____________________________________________
|                                             \  1.636.410.0632 (voice)
| Free Daemon Consulting, LLC                 \  1.405.227.9094 (voice)
| http://FreeDaemonConsulting.com             \  1.866.792.3418 (FAX)
| "..in support of free software solutions."  \          250797 (FWD)
|                                             \
 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
                                                 
              37E7 D3EB 74D0 8D66 A68D  B866 0326 204E 3F42 004A
                        http://todd.fries.net/pgp.txt

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] Patch: cpu-all.h for better cycle counter
  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
  0 siblings, 1 reply; 6+ messages in thread
From: andrzej zaborowski @ 2007-03-25 22:07 UTC (permalink / raw)
  To: todd, qemu-devel

Hi,

On 21/03/07, Todd T. Fries <todd@fries.net> wrote:
> This is relative to the 20070319 snapshot.
>
> --- cpu-all.h.orig      Fri Mar 16 18:58:11 2007
> +++ cpu-all.h   Tue Mar 20 21:14:10 2007
> @@ -1012,13 +1012,22 @@ static inline int64_t cpu_get_real_ticks
>  #endif
>  }
>  #else
> -/* The host CPU doesn't have an easily accessible cycle counter.
> -   Just return a monotonically increasing vlue.  This will be totally wrong,
> -   but hopefully better than nothing.  */
> +# 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.

>  }
>  #endif
>
> --
> Todd Fries .. todd@fries.net
>
>  _____________________________________________
> |                                             \  1.636.410.0632 (voice)
> | Free Daemon Consulting, LLC                 \  1.405.227.9094 (voice)
> | http://FreeDaemonConsulting.com             \  1.866.792.3418 (FAX)
> | "..in support of free software solutions."  \          250797 (FWD)
> |                                             \
>  \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
>
>               37E7 D3EB 74D0 8D66 A68D  B866 0326 204E 3F42 004A
>                         http://todd.fries.net/pgp.txt
>
>
>
>

Regards,
Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] Patch: cpu-all.h for better cycle counter
  2007-03-25 22:07 ` andrzej zaborowski
@ 2007-03-25 22:08   ` andrzej zaborowski
  2007-03-26 12:52     ` Marc Lörner
  0 siblings, 1 reply; 6+ messages in thread
From: andrzej zaborowski @ 2007-03-25 22:08 UTC (permalink / raw)
  To: todd, qemu-devel

On 26/03/07, andrzej zaborowski <balrog@zabor.org> wrote:
> Hi,
>
> On 21/03/07, Todd T. Fries <todd@fries.net> wrote:
> > This is relative to the 20070319 snapshot.
> >
> > --- cpu-all.h.orig      Fri Mar 16 18:58:11 2007
> > +++ cpu-all.h   Tue Mar 20 21:14:10 2007
> > @@ -1012,13 +1012,22 @@ static inline int64_t cpu_get_real_ticks
> >  #endif
> >  }
> >  #else
> > -/* The host CPU doesn't have an easily accessible cycle counter.
> > -   Just return a monotonically increasing vlue.  This will be totally wrong,
> > -   but hopefully better than nothing.  */
> > +# 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)

>
> >  }
> >  #endif
> >
> > --
> > Todd Fries .. todd@fries.net
> >
> >  _____________________________________________
> > |                                             \  1.636.410.0632 (voice)
> > | Free Daemon Consulting, LLC                 \  1.405.227.9094 (voice)
> > | http://FreeDaemonConsulting.com             \  1.866.792.3418 (FAX)
> > | "..in support of free software solutions."  \          250797 (FWD)
> > |                                             \
> >  \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
> >
> >               37E7 D3EB 74D0 8D66 A68D  B866 0326 204E 3F42 004A
> >                         http://todd.fries.net/pgp.txt
> >
> >
> >
> >
>
> Regards,
> Andrew
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] Patch: cpu-all.h for better cycle counter
  2007-03-25 22:08   ` andrzej zaborowski
@ 2007-03-26 12:52     ` Marc Lörner
  2007-03-26 20:37       ` andrzej zaborowski
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Lörner @ 2007-03-26 12:52 UTC (permalink / raw)
  To: balrogg, qemu-devel

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.
>
<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: 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] Patch: cpu-all.h for better cycle counter
  2007-03-26 12:52     ` Marc Lörner
@ 2007-03-26 20:37       ` andrzej zaborowski
  2007-03-27  6:33         ` Marc Lörner
  0 siblings, 1 reply; 6+ messages in thread
From: andrzej zaborowski @ 2007-03-26 20:37 UTC (permalink / raw)
  To: Marc Lörner; +Cc: qemu-devel

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] Patch: cpu-all.h for better cycle counter
  2007-03-26 20:37       ` andrzej zaborowski
@ 2007-03-27  6:33         ` Marc Lörner
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Lörner @ 2007-03-27  6:33 UTC (permalink / raw)
  To: balrogg; +Cc: qemu-devel

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-03-27  6:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).