|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifndef MPL_TIMER_LINUX86_CYCLE_H_INCLUDED
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_LINUX86_CYCLE_H_INCLUDED
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static inline int MPL_wtime(MPL_time_t * timeval)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
/* The rdtsc instruction is not a "serializing" instruction, so the
|
|
Packit Service |
c5cf8c |
processor is free to reorder it. In order to get more accurate
|
|
Packit Service |
c5cf8c |
timing numbers with rdtsc, we need to put a serializing
|
|
Packit Service |
c5cf8c |
instruction, like cpuid, before rdtsc. X86_64 architectures have
|
|
Packit Service |
c5cf8c |
the rdtscp instruction which is synchronizing, we use this when we
|
|
Packit Service |
c5cf8c |
can. */
|
|
Packit Service |
c5cf8c |
#ifdef MPL_LINUX86_CYCLE_RDTSCP
|
|
Packit Service |
c5cf8c |
unsigned long long lower, upper, extra;
|
|
Packit Service |
c5cf8c |
__asm__ __volatile__("rdtscp\n":"=a"(lower), "=d"(upper), "=c"(extra));
|
|
Packit Service |
c5cf8c |
*timeval = (upper << 32) + lower;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#elif defined(MPL_LINUX86_CYCLE_CPUID_RDTSC64)
|
|
Packit Service |
c5cf8c |
unsigned long long lower, upper;
|
|
Packit Service |
c5cf8c |
__asm__ __volatile__("cpuid ; rdtsc":"=a"(lower), "=d"(upper)::"ebx", "ecx");
|
|
Packit Service |
c5cf8c |
*timeval = (upper << 32) + lower;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#elif defined(MPL_LINUX86_CYCLE_CPUID_RDTSC32)
|
|
Packit Service |
c5cf8c |
__asm__ __volatile__("cpuid ; rdtsc":"=A"(*timeval)::"ebx", "ecx");
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#elif defined(MPL_LINUX86_CYCLE_RDTSC)
|
|
Packit Service |
c5cf8c |
/* The configure test using cpuid must have failed, try just rdtsc by itself */
|
|
Packit Service |
c5cf8c |
__asm__ __volatile__("rdtsc":"=A"(*timeval));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#error Dont know which Linux timer to use
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return MPL_TIMER_SUCCESS;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#endif /* MPL_TIMER_LINUX86_CYCLE_H_INCLUDED */
|