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 <PsMomeController.h> 00019 00020 PsnSharedMemoryManager * PsMomeController::STLSharedMemoryManager=NULL; 00021 PsnRelaxedMemoryManager * PsMomeController::outputDataSharedMemoryManager=NULL; 00022 PsnCoherantMemoryManager * PsMomeController::controlersDataSharedMemoryManager=NULL; 00023 PsnCoherantMemoryManager * PsMomeController::strictMemoryManager=NULL; 00024 PsnRelaxedMemoryManager * PsMomeController::weakMemoryManager=NULL; 00025 char * PsMomeController::nomExecutable="none" ; 00026 #ifdef _MOME 00027 #include <unistd.h> 00028 #include <sys/mman.h> 00029 #include <malloc.h> 00030 typedef unsigned char TpProcessorNumber; 00031 typedef unsigned char TpGroupeNumber; 00032 #include <MomeDsm.h> 00033 #include <PsnCoherantMemoryManager.h> 00034 #include <PsnRelaxedMemoryManager.h> 00035 #include <PsnOutputOffsetTable.h> 00036 #include <PsnOutputSharedData.h> 00037 #include <PsnUniqueCreator.h> 00038 #include <PsClassicalNameServer.h> 00039 #include <mySharedAllocator.h> 00040 #include <PsnMomeMirrorObjectHandle.h> 00041 #include <PsnMomeReferenceObjectHandle.h> 00042 #include <PsnNew.h> 00043 #include <glib.h> 00044 #endif 00045 00046 void PsMomeController::SigSegvExceptionThrower(void *) { 00047 cerr<<"PsMomeController::SigSegvExceptionThrower"<<endl; 00048 exit(0); 00049 } 00050 00051 PsMomeController::PsMomeController(PsObjectDescriptor & initialObjects, const PsDate & initialDate) : 00052 PsDistributedController(initialObjects, initialDate) 00053 { 00054 #ifdef _MOME 00055 chdir(g_dirname(nomExecutable)); 00056 cout<<"I am controler "<<MomeMe<<"(named "<<getObjectDescriptor().getName()<<") of "<<MomeNumberOfProcessors<<" of thread "<<pthread_self()<<endl; 00057 _tailleAlloueParSegment = 4*1024*MomePageSize; 00058 int numSeg = MomeAllocateSharedSegment(2*_tailleAlloueParSegment); 00059 //cout<<"Me suis alloué un segment partagé"<<endl; 00060 void * zone = memalign(4096,2*_tailleAlloueParSegment); 00061 //cout<<"Me suis alloué la mémoire correspondante"<<endl; 00062 void * buffer = MomeMapMemory(zone,2*_tailleAlloueParSegment,MomeWrite,MAP_FIXED,numSeg,0); 00063 00064 _zoneCoherenceForte = (int *) buffer ; 00065 00066 if (MomeMe!=0) { 00067 MomeBarrier(); 00068 cerr<<"passage de la barrière****************************************"<<endl; 00069 } 00070 00071 cerr<<"gestion des adresses depuis "<<buffer<<" et jusqu'à "<<(void *)((unsigned int)buffer+2*_tailleAlloueParSegment)<<endl; 00072 //sleep(3); 00073 00074 strictMemoryManager = new PsnCoherantMemoryManager(buffer,_tailleAlloueParSegment, MomePageSize ); 00075 00076 cerr<<"Mémoire cohérante crée"<<endl; 00077 00078 STLSharedMemoryManager = strictMemoryManager; 00079 controlersDataSharedMemoryManager = strictMemoryManager; 00080 00081 cerr<<"Initialisation des données partagées"<<endl; 00082 _sharedObjectFactory = new PsnUniqueCreator(controlersDataSharedMemoryManager); 00083 00084 //si MomeMe == 0, on sait qu'on est déjà en exclusion 00085 cerr<<"Unique creator créé "<<endl; 00086 00087 /* on initialise le gestionnaire de broadcast avant le gestionnaire de noms pour obtenir un bon verrou */ 00088 cerr<<"initialisation du broadcastManager"<<endl; 00089 00090 _myBroadcastManager = new PsnBroadcastManager(*_sharedObjectFactory); 00091 00092 //Feinte : rendu ici, sur tous les noeuds, le PsNameServer doit être le même, au niveau contenu 00093 //On le recopie donc dans un PsNameServer partagé, et on vérifie 00094 cerr<<"Nouveau serveur de nom a créer "<<endl; 00095 00096 PsMomeNameServer * unAutreServeur = _sharedObjectFactory->newPsNameServer(MomeMe+1); 00097 PsNameServer * oldNameServer = PsName::getNameServer() ; 00098 cerr<<"nouveau serveur de nom créé"<<endl; 00099 PsName::setNameServer ( unAutreServeur ) ; 00100 delete oldNameServer ; 00101 00102 00103 myOutputOffsetTable = _sharedObjectFactory->newPsnOutputOffsetTable(); 00104 00105 assert(myOutputOffsetTable != NULL ) ; 00106 00107 if(MomeMe==0) { 00108 cerr<<"Arrivé à la barrière de fin d'initialisation"<<endl; 00109 MomeBarrier(); 00110 cerr<<"Passage de la barrière****************************************"<<endl; 00111 } 00112 //gestion des SIGSEGV 00113 // MomeSIGSEGVHandler( & PsMomeController::SigSegvExceptionThrower ); 00114 00115 #endif 00116 } 00117 00118 PsMomeController::~PsMomeController() { 00119 #ifdef _MOME 00120 cout<<"PsMomeController::~PsMomeController()"<<endl; 00121 PsClassicalNameServer * unAutreServeur = new PsClassicalNameServer(PsName::getNameServer()->getCanonicalRepresentation()); 00122 PsNameServer * oldNameServer = PsName::getNameServer() ; 00123 PsName::setNameServer(unAutreServeur); 00124 MomeBarrier(); //tout le monde doit avoir sa copie du serveur de nom avant la destruction 00125 if (MomeMe==0) delete oldNameServer ; 00126 cout<<"destruction du Serveur de nom spécifique Mome"<<endl; 00127 destroyControlledObjects(); 00128 cout<<"PsMomeController::~PsMomeController() Les objets controlés ont été détruits"<<endl; 00129 MomeBarrier() ; 00130 delete weakMemoryManager ; 00131 //if (MomeMe==0) delete myOutputOffsetTable; 00132 MomeFinalize(0); 00133 #endif 00134 } 00135 00136 00137 void PsMomeController::init() { 00138 #ifdef _MOME 00139 MomeBarrier(); 00140 cerr<<"PsMomeController::init() classique tentée "<<_stepPeriod<<endl; 00141 PsDistributedController::init(); 00142 cerr<<"PsMomeController::init() : frequency locale : "<<_stepPeriod<<endl; 00143 while (! tableDesNonInitialises.empty ()) { 00144 cerr<<"Nouvelle initialisation des objets dont l'init a échouée"<<endl; 00145 weakMemoryManager->strongSynchronizeRegion(0,_tailleAlloueParSegment); 00146 //syncAttributesAndEvents(); 00147 PsNameToPointerMap<PsSimulatedObject> aInitialiser = tableDesNonInitialises ; 00148 tableDesNonInitialises.clear () ; 00149 PsNameToPointerMap<PsSimulatedObject>::iterator pNI ; 00150 //cout<<"*"<<endl; 00151 for (pNI = aInitialiser.begin () ; 00152 pNI != aInitialiser.end () ; 00153 pNI ++) { 00154 cout<<pNI->second->getName()<<" " ; 00155 initObjetReferentiel (pNI->second) ; 00156 cout<<"."; 00157 } 00158 cout<<endl; 00159 } 00160 cerr<<"PsMomeController::init Synchronisation "; 00161 weakMemoryManager->strongSync(); 00162 cerr<<"efffective"<<endl; 00163 #endif 00164 } 00165 00166 PsnSharedMemoryManager * PsMomeController::whichSharedMemoryManager(void * ptr) { 00167 #ifdef _MOME 00168 if(strictMemoryManager!=NULL) { 00169 if(strictMemoryManager->inAdressSpace(ptr)) return strictMemoryManager; 00170 } 00171 if (weakMemoryManager!=NULL) { 00172 if(weakMemoryManager->inAdressSpace(ptr)) return weakMemoryManager; 00173 } 00174 return 0 ; 00175 #else 00176 return 0 ; 00177 #endif 00178 } 00179 00180 PsnOutputSharedData * PsMomeController::creerDonneesOutput (const PsName & object, const PsName & name) { 00181 #ifdef _MOME 00182 PsnOutputSharedData * res; 00183 #ifdef _DEBUGCREATIONOUTPUT 00184 cerr<<"on cherche "<<object<<","<<name<<endl; 00185 #endif 00186 pair<bool,unsigned int> present = myOutputOffsetTable->getOutputOffset(object,name); 00187 if (present.first) { 00188 #ifdef _DEBUGCREATIONOUTPUT 00189 cerr<<"on a retrouvé la output "<<object<<","<<name<<endl; 00190 #endif 00191 res = (PsnOutputSharedData * )outputDataSharedMemoryManager->localAddressToGlobal(present.second); 00192 } 00193 else { 00194 myOutputOffsetTable->lock(); 00195 #ifdef _DEBUGCREATIONOUTPUT 00196 cerr<<"On va déclarer la output "<<object<<","<<name<<endl; 00197 #endif 00198 res = new PsnOutputSharedData(); 00199 #ifdef _DEBUGCREATIONOUTPUT 00200 cerr<<"On a déclaré la structure de donnée"<<endl; 00201 #endif 00202 myOutputOffsetTable->declareOutput(object, 00203 name, 00204 outputDataSharedMemoryManager->globalAddressToLocal(res)); 00205 #ifdef _DEBUGCREATIONOUTPUT 00206 cerr<<"On a déclaré la output "<<object<<","<<name<<endl; 00207 #endif 00208 myOutputOffsetTable->unlock(); 00209 } 00210 return res; 00211 #else 00212 return 0 ; 00213 #endif 00214 } 00215 00216 void PsMomeController::invalidateOutput(const PsName & object, const PsName & name) { 00217 #ifdef _MOME 00218 //cerr<<"PsMomeController::invalidateOutput("<<object<<","<<name<<")"<<endl; 00219 myOutputOffsetTable->lock(); 00220 myOutputOffsetTable->invalidateOutput(object,name); 00221 myOutputOffsetTable->unlock(); 00222 //cerr<<"PsMomeController::invalidateOutput done"<<endl; 00223 #endif 00224 } 00225 00226 #include <PsOutputNT.h> 00227 #include <PsControlParameter.h> 00228 #include <PsnMirrorObjectHandle.h> 00229 00230 void PsMomeController::syncAttributesAndEvents( void ) 00231 { 00232 #ifdef _MOME 00233 //Synchroniser les données partagées avec les données locales 00234 // PsNameToPointerMap<PsnMirrorObjectHandle>::iterator i; 00235 // PsNameToPointerMap<PsOutputNT> * tableDesOutputs; 00236 // PsNameToPointerMap<PsOutputNT>::iterator ii; 00237 // PsNameToPointerMap<PsControlParameterNT> * tableDesParametres; 00238 // PsNameToPointerMap<PsControlParameterNT>::iterator iii; 00239 // for(i=_mirrorObjectsMap.begin();i!=_mirrorObjectsMap.end();i++){ 00240 // tableDesOutputs=((*i).second)->objetSimul()->TabOutputs(); 00241 // for(ii=tableDesOutputs->begin();ii!=tableDesOutputs->end();ii++) { 00242 // (*ii).second->extract(); 00243 // //cout<<(*ii).first<<" : "<<*((*ii).second)<<endl; 00244 // } 00245 // tableDesParametres=((*i).second)->objetSimul()->TabParams(); 00246 // for(iii=tableDesParametres->begin();iii!=tableDesParametres->end();iii++) { 00247 // (*iii).second->extract(); 00248 // //cout<<(*ii).first<<" : "<<*((*ii).second)<<endl; 00249 // } 00250 // } 00251 _myBroadcastManager->sync(); 00252 #endif 00253 } 00254 00255 void PsMomeController::computeNextSimulationStep() { 00256 #ifdef _MOME 00257 #ifdef _DEBUGEXEC 00258 cerr<<"PsMomeController::computeNextSimulationStep synchronisation de la mémoire "<<endl; 00259 #endif 00260 weakMemoryManager->sync(); 00261 #ifdef _DEBUGEXEC 00262 cerr<<"PsMomeController::computeNextSimulationStep synchronisation des messages et des événements "<<endl; 00263 #endif 00264 00265 #ifdef _DEBUGEXEC 00266 cerr<<"PsMomeController::computeNextSimulationStep appel de la méthode ancêtre "<<endl; 00267 #endif 00268 PsDistributedController::computeNextSimulationStep(); 00269 #ifdef _DEBUGEXEC 00270 cerr<<"PsMomeController::computeNextSimulationStep fait"<<endl; 00271 #endif 00272 #endif 00273 } 00274 00275 PsnMirrorObjectHandle * PsMomeController::newPsnMirrorObjectHandle (PsSimulatedObject & obj) { 00276 #ifdef _MOME 00277 return new PsnMomeMirrorObjectHandle(obj, *_myBroadcastManager, *strictMemoryManager); 00278 #else 00279 return 0 ; 00280 #endif 00281 } 00282 00283 PsnReferenceObjectHandle * PsMomeController::newPsnReferenceObjectHandle (PsSimulatedObject & object, 00284 PsController & controller, 00285 PsnSignalDispatcher * signalDispatcher) 00286 { 00287 #ifdef _MOME 00288 return new PsnMomeReferenceObjectHandle(obj, controller, signalDispatcher) ; 00289 #else 00290 return 0 ; 00291 #endif 00292 } 00293 00294 void PsMomeController::prepareEventProcessing ( list <PsEvent *> & myList ) { 00295 #ifdef _MOME 00296 syncAttributesAndEvents(); 00297 #ifdef _DEBUGEVT 00298 cerr<<"PsMomeController::prepareEventProcessing de "<<getObjectDescriptor().Processus()<<endl; 00299 #endif 00300 //dispatch events received from the broadcast manager 00301 _myBroadcastManager->dispatchEventsOfList(*this); 00302 #ifdef _DEBUGEVT 00303 cerr<<"PsMomeController::traiterEvt : events dispatched"<<endl; 00304 #endif 00305 #endif 00306 } 00307 00308 00309 void PsMomeController::actOnSystemEvent( PsEvent * evt ) { 00310 #ifdef _MOME 00311 #ifdef _DEBUGEVT 00312 cerr<<"PsMomeController::actOnSystemEvent"<<evt<<endl; 00313 #endif 00314 if(evt->receiver == getName()) {//il faut diffuser l'évenement 00315 HeapStackTop toto(controlersDataSharedMemoryManager); 00316 _myBroadcastManager->broadcastEvent(controlersDataSharedMemoryManager->globalAddressToLocal(evt->clone())); 00317 } 00318 else { 00319 PsDistributedController::actOnSystemEvent ( evt ) ; 00320 } 00321 #else 00322 PsDistributedController::actOnSystemEvent ( evt ) ; 00323 #endif 00324 } 00325 00326 int PsMomeController::getOutputHistorySize(void) { 00327 //on aligne sur un multiple de nbMinor 00328 int resul = PsDistributedController::getOutputHistorySize() ; 00329 if (resul % _nbStepsByCycle != 0) { 00330 resul = (resul / _nbStepsByCycle + 1) * _nbStepsByCycle ; 00331 } 00332 return 2 * resul; 00333 } 00334 00335 void PsMomeController::createControlledObjects( const PsObjectDescriptor * subTree ) 00336 { 00337 #ifdef _MOME 00338 cerr<<"PsMomeController::createControlledObjects"<<endl; 00339 weakMemoryManager = new PsnRelaxedMemoryManager((int *)(((int)_zoneCoherenceForte)+_tailleAlloueParSegment), 00340 _tailleAlloueParSegment, 00341 MomePageSize, 00342 _sharedObjectFactory, 00343 getOutputHistorySize() ); 00344 00345 outputDataSharedMemoryManager = weakMemoryManager; 00346 00347 cerr<<"PsMomeController::createControlledObjects appel ancetre"<<endl; 00348 PsDistributedController::createControlledObjects( subTree ) ; 00349 cerr<<"PsMomeController::createControlledObjects fait"<<endl; 00350 #endif 00351 } 00352 void PsMomeController::broadcast (const PsName & nomDestinataire, const PsString & message) { 00353 assert (false) ; // non implementé 00354 }
| Documentation generated on Mon Nov 25 15:25:00 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |