diff VMS.c @ 12:d801fe740275

Middle of testing core loop
author Me
date Sat, 19 Jun 2010 19:26:38 -0700
parents 9a1b7de19e39
children 65c8fb2821ee
line diff
     1.1 --- a/VMS.c	Sat Jun 19 19:26:12 2010 -0700
     1.2 +++ b/VMS.c	Sat Jun 19 19:26:38 2010 -0700
     1.3 @@ -47,10 +47,10 @@
     1.4  void
     1.5  VMS__init()
     1.6   { MasterEnv  *masterEnv;
     1.7 -   QueueStruc *workQ;
     1.8 +   CASQueueStruc *workQ;
     1.9  
    1.10        //Make the central work-queue
    1.11 -   _VMSWorkQ = makeQ();
    1.12 +   _VMSWorkQ = makeCASQ();
    1.13     workQ     = _VMSWorkQ;
    1.14  
    1.15     _VMSMasterEnv = malloc( sizeof(MasterEnv) );
    1.16 @@ -68,7 +68,10 @@
    1.17  
    1.18        //First core loop to start up gets this, which will schedule seed Pr
    1.19        //TODO: debug: check address of masterVirtPr
    1.20 -   writeQ( masterEnv->masterVirtPr, workQ );
    1.21 +//TODO: commented out for debugging -- put it back in!!
    1.22 +//   writeCASQ( masterEnv->masterVirtPr, workQ );
    1.23 +
    1.24 +   numProcrsCreated = 1;
    1.25   }
    1.26  
    1.27  
    1.28 @@ -98,25 +101,25 @@
    1.29   *This creates the core loops, pins them to physical cores, gives them the
    1.30   * pointer to the workQ, and starts them running.
    1.31   */
    1.32 - void
    1.33 +void
    1.34  VMS__start()
    1.35 - { int retCode, coreIdx;
    1.36 + { int coreIdx;
    1.37  
    1.38     //Create the win threads that animate the core loops
    1.39     for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
    1.40      {
    1.41 -      thdParams[coreIdx]          = (ThdParams *)malloc( sizeof(ThdParams) );
    1.42 -      thdParams[coreIdx]->coreNum = coreIdx;
    1.43 +      coreLoopThdParams[coreIdx] = (ThdParams *)malloc( sizeof(ThdParams) );
    1.44 +      coreLoopThdParams[coreIdx]->coreNum = coreIdx;
    1.45  
    1.46 -      coreLoopThds[coreIdx] =
    1.47 -          CreateThread (   NULL, // Security attributes
    1.48 -                           0, // Stack size
    1.49 -                           coreLoop,
    1.50 -                           thdParams[coreIdx],
    1.51 -                           CREATE_SUSPENDED,
    1.52 -                           &(thdIds[coreIdx])
    1.53 -                          );
    1.54 -      ResumeThread( coreLoopThds[coreIdx] ); //starts thread
    1.55 +      coreLoopThdHandles[coreIdx] =
    1.56 +          CreateThread ( NULL, // Security attributes
    1.57 +                         0, // Stack size
    1.58 +                         coreLoop,
    1.59 +                         coreLoopThdParams[coreIdx],
    1.60 +                         CREATE_SUSPENDED,
    1.61 +                         &(coreLoopThdIds[coreIdx])
    1.62 +                        );
    1.63 +      ResumeThread( coreLoopThdHandles[coreIdx] ); //starts thread
    1.64      }
    1.65   }
    1.66  
    1.67 @@ -138,6 +141,7 @@
    1.68     char      *stackLocs, *stackPtr;
    1.69  
    1.70     newPr              = malloc( sizeof(VirtProcr) );
    1.71 +   newPr->procrID     = numProcrsCreated++;
    1.72     newPr->nextInstrPt = fnPtr;
    1.73     newPr->initialData = initialData;
    1.74  
    1.75 @@ -146,8 +150,8 @@
    1.76     stackLocs = malloc( 0x100000 ); //1 meg stack -- default Win thread's size
    1.77     stackPtr = ( (char *)stackLocs + 0x100000 - 0x8 );
    1.78        //setup __cdecl on stack -- coreloop will switch to stackPtr before jmp
    1.79 -   *(stackPtr + 4) = newPr;  //rightmost param
    1.80 -   *stackPtr = initialData;  //next  param to left
    1.81 +   *( (int *)stackPtr + 1) = (int) newPr;  //rightmost param -- 32bit pointer
    1.82 +   *( (int *)stackPtr )    = (int) initialData;  //next  param to left
    1.83     newPr->stackPtr = stackPtr; //core loop will switch to this, then
    1.84     newPr->framePtr = stackPtr; //suspend loop will save new stack & frame ptr
    1.85  
    1.86 @@ -198,7 +202,9 @@
    1.87     /* outputs */ : "=g" (stackPtr), "=g" (framePtr)
    1.88     /* inputs  */ : "g" (jmpPt)
    1.89     /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi"
    1.90 -                );
    1.91 +                ); //list everything as clobbered to force GCC to save all
    1.92 +                   // live vars that are in regs on stack before this
    1.93 +                   // assembly, so that stack pointer is correct, before jmp
    1.94  
    1.95  ResumePt:
    1.96     return;
    1.97 @@ -229,4 +235,17 @@
    1.98      {
    1.99  
   1.100      }
   1.101 - }
   1.102 \ No newline at end of file
   1.103 + }
   1.104 +
   1.105 +
   1.106 +
   1.107 +inline TSCount getTSCount()
   1.108 + { unsigned int low, high;
   1.109 +   TSCount  out;
   1.110 +
   1.111 +   saveTimeStampCountInto( low, high );
   1.112 +   out = high;
   1.113 +   out = (out << 32) + low;
   1.114 +   return out;
   1.115 + }
   1.116 +