VMS/VMS_Implementations/SSR_impls/SSR__MC_shared_impl

view SSR_PluginFns.c @ 77:833b31a8abc1

working version (w/ old hash impl)
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Tue, 28 Aug 2012 13:40:07 +0200
parents 6647aea90477
children ce07f1a42ddf
line source
1 /*
2 * Copyright 2010 OpenSourceCodeStewardshipFoundation
3 *
4 * Licensed under BSD
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
10 #include "Queue_impl/PrivateQueue.h"
11 #include "SSR.h"
12 #include "SSR_Request_Handlers.h"
14 //=========================== Local Fn Prototypes ===========================
15 void
16 resume_slaveVP( SlaveVP *procr, SSRSemEnv *semEnv );
18 void
19 handleSemReq( VMSReqst *req, SlaveVP *requestingPr, SSRSemEnv *semEnv );
21 void
22 handleDissipate( SlaveVP *requestingPr, SSRSemEnv *semEnv );
24 void
25 handleCreate( VMSReqst *req, SlaveVP *requestingPr, SSRSemEnv *semEnv );
28 //============================== Assigner ==================================
29 //
30 /*For SSR, assigning a slave simply takes the next work-unit off the
31 * ready-to-go work-unit queue and assigns it to the offered slot.
32 *If the ready-to-go work-unit queue is empty, then nothing to assign
33 * to the animation slot -- return FALSE to let Master loop know assigning
34 * that slot failed.
35 */
36 SlaveVP *
37 SSR__assign_slaveVP_to_slot( void *_semEnv, AnimSlot *slot )
38 { SlaveVP *assignPr;
39 SSRSemEnv *semEnv;
40 int32 coreNum, slotNum;
42 coreNum = slot->coreSlotIsOn;
43 slotNum = slot->slotIdx;
45 semEnv = (SSRSemEnv *)_semEnv;
47 assignPr = readPrivQ( semEnv->readyVPQs[coreNum] );
48 //Note, using a non-blocking queue -- it returns NULL if queue empty
49 #ifdef IDLE_SLAVES
50 if(!assignPr){
51 assignPr = semEnv->idlePr[coreNum][slotNum];
53 if(semEnv->shutdownInitiated) {
54 assignPr = VMS_SS__create_shutdown_slave();
55 }
56 //things that would normally happen in resume(), but these VPs never go there
57 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
58 else{
59 assignPr->assignCount++; //Somewhere here!
60 Unit newu;
61 newu.vp = assignPr->slaveID;
62 newu.task = assignPr->assignCount;
63 addToListOfArrays(Unit,newu,semEnv->unitList);
65 if (assignPr->assignCount > 1){
66 Dependency newd;
67 newd.from_vp = assignPr->slaveID;
68 newd.from_task = assignPr->assignCount - 1;
69 newd.to_vp = assignPr->slaveID;
70 newd.to_task = assignPr->assignCount;
71 addToListOfArrays(Dependency, newd ,semEnv->ctlDependenciesList);
72 }
73 }
74 #endif
75 }
76 #endif
77 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
78 if (assignPr && (assignPr->typeOfVP == Slave || assignPr->typeOfVP == Idle)) {
79 //assignPr->numTimesAssigned++;
80 Unit prev_in_slot = semEnv->last_in_slot[coreNum * NUM_ANIM_SLOTS + slotNum];
81 if(prev_in_slot.vp != 0){
82 Dependency newd;
83 newd.from_vp = prev_in_slot.vp;
84 newd.from_task = prev_in_slot.task;
85 newd.to_vp = assignPr->slaveID;
86 newd.to_task = assignPr->assignCount;
87 addToListOfArrays(Dependency,newd,semEnv->hwArcs);
88 }
89 prev_in_slot.vp = assignPr->slaveID;
90 prev_in_slot.task = assignPr->assignCount;
91 semEnv->last_in_slot[coreNum * NUM_ANIM_SLOTS + slotNum] = prev_in_slot;
92 }
93 #endif
94 return( assignPr );
95 }
98 //=========================== Request Handler =============================
99 //
100 /*Will get requests to send, to receive, and to create new processors.
101 * Upon send, check the hash to see if a receive is waiting.
102 * Upon receive, check hash to see if a send has already happened.
103 * When other is not there, put in. When other is there, the comm.
104 * completes, which means the receiver P gets assigned and
105 * picks up right after the receive request. So make the work-unit
106 * and put it into the queue of work-units ready to go.
107 * Other request is create a new Processor, with the function to run in the
108 * Processor, and initial data.
109 */
110 void
111 SSR__Request_Handler( SlaveVP *requestingPr, void *_semEnv )
112 { SSRSemEnv *semEnv;
113 VMSReqst *req;
115 semEnv = (SSRSemEnv *)_semEnv;
117 req = VMS_PI__take_next_request_out_of( requestingPr );
119 while( req != NULL )
120 {
121 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
122 semEnv->lastReqType = 0;
123 #endif
124 switch( req->reqType )
125 { case semantic: handleSemReq( req, requestingPr, semEnv);
126 break;
127 case createReq: handleCreate( req, requestingPr, semEnv);
128 break;
129 case dissipate: handleDissipate( requestingPr, semEnv);
130 break;
131 case VMSSemantic: VMS_PI__handle_VMSSemReq(req, requestingPr, semEnv,
132 (ResumeSlvFnPtr) &resume_slaveVP);
133 break;
134 default:
135 break;
136 }
138 req = VMS_PI__take_next_request_out_of( requestingPr );
139 } //while( req != NULL )
141 }
144 void
145 handleSemReq( VMSReqst *req, SlaveVP *reqPr, SSRSemEnv *semEnv )
146 { SSRSemReq *semReq;
148 semReq = VMS_PI__take_sem_reqst_from(req);
149 if( semReq == NULL ) return;
150 switch( semReq->reqType ) //sem handlers are all in other file
151 {
152 case send_type: handleSendType( semReq, semEnv);
153 break;
154 case send_from_to: handleSendFromTo( semReq, semEnv);
155 break;
156 case receive_type: handleReceiveType( semReq, semEnv);
157 break;
158 case receive_from_to: handleReceiveFromTo(semReq, semEnv);
159 break;
160 case transfer_to: handleTransferTo( semReq, semEnv);
161 break;
162 case transfer_out: handleTransferOut( semReq, semEnv);
163 break;
164 case malloc_req: handleMalloc( semReq, reqPr, semEnv);
165 break;
166 case free_req: handleFree( semReq, reqPr, semEnv);
167 break;
168 case singleton_fn_start: handleStartFnSingleton(semReq, reqPr, semEnv);
169 break;
170 case singleton_fn_end: handleEndFnSingleton( semReq, reqPr, semEnv);
171 break;
172 case singleton_data_start:handleStartDataSingleton(semReq,reqPr,semEnv);
173 break;
174 case singleton_data_end: handleEndDataSingleton(semReq, reqPr, semEnv);
175 break;
176 case atomic: handleAtomic( semReq, reqPr, semEnv);
177 break;
178 case trans_start: handleTransStart( semReq, reqPr, semEnv);
179 break;
180 case trans_end: handleTransEnd( semReq, reqPr, semEnv);
181 break;
182 }
183 }
187 //=========================== VMS Request Handlers ==============================
188 //
189 void
190 handleDissipate( SlaveVP *requestingPr, SSRSemEnv *semEnv )
191 {
192 DEBUG__printf1(dbgRqstHdlr,"Dissipate request from processor %d",requestingPr->slaveID)
193 //free any semantic data allocated to the virt procr
194 VMS_PI__free( requestingPr->semanticData );
196 //Now, call VMS to free_all AppVP state -- stack and so on
197 VMS_PI__dissipate_slaveVP( requestingPr );
199 semEnv->numSlaveVP -= 1;
200 if( semEnv->numSlaveVP == 0 )
201 { //no more work, so shutdown
202 #ifdef IDLE_SLAVES
203 semEnv->shutdownInitiated = TRUE;
204 #else
205 VMS_SS__shutdown();
206 #endif
207 }
208 }
210 /*Re-use this in the entry-point fn
211 */
212 SlaveVP *
213 SSR__create_procr_helper( TopLevelFnPtr fnPtr, void *initData,
214 SSRSemEnv *semEnv, int32 coreToAssignOnto )
215 { SlaveVP *newPr;
216 SSRSemData *semData;
218 //This is running in master, so use internal version
219 newPr = VMS_PI__create_slaveVP( fnPtr, initData );
221 semEnv->numSlaveVP += 1;
223 semData = VMS_PI__malloc( sizeof(SSRSemData) );
224 semData->highestTransEntered = -1;
225 semData->lastTransEntered = NULL;
227 newPr->semanticData = semData;
229 //=================== Assign new processor to a core =====================
230 #ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE
231 newPr->coreAnimatedBy = 0;
233 #else
235 if(coreToAssignOnto < 0 || coreToAssignOnto >= NUM_CORES )
236 { //out-of-range, so round-robin assignment
237 newPr->coreAnimatedBy = semEnv->nextCoreToGetNewPr;
239 if( semEnv->nextCoreToGetNewPr >= NUM_CORES - 1 )
240 semEnv->nextCoreToGetNewPr = 0;
241 else
242 semEnv->nextCoreToGetNewPr += 1;
243 }
244 else //core num in-range, so use it
245 { newPr->coreAnimatedBy = coreToAssignOnto;
246 }
247 #endif
248 //========================================================================
250 return newPr;
251 }
253 void
254 handleCreate( VMSReqst *req, SlaveVP *requestingPr, SSRSemEnv *semEnv )
255 { SSRSemReq *semReq;
256 SlaveVP *newPr;
259 semReq = VMS_PI__take_sem_reqst_from( req );
261 newPr = SSR__create_procr_helper( semReq->fnPtr, semReq->initData, semEnv,
262 semReq->coreToAssignOnto );
264 DEBUG__printf2(dbgRqstHdlr,"Create from: %d, new VP: %d", requestingPr->slaveID, newPr->slaveID)
266 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
267 Dependency newd;
268 newd.from_vp = requestingPr->slaveID;
269 newd.from_task = requestingPr->assignCount;
270 newd.to_vp = newPr->slaveID;
271 newd.to_task = 1;
272 addToListOfArrays(Dependency,newd,semEnv->commDependenciesList);
273 #endif
275 //For SSR, caller needs ptr to created processor returned to it
276 requestingPr->dataRetFromReq = newPr;
278 resume_slaveVP( newPr, semEnv );
279 resume_slaveVP( requestingPr, semEnv );
280 }
283 //=========================== Helper ==============================
284 void
285 resume_slaveVP( SlaveVP *procr, SSRSemEnv *semEnv )
286 {
287 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
288 /*
289 int lastRecordIdx = procr->counter_history_array_info->numInArray -1;
290 CounterRecord* lastRecord = procr->counter_history[lastRecordIdx];
291 saveLowTimeStampCountInto(lastRecord->unblocked_timestamp);
292 */
293 #endif
294 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
295 procr->assignCount++; //Somewhere here!
296 Unit newu;
297 newu.vp = procr->slaveID;
298 newu.task = procr->assignCount;
299 newu.reqType = semEnv->lastReqType;
300 if(procr->assignCount <= 1){
301 newu.ret_ptr = procr->resumeInstrPtr;
302 } else {
303 /*void* frame_ptr0 = procr->framePtr;
304 void* frame_ptr1 = *((void**)frame_ptr0);
305 void* frame_ptr2 = *((void**)frame_ptr1);
306 void* frame_ptr3 = *((void**)frame_ptr2);
307 void* ret_addr = *((void**)frame_ptr3 + 1);
308 newu.ret_ptr = ret_addr; */
309 newu.ret_ptr = procr->resumeInstrPtr;
310 }
311 addToListOfArrays(Unit,newu,semEnv->unitList);
313 if (procr->assignCount > 1){
314 Dependency newd;
315 newd.from_vp = procr->slaveID;
316 newd.from_task = procr->assignCount - 1;
317 newd.to_vp = procr->slaveID;
318 newd.to_task = procr->assignCount;
319 addToListOfArrays(Dependency, newd ,semEnv->ctlDependenciesList);
320 }
321 #endif
322 writePrivQ( procr, semEnv->readyVPQs[ procr->coreAnimatedBy] );
323 }