Why I can't get the seconds and nanoseconds like this?

Adam Lackorzynski adam at os.inf.tu-dresden.de
Mon Jan 8 09:32:04 CET 2007


On Mon Jan 08, 2007 at 06:49:37 +0100, Nicholas Mc Guire wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> 
> > Hi:
> > 	I wrote the simple application like this.
> >
> > #include <stdio.h>
> > #include <l4/util/rdtsc.h>
> > #include <l4/sys/l4int.h>
> > #include <l4/thread/thread.h>
> >
> > char LOG_tag[4]="clk";
> >
> > int main(void)
> > {
> >        l4_uint32_t     *second;
> >        l4_uint32_t     *nanosecond;
> >        l4_cpu_time_t   tsc;
> >        tsc = l4_rdtsc();
> >        l4_tsc_to_s_and_ns(tsc, second, nanosecond);
> >        printf("%d, %d \n", *second, *nanosecond);

Don't do this, where are those pointers pointing to? You need to
allocate some memory to put the data in:

      l4_uint32_t     second;
      l4_uint32_t     nanosecond;
      l4_cpu_time_t   tsc;
      tsc = l4_rdtsc();
      l4_tsc_to_s_and_ns(tsc, &second, &nanosecond);
      printf("%d, %d \n", second, nanosecond);



> > }
> >
> > The result is :
> > clk     | 0, 0
> > clk     |
> > clk     | Exiting with 6
> >
> > 	Does these code have some problems?
> > 	Thank you.
> > 															cheng
> did you ever initialize the tsc scallare ? it depends on your 
> configuration - it is not necessarily done automatically - you could check
> if thats the problem first by simply printing the tsc value it self (as 64
> bit value) and if that is non-0 (as to be expected) then the 
> initialization is most likely the problem. to initialized the scalar you 
> use:

Usually l4_calibrate_tsc() is what's used.



Adam
-- 
Adam                 adam at os.inf.tu-dresden.de
  Lackorzynski         http://os.inf.tu-dresden.de/~adam/




More information about the l4-hackers mailing list