Rolling back to the version just before the check-ins of bigsim ooc related changes...
authorChao Mei <chaomei2@illinois.edu>
Fri, 2 Jan 2009 10:41:37 +0000 (10:41 +0000)
committerChao Mei <chaomei2@illinois.edu>
Fri, 2 Jan 2009 10:41:37 +0000 (10:41 +0000)
src/conv-core/threads.c
src/libs/ck-libs/tcharm/tcharm.C
src/libs/ck-libs/tcharm/tcharm_impl.h

index 8b826b3e24e4215fdc0b55ad7cc4b4b2cdc3f414..a1b9bae718cf92ac11016a0751abf640d9425130 100644 (file)
 
 */
 
-#define THD_MAGIC_NUM 0x12345678
-
 typedef struct CthThreadBase
 {
   CthThreadToken *token; /* token that shall be enqueued into the ready queue*/
@@ -170,9 +168,6 @@ typedef struct CthThreadBase
   void      *stack; /*Pointer to thread stack*/
   int        stacksize; /*Size of thread stack (bytes)*/
   struct CthThreadListener *listener; /* pointer to the first of the listeners */
-
-  int magic; /* magic number for checking corruption */
-
 } CthThreadBase;
 
 /* By default, there are no flags */
@@ -417,9 +412,6 @@ static void CthThreadBaseInit(CthThreadBase *th)
   th->tid.id[2] = 0;
 
   th->listener = NULL;
-
-
-  th->magic = THD_MAGIC_NUM;
 }
 
 static void *CthAllocateStack(CthThreadBase *th,int *stackSize,int useMigratable)
@@ -508,51 +500,13 @@ void CthPupBase(pup_er p,CthThreadBase *t,int useMigratable)
        if ((CthThread)t==CthCpvAccess(CthCurrent))
                CmiAbort("CthPupBase: Cannot pack running thread!");
 #endif
-       /*
-        * Token will never be freed, so its pointer should be pupped.
-        * When packing, set the thread pointer in this token to be NULL.
-        * When unpacking, reset the thread pointer in token to this thread.
-        */
-         
-        if(BgOutOfCoreFlag!=0){
-           pup_bytes(p, &t->token, sizeof(void *));
-           if(!pup_isUnpacking(p)){
-               t->token->thread = NULL;
-           }
-           pup_int(p, &t->scheduled);
-       }
+       /*recreate the token when unpacking and set the thread
+         pointer in it to NULL if the thread is being deleted*/
        if(pup_isUnpacking(p)){
-               if(BgOutOfCoreFlag==0){
-                   t->token = (CthThreadToken *)malloc(sizeof(CthThreadToken));
-                   t->token->thread = S(t);
-                   //For normal runs where this pup is needed,
-                   //set scheduled to 0 in the unpacking period since the thread has
-                   //not been scheduled
-                   t->scheduled = 0;
-               }else{
-               /* During out-of-core emulation */
-                   /* 
-                    * When t->scheduled is set, the thread is in the queue so the token
-                    * should be kept. Otherwise, allocate a new space for the token
-                    */
-                   if(t->scheduled==0){
-                       /*CmiPrintf("Creating a new token for %p!\n", t->token);*/
-                       t->token = (CthThreadToken *)malloc(sizeof(CthThreadToken));
-                   }
-                   t->token->thread = S(t);
-               }
+               t->token = (CthThreadToken *)malloc(sizeof(CthThreadToken));
+               t->token->thread = S(t);
+               t->scheduled = 0;
        }
-       
-       //BIGSIM_OOC DEBUGGING
-       //if(BgOutOfCoreFlag!=0){
-       //   if(pup_isUnpacking(p)){
-       //      CmiPrintf("Unpacking: ");
-       //    }else{
-       //      CmiPrintf("Packing: ");
-       //    } 
-       //    CmiPrintf("thd=%p, its token=%p, token's thd=%p\n", t, t->token, t->token->thread); 
-       //}
-
        /*Really need a pup_functionPtr here:*/
        pup_bytes(p,&t->awakenfn,sizeof(t->awakenfn));
        pup_bytes(p,&t->choosefn,sizeof(t->choosefn));
@@ -588,8 +542,6 @@ void CthPupBase(pup_er p,CthThreadBase *t,int useMigratable)
                /* FIXME:  restore thread listener */
                t->listener = NULL;
        }
-
-       pup_int(p, &t->magic);
 }
 
 static void CthThreadFinished(CthThread t)
@@ -598,7 +550,6 @@ static void CthThreadFinished(CthThread t)
        CthSuspend();
 }
 
-
 /************ Scheduler Interface **********/
 
 void CthSetSuspendable(CthThread t, int val) { B(t)->suspendable = val; }
@@ -662,17 +613,7 @@ void CthSuspend(void)
   }
   if (cur->choosefn == 0) CthNoStrategy();
   next = cur->choosefn();
-  if(BgOutOfCoreFlag==0) cur->scheduled=0;
-  else{
-    //cur->scheduled=0;
-    //changed due to out-of-core emulation in BigSim
-    cur->scheduled--;
-  }
-#ifndef CMK_OPTIMIZE
-  if(cur->scheduled<0)
-    CmiAbort("A thread's scheduler should not be less than 0!\n");
-#endif    
-
+  cur->scheduled=0;
 #ifndef CMK_OPTIMIZE
 #if !CMK_TRACE_IN_CHARM
   if(CpvAccess(traceOn))
@@ -685,13 +626,6 @@ void CthSuspend(void)
 void CthAwaken(CthThread th)
 {
   if (B(th)->awakenfn == 0) CthNoStrategy();
-
-  //BIGSIM_OOC DEBUGGING
-  //if(B(th)->scheduled==1){
-    //CmiPrintf("====Thread %p is already scheduled!!!!\n", th);
-    //return;
-  //}
-
 #ifndef CMK_OPTIMIZE
 #if ! CMK_TRACE_IN_CHARM
   if(CpvAccess(traceOn))
@@ -699,12 +633,7 @@ void CthAwaken(CthThread th)
 #endif
 #endif
   B(th)->awakenfn(B(th)->token, CQS_QUEUEING_FIFO, 0, 0);
-  if(BgOutOfCoreFlag==0) B(th)->scheduled=1;
-  else{
-    //B(th)->scheduled = 1;
-    //changed due to out-of-core emulation in BigSim
-    B(th)->scheduled++;
-  }
+  B(th)->scheduled = 1;
 }
 
 void CthYield()
@@ -723,12 +652,7 @@ void CthAwakenPrio(CthThread th, int s, int pb, unsigned int *prio)
 #endif
 #endif
   B(th)->awakenfn(B(th)->token, s, pb, prio);
-  if(BgOutOfCoreFlag==0) B(th)->scheduled=1;
-  else{
-    //B(th)->scheduled = 1;
-    //changed due to out-of-core emulation in BigSim
-    B(th)->scheduled++;
-  }
+       B(th)->scheduled = 1;
 }
 
 void CthYieldPrio(int s, int pb, unsigned int *prio)
@@ -823,11 +747,10 @@ CthThread CthPup(pup_er p, CthThread t)
 
     if (pup_isDeleting(p))
       {CthFree(t);t=0;}
+
     return t;
 }
 
-
-
 struct CthProcInfo
 {
   qt_t      *stackbase;
@@ -1886,13 +1809,3 @@ void CthTraceResume(CthThread t)
   traceResume(&t->base.tid);
 }
 
-//Functions that help debugging of out-of-core emulation in BigSim
-void CthPrintThdMagic(CthThread t){
-    CmiPrintf("CthThread[%p]'s magic: %x\n", t, t->base.magic);
-}
-
-#if !CMK_THREADS_USE_CONTEXT
-void CthPrintThdStack(CthThread t){
-    CmiPrintf("thread=%p, base stack=%p, stack pointer=%p\n", t, t->base.stack, t->stackp);
-}
-#endif
index 344e2608d299822852b9a430338cf1bed6275f0f..c3d317439850efd36ebcd712a54ef03d4fe7fc15 100644 (file)
@@ -7,7 +7,7 @@ Orion Sky Lawlor, olawlor@acm.org, 11/19/2001
 #include "tcharm.h"
 #include <ctype.h>
 
-#if 0 
+#if 0
     /*Many debugging statements:*/
 #    define DBG(x) ckout<<"["<<thisIndex<<","<<CkMyPe()<<"] TCHARM> "<<x<<endl;
 #    define DBGX(x) ckout<<"PE("<<CkMyPe()<<") TCHARM> "<<x<<endl;
@@ -119,7 +119,6 @@ static void startTCharmThread(TCharmInitMsg *msg)
        DBGX("thread started");
        TCharm::activateThread();
        typedef void (*threadFn_t)(void *);
-
 #if CMK_TCHARM_FNPTR_HACK
        ((threadFn_t)AMPI_threadstart)(msg->data);
 #else
@@ -148,7 +147,6 @@ TCharm::TCharm(TCharmInitMsg *initMsg_)
     }
 #if CMK_BLUEGENE_CHARM
     BgAttach(tid);
-    BgUnsetStartOutOfCore();
 #endif
   }
   CtvAccessOther(tid,_curTCharm)=this;
@@ -158,7 +156,6 @@ TCharm::TCharm(TCharmInitMsg *initMsg_)
        AsyncEvacuate(CmiTrue);
   skipResume=false;
   exitWhenDone=initMsg->opts.exitWhenDone;
-  isSelfDone = false;
   threadInfo.tProxy=CProxy_TCharm(thisArrayID);
   threadInfo.thisElement=thisIndex;
   threadInfo.numElements=initMsg->numElements;
@@ -196,27 +193,19 @@ void TCharm::pup(PUP::er &p) {
 //Pup superclass
   ArrayElement1D::pup(p);
 
-  //BIGSIM_OOC DEBUGGING
-  //if(!p.isUnpacking()){
-  //  CmiPrintf("TCharm[%d] packing: ", thisIndex);
-  //  CthPrintThdStack(tid);
-  //}
-
   checkPupMismatch(p,5134,"before TCHARM");
-  p(isStopped); p(resumeAfterMigration); p(exitWhenDone); p(isSelfDone); p(skipResume);
+  p(isStopped); p(resumeAfterMigration); p(exitWhenDone); p(skipResume);
   p(threadInfo.thisElement);
   p(threadInfo.numElements);
   
-  if (sema.size()>0){
+  if (sema.size()>0) 
        CkAbort("TCharm::pup> Cannot migrate with unconsumed semaphores!\n");
-  }
 
 #ifndef CMK_OPTIMIZE
   DBG("Packing thread");
   if (!isStopped && !CmiMemoryIs(CMI_MEMORY_IS_ISOMALLOC)){
-    if(BgOutOfCoreFlag==0) //not doing out-of-core scheduling
-       CkAbort("Cannot pup a running thread.  You must suspend before migrating.\n");
-  }    
+    CkAbort("Cannot pup a running thread.  You must suspend before migrating.\n");
+       }       
   if (tcharm_nomig) CkAbort("Cannot migrate with the +tcharm_nomig option!\n");
 #endif
 
@@ -270,13 +259,6 @@ void TCharm::pup(PUP::er &p) {
   
   s.endBlock(); //End of seeking block
   checkPupMismatch(p,5140,"after TCHARM");
-  
-  //BIGSIM_OOC DEBUGGING
-  //if(p.isUnpacking()){
-  //  CmiPrintf("TCharm[%d] unpacking: ", thisIndex);
-  //  CthPrintThdStack(tid);
-  //}
-
 }
 
 // Pup our thread and related data
@@ -330,9 +312,6 @@ void TCharm::UserData::pup(PUP::er &p)
 
 TCharm::~TCharm()
 {
-  //BIGSIM_OOC DEBUGGING
-  //CmiPrintf("TCharm destructor called with heapBlocks=%p!\n", heapBlocks);
-  
   if (heapBlocks) CmiIsomallocBlockListDelete(heapBlocks);
   CthFree(tid);
   CtgFree(threadGlobals);
@@ -357,15 +336,6 @@ void TCharm::ckJustMigrated(void) {
        }
 }
 
-void TCharm::ckJustRestored(void) {
-       //CkPrintf("call just restored from TCharm[%d]\n", thisIndex);
-       ArrayElement::ckJustRestored();
-       //if (resumeAfterMigration) {
-       //      resumeAfterMigration=false;
-       //      resume(); //Start the thread running
-       //}
-}
-
 /*
        FAULT_EVAC
 
@@ -424,7 +394,6 @@ void TCharm::stop(void)
   stopTiming();
   isStopped=true;
   DBG("thread suspended");
-
   CthSuspend();
 //     DBG("thread resumed");
   /*SUBTLE: We have to do the get() because "this" may have changed
@@ -435,7 +404,7 @@ void TCharm::stop(void)
   TCharm *dis=TCharm::get();
   dis->isStopped=false;
   dis->startTiming();
-  //CkPrintf("[%d] Thread resumed  for tid %p\n",dis->thisIndex,dis->tid);
+//     printf("[%d] Thread resumed  for tid %p\n",dis->thisIndex,dis->tid);
 }
 
 //Resume the waiting thread
@@ -444,8 +413,6 @@ void TCharm::start(void)
   //  since this thread is scheduled, it is not a good idea to migrate 
   isStopped=false;
   DBG("thread resuming soon");
-  //CkPrintf("TCharm[%d]::start()\n", thisIndex);
-  //CmiPrintStackTrace(0);
   CthAwaken(tid);
 }
 
@@ -520,7 +487,6 @@ void TCharm::allow_migrate(void)
 //Resume from sync: start the thread again
 void TCharm::ResumeFromSync(void)
 {
-  if(isSelfDone) return;
   if (!skipResume) start();
 }
 
@@ -572,25 +538,22 @@ void TCharm::atBarrier(CkReductionMsg *m) {
 
 //Called when the thread is done running
 void TCharm::done(void) {
-       //CmiPrintStackTrace(0);
        DBG("TCharm thread "<<thisIndex<<" done")
        if (exitWhenDone) {
                //Contribute to a synchronizing reduction
                CkCallback cb(index_t::atExit(0), thisProxy[0]);
                contribute(sizeof(vals),&vals,CkReduction::sum_int,cb);
        }
-       isSelfDone = true;
        stop();
 }
 //Called when all threads are done running
 void TCharm::atExit(CkReductionMsg *m) {
-       DBGX("TCharm::atExit1> exiting");
+       DBGX("TCharm::atExit> exiting");
        delete m;
-       //thisProxy.unsetFlags();
        CkExit();
-       //CkPrintf("After CkExit()!!!!!!!\n");
 }
 
+
 /************* Setup **************/
 
 //Globals used to control setup process
@@ -716,9 +679,6 @@ CkArrayOptions TCHARM_Attach_start(CkArrayID *retTCharmArray,int *retNumElts)
        if (!tc)
                CkAbort("You must call TCHARM initialization routines from a TCHARM thread!");
        int nElts=tc->getNumElements();
-      
-        //CmiPrintf("TCHARM Elements = %d\n", nElts);  
-      
        if (retNumElts!=NULL) *retNumElts=nElts;
        *retTCharmArray=tc->getProxy();
        CkArrayOptions opts(nElts);
index 9829e67e474b744247aa107f20e1eb62bea97e74..6c0a660eb0de77b86c7bd31b156534042695091a 100644 (file)
@@ -141,10 +141,7 @@ class TCharm: public CBase_TCharm
        CtgGlobals threadGlobals; //Global data
        void pupThread(PUP::er &p);
 
-       //isSelfDone is added for out-of-core emulation in BigSim
-       //when thread is brought back into core, ResumeFromSync is called
-       //so if the thread has finished its stuff, it should not start again
-       bool isStopped, resumeAfterMigration, exitWhenDone, isSelfDone, skipResume;
+       bool isStopped, resumeAfterMigration, exitWhenDone, skipResume;
        ThreadInfo threadInfo;
        double timeOffset; //Value to add to CkWallTimer to get my clock
 
@@ -161,7 +158,6 @@ class TCharm: public CBase_TCharm
        ~TCharm();
        
        virtual void ckJustMigrated(void);
-       virtual void ckJustRestored(void);
        virtual void ckAboutToMigrate(void);
        
        void migrateDelayed(int destPE);
@@ -218,13 +214,8 @@ class TCharm: public CBase_TCharm
        void start(void);
        //Aliases:
        inline void suspend(void) {stop();}
-       inline void resume(void) {
-               //printf("in thcarm::resume, isStopped=%d\n", isStopped); 
-               if (isStopped){ 
-                   start(); 
-               }
-               else {
-                   //printf("[%d] TCharm resume called on already running thread pe %d \n",thisIndex,CkMyPe());
+       inline void resume(void) { if (isStopped) start(); else {
+       //      printf("[%d] TCharm resume called on already running thread pe %d \n",thisIndex,CkMyPe());
                }
        }
 
@@ -266,8 +257,6 @@ class TCharm: public CBase_TCharm
        /// System() call emulation:
        int system(const char *cmd);
        void callSystem(const callSystemStruct &s);
-
-       inline CthThread getTid() { return tid; }
 };