RTEMS: Counting time, again... (help)

Jay.Kulpinski at gd-ais.com Jay.Kulpinski at gd-ais.com
Fri Mar 26 16:34:53 UTC 2004


On Friday 26 March 2004 05:56 am, Alex wrote:
> Hi,
>
> I know that will be some users that will say to me that this doubt is
> already explain in the mailling list, but before sent this mail I search in
> the mailling list and I saw nothings...
>
> Weel, I need to measure time in microseconds (or nanoseconds, this will be
> great). Using the posix calls the maximum resolution I get is 20
> milliseconds. That doesnt feet my needs... :-(
>
> So, I thinking to use an osciloscope or some device like that to measure
> those times. Another idea is to access the hardware ticks.
>
> Which is the best way to measure those times? External counter device or
> access hardware ticker?
>
> Is there any free source code to access the hardware ticks?
>
> Thanks in advance...
>
> BSP: i686
>
> Alex

/* compile with optimization enable to get this inlined */
static inline int read_timer(void) {
    int result;

    asm volatile ("rdtsc" : "=a" (result) : : "edx");
    return result;
}

void example(void) {
    int before, after;

    before = read_timer();
    /* some code to time */
    after = read_timer();
    printf("code took %d cycles\n", after - before);
}



More information about the users mailing list