VMS/VMS_Implementations/VSs_impls/VSs__MC_shared_impl

changeset 5:8188c5b4bfd7

implemented taskwait
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Fri, 13 Jul 2012 17:35:49 +0200
parents 13af59ed7ea5
children 1780f6b00e3d
files VSs.c VSs.h VSs_PluginFns.c VSs_Request_Handlers.c
diffstat 4 files changed, 114 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/VSs.c	Thu Jun 14 18:44:47 2012 -0700
     1.2 +++ b/VSs.c	Fri Jul 13 17:35:49 2012 +0200
     1.3 @@ -501,6 +501,19 @@
     1.4   }
     1.5  
     1.6  
     1.7 +void
     1.8 +VSs__taskwait(SlaveVP *animSlv)
     1.9 +{
    1.10 +    VSsSemReq  reqData;
    1.11 +
    1.12 +   reqData.reqType      = taskwait;
    1.13 +   reqData.callingSlv   = animSlv;
    1.14 +   
    1.15 +   VMS_WL__send_sem_request( &reqData, animSlv );
    1.16 +}
    1.17 +
    1.18 +
    1.19 +
    1.20  //==========================  send and receive ============================
    1.21  //
    1.22  
     2.1 --- a/VSs.h	Thu Jun 14 18:44:47 2012 -0700
     2.2 +++ b/VSs.h	Fri Jul 13 17:35:49 2012 +0200
     2.3 @@ -61,7 +61,9 @@
     2.4   }
     2.5  VSsPointerEntry;
     2.6  
     2.7 -typedef struct
     2.8 +typedef struct _VSsTaskStub VSsTaskStub;
     2.9 +
    2.10 +struct _VSsTaskStub
    2.11   {
    2.12     void       **args; //ctld args must come first, as ptrs
    2.13     VSsTaskType *taskType;
    2.14 @@ -69,8 +71,20 @@
    2.15     int32        numBlockingProp;
    2.16     SlaveVP     *slaveAssignedTo;
    2.17     VSsPointerEntry  **ptrEntries;
    2.18 +   void*        parent;
    2.19 +   bool32       parentIsTask;
    2.20 +   int32        numChildTasks;
    2.21 +   bool32         isWaiting;
    2.22   }
    2.23 -VSsTaskStub;
    2.24 +;
    2.25 +
    2.26 +typedef struct {
    2.27 +    void* parent;
    2.28 +    bool32       parentIsTask;
    2.29 +    int32        numChildTasks;
    2.30 +    bool32       isWaiting;
    2.31 +   SlaveVP     *slaveAssignedTo;    
    2.32 +} VSsThreadInfo;
    2.33  
    2.34  typedef struct
    2.35   {
    2.36 @@ -123,6 +137,7 @@
    2.37     send_from_to,
    2.38     receive_from_to,
    2.39     //===============================
    2.40 +   taskwait,
    2.41     malloc_req,
    2.42     free_req,
    2.43     singleton_fn_start,
    2.44 @@ -213,12 +228,15 @@
    2.45   };
    2.46  //TransListElem
    2.47   
    2.48 + 
    2.49 + 
    2.50  typedef struct
    2.51   {
    2.52     int32          highestTransEntered;
    2.53     TransListElem *lastTransEntered;
    2.54     bool32         needsTaskAssigned;
    2.55     VSsTaskStub   *taskStub;
    2.56 +   VSsThreadInfo *threadInfo;
    2.57   }
    2.58  VSsSemData;
    2.59   
    2.60 @@ -285,6 +303,9 @@
    2.61  VSs__end_task( SlaveVP *animSlv );
    2.62  
    2.63  //=========================
    2.64 +void
    2.65 +VSs__taskwait(SlaveVP *animSlv);
    2.66 +
    2.67  
    2.68  inline int32 *
    2.69  VSs__give_self_taskID( SlaveVP *animSlv );
     3.1 --- a/VSs_PluginFns.c	Thu Jun 14 18:44:47 2012 -0700
     3.2 +++ b/VSs_PluginFns.c	Fri Jul 13 17:35:49 2012 +0200
     3.3 @@ -227,6 +227,8 @@
     3.4           break;
     3.5           
     3.6        //====================================================================
     3.7 +       case taskwait:   handleTaskwait(semReq, reqSlv, semEnv);
     3.8 +           break;
     3.9        case malloc_req:      handleMalloc(       semReq, reqSlv, semEnv);
    3.10           break;
    3.11        case free_req:        handleFree(         semReq, reqSlv, semEnv);
    3.12 @@ -282,6 +284,13 @@
    3.13     semData->lastTransEntered    = NULL;
    3.14     semData->needsTaskAssigned   = TRUE;
    3.15     
    3.16 +   semData->threadInfo = VMS_PI__malloc( sizeof(VSsThreadInfo) );
    3.17 +   semData->threadInfo->isWaiting = FALSE;
    3.18 +   semData->threadInfo->numChildTasks = 0;
    3.19 +   semData->threadInfo->parent = NULL;
    3.20 +   semData->threadInfo->parentIsTask = FALSE;
    3.21 +   semData->threadInfo->slaveAssignedTo = newSlv;
    3.22 +   
    3.23     newSlv->semanticData = semData;
    3.24  
    3.25     //=================== Assign new processor to a core =====================
    3.26 @@ -321,6 +330,8 @@
    3.27     newSlv = VSs__create_slave_helper( semReq->fnPtr, semReq->initData, semEnv,
    3.28                                       semReq->coreToAssignOnto );
    3.29     
    3.30 +   ((VSsSemData*)newSlv->semanticData)->threadInfo->parent = requestingSlv;
    3.31 +   
    3.32           DEBUG__printf2(dbgRqstHdlr,"Create from: %d, new VP: %d", requestingSlv->slaveID, newSlv->slaveID)
    3.33  
    3.34     #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
     4.1 --- a/VSs_Request_Handlers.c	Thu Jun 14 18:44:47 2012 -0700
     4.2 +++ b/VSs_Request_Handlers.c	Fri Jul 13 17:35:49 2012 +0200
     4.3 @@ -93,7 +93,8 @@
     4.4        VMS_int__malloc( taskType->numCtldArgs * sizeof(VSsPointerEntry *) );
     4.5     newArgs = (void **)( (uint8 *)newStub + sizeof(VSsTaskStub) );
     4.6     newStub->args = newArgs;
     4.7 -   
     4.8 +   newStub->numChildTasks = 0;
     4.9 +   newStub->parent = NULL;
    4.10        //Copy the arg-pointers.. can be more arguments than just the ones 
    4.11        // that StarSs uses to control ordering of task execution.
    4.12     memcpy( newArgs, args, taskType->sizeOfArgs );
    4.13 @@ -224,7 +225,7 @@
    4.14     HashTable *
    4.15     argPtrHashTbl = semEnv->argPtrHashTbl;
    4.16     
    4.17 -         DEBUG__printf1(dbgRqstHdlr,"SendType request from processor %d",semReq->callingSlv->slaveID)
    4.18 +         DEBUG__printf1(dbgRqstHdlr,"Submit request from processor %d",semReq->callingSlv->slaveID)
    4.19   
    4.20     /* ==========================  creation  ========================== 
    4.21      * 
    4.22 @@ -239,6 +240,19 @@
    4.23     taskStub = create_task_stub( taskType, args );//copies arg ptrs
    4.24     taskStub->numBlockingProp = taskType->numCtldArgs;
    4.25     taskStub->taskID = semReq->taskID; //may be NULL
    4.26 +   taskStub->numChildTasks = 0;
    4.27 +   
    4.28 +   VSsSemData* parentSemData = (VSsSemData*) semReq->callingSlv->semanticData;
    4.29 +   if(parentSemData->taskStub != NULL){ //calling is task
    4.30 +       taskStub->parentIsTask = TRUE;
    4.31 +       taskStub->parent = (void*) parentSemData->taskStub;
    4.32 +       parentSemData->taskStub->numChildTasks++;
    4.33 +   } else {
    4.34 +       taskStub->parentIsTask = FALSE;
    4.35 +       taskStub->parent = (void*) parentSemData->threadInfo;
    4.36 +       parentSemData->threadInfo->numChildTasks++;
    4.37 +   }
    4.38 +   
    4.39     
    4.40     /*The controlled arguments are then processed one by one.
    4.41      *Processing an argument means getting the hash of the pointer.  Then,
    4.42 @@ -376,7 +390,7 @@
    4.43     HashTable *
    4.44     ptrHashTbl = semEnv->argPtrHashTbl;
    4.45     
    4.46 -         DEBUG__printf1(dbgRqstHdlr,"SendType request from processor %d",semReq->callingSlv->slaveID)
    4.47 +         DEBUG__printf1(dbgRqstHdlr,"EndTask request from processor %d",semReq->callingSlv->slaveID)
    4.48   
    4.49     /* ========================== end of task ===========================
    4.50      *At the end of a task, the task-stub is sent in the request.
    4.51 @@ -387,6 +401,23 @@
    4.52     endingTaskType = endingTaskStub->taskType;
    4.53     ptrEntries     = endingTaskStub->ptrEntries; //saved in stub when create
    4.54     
    4.55 +   /* Check if parent was waiting on this task */
    4.56 +   if(endingTaskStub->parentIsTask){
    4.57 +       VSsTaskStub* parent = (VSsTaskStub*) endingTaskStub->parent;
    4.58 +       parent->numChildTasks--;
    4.59 +       if(parent->isWaiting && parent->numChildTasks == 0){
    4.60 +           parent->isWaiting = FALSE;
    4.61 +           resume_slaveVP( parent->slaveAssignedTo, semEnv );
    4.62 +       }
    4.63 +   } else {
    4.64 +       VSsThreadInfo* parent = (VSsThreadInfo*) endingTaskStub->parent;
    4.65 +       parent->numChildTasks--;
    4.66 +       if(parent->isWaiting && parent->numChildTasks == 0){
    4.67 +           parent->isWaiting = FALSE;
    4.68 +           resume_slaveVP( parent->slaveAssignedTo, semEnv );
    4.69 +       }
    4.70 +   }
    4.71 +   
    4.72     /*The task's controlled arguments are processed one by one.
    4.73      *Processing an argument means getting arg-pointer's entry.
    4.74      */
    4.75 @@ -527,7 +558,7 @@
    4.76     HashEntry  *entry;
    4.77     HashTable  *commHashTbl = semEnv->commHashTbl;
    4.78     
    4.79 -         DEBUG__printf1(dbgRqstHdlr,"SendType request from processor %d",semReq->sendPr->slaveID)
    4.80 +         DEBUG__printf1(dbgRqstHdlr,"SendType request from processor %d",semReq->senderSlv->slaveID)
    4.81   
    4.82     receiverID  = semReq->receiverID; //For "send", know both send & recv procrs
    4.83     senderSlv   = semReq->senderSlv;
    4.84 @@ -623,7 +654,7 @@
    4.85     HashEntry   *entry;
    4.86     HashTable   *commHashTbl = semEnv->commHashTbl;
    4.87  
    4.88 -         DEBUG__printf2(dbgRqstHdlr,"SendFromTo request from processor %d to %d",semReq->sendPr->slaveID,semReq->receivePr->slaveID)
    4.89 +         DEBUG__printf2(dbgRqstHdlr,"SendFromTo request from processor %d to %d",semReq->senderID,semReq->receiverID)
    4.90     
    4.91     receiverID  = semReq->receiverID; //For "send", know both send & recv procrs
    4.92     senderID    = semReq->senderID;
    4.93 @@ -699,7 +730,7 @@
    4.94     HashEntry  *entry;
    4.95     HashTable  *commHashTbl = semEnv->commHashTbl;
    4.96     
    4.97 -         DEBUG__printf1(dbgRqstHdlr,"SendType request from processor %d",semReq->sendPr->slaveID)
    4.98 +         DEBUG__printf1(dbgRqstHdlr,"SendType request to %d",semReq->receiverID)
    4.99   
   4.100     receiverID  = semReq->receiverID; //For "send", know both send & recv procrs
   4.101     receiverSlv = semReq->receiverSlv;
   4.102 @@ -781,7 +812,7 @@
   4.103     HashEntry   *entry;
   4.104     HashTable   *commHashTbl = semEnv->commHashTbl;
   4.105  
   4.106 -         DEBUG__printf2(dbgRqstHdlr,"SendFromTo request from processor %d to %d",semReq->sendPr->slaveID,semReq->receivePr->slaveID)
   4.107 +         DEBUG__printf2(dbgRqstHdlr,"SendFromTo request from %d to %d",semReq->senderID,semReq->receiverID)
   4.108     
   4.109     receiverID  = semReq->receiverID; //For "send", know both send & recv procrs
   4.110     senderID    = semReq->senderID;
   4.111 @@ -835,6 +866,35 @@
   4.112     printf("\nLang Impl Error: Should never be two waiting receives!\n");
   4.113   }
   4.114  
   4.115 +//==========================================================================
   4.116 +void
   4.117 +handleTaskwait( VSsSemReq *semReq, SlaveVP *requestingSlv, VSsSemEnv *semEnv )
   4.118 + {
   4.119 +    VSsTaskStub* requestingTaskStub;
   4.120 +    
   4.121 +    DEBUG__printf1(dbgRqstHdlr,"Taskwait request from processor %d",requestingSlv->slaveID)
   4.122 +    
   4.123 +    VSsSemData* semData = ((VSsSemData *)semReq->callingSlv->semanticData);
   4.124 +            
   4.125 +    requestingTaskStub = semData->taskStub;
   4.126 +            
   4.127 +    if(requestingTaskStub == NULL){ //calling VP is hosting a thread
   4.128 +        if(semData->threadInfo->numChildTasks == 0){ //nobody to wait for, proceed
   4.129 +            resume_slaveVP( requestingSlv,   semEnv );
   4.130 +        } else { //have to wait
   4.131 +            semData->threadInfo->isWaiting = TRUE;
   4.132 +            return;
   4.133 +        }
   4.134 +    } else { //calling VP is executing a task
   4.135 +        if(requestingTaskStub->numChildTasks == 0){
   4.136 +            resume_slaveVP( requestingSlv,   semEnv );
   4.137 +        } else { //have to wait
   4.138 +            requestingTaskStub->isWaiting = TRUE;
   4.139 +            return;
   4.140 +        }
   4.141 +    }
   4.142 +    
   4.143 +}
   4.144  
   4.145  
   4.146  //==========================================================================