why "mov %0, %0" after "rd %%tick, %0"?
Quoted 2 lines · On Fri, 23 Jan 2004 15:59:13 -0500 Ed L Cashin <[email protected]> wrote:
One thing I don't get is why there's a mov %0, %0 instruction after reading the tick register. Is this because of the delay slot?
No, there is a bug in some of the UltraSPARC processors in that if you go:
rd %tick, %reg cmp %reg, XXX
the compare will get an incorrect result. If we force the %tick result into a simple move instruction this prevents the sequence that leads up to the bug.
Hi. In arch/sparc64/kernel/time.c, there are some routines that use the %tick register. It seems analogous to the Pentium's TSC. I'm planning to use that register in userland via inline asm. (Thanks for making sure that non-privileged access is allowed, BTW!)
One thing I don't get is why there's a mov %0, %0 instruction after reading the tick register. Is this because of the delay slot?
static unsigned long tick_get_tick(void)
{
unsigned long ret;
__asm__ __volatile__("rd %%tick, %0\n\t"
"mov %0, %0"
: "=r" (ret));
return ret & ~TICK_PRIV_BIT;
}Signature · 2 lines
--Ed L Cashin | PGP public key: [email protected] | http://noserose.net/e/pgp/
Quoted 9 lines · David S. Miller
Quoted 2 lines · On Fri, 23 Jan 2004 15:59:13 -0500 Ed L Cashin <[email protected]> wrote:
One thing I don't get is why there's a mov %0, %0 instruction after reading the tick register. Is this because of the delay slot?
No, there is a bug in some of the UltraSPARC processors in that if you go:
Quoted 6 lines
rd %tick, %reg cmp %reg, XXXthe compare will get an incorrect result. If we force the %tick result into a simple move instruction this prevents the sequence that leads up to the bug.
Oh! Thanks. Do you think it's worth a comment?
arch/sparc64/kernel/time.c renamed from arch/sparc64/kernel/time.c.orig +8 -0
@@ -108,6 +108,14 @@ {unsigned long ret; +/* There is a bug in some of the UltraSPARC processors +* where a compare following a read of the %tick +* register gets an incorrect result. +* +* If we force the %tick result into a simple move +* instruction this prevents the sequence that leads up +* to the bug. +*/ __asm__ __volatile__("rd %%tick, %0\n\t" "mov %0, %0" :"=r" (ret));
Signature · 2 lines
--Ed L Cashin | PGP public key: [email protected] | http://noserose.net/e/pgp/