00001 /* 00002 * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software 00003 * 00004 * The Software has been developped within the Siames Project. 00005 * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights 00006 * 00007 * The Software has been registered with the Agence pour la Protection des 00008 * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200 00009 * 00010 * This file may be distributed under the terms of the Q Public License 00011 * version 1.0 as defined by Trolltech AS of Norway and appearing in the file 00012 * LICENSE.QPL included in the packaging of this file. 00013 * 00014 * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 00015 * for the software may use this file in accordance with that specific license 00016 * 00017 */ 00018 #include <PsBenchController.h> 00019 #include <sys/time.h> 00020 #ifdef _SGI 00021 #include <sys/syssgi.h> 00022 #endif 00023 #include <unistd.h> 00024 #include <PsnDoubleListElement.h> 00025 #include <PsnDoubleList.h> 00026 #include "PsnBenchScheduler.h" 00027 #include "PsConfigurationParameterDescriptor.h" 00028 00029 PsBenchController::PsBenchController(PsObjectDescriptor & scenario, const PsDate & initialDate ) 00030 : PsController(scenario, initialDate), 00031 _file (NULL ), 00032 _startSamplingDate ( initialDate ), 00033 _endSamplingDate ( initialDate+1000 ) 00034 { 00035 00036 if (getConfigurationParameters() != NULL ) 00037 { 00038 const PsConfigurationParameterDescriptor * param = getConfigurationParameters()->getSubDescriptorByName("TimeFrom") ; 00039 if ( param != NULL ) 00040 { 00041 _startSamplingDate=atoi(param->getAssociatedString().c_str() ) ; 00042 } 00043 00044 param = getConfigurationParameters()->getSubDescriptorByName("TimeUntil") ; 00045 if ( param != NULL ) 00046 { 00047 _endSamplingDate = atoi(param->getAssociatedString().c_str() ) ; 00048 } 00049 param = getConfigurationParameters()->getSubDescriptorByName("BenchResultFile") ; 00050 if ( param != NULL ) 00051 { 00052 _resultFilename = param->getAssociatedString() ; 00053 _file = new ofstream ( _resultFilename.getCString() ); 00054 } 00055 } 00056 00057 if (_startSamplingDate>_endSamplingDate) 00058 { 00059 cout<<"PsBenchController::WARNING : sampling dates dont make an interval"<<endl; 00060 cout<<"PsBenchController::WARNING : default sampling dates used "<<endl; 00061 _startSamplingDate=PsController::initialSimulationDate; 00062 _endSamplingDate=PsController::initialSimulationDate+1000; 00063 } 00064 } 00065 00066 00067 void 00068 PsBenchController::flushResults() 00069 { 00070 if(_file == NULL) 00071 { 00072 printToStream(cout); 00073 } 00074 else 00075 { 00076 printToStream(*_file); 00077 } 00078 } 00079 00080 00081 00082 PsBenchController::~PsBenchController() 00083 { 00084 if (_date<_endSamplingDate) flushResults(); 00085 delete [] _stepDurationTab; 00086 delete [] _slowedDownStepDurationTab; 00087 } 00088 00089 void PsBenchController::init() 00090 { 00091 PsController::init() ; 00092 00093 if (_startSamplingDate<PsController::initialSimulationDate) 00094 { 00095 _startSamplingDate=PsController::initialSimulationDate; 00096 cout<<"PsBenchController::WARNING : no values PsController::initialSimulationDate (" 00097 <<PsController::initialSimulationDate<<")"<<endl; 00098 } 00099 00100 _numberOfSamples = (_endSamplingDate-_startSamplingDate)/_stepPeriod + 1; 00101 00102 _sampleIndex=0; 00103 00104 _stepDurationTab = new long[_numberOfSamples]; 00105 _slowedDownStepDurationTab = new long[_numberOfSamples]; 00106 } 00107 00108 PsnScheduler * PsBenchController::createScheduler() { 00109 PsnScheduler * res ; 00110 cout<<"Benchmarking between "<<_startSamplingDate<<" and "<<_endSamplingDate << endl; 00111 if ( _file != NULL ) { 00112 res = new PsnBenchScheduler(nbMinor, _sampleIndex, _numberOfSamples,*_file) ; 00113 } 00114 else { 00115 res = new PsnBenchScheduler(nbMinor, _sampleIndex, _numberOfSamples, cout ) ; 00116 } 00117 //res = new PsnFrameScheduler(_nbStepsByCycle) ; 00118 return res ; 00119 } 00120 00121 void PsBenchController::compute (){ 00122 static long avance = 0 ; 00123 //initialisation des compteurs du pas de calcul 00124 if ((_startSamplingDate<=_date)&&(_date<=_endSamplingDate)) { 00125 static timespec avant, apres; 00126 clock_gettime(CLOCK_SGI_CYCLE, &avant); 00127 PsController::compute (); 00128 //lecture des compteurs du pas de calcul 00129 clock_gettime(CLOCK_SGI_CYCLE, &apres); 00130 //remplissage de la table globale 00131 long duree = apres.tv_nsec - avant.tv_nsec ; 00132 if (duree < 0 ) duree = apres.tv_nsec + ( LONG_MAX/2 - avant.tv_nsec ) ; 00133 _stepDurationTab[_sampleIndex] = duree ; 00134 _sampleIndex++; 00135 //Les 4 lignes qui suivent sont une tentative primitive d'atteinte du temps réel 00136 avance += _stepPeriod * 1000 - duree / 1000 ; 00137 if (avance > 10000) { 00138 usleep( avance ); 00139 clock_gettime(CLOCK_SGI_CYCLE, &apres); 00140 if (apres.tv_nsec > avant.tv_nsec) { 00141 avance = avance - (apres.tv_nsec - avant.tv_nsec) / 1000 ; 00142 } 00143 else { 00144 avance = avance - (( LONG_MAX/2 - avant.tv_nsec ) + apres.tv_nsec ) / 1000 ; 00145 } 00146 } 00147 _slowedDownStepDurationTab[_numberOfSimulatedSteps%_numberOfSamples] = apres.tv_nsec - avant.tv_nsec ; 00148 if (_slowedDownStepDurationTab[_numberOfSimulatedSteps%_numberOfSamples] < 0) { 00149 _slowedDownStepDurationTab[_numberOfSimulatedSteps%_numberOfSamples] = ( LONG_MAX/2 - avant.tv_nsec ) + apres.tv_nsec ; 00150 } 00151 if (_date==_endSamplingDate) { 00152 flushResults(); 00153 _sampleIndex=-1; 00154 } 00155 } 00156 else { 00157 PsController::compute (); 00158 } 00159 } 00160 00161 void PsBenchController::printToStream(ostream & out) { 00162 timespec resolutionHorloge; 00163 long moyenne; 00164 long averageTimeSlowed = 0 ; 00165 int nbValeurs; 00166 long duree; 00167 out<<syssgi(SGI_CYCLECNTR_SIZE) ; 00168 clock_getres(CLOCK_SGI_CYCLE,&resolutionHorloge); 00169 out<<"resolution de l'horloge en secondes : "<<resolutionHorloge.tv_sec<<endl; 00170 out<<"resolution de l'horloge en nanosecondes : "<<resolutionHorloge.tv_nsec<<endl; 00171 moyenne=0; 00172 nbValeurs=0; 00173 for(int i=0;i<_numberOfSamples;i++) { 00174 duree=_stepDurationTab[i]; 00175 out<<duree/1000<<" "<<_slowedDownStepDurationTab[i]/1000<<endl; 00176 if (duree>=0) { 00177 moyenne = moyenne+(duree/1000); 00178 averageTimeSlowed = averageTimeSlowed + (_slowedDownStepDurationTab[i]/1000); 00179 nbValeurs++; 00180 } 00181 } 00182 out<<"Soit une moyenne corrigée de : "<<moyenne/nbValeurs<<" microsecondes"<<endl; 00183 out<<"Soit une moyenne ralentie de : "<<averageTimeSlowed/(1000*nbValeurs)<<" millisecondes "<<_stepPeriod<<endl; 00184 } 00185 00186 00187 00188 00189 00190
| Documentation generated on Mon Nov 25 15:25:02 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |