diff VMS.c @ 28:8b9e4c333fe6

Sequential Version -- first compile succeeded
author Me
date Mon, 26 Jul 2010 16:42:59 -0700
parents 668278fa7a63
children 0e008278fe3c
line diff
     1.1 --- a/VMS.c	Mon Jul 26 15:29:26 2010 -0700
     1.2 +++ b/VMS.c	Mon Jul 26 16:42:59 2010 -0700
     1.3 @@ -21,6 +21,12 @@
     1.4  void
     1.5  create_sched_slots( MasterEnv *masterEnv );
     1.6  
     1.7 +void
     1.8 +create_masterEnv();
     1.9 +
    1.10 +void
    1.11 +create_the_coreLoop_OS_threads();
    1.12 +
    1.13  pthread_mutex_t suspendLock = PTHREAD_MUTEX_INITIALIZER;
    1.14  pthread_cond_t  suspend_cond  = PTHREAD_COND_INITIALIZER;
    1.15  
    1.16 @@ -56,6 +62,21 @@
    1.17   */
    1.18  void
    1.19  VMS__init()
    1.20 + {
    1.21 +   create_masterEnv();
    1.22 +   create_the_coreLoop_OS_threads();
    1.23 + }
    1.24 +
    1.25 +/*To initialize the sequential version, just don't create the threads
    1.26 + */
    1.27 +void
    1.28 +VMS__init_Seq()
    1.29 + {
    1.30 +   create_masterEnv();
    1.31 + }
    1.32 +
    1.33 +void
    1.34 +create_masterEnv()
    1.35   { MasterEnv  *masterEnv;
    1.36     VMSQueueStruc *workQ;
    1.37  
    1.38 @@ -73,34 +94,12 @@
    1.39  
    1.40     masterEnv->stillRunning = FALSE;
    1.41     masterEnv->numToPrecede = NUM_CORES;
    1.42 -   
    1.43 +
    1.44        //First core loop to start up gets this, which will schedule seed Pr
    1.45        //TODO: debug: check address of masterVirtPr
    1.46     writeVMSQ( masterEnv->masterVirtPr, workQ );
    1.47  
    1.48 -   numProcrsCreated = 1;
    1.49 -
    1.50 -   //========================================================================
    1.51 -   //                      Create the Threads
    1.52 -   int coreIdx, retCode;
    1.53 -   
    1.54 -      //Need the threads to be created suspended, and wait for a signal
    1.55 -      // before proceeding -- gives time after creating to initialize other
    1.56 -      // stuff before the coreLoops set off.
    1.57 -   _VMSMasterEnv->setupComplete = 0;
    1.58 -
    1.59 -      //Make the threads that animate the core loops
    1.60 -   for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
    1.61 -    { coreLoopThdParams[coreIdx]          = malloc( sizeof(ThdParams) );
    1.62 -      coreLoopThdParams[coreIdx]->coreNum = coreIdx;
    1.63 -
    1.64 -      retCode =
    1.65 -      pthread_create( &(coreLoopThdHandles[coreIdx]), 
    1.66 -                        thdAttrs,
    1.67 -                       &coreLoop,
    1.68 -               (void *)(coreLoopThdParams[coreIdx]) );
    1.69 -      if(retCode){printf("ERROR creating thread: %d\n", retCode); exit(0);}
    1.70 -    }
    1.71 +   numProcrsCreated = 1;  //global counter for debugging
    1.72   }
    1.73  
    1.74  void
    1.75 @@ -124,6 +123,32 @@
    1.76   }
    1.77  
    1.78  
    1.79 +void
    1.80 +create_the_coreLoop_OS_threads()
    1.81 + {
    1.82 +   //========================================================================
    1.83 +   //                      Create the Threads
    1.84 +   int coreIdx, retCode;
    1.85 +
    1.86 +      //Need the threads to be created suspended, and wait for a signal
    1.87 +      // before proceeding -- gives time after creating to initialize other
    1.88 +      // stuff before the coreLoops set off.
    1.89 +   _VMSMasterEnv->setupComplete = 0;
    1.90 +
    1.91 +      //Make the threads that animate the core loops
    1.92 +   for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
    1.93 +    { coreLoopThdParams[coreIdx]          = malloc( sizeof(ThdParams) );
    1.94 +      coreLoopThdParams[coreIdx]->coreNum = coreIdx;
    1.95 +
    1.96 +      retCode =
    1.97 +      pthread_create( &(coreLoopThdHandles[coreIdx]),
    1.98 +                        thdAttrs,
    1.99 +                       &coreLoop,
   1.100 +               (void *)(coreLoopThdParams[coreIdx]) );
   1.101 +      if(retCode){printf("ERROR creating thread: %d\n", retCode); exit(0);}
   1.102 +    }
   1.103 + }
   1.104 +
   1.105  /*Semantic layer calls this when it want the system to start running..
   1.106   *
   1.107   *This starts the core loops running then waits for them to exit.
   1.108 @@ -168,6 +193,18 @@
   1.109        printf("\n Time startup to shutdown: %f\n", runTime); fflush( stdin );
   1.110   }
   1.111  
   1.112 +/*Only difference between version with an OS thread pinned to each core and
   1.113 + * the sequential version of VMS is VMS__init_Seq, this, and coreLoop_Seq.
   1.114 + */
   1.115 +void
   1.116 +VMS__start_the_work_then_wait_until_done_Seq()
   1.117 + {
   1.118 +         //Instead of un-suspending threads, just call the one and only
   1.119 +         // core loop (sequential version), in the main thread.
   1.120 +      coreLoop_Seq( NULL );
   1.121 +
   1.122 + }
   1.123 +
   1.124  
   1.125  
   1.126  /*Create stack, then create __cdecl structure on it and put initialData and