source: Plugins/rdtscTimeSource/TimeSource.h @ 1

Revision 1, 3.2 KB checked in by art, 13 years ago (diff)
Line 
1/***************************************************************************
2 *                                                                         *
3 *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
4 *       mailto: <tevs@mpi-sb.mpg.de>                                      *
5 *                                                                         *
6 *   This program is free software; you can redistribute it and/or modify  *
7 *   it under the terms of the GNU General Public License as published by  *
8 *   the Free Software Foundation; either version 2 of the License, or     *
9 *   (at your option) any later version.                                   *
10 *                                                                         *
11 ***************************************************************************/
12
13
14#ifndef _PLUGIN_RDTSC_TIMESOURCE_H_
15#define _PLUGIN_RDTSC_TIMESOURCE_H_
16
17//----------------------------------------------------------------------------------
18// Includes
19//----------------------------------------------------------------------------------
20#include <nrEngine.h>
21#include "Cpu.h"
22#include <boost/shared_ptr.hpp>
23
24
25using namespace nrEngine;
26
27
28/**
29* This is a derived class of time source which provide the functionality
30* of rdtsc and cpuid instructions to get the time.
31* Use this as Plugin for the engine.
32* \par
33* Because we are using high definition timers in our engine, so each time
34* step depends on the current cpu frequency. If you retrive a wrong speed
35* by initialization of the clock, you will get wrong time calculations
36* along whole time calculation process. So sometimes we need to recalculate
37* the speed of used cpu (i.e. CPU/FSB speed stepping)<br>
38* To do this our clock has a function named sync(). This will snyc the current
39* clock with a system time and will force the CPU class to recalculate it's speed.
40* Syncing is done automatically every user defined time step. Sou you can decide
41* how important the high performance time for your application is.
42**/
43class rdtscTimeSource : public TimeSource {
44public:
45       
46        /**
47        * Create an instance of the time source object.
48        **/
49        rdtscTimeSource(boost::shared_ptr<Cpu> cpu);
50
51        /**
52        * Release used memory
53        **/
54        ~rdtscTimeSource();
55       
56        /**
57        * Get the current time in seconds. Returned time is not the same as system time.
58        * @return current time in seconds
59        **/
60        float64 getTime();
61
62       
63        /**
64        * Reset the time source, so it can start reading the time from the beginning.
65        * You do not have to call this method, clock will do it automaticaly, if
66        * it is needed.
67        **/
68        void reset();
69
70        /**
71        * Syncing the time source means we get the current time store it as sync time point
72        * caluclate the new start point do all calculations again.
73        * This syncing can help us to sync clock for example if the cpu speed changes.
74        * If no new calculation about the cpu speed is done and we use rdtsc to compute
75        * the current time, so we will get wrong time steps. Syncing should prevent this.<br>
76        * Clock-Engine will decide by itself when to sync, so time source shouldn't do it.
77        **/
78        void sync();
79       
80private:
81
82        //! Store the start time as 64Bit integer, for rtdsc counter
83        uint64  _startTimeRT;
84
85        //! Cpu to get info
86        boost::shared_ptr<Cpu>  mCpu;
87               
88};
89
90#endif
Note: See TracBrowser for help on using the repository browser.