Re: get_cycles() on i386
From: Linus Torvalds
Date: Tue Nov 04 2003 - 18:55:50 EST
On 4 Nov 2003, john stultz wrote:
>
> CONFIG_X86_TSC be the devil. Personally, I'd much prefer dropping the
> compile time option and using dynamic detection. Something like (not
> recently tested and i believe against 2.5.something, but you get the
> idea):
Some of the users are really timing-critical (eg scheduler).
How about just using the "alternative()" infrastructure that we already
have in 2.6.x for this? See <asm-i386/system.h> for details.
We don't have an "alternative_output()" available yet, but using that it
would look something like:
static inline unsigned long long get_cycle(void)
{
unsigned long long tsc;
alternative_output(
"xorl %%eax,%%eax ; xorl %%edx,%%edx",
"rdtsc",
X86_FEATURE_TSC,
"=A" (tsc));
return tsc;
}
which should allow for "perfect" code (well, gcc tends to mess up 64-bit
stuff, but you get the idea).
We use the "alternative_input()" thing for prefetch() handling (see
<asm-i386/processor.h>).
Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/