Changeset 55 for trunk


Ignore:
Timestamp:
09/27/07 23:53:07 (12 years ago)
Author:
art
Message:
  • rdtscTimerSource plugin added
  • NOTE: Be carefull on systems with dynamicly changeable frequencies, since the rdtsc instruction may produce wrong results
Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Plugins/Makefile

    r31 r55  
    33include $(TOPDIR)/Make/Makedefs 
    44 
    5 SUBDIRS = luaScripting dynamicResources 
     5SUBDIRS = luaScripting dynamicResources rdtscTimeSource 
    66         
    77include $(TOPDIR)/Make/Makedirrules 
  • trunk/Plugins/rdtscTimeSource/Plugin.cpp

    r1 r55  
     1#include <nrEngine/nrEngine.h> 
    12 
    2  
    3 #include <nrEngine.h> 
    4 #include <boost/shared_ptr.hpp> 
     3#if NR_PLATFORM == NR_PLATFORM_WIN32 
     4    #define _PluginExport __declspec( dllexport ) 
     5#else 
     6    #define _PluginExport 
     7#endif 
    58 
    69#include "Cpu.h" 
     
    2124//std::vector<Plugin::PlgMethod>                mMethods; 
    2225 
    23  
    2426//--------------------------------------------------------- 
    2527// Initialize the plugin 
    2628//--------------------------------------------------------- 
    2729extern "C" int plgInitialize(Engine* root) 
    28 { 
    29          
     30{        
    3031        mRoot = root; 
     32    mOldTimeSource = mRoot->sClock()->getTimeSource(); 
     33 
    3134         
    3235        // create cpu instance 
     
    3942        mTimeSource.reset( new rdtscTimeSource(mCpu) ); 
    4043 
    41         // get the current time source 
    42         mOldTimeSource = mRoot->sClock()->getTimeSource(); 
    43                  
    44         // now set new time source to the clock 
    45         NR_Log(Log::LOG_PLUGIN, "rdtscTimeSource: Set the high performance time source for the clock"); 
    46         mRoot->sClock()->setTimeSource(mTimeSource); 
     44    // check whenever CPU does support the thing 
     45    if (mTimeSource->isSupported()) 
     46    {                
     47            // now set new time source to the clock 
     48            NR_Log(Log::LOG_PLUGIN, "rdtscTimeSource: Set the high performance time source for the clock"); 
     49            mRoot->sClock()->setTimeSource(mTimeSource); 
    4750 
    48         // declare new function to the scripting engine 
    49         //std::vector<ScriptParam> param; 
    50         //param.push_back(mCpu.get()); 
    51         mRoot->sScriptEngine()->add("getCpuString", Cpu::getCpuString, VarArg(mCpu.get())); 
    52                  
     51        // let sync the timesource every 500 ms 
     52        mRoot->sClock()->setSyncInterval(500); 
     53         
     54            // declare new function to the scripting engine 
     55            //std::vector<ScriptParam> param; 
     56            //param.push_back(mCpu.get()); 
     57            mRoot->sScriptEngine()->add("rdtscPlugin_getCpuString", Cpu::getCpuString, VarArg(mCpu.get())); 
     58        }else{ 
     59        NR_Log(Log::LOG_PLUGIN, "rdtscTimeSource: Your CPU seems not to support the rdtsc instruction"); 
     60    }    
    5361        return 0;        
    5462}  
    5563   
     64 
     65//--------------------------------------------------------- 
     66// Get full string according to the plugin version 
     67//--------------------------------------------------------- 
     68extern "C" _PluginExport char* plgVersionString( void ) 
     69{ 
     70    return "High Performance Time Source v0.1 (rdtsc & cpuid instruction using)"; 
     71} 
    5672 
    5773//--------------------------------------------------------- 
     
    6076extern "C" unsigned int plgEngineVersion( void ) 
    6177{ 
    62         return createVersionInteger(0,0,5); 
    63 } 
    64  
    65  
    66 //--------------------------------------------------------- 
    67 // Get full string according to the plugin version 
    68 //--------------------------------------------------------- 
    69 extern "C" char* plgVersionString( void ) 
    70 { 
    71         return "High Performance Time Source v0.1 (rdtsc & cpuid instruction using)"; 
     78        return createVersionInteger(0,0,8); 
    7279} 
    7380 
     
    93100        // set the old time source to the clock back 
    94101        mRoot->sClock()->setTimeSource(mOldTimeSource); 
     102    mRoot->sClock()->setSyncInterval(0); 
    95103                 
    96104        // some log 
     
    98106} 
    99107 
    100 //--------------------------------------------------------- 
    101 // Get information about provided subroutines 
    102 //--------------------------------------------------------- 
    103 /*extern "C" void plgGetMethods( std::vector<Plugin::PlgMethod>& methods) 
    104 { 
    105         methods = mMethods; 
    106 } 
    107  
    108  
    109 //--------------------------------------------------------- 
    110 // Call certain subroutine  
    111 //--------------------------------------------------------- 
    112 extern "C" void plgCall(const std::string& name, std::vector<Plugin::PlgParam>& params) 
    113 { 
    114  
    115         if (name == "getCpuInfo"){ 
    116                 getCpuInfoString(); 
    117         } 
    118          
    119 }*/ 
    120  
  • trunk/Plugins/rdtscTimeSource/TimeSource.cpp

    r1 r55  
    3030{ 
    3131        mCpu = cpu; 
    32          
     32    _isSupported = false; 
     33         
    3334        // check whenever we have got the high performance counter support 
    3435        if (mCpu->isRDTSC()) 
     
    3637                NR_Log(Log::LOG_PLUGIN, "rdtscTimeSource: It seems your CPU supports the \"rdtsc\" instruction"); 
    3738                NR_Log(Log::LOG_PLUGIN, "rdtscTimeSource: High perfromance time counter will be used!"); 
     39        _isSupported = true;       
    3840        } 
    3941} 
     
    5052{ 
    5153        // get current time 
    52         if (mCpu->isRDTSC()){ 
    53                  
     54        if (mCpu->isRDTSC()) 
     55    { 
    5456                // retrive current ticks number 
    5557                uint64 now = _startTimeRT; 
     
    6365                                 
    6466                // calculate current time in seconds 
    65                 _currentTime = (0.001 * float64(b)) / float64(mCpu->getSpeed()) + _syncTime; 
     67                _currentTime = (0.001 * float64(b)) / float64(mCpu->getSpeed()) + _resetTime + _syncTime; 
    6668        } 
    6769         
     
    7173 
    7274//------------------------------------------------------------------------ 
    73 void rdtscTimeSource::reset() 
     75void rdtscTimeSource::reset(float64 startValue) 
    7476{ 
    7577        // check whenever we have got the RDTSC support 
     
    7779                mCpu->rdtsc(_startTimeRT); 
    7880        } 
    79          
     81        _resetTime = startValue; 
    8082} 
    8183 
  • trunk/Plugins/rdtscTimeSource/TimeSource.h

    r1 r55  
    1818// Includes 
    1919//---------------------------------------------------------------------------------- 
    20 #include <nrEngine.h> 
     20#include <nrEngine/nrEngine.h> 
    2121#include "Cpu.h" 
    22 #include <boost/shared_ptr.hpp> 
    2322 
    2423 
     
    6665        * it is needed. 
    6766        **/ 
    68         void reset(); 
     67        void reset(float64 startValue = 0.0); 
    6968 
    7069        /** 
     
    7776        **/ 
    7877        void sync(); 
    79          
     78 
     79    /** 
     80     * Check if the rdtsc instruction is supported 
     81     **/ 
     82    bool isSupported() { return _isSupported; } 
     83        
    8084private: 
    8185 
     86    //! Is supported 
     87    bool _isSupported; 
     88     
    8289        //! Store the start time as 64Bit integer, for rtdsc counter 
    8390        uint64  _startTimeRT; 
  • trunk/include/nrEngine/Clock.h

    r45 r55  
    226226                **/ 
    227227                void setSyncInterval(uint32 milliseconds); 
    228                  
     228 
     229        //! Return the sync interval in millisconds 
     230        uint32 getSyncInterval() const { return syncInterval; } 
     231         
    229232                /** 
    230233                 * Reset the clock. The clock time will be resetted to the given time. 
Note: See TracChangeset for help on using the changeset viewer.