Discussion:
How to measure time accurately.
(too old to reply)
Lee Revell
2005-03-29 03:45:48 UTC
Permalink
Hi All,
Can any one tell me how to measure time accurately for a block of C code
in device drivers.
For example, If I want to measure the time duration of firmware download.
rdtsc()

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



-------------------------------------------------------------------------------
Achtung: diese Newsgruppe ist eine unidirektional gegatete Mailingliste.
Antworten nur per Mail an die im Reply-To-Header angegebene Adresse.
Fragen zum Gateway -> ***@inka.de.
-------------------------------------------------------------------------------
Chris Friesen
2005-03-29 05:10:23 UTC
Permalink
Hi All,
Can any one tell me how to measure time accurately for a block of C code
in device drivers.
For example, If I want to measure the time duration of firmware download.
Most cpus have some way of getting at a counter or decrementer of
various frequencies. Usually it requires low-level hardware knowledge
and often it needs assembly code.

On ppc you'd use the mftbu/mftbl instructions, as suggested by Lee on
x86 you'd use the rdtsc instruction.

Chris
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



-------------------------------------------------------------------------------
Achtung: diese Newsgruppe ist eine unidirektional gegatete Mailingliste.
Antworten nur per Mail an die im Reply-To-Header angegebene Adresse.
Fragen zum Gateway -> ***@inka.de.
-------------------------------------------------------------------------------
Jan Engelhardt
2005-03-29 09:32:06 UTC
Permalink
In some cases you can simply count jiffies - depending on how accurate you
These "some cases" exclude this one:
If interrupts are disabled, a jiffy might be missed. Take care.

If you are on UP and want to measure within
- a tick [when using preempt]
- kernel space [no preempt]
disabled interrupts should usually not be the case.

Jan Engelhardt
--
No TOFU for me, please.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



-------------------------------------------------------------------------------
Achtung: diese Newsgruppe ist eine unidirektional gegatete Mailingliste.
Antworten nur per Mail an die im Reply-To-Header angegebene Adresse.
Fragen zum Gateway -> ***@inka.de.
-------------------------------------------------------------------------------
Jesper Juhl
2005-03-29 09:17:06 UTC
Permalink
Date: Mon, 28 Mar 2005 23:07:14 -0600
Subject: Re: How to measure time accurately.
Hi All,
Can any one tell me how to measure time accurately for a block of C code in
device drivers.
For example, If I want to measure the time duration of firmware download.
Most cpus have some way of getting at a counter or decrementer of various
frequencies. Usually it requires low-level hardware knowledge and often it
needs assembly code.
On ppc you'd use the mftbu/mftbl instructions, as suggested by Lee on x86
you'd use the rdtsc instruction.
In some cases you can simply count jiffies - depending on how accurate you
need to time things I'd say that often something like this is adequate :

unsigned long start, time_spent;

start = jiffies;
/* do stuff */
time_spent = jiffies - start;
printk("stuff took %d jiffies (%d seconds)\n", time_spent, time_spent/HZ);
--
Jesper Juhl

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



-------------------------------------------------------------------------------
Achtung: diese Newsgruppe ist eine unidirektional gegatete Mailingliste.
Antworten nur per Mail an die im Reply-To-Header angegebene Adresse.
Fragen zum Gateway -> ***@inka.de.
-------------------------------------------------------------------------------
Loading...