Messages in this thread | | | Date | Sat, 27 Mar 1999 14:11:26 +0100 (MET) | From | Ruediger Oertel <> | Subject | Re: [patch] __volatile__ needed in get_cycles()? |
| |
On Sat, 27 Mar 1999, Tigran Aivazian wrote:
> Hi again, > > Before people start replying pointing out that my program has a bug (I > should have told GAS that cpuid clobbers eax, ebx, ecx and edx) - it still > appears that __volatile__ is needed. guess you are using a recent compiler (egcs...); I had the same problem compiling SMP on alpha; needed volatile in include/asm-alphe/hwrpb.h at least for the variable "flags" in per_cpu_struct
I wonder how many plaecs we'd need "volatile"
> > Regards, > Tigran. > > On Sat, 27 Mar 1999, Tigran Aivazian wrote: > > > Hi guys, > > > > I think __volatile__ is needed when we calculate rdtsc in get_cycles(). > > because this simple program will print the wrong value otherwise. > > > > Regards, > > Tigran. > > > > /* > > Compile with: CFLAGS = -Wall -Wstrict-prototypes -O2 -g -fomit-frame-pointer > > */ > > > > #include <stdio.h> > > #include <unistd.h> > > #include <sys/types.h> > > > > typedef unsigned long cycles_t; > > > > static inline cycles_t get_cycles(void) > > { > > unsigned long eax, edx; > > __asm__ __volatile__ ("rdtsc":"=a" (eax), "=d" (edx)); > > return eax; > > } > > > > int main(int argc, char *argv[]) > > { > > cycles_t x, y; > > > > x = get_cycles(); > > __asm__("cpuid"); > > y = get_cycles(); > > fprintf(stderr, "%lu\n", y - x); > > return 0; > > } > > > > Hence this simple patch (for include/asm-i386/timex.h): > > > > --- 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 > > } > > > > > > > > > - > 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/ >
mit freundlichen Gruessen (mit freundlichem Grinsen), Ruediger Oertel (ro@suse.de) ----------------------------------------------------------------- :-)) The perfect time to compile a linux 2.2 kernel :-)) ----ALWAYS REMEMBER: WHATEVER I SAY, IT'S MY PERSONAL OPINION----
- 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/
| |