Re: [patch] __volatile__ needed in get_cycles()?

Tigran Aivazian (tigran@aivazian.demon.co.uk)
Sun, 28 Mar 1999 09:47:09 +0100 (BST)


Dear Linus,

I am forwarding my patch to you as it seems that my suspicion that
__volatile__ is needed in get_cycles() of include/asm-i386/timex.h is
justified.

I understand that for the current usage thereof (in
kernel/sched.c/schedule() on SMP only) it may be irrelevant, but since the
macro is there, it is tempting to use it for other purposes (e.g. to
"pseudo-profile" various instruction sequences as per Intel's article on
RDTSC) whereby without __volatile__ one would get wrong numbers.

Regards,
Tigran.

--- timex.h.0 Sat Mar 27 12:41:54 1999
+++ timex.h Sat Mar 27 12:42:07 1999
@@ -39,7 +39,7 @@
#else
unsigned long eax, edx;

- __asm__("rdtsc":"=a" (eax), "=d" (edx));
+ __asm__ __volatile__ ("rdtsc":"=a" (eax), "=d" (edx));
return eax;
#endif
}

On Sat, 27 Mar 1999, Richard Henderson wrote:

> On Sat, Mar 27, 1999 at 12:44:22PM +0000, Tigran Aivazian wrote:
> > x = get_cycles();
> > __asm__("cpuid");
> > y = get_cycles();
> [...]
> > - __asm__("rdtsc":"=a" (eax), "=d" (edx));
> > + __asm__ __volatile__ ("rdtsc":"=a" (eax), "=d" (edx));
>
> Yes, volatile is needed to keep the asm from being moved "too far".
>
>
> r~
>

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