Commit a12a8ba9 authored by berenger-bramas's avatar berenger-bramas

Add a new timer based on the direct ASM access,

from http://dept-info.labri.fr/~denis/Enseignement/2006-SSECPD/timing.h

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@313 2616d619-271b-44dc-8df4-d4a8f33a7222
parent a2886923
#include "FTic.hpp"
// The fallowing code is only needed when using the special timer
#ifdef FSPECIAL_TIMER
// This function is used to get the scale between tick and second
double GetTickScale() {
typedef union u_tick {
uint64_t tick;
struct {
uint32_t low;
uint32_t high;
} sub;
} tick_t;
tick_t tickCounterStart, tickCounterEnd;
timeval todStart, todEnd;
__asm__ volatile("rdtsc" : "=a" (tickCounterStart.sub.low), "=d" (tickCounterStart.sub.high));
gettimeofday(&todStart,0);
usleep(500000);
__asm__ volatile("rdtsc" : "=a" (tickCounterEnd.sub.low), "=d" (tickCounterEnd.sub.high));
gettimeofday(&todEnd,0);
return ( (double(todEnd.tv_sec) + (double(todEnd.tv_usec)/1e6)) - (double(todStart.tv_sec) + (double(todStart.tv_usec)/1e6)) ) /
double(tickCounterEnd.tick - tickCounterStart.tick);
}
// For the special timer
const double FTic::Scale = GetTickScale();
#endif
#ifndef FTIC_HPP
#define FTIC_HPP
#include <time.h>
#include "FGlobal.hpp"
#include <time.h>
// We need an os specific function
#if defined(WINDOWS)
......@@ -12,14 +11,18 @@
#ifndef POSIX
#warning Posix used withoug being explicitly defined
#endif
#if defined(__i386__) || defined(__pentium__) || defined(__pentiumpro__) || defined(__i586__) || defined(__i686__) || defined(__k6__) || defined(__k7__) || defined(__x86_64__)
#define FSPECIAL_TIMER
#endif
#include <sys/time.h>
#include <unistd.h>
#include <stdint.h>
#endif
/** @author Berenger Bramas (berenger.bramas@inria.fr)
* This class is a easy to use time counter
* With it you can very easyli estimate elapsed
* time between two moments
* With it you can very easyli estimate elapsed time between two moments
* <code>
* FTic counter;<br>
* counter.tic();<br>
......@@ -27,6 +30,9 @@
* counter.tac();<br>
* counter.elapsed(); //> time in s<br>
* </code>
*
* The special method that uses asm register is based on the code by : Alexandre DENIS
* http://dept-info.labri.fr/~denis/Enseignement/2006-SSECPD/timing.h
*/
class FTic {
private:
......@@ -73,17 +79,35 @@ public:
/** Global get time
* @return a global time
* GetTickCount on windows
* gettimeofday on linux
* gettimeofday on linux or a direct ASM method
*/
static double GetTime(){
#ifdef WINDOWS
return static_cast<double>(GetTickCount())/1000.0;
#else
#else // We are in linux/posix
#ifndef FSPECIAL_TIMER
timeval t;
gettimeofday(&t, NULL);
return double(t.tv_sec) + (double(t.tv_usec)/1000000.0);
#else //FSPECIAL_TIMER is defined
typedef union u_tick {
uint64_t tick;
struct {
uint32_t low;
uint32_t high;
} sub;
} tick_t;
tick_t counter;
__asm__ volatile("rdtsc" : "=a" (counter.sub.low), "=d" (counter.sub.high));
return double(counter.tick) * Scale;
#endif
#endif
}
#ifdef FSPECIAL_TIMER
static const double Scale;
#endif
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment