rev |
line source |
seanhalle@0
|
1 /*
|
seanhalle@0
|
2 * Copyright 2010 OpenSourceCodeStewardshipFoundation
|
seanhalle@0
|
3 *
|
seanhalle@0
|
4 * Licensed under BSD
|
seanhalle@0
|
5 */
|
seanhalle@0
|
6
|
seanhalle@0
|
7 #include <stdio.h>
|
seanhalle@0
|
8 #include <stdlib.h>
|
seanhalle@0
|
9 #include <malloc.h>
|
seanhalle@0
|
10
|
seanhalle@0
|
11 #include "Queue_impl/PrivateQueue.h"
|
seanhalle@0
|
12 #include "Hash_impl/PrivateHash.h"
|
seanhalle@0
|
13
|
seanhalle@2
|
14 #include "VSs.h"
|
seanhalle@3
|
15 #include "Measurement/VSs_Counter_Recording.h"
|
seanhalle@0
|
16
|
seanhalle@0
|
17 //==========================================================================
|
seanhalle@0
|
18
|
seanhalle@0
|
19 void
|
seanhalle@2
|
20 VSs__init();
|
seanhalle@0
|
21
|
seanhalle@0
|
22 void
|
seanhalle@2
|
23 VSs__init_Helper();
|
seanhalle@0
|
24 //==========================================================================
|
seanhalle@0
|
25
|
seanhalle@0
|
26
|
seanhalle@0
|
27
|
seanhalle@0
|
28 //===========================================================================
|
seanhalle@0
|
29
|
seanhalle@0
|
30
|
seanhalle@0
|
31 /*These are the library functions *called in the application*
|
seanhalle@0
|
32 *
|
seanhalle@0
|
33 *There's a pattern for the outside sequential code to interact with the
|
seanhalle@0
|
34 * VMS_HW code.
|
seanhalle@2
|
35 *The VMS_HW system is inside a boundary.. every VSs system is in its
|
seanhalle@0
|
36 * own directory that contains the functions for each of the processor types.
|
seanhalle@0
|
37 * One of the processor types is the "seed" processor that starts the
|
seanhalle@0
|
38 * cascade of creating all the processors that do the work.
|
seanhalle@0
|
39 *So, in the directory is a file called "EntryPoint.c" that contains the
|
seanhalle@0
|
40 * function, named appropriately to the work performed, that the outside
|
seanhalle@0
|
41 * sequential code calls. This function follows a pattern:
|
seanhalle@2
|
42 *1) it calls VSs__init()
|
seanhalle@0
|
43 *2) it creates the initial data for the seed processor, which is passed
|
seanhalle@0
|
44 * in to the function
|
seanhalle@2
|
45 *3) it creates the seed VSs processor, with the data to start it with.
|
seanhalle@2
|
46 *4) it calls startVSsThenWaitUntilWorkDone
|
seanhalle@0
|
47 *5) it gets the returnValue from the transfer struc and returns that
|
seanhalle@0
|
48 * from the function
|
seanhalle@0
|
49 *
|
seanhalle@2
|
50 *For now, a new VSs system has to be created via VSs__init every
|
seanhalle@0
|
51 * time an entry point function is called -- later, might add letting the
|
seanhalle@2
|
52 * VSs system be created once, and let all the entry points just reuse
|
seanhalle@0
|
53 * it -- want to be as simple as possible now, and see by using what makes
|
seanhalle@0
|
54 * sense for later..
|
seanhalle@0
|
55 */
|
seanhalle@0
|
56
|
seanhalle@0
|
57
|
seanhalle@0
|
58
|
seanhalle@0
|
59 //===========================================================================
|
seanhalle@0
|
60
|
seanhalle@0
|
61 /*This is the "border crossing" function -- the thing that crosses from the
|
seanhalle@0
|
62 * outside world, into the VMS_HW world. It initializes and starts up the
|
seanhalle@0
|
63 * VMS system, then creates one processor from the specified function and
|
seanhalle@0
|
64 * puts it into the readyQ. From that point, that one function is resp.
|
seanhalle@0
|
65 * for creating all the other processors, that then create others, and so
|
seanhalle@0
|
66 * forth.
|
seanhalle@0
|
67 *When all the processors, including the seed, have dissipated, then this
|
seanhalle@0
|
68 * function returns. The results will have been written by side-effect via
|
seanhalle@0
|
69 * pointers read from, or written into initData.
|
seanhalle@0
|
70 *
|
seanhalle@0
|
71 *NOTE: no Threads should exist in the outside program that might touch
|
seanhalle@0
|
72 * any of the data reachable from initData passed in to here
|
seanhalle@0
|
73 */
|
seanhalle@0
|
74 void
|
seanhalle@2
|
75 VSs__create_seed_slave_and_do_work( TopLevelFnPtr fnPtr, void *initData )
|
seanhalle@6
|
76 { VSsSemEnv *semEnv;
|
seanhalle@6
|
77 SlaveVP *seedSlv;
|
seanhalle@6
|
78 VSsSemData *semData;
|
seanhalle@8
|
79 VSsTaskStub *threadTaskStub, *parentTaskStub;
|
seanhalle@0
|
80
|
seanhalle@2
|
81 VSs__init(); //normal multi-thd
|
seanhalle@0
|
82
|
seanhalle@0
|
83 semEnv = _VMSMasterEnv->semanticEnv;
|
seanhalle@0
|
84
|
seanhalle@2
|
85 //VSs starts with one processor, which is put into initial environ,
|
seanhalle@0
|
86 // and which then calls create() to create more, thereby expanding work
|
seanhalle@3
|
87 seedSlv = VSs__create_slave_helper( fnPtr, initData,
|
seanhalle@6
|
88 semEnv, semEnv->nextCoreToGetNewSlv++ );
|
seanhalle@3
|
89
|
seanhalle@8
|
90 //seed slave is a thread slave, so make a thread's task stub for it
|
seanhalle@8
|
91 // and then make another to stand for the seed's parent task. Make
|
seanhalle@8
|
92 // the parent be already ended, and have one child (the seed). This
|
seanhalle@8
|
93 // will make the dissipate handler do the right thing when the seed
|
seanhalle@8
|
94 // is dissipated.
|
seanhalle@8
|
95 threadTaskStub = create_thread_task_stub( initData );
|
seanhalle@8
|
96 parentTaskStub = create_thread_task_stub( NULL );
|
seanhalle@8
|
97 parentTaskStub->isEnded = TRUE;
|
seanhalle@8
|
98 parentTaskStub->numLiveChildThreads = 1; //so dissipate works for seed
|
nengel@11
|
99 threadTaskStub->parentTaskStub = parentTaskStub;
|
nengel@16
|
100 threadTaskStub->slaveAssignedTo = seedSlv;
|
nengel@16
|
101
|
seanhalle@6
|
102 semData = (VSsSemData *)seedSlv->semanticData;
|
seanhalle@8
|
103 //seedVP is a thread, so has a permanent task
|
seanhalle@6
|
104 semData->needsTaskAssigned = FALSE;
|
seanhalle@8
|
105 semData->taskStub = threadTaskStub;
|
nengel@13
|
106 semData->slaveType = ThreadSlv;
|
seanhalle@0
|
107
|
seanhalle@6
|
108 resume_slaveVP( seedSlv, semEnv ); //returns right away, just queues Slv
|
seanhalle@0
|
109
|
seanhalle@0
|
110 VMS_SS__start_the_work_then_wait_until_done(); //normal multi-thd
|
seanhalle@0
|
111
|
seanhalle@2
|
112 VSs__cleanup_after_shutdown();
|
seanhalle@0
|
113 }
|
seanhalle@0
|
114
|
seanhalle@0
|
115
|
seanhalle@0
|
116 int32
|
seanhalle@2
|
117 VSs__giveMinWorkUnitCycles( float32 percentOverhead )
|
seanhalle@0
|
118 {
|
seanhalle@0
|
119 return MIN_WORK_UNIT_CYCLES;
|
seanhalle@0
|
120 }
|
seanhalle@0
|
121
|
seanhalle@0
|
122 int32
|
seanhalle@2
|
123 VSs__giveIdealNumWorkUnits()
|
seanhalle@0
|
124 {
|
seanhalle@0
|
125 return NUM_ANIM_SLOTS * NUM_CORES;
|
seanhalle@0
|
126 }
|
seanhalle@0
|
127
|
seanhalle@0
|
128 int32
|
seanhalle@2
|
129 VSs__give_number_of_cores_to_schedule_onto()
|
seanhalle@0
|
130 {
|
seanhalle@0
|
131 return NUM_CORES;
|
seanhalle@0
|
132 }
|
seanhalle@0
|
133
|
seanhalle@0
|
134 /*For now, use TSC -- later, make these two macros with assembly that first
|
seanhalle@0
|
135 * saves jump point, and second jumps back several times to get reliable time
|
seanhalle@0
|
136 */
|
seanhalle@0
|
137 void
|
seanhalle@2
|
138 VSs__start_primitive()
|
seanhalle@2
|
139 { saveLowTimeStampCountInto( ((VSsSemEnv *)(_VMSMasterEnv->semanticEnv))->
|
seanhalle@0
|
140 primitiveStartTime );
|
seanhalle@0
|
141 }
|
seanhalle@0
|
142
|
seanhalle@0
|
143 /*Just quick and dirty for now -- make reliable later
|
seanhalle@0
|
144 * will want this to jump back several times -- to be sure cache is warm
|
seanhalle@0
|
145 * because don't want comm time included in calc-time measurement -- and
|
seanhalle@0
|
146 * also to throw out any "weird" values due to OS interrupt or TSC rollover
|
seanhalle@0
|
147 */
|
seanhalle@0
|
148 int32
|
seanhalle@2
|
149 VSs__end_primitive_and_give_cycles()
|
seanhalle@0
|
150 { int32 endTime, startTime;
|
seanhalle@0
|
151 //TODO: fix by repeating time-measurement
|
seanhalle@0
|
152 saveLowTimeStampCountInto( endTime );
|
seanhalle@2
|
153 startTime =((VSsSemEnv*)(_VMSMasterEnv->semanticEnv))->primitiveStartTime;
|
seanhalle@0
|
154 return (endTime - startTime);
|
seanhalle@0
|
155 }
|
seanhalle@0
|
156
|
seanhalle@0
|
157 //===========================================================================
|
seanhalle@0
|
158
|
seanhalle@2
|
159 /*Initializes all the data-structures for a VSs system -- but doesn't
|
seanhalle@0
|
160 * start it running yet!
|
seanhalle@0
|
161 *
|
seanhalle@0
|
162 *This runs in the main thread -- before VMS starts up
|
seanhalle@0
|
163 *
|
seanhalle@0
|
164 *This sets up the semantic layer over the VMS system
|
seanhalle@0
|
165 *
|
seanhalle@0
|
166 *First, calls VMS_Setup, then creates own environment, making it ready
|
seanhalle@0
|
167 * for creating the seed processor and then starting the work.
|
seanhalle@0
|
168 */
|
seanhalle@0
|
169 void
|
seanhalle@2
|
170 VSs__init()
|
seanhalle@0
|
171 {
|
seanhalle@0
|
172 VMS_SS__init();
|
seanhalle@0
|
173 //masterEnv, a global var, now is partially set up by init_VMS
|
seanhalle@0
|
174 // after this, have VMS_int__malloc and VMS_int__free available
|
seanhalle@0
|
175
|
seanhalle@2
|
176 VSs__init_Helper();
|
seanhalle@0
|
177 }
|
seanhalle@0
|
178
|
seanhalle@0
|
179
|
seanhalle@0
|
180 void idle_fn(void* data, SlaveVP *animatingSlv){
|
seanhalle@0
|
181 while(1){
|
seanhalle@0
|
182 VMS_int__suspend_slaveVP_and_send_req(animatingSlv);
|
seanhalle@0
|
183 }
|
seanhalle@0
|
184 }
|
seanhalle@0
|
185
|
seanhalle@0
|
186 void
|
seanhalle@2
|
187 VSs__init_Helper()
|
seanhalle@2
|
188 { VSsSemEnv *semanticEnv;
|
seanhalle@6
|
189 int32 i, coreNum, slotNum;
|
seanhalle@10
|
190 VSsSemData *semData;
|
seanhalle@0
|
191
|
seanhalle@0
|
192 //Hook up the semantic layer's plug-ins to the Master virt procr
|
seanhalle@2
|
193 _VMSMasterEnv->requestHandler = &VSs__Request_Handler;
|
seanhalle@2
|
194 _VMSMasterEnv->slaveAssigner = &VSs__assign_slaveVP_to_slot;
|
seanhalle@0
|
195
|
seanhalle@0
|
196 //create the semantic layer's environment (all its data) and add to
|
seanhalle@0
|
197 // the master environment
|
seanhalle@2
|
198 semanticEnv = VMS_int__malloc( sizeof( VSsSemEnv ) );
|
seanhalle@0
|
199 _VMSMasterEnv->semanticEnv = semanticEnv;
|
seanhalle@0
|
200
|
seanhalle@0
|
201 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
|
seanhalle@15
|
202 _VMSMasterEnv->counterHandler = &VSs__counter_handler;
|
seanhalle@2
|
203 VSs__init_counter_data_structs();
|
seanhalle@0
|
204 #endif
|
seanhalle@3
|
205
|
seanhalle@0
|
206 semanticEnv->shutdownInitiated = FALSE;
|
seanhalle@3
|
207 semanticEnv->coreIsDone = VMS_int__malloc( NUM_CORES * sizeof( bool32 ) );
|
seanhalle@6
|
208 //For each animation slot, there is an idle slave, and an initial
|
seanhalle@6
|
209 // slave assigned as the current-task-slave. Create them here.
|
seanhalle@10
|
210 SlaveVP *idleSlv, *slotTaskSlv;
|
seanhalle@6
|
211 for( coreNum = 0; coreNum < NUM_CORES; coreNum++ )
|
seanhalle@6
|
212 { semanticEnv->coreIsDone[coreNum] = FALSE; //use during shutdown
|
seanhalle@6
|
213
|
seanhalle@6
|
214 for( slotNum = 0; slotNum < NUM_ANIM_SLOTS; ++slotNum )
|
seanhalle@10
|
215 { idleSlv = VSs__create_slave_helper( &idle_fn, NULL, semanticEnv, 0);
|
seanhalle@6
|
216 idleSlv->coreAnimatedBy = coreNum;
|
seanhalle@9
|
217 idleSlv->animSlotAssignedTo =
|
seanhalle@9
|
218 _VMSMasterEnv->allAnimSlots[coreNum][slotNum];
|
seanhalle@6
|
219 semanticEnv->idleSlv[coreNum][slotNum] = idleSlv;
|
seanhalle@6
|
220
|
seanhalle@10
|
221 slotTaskSlv = VSs__create_slave_helper( &idle_fn, NULL, semanticEnv, 0);
|
seanhalle@10
|
222 slotTaskSlv->coreAnimatedBy = coreNum;
|
seanhalle@10
|
223 slotTaskSlv->animSlotAssignedTo =
|
seanhalle@9
|
224 _VMSMasterEnv->allAnimSlots[coreNum][slotNum];
|
seanhalle@10
|
225
|
seanhalle@10
|
226 semData = slotTaskSlv->semanticData;
|
seanhalle@10
|
227 semData->needsTaskAssigned = TRUE;
|
seanhalle@10
|
228 semData->slaveType = SlotTaskSlv;
|
seanhalle@10
|
229 semanticEnv->slotTaskSlvs[coreNum][slotNum] = slotTaskSlv;
|
seanhalle@0
|
230 }
|
seanhalle@3
|
231 }
|
seanhalle@0
|
232
|
seanhalle@6
|
233 //create the ready queues, hash tables used for matching and so forth
|
seanhalle@6
|
234 semanticEnv->slavesReadyToResumeQ = makeVMSQ();
|
seanhalle@9
|
235 semanticEnv->freeExtraTaskSlvQ = makeVMSQ();
|
seanhalle@6
|
236 semanticEnv->taskReadyQ = makeVMSQ();
|
seanhalle@0
|
237
|
seanhalle@3
|
238 semanticEnv->argPtrHashTbl = makeHashTable32( 16, &VMS_int__free );
|
seanhalle@4
|
239 semanticEnv->commHashTbl = makeHashTable32( 16, &VMS_int__free );
|
seanhalle@6
|
240
|
seanhalle@6
|
241 semanticEnv->nextCoreToGetNewSlv = 0;
|
seanhalle@6
|
242
|
nengel@18
|
243 #ifdef EXTERNAL_SCHEDULER
|
nengel@18
|
244 VSs__init_ext_scheduler();
|
nengel@18
|
245 #endif
|
seanhalle@0
|
246 //TODO: bug -- turn these arrays into dyn arrays to eliminate limit
|
seanhalle@0
|
247 //semanticEnv->singletonHasBeenExecutedFlags = makeDynArrayInfo( );
|
seanhalle@0
|
248 //semanticEnv->transactionStrucs = makeDynArrayInfo( );
|
seanhalle@0
|
249 for( i = 0; i < NUM_STRUCS_IN_SEM_ENV; i++ )
|
seanhalle@0
|
250 {
|
seanhalle@0
|
251 semanticEnv->fnSingletons[i].endInstrAddr = NULL;
|
seanhalle@0
|
252 semanticEnv->fnSingletons[i].hasBeenStarted = FALSE;
|
seanhalle@0
|
253 semanticEnv->fnSingletons[i].hasFinished = FALSE;
|
seanhalle@0
|
254 semanticEnv->fnSingletons[i].waitQ = makeVMSQ();
|
seanhalle@0
|
255 semanticEnv->transactionStrucs[i].waitingVPQ = makeVMSQ();
|
nengel@21
|
256 semanticEnv->criticalSection[i].isOccupied = FALSE;
|
nengel@21
|
257 semanticEnv->criticalSection[i].waitQ = makeVMSQ();
|
nengel@21
|
258 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
|
nengel@21
|
259 semanticEnv->criticalSection[i].previous.vp = 0;
|
nengel@21
|
260 semanticEnv->criticalSection[i].previous.task = 0;
|
nengel@21
|
261 #endif
|
seanhalle@0
|
262 }
|
seanhalle@6
|
263
|
seanhalle@8
|
264 semanticEnv->numLiveExtraTaskSlvs = 0; //must be last
|
seanhalle@15
|
265 semanticEnv->numLiveThreadSlvs = 1; //must be last, counts the seed
|
seanhalle@6
|
266
|
seanhalle@6
|
267 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
|
seanhalle@6
|
268 semanticEnv->unitList = makeListOfArrays(sizeof(Unit),128);
|
seanhalle@6
|
269 semanticEnv->ctlDependenciesList = makeListOfArrays(sizeof(Dependency),128);
|
seanhalle@6
|
270 semanticEnv->commDependenciesList = makeListOfArrays(sizeof(Dependency),128);
|
seanhalle@6
|
271 semanticEnv->dynDependenciesList = makeListOfArrays(sizeof(Dependency),128);
|
nengel@16
|
272 semanticEnv->dataDependenciesList = makeListOfArrays(sizeof(Dependency),128);
|
nengel@16
|
273 semanticEnv->singletonDependenciesList = makeListOfArrays(sizeof(Dependency),128);
|
nengel@17
|
274 semanticEnv->warDependenciesList = makeListOfArrays(sizeof(Dependency),128);
|
seanhalle@6
|
275 semanticEnv->ntonGroupsInfo = makePrivDynArrayOfSize((void***)&(semanticEnv->ntonGroups),8);
|
seanhalle@6
|
276
|
seanhalle@6
|
277 semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128);
|
seanhalle@6
|
278 memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_ANIM_SLOTS * sizeof(Unit)));
|
seanhalle@6
|
279 #endif
|
seanhalle@0
|
280 }
|
seanhalle@0
|
281
|
seanhalle@0
|
282
|
seanhalle@2
|
283 /*Frees any memory allocated by VSs__init() then calls VMS_int__shutdown
|
seanhalle@0
|
284 */
|
seanhalle@0
|
285 void
|
seanhalle@2
|
286 VSs__cleanup_after_shutdown()
|
seanhalle@2
|
287 { VSsSemEnv *semanticEnv;
|
seanhalle@0
|
288
|
seanhalle@0
|
289 semanticEnv = _VMSMasterEnv->semanticEnv;
|
nengel@20
|
290
|
nengel@20
|
291 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
|
seanhalle@0
|
292 FILE* output;
|
seanhalle@0
|
293 int n;
|
nengel@20
|
294 char filename[255];
|
nengel@18
|
295 //UCC
|
seanhalle@0
|
296 for(n=0;n<255;n++)
|
seanhalle@0
|
297 {
|
seanhalle@0
|
298 sprintf(filename, "./counters/UCC.%d",n);
|
seanhalle@0
|
299 output = fopen(filename,"r");
|
seanhalle@0
|
300 if(output)
|
seanhalle@0
|
301 {
|
seanhalle@0
|
302 fclose(output);
|
seanhalle@0
|
303 }else{
|
seanhalle@0
|
304 break;
|
seanhalle@0
|
305 }
|
seanhalle@0
|
306 }
|
seanhalle@0
|
307 if(n<255){
|
seanhalle@0
|
308 printf("Saving UCC to File: %s ...\n", filename);
|
seanhalle@0
|
309 output = fopen(filename,"w+");
|
seanhalle@0
|
310 if(output!=NULL){
|
seanhalle@0
|
311 set_dependency_file(output);
|
seanhalle@0
|
312 //fprintf(output,"digraph Dependencies {\n");
|
seanhalle@0
|
313 //set_dot_file(output);
|
seanhalle@0
|
314 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
|
seanhalle@0
|
315 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
|
seanhalle@0
|
316 forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file);
|
seanhalle@0
|
317 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
|
seanhalle@0
|
318 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
|
nengel@16
|
319 forAllInListOfArraysDo( semanticEnv->dataDependenciesList, &print_data_dependency_to_file );
|
nengel@16
|
320 forAllInListOfArraysDo( semanticEnv->singletonDependenciesList, &print_singleton_dependency_to_file );
|
nengel@17
|
321 forAllInListOfArraysDo( semanticEnv->warDependenciesList, &print_war_dependency_to_file );
|
seanhalle@0
|
322 forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file);
|
seanhalle@0
|
323 //fprintf(output,"}\n");
|
seanhalle@0
|
324 fflush(output);
|
seanhalle@0
|
325
|
seanhalle@0
|
326 } else
|
seanhalle@0
|
327 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
|
seanhalle@0
|
328 } else {
|
seanhalle@0
|
329 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
|
seanhalle@0
|
330 }
|
seanhalle@0
|
331 //Loop Graph
|
seanhalle@0
|
332 for(n=0;n<255;n++)
|
seanhalle@0
|
333 {
|
seanhalle@0
|
334 sprintf(filename, "./counters/LoopGraph.%d",n);
|
seanhalle@0
|
335 output = fopen(filename,"r");
|
seanhalle@0
|
336 if(output)
|
seanhalle@0
|
337 {
|
seanhalle@0
|
338 fclose(output);
|
seanhalle@0
|
339 }else{
|
seanhalle@0
|
340 break;
|
seanhalle@0
|
341 }
|
seanhalle@0
|
342 }
|
seanhalle@0
|
343 if(n<255){
|
seanhalle@0
|
344 printf("Saving LoopGraph to File: %s ...\n", filename);
|
seanhalle@0
|
345 output = fopen(filename,"w+");
|
seanhalle@0
|
346 if(output!=NULL){
|
seanhalle@0
|
347 set_dependency_file(output);
|
seanhalle@0
|
348 //fprintf(output,"digraph Dependencies {\n");
|
seanhalle@0
|
349 //set_dot_file(output);
|
seanhalle@0
|
350 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
|
seanhalle@0
|
351 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
|
seanhalle@0
|
352 forAllInListOfArraysDo( semanticEnv->unitList, &print_unit_to_file );
|
seanhalle@0
|
353 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
|
seanhalle@0
|
354 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
|
nengel@16
|
355 forAllInListOfArraysDo( semanticEnv->dataDependenciesList, &print_data_dependency_to_file );
|
nengel@16
|
356 forAllInListOfArraysDo( semanticEnv->singletonDependenciesList, &print_singleton_dependency_to_file );
|
seanhalle@0
|
357 forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_dependency_to_file );
|
nengel@17
|
358 forAllInListOfArraysDo( semanticEnv->warDependenciesList, &print_war_dependency_to_file );
|
seanhalle@0
|
359 forAllInListOfArraysDo( semanticEnv->hwArcs, &print_hw_dependency_to_file );
|
seanhalle@0
|
360 //fprintf(output,"}\n");
|
seanhalle@0
|
361 fflush(output);
|
seanhalle@0
|
362
|
seanhalle@0
|
363 } else
|
seanhalle@0
|
364 printf("Opening LoopGraph file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
|
seanhalle@0
|
365 } else {
|
seanhalle@0
|
366 printf("Could not open LoopGraph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
|
seanhalle@0
|
367 }
|
seanhalle@0
|
368
|
seanhalle@0
|
369
|
seanhalle@0
|
370 freeListOfArrays(semanticEnv->unitList);
|
seanhalle@0
|
371 freeListOfArrays(semanticEnv->commDependenciesList);
|
seanhalle@0
|
372 freeListOfArrays(semanticEnv->ctlDependenciesList);
|
seanhalle@0
|
373 freeListOfArrays(semanticEnv->dynDependenciesList);
|
nengel@16
|
374 freeListOfArrays(semanticEnv->dataDependenciesList);
|
nengel@17
|
375 freeListOfArrays(semanticEnv->warDependenciesList);
|
nengel@17
|
376 freeListOfArrays(semanticEnv->singletonDependenciesList);
|
nengel@17
|
377 freeListOfArrays(semanticEnv->hwArcs);
|
seanhalle@0
|
378
|
seanhalle@0
|
379 #endif
|
nengel@20
|
380 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
|
nengel@20
|
381 FILE* output2;
|
nengel@20
|
382 int n2;
|
nengel@20
|
383 char filename2[255];
|
nengel@20
|
384 for(n2=0;n2<255;n2++)
|
seanhalle@0
|
385 {
|
nengel@20
|
386 sprintf(filename2, "./counters/Counters.%d.csv",n2);
|
nengel@20
|
387 output2 = fopen(filename2,"r");
|
nengel@20
|
388 if(output2)
|
seanhalle@0
|
389 {
|
nengel@20
|
390 fclose(output2);
|
seanhalle@0
|
391 }else{
|
seanhalle@0
|
392 break;
|
seanhalle@0
|
393 }
|
seanhalle@0
|
394 }
|
nengel@20
|
395 if(n2<255){
|
nengel@20
|
396 printf("Saving Counter measurements to File: %s ...\n", filename2);
|
nengel@20
|
397 output2 = fopen(filename2,"w+");
|
nengel@20
|
398 if(output2!=NULL){
|
nengel@20
|
399 set_counter_file(output2);
|
seanhalle@0
|
400 int i;
|
seanhalle@0
|
401 for(i=0;i<NUM_CORES;i++){
|
seanhalle@0
|
402 forAllInListOfArraysDo( semanticEnv->counterList[i], &print_counter_events_to_file );
|
nengel@20
|
403 fflush(output2);
|
seanhalle@0
|
404 }
|
seanhalle@0
|
405
|
seanhalle@0
|
406 } else
|
seanhalle@0
|
407 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
|
seanhalle@0
|
408 } else {
|
seanhalle@0
|
409 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
|
seanhalle@0
|
410 }
|
seanhalle@0
|
411
|
seanhalle@0
|
412 #endif
|
seanhalle@0
|
413 /* It's all allocated inside VMS's big chunk -- that's about to be freed, so
|
seanhalle@0
|
414 * nothing to do here
|
seanhalle@0
|
415
|
seanhalle@0
|
416
|
seanhalle@0
|
417 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
|
seanhalle@0
|
418 {
|
seanhalle@0
|
419 VMS_int__free( semanticEnv->readyVPQs[coreIdx]->startOfData );
|
seanhalle@0
|
420 VMS_int__free( semanticEnv->readyVPQs[coreIdx] );
|
seanhalle@0
|
421 }
|
seanhalle@0
|
422 VMS_int__free( semanticEnv->readyVPQs );
|
seanhalle@0
|
423
|
seanhalle@0
|
424 freeHashTable( semanticEnv->commHashTbl );
|
seanhalle@0
|
425 VMS_int__free( _VMSMasterEnv->semanticEnv );
|
seanhalle@0
|
426 */
|
seanhalle@0
|
427 VMS_SS__cleanup_at_end_of_shutdown();
|
seanhalle@0
|
428 }
|
seanhalle@0
|
429
|
seanhalle@0
|
430
|
seanhalle@0
|
431 //===========================================================================
|
seanhalle@0
|
432
|
seanhalle@2
|
433 SlaveVP *
|
seanhalle@7
|
434 VSs__create_thread( TopLevelFnPtr fnPtr, void *initData,
|
seanhalle@7
|
435 SlaveVP *creatingThd )
|
seanhalle@2
|
436 { VSsSemReq reqData;
|
seanhalle@0
|
437
|
seanhalle@0
|
438 //the semantic request data is on the stack and disappears when this
|
seanhalle@0
|
439 // call returns -- it's guaranteed to remain in the VP's stack for as
|
seanhalle@0
|
440 // long as the VP is suspended.
|
seanhalle@0
|
441 reqData.reqType = 0; //know type because in a VMS create req
|
seanhalle@0
|
442 reqData.fnPtr = fnPtr;
|
seanhalle@0
|
443 reqData.initData = initData;
|
seanhalle@7
|
444 reqData.callingSlv = creatingThd;
|
seanhalle@0
|
445
|
seanhalle@7
|
446 VMS_WL__send_create_slaveVP_req( &reqData, creatingThd );
|
seanhalle@0
|
447
|
seanhalle@7
|
448 return creatingThd->dataRetFromReq;
|
seanhalle@0
|
449 }
|
seanhalle@0
|
450
|
seanhalle@10
|
451 /*This is always the last thing done in the code animated by a thread VP.
|
seanhalle@7
|
452 * Normally, this would be the last line of the thread's top level function.
|
seanhalle@7
|
453 * But, if the thread exits from any point, it has to do so by calling
|
seanhalle@7
|
454 * this.
|
seanhalle@10
|
455 *
|
seanhalle@10
|
456 *It simply sends a dissipate request, which handles all the state cleanup.
|
seanhalle@7
|
457 */
|
seanhalle@2
|
458 void
|
seanhalle@7
|
459 VSs__end_thread( SlaveVP *thdToEnd )
|
nengel@20
|
460 {
|
seanhalle@8
|
461
|
seanhalle@7
|
462 VMS_WL__send_dissipate_req( thdToEnd );
|
seanhalle@0
|
463 }
|
seanhalle@0
|
464
|
seanhalle@0
|
465
|
seanhalle@10
|
466
|
seanhalle@0
|
467 //===========================================================================
|
seanhalle@0
|
468
|
seanhalle@0
|
469
|
seanhalle@4
|
470 //======================= task submit and end ==============================
|
seanhalle@4
|
471 /*
|
seanhalle@2
|
472 */
|
seanhalle@4
|
473 void
|
seanhalle@2
|
474 VSs__submit_task( VSsTaskType *taskType, void *args, SlaveVP *animSlv)
|
seanhalle@2
|
475 { VSsSemReq reqData;
|
seanhalle@0
|
476
|
seanhalle@2
|
477 reqData.reqType = submit_task;
|
seanhalle@4
|
478
|
seanhalle@2
|
479 reqData.taskType = taskType;
|
seanhalle@2
|
480 reqData.args = args;
|
seanhalle@4
|
481 reqData.callingSlv = animSlv;
|
seanhalle@2
|
482
|
seanhalle@4
|
483 reqData.taskID = NULL;
|
seanhalle@2
|
484
|
seanhalle@2
|
485 VMS_WL__send_sem_request( &reqData, animSlv );
|
seanhalle@0
|
486 }
|
seanhalle@0
|
487
|
nengel@20
|
488 int32 *
|
seanhalle@4
|
489 VSs__create_taskID_of_size( int32 numInts, SlaveVP *animSlv )
|
seanhalle@4
|
490 { int32 *taskID;
|
seanhalle@4
|
491
|
seanhalle@4
|
492 taskID = VMS_WL__malloc( sizeof(int32) + numInts * sizeof(int32) );
|
seanhalle@4
|
493 taskID[0] = numInts;
|
seanhalle@4
|
494 return taskID;
|
seanhalle@4
|
495 }
|
seanhalle@4
|
496
|
seanhalle@4
|
497 void
|
seanhalle@4
|
498 VSs__submit_task_with_ID( VSsTaskType *taskType, void *args, int32 *taskID,
|
seanhalle@4
|
499 SlaveVP *animSlv)
|
seanhalle@4
|
500 { VSsSemReq reqData;
|
seanhalle@4
|
501
|
seanhalle@4
|
502 reqData.reqType = submit_task;
|
seanhalle@4
|
503
|
seanhalle@4
|
504 reqData.taskType = taskType;
|
seanhalle@4
|
505 reqData.args = args;
|
seanhalle@4
|
506 reqData.taskID = taskID;
|
seanhalle@4
|
507 reqData.callingSlv = animSlv;
|
seanhalle@4
|
508
|
seanhalle@4
|
509 VMS_WL__send_sem_request( &reqData, animSlv );
|
seanhalle@4
|
510 }
|
seanhalle@4
|
511
|
seanhalle@4
|
512
|
seanhalle@4
|
513 /*This call is the last to happen in every task. It causes the slave to
|
seanhalle@2
|
514 * suspend and get the next task out of the task-queue. Notice there is no
|
seanhalle@2
|
515 * assigner here.. only one slave, no slave ReadyQ, and so on..
|
seanhalle@2
|
516 *Can either make the assigner take the next task out of the taskQ, or can
|
seanhalle@2
|
517 * leave all as it is, and make task-end take the next task.
|
seanhalle@2
|
518 *Note: this fits the case in the new VMS for no-context tasks, so will use
|
seanhalle@2
|
519 * the built-in taskQ of new VMS, and should be local and much faster.
|
seanhalle@2
|
520 *
|
seanhalle@2
|
521 *The task-stub is saved in the animSlv, so the request handler will get it
|
seanhalle@2
|
522 * from there, along with the task-type which has arg types, and so on..
|
seanhalle@4
|
523 *
|
seanhalle@4
|
524 * NOTE: if want, don't need to send the animating SlaveVP around..
|
seanhalle@4
|
525 * instead, can make a single slave per core, and coreCtrlr looks up the
|
seanhalle@4
|
526 * slave from having the core number.
|
seanhalle@4
|
527 *
|
seanhalle@4
|
528 *But, to stay compatible with all the other VMS languages, leave it in..
|
seanhalle@0
|
529 */
|
seanhalle@0
|
530 void
|
seanhalle@2
|
531 VSs__end_task( SlaveVP *animSlv )
|
seanhalle@2
|
532 { VSsSemReq reqData;
|
seanhalle@0
|
533
|
seanhalle@2
|
534 reqData.reqType = end_task;
|
seanhalle@2
|
535 reqData.callingSlv = animSlv;
|
seanhalle@2
|
536
|
seanhalle@2
|
537 VMS_WL__send_sem_request( &reqData, animSlv );
|
seanhalle@0
|
538 }
|
seanhalle@0
|
539
|
seanhalle@4
|
540
|
nengel@5
|
541 void
|
nengel@5
|
542 VSs__taskwait(SlaveVP *animSlv)
|
nengel@5
|
543 {
|
nengel@5
|
544 VSsSemReq reqData;
|
nengel@5
|
545
|
nengel@5
|
546 reqData.reqType = taskwait;
|
nengel@5
|
547 reqData.callingSlv = animSlv;
|
nengel@5
|
548
|
nengel@5
|
549 VMS_WL__send_sem_request( &reqData, animSlv );
|
nengel@5
|
550 }
|
nengel@5
|
551
|
nengel@21
|
552 void
|
nengel@21
|
553 VSs__taskwait_on(SlaveVP *animSlv,void* ptr){
|
nengel@21
|
554 VSsSemReq reqData;
|
nengel@5
|
555
|
nengel@21
|
556 reqData.reqType = taskwait_on;
|
nengel@21
|
557 reqData.callingSlv = animSlv;
|
nengel@21
|
558
|
nengel@21
|
559 reqData.args = ptr;
|
nengel@21
|
560
|
nengel@21
|
561 VMS_WL__send_sem_request( &reqData, animSlv );
|
nengel@21
|
562 }
|
nengel@21
|
563
|
nengel@21
|
564 void
|
nengel@21
|
565 VSs__start_critical(SlaveVP *animSlv,int32 name){
|
nengel@21
|
566 VSsSemReq reqData;
|
nengel@21
|
567
|
nengel@21
|
568 reqData.reqType = critical_start;
|
nengel@21
|
569 reqData.callingSlv = animSlv;
|
nengel@21
|
570
|
nengel@21
|
571 reqData.criticalID = name;
|
nengel@21
|
572
|
nengel@21
|
573 VMS_WL__send_sem_request( &reqData, animSlv );
|
nengel@21
|
574 }
|
nengel@21
|
575
|
nengel@21
|
576 void
|
nengel@21
|
577 VSs__end_critical(SlaveVP *animSlv,int32 name){
|
nengel@21
|
578 VSsSemReq reqData;
|
nengel@21
|
579
|
nengel@21
|
580 reqData.reqType = critical_end;
|
nengel@21
|
581 reqData.callingSlv = animSlv;
|
nengel@21
|
582
|
nengel@21
|
583 reqData.criticalID = name;
|
nengel@21
|
584
|
nengel@21
|
585 VMS_WL__send_sem_request( &reqData, animSlv );
|
nengel@21
|
586 }
|
nengel@5
|
587
|
seanhalle@4
|
588 //========================== send and receive ============================
|
seanhalle@4
|
589 //
|
seanhalle@4
|
590
|
nengel@20
|
591 int32 *
|
seanhalle@4
|
592 VSs__give_self_taskID( SlaveVP *animSlv )
|
seanhalle@4
|
593 {
|
seanhalle@4
|
594 return ((VSsSemData*)animSlv->semanticData)->taskStub->taskID;
|
seanhalle@4
|
595 }
|
seanhalle@4
|
596
|
seanhalle@4
|
597 //================================ send ===================================
|
seanhalle@4
|
598
|
seanhalle@4
|
599 void
|
seanhalle@4
|
600 VSs__send_of_type_to( void *msg, const int32 type, int32 *receiverID,
|
seanhalle@4
|
601 SlaveVP *senderSlv )
|
seanhalle@4
|
602 { VSsSemReq reqData;
|
seanhalle@4
|
603
|
seanhalle@4
|
604 reqData.reqType = send_type_to;
|
seanhalle@4
|
605
|
seanhalle@4
|
606 reqData.msg = msg;
|
seanhalle@4
|
607 reqData.msgType = type;
|
seanhalle@4
|
608 reqData.receiverID = receiverID;
|
seanhalle@4
|
609 reqData.senderSlv = senderSlv;
|
seanhalle@4
|
610
|
seanhalle@4
|
611 reqData.nextReqInHashEntry = NULL;
|
seanhalle@4
|
612
|
seanhalle@4
|
613 VMS_WL__send_sem_request( &reqData, senderSlv );
|
seanhalle@4
|
614
|
seanhalle@4
|
615 //When come back from suspend, no longer own data reachable from msg
|
seanhalle@4
|
616 }
|
seanhalle@4
|
617
|
seanhalle@4
|
618 void
|
seanhalle@4
|
619 VSs__send_from_to( void *msg, int32 *senderID, int32 *receiverID, SlaveVP *senderSlv )
|
seanhalle@4
|
620 { VSsSemReq reqData;
|
seanhalle@4
|
621
|
seanhalle@4
|
622 reqData.reqType = send_from_to;
|
seanhalle@4
|
623
|
seanhalle@4
|
624 reqData.msg = msg;
|
seanhalle@4
|
625 reqData.senderID = senderID;
|
seanhalle@4
|
626 reqData.receiverID = receiverID;
|
seanhalle@4
|
627 reqData.senderSlv = senderSlv;
|
seanhalle@4
|
628
|
seanhalle@4
|
629 reqData.nextReqInHashEntry = NULL;
|
seanhalle@4
|
630
|
seanhalle@4
|
631 VMS_WL__send_sem_request( &reqData, senderSlv );
|
seanhalle@4
|
632 }
|
seanhalle@4
|
633
|
seanhalle@4
|
634
|
seanhalle@4
|
635 //================================ receive ================================
|
seanhalle@4
|
636
|
seanhalle@4
|
637 /*The "type" version of send and receive creates a many-to-one relationship.
|
seanhalle@4
|
638 * The sender is anonymous, and many sends can stack up, waiting to be
|
seanhalle@4
|
639 * received. The same receiver can also have send from-to's
|
seanhalle@4
|
640 * waiting for it, and those will be kept separate from the "type"
|
seanhalle@4
|
641 * messages.
|
seanhalle@4
|
642 */
|
seanhalle@4
|
643 void *
|
seanhalle@4
|
644 VSs__receive_type_to( const int32 type, int32* receiverID, SlaveVP *receiverSlv )
|
seanhalle@4
|
645 { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to %d",receiverID[1] );
|
seanhalle@4
|
646 VSsSemReq reqData;
|
seanhalle@4
|
647
|
seanhalle@4
|
648 reqData.reqType = receive_type_to;
|
seanhalle@4
|
649
|
seanhalle@4
|
650 reqData.msgType = type;
|
seanhalle@4
|
651 reqData.receiverID = receiverID;
|
seanhalle@4
|
652 reqData.receiverSlv = receiverSlv;
|
seanhalle@4
|
653
|
seanhalle@4
|
654 reqData.nextReqInHashEntry = NULL;
|
seanhalle@4
|
655
|
seanhalle@4
|
656 VMS_WL__send_sem_request( &reqData, receiverSlv );
|
seanhalle@4
|
657
|
seanhalle@4
|
658 return receiverSlv->dataRetFromReq;
|
seanhalle@4
|
659 }
|
seanhalle@4
|
660
|
seanhalle@4
|
661
|
seanhalle@4
|
662
|
seanhalle@4
|
663 /*Call this at the point a receiving task wants in-coming data.
|
seanhalle@4
|
664 * Use this from-to form when know senderID -- it makes a direct channel
|
seanhalle@4
|
665 * between sender and receiver.
|
seanhalle@4
|
666 */
|
seanhalle@4
|
667 void *
|
seanhalle@4
|
668 VSs__receive_from_to( int32 *senderID, int32 *receiverID, SlaveVP *receiverSlv )
|
seanhalle@4
|
669 {
|
seanhalle@4
|
670 VSsSemReq reqData;
|
seanhalle@4
|
671
|
seanhalle@4
|
672 reqData.reqType = receive_from_to;
|
seanhalle@4
|
673
|
seanhalle@4
|
674 reqData.senderID = senderID;
|
seanhalle@4
|
675 reqData.receiverID = receiverID;
|
seanhalle@4
|
676 reqData.receiverSlv = receiverSlv;
|
seanhalle@4
|
677
|
seanhalle@4
|
678 reqData.nextReqInHashEntry = NULL;
|
seanhalle@4
|
679 DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", reqData.senderID[1], reqData.receiverID[1]);
|
seanhalle@4
|
680
|
seanhalle@4
|
681 VMS_WL__send_sem_request( &reqData, receiverSlv );
|
seanhalle@4
|
682
|
seanhalle@4
|
683 return receiverSlv->dataRetFromReq;
|
seanhalle@4
|
684 }
|
seanhalle@4
|
685
|
seanhalle@4
|
686
|
seanhalle@4
|
687
|
seanhalle@4
|
688
|
seanhalle@2
|
689 //==========================================================================
|
seanhalle@0
|
690 //
|
seanhalle@0
|
691 /*A function singleton is a function whose body executes exactly once, on a
|
seanhalle@0
|
692 * single core, no matter how many times the fuction is called and no
|
seanhalle@0
|
693 * matter how many cores or the timing of cores calling it.
|
seanhalle@0
|
694 *
|
seanhalle@0
|
695 *A data singleton is a ticket attached to data. That ticket can be used
|
seanhalle@0
|
696 * to get the data through the function exactly once, no matter how many
|
seanhalle@0
|
697 * times the data is given to the function, and no matter the timing of
|
seanhalle@0
|
698 * trying to get the data through from different cores.
|
seanhalle@0
|
699 */
|
seanhalle@0
|
700
|
seanhalle@0
|
701 /*asm function declarations*/
|
seanhalle@2
|
702 void asm_save_ret_to_singleton(VSsSingleton *singletonPtrAddr);
|
seanhalle@2
|
703 void asm_write_ret_from_singleton(VSsSingleton *singletonPtrAddr);
|
seanhalle@0
|
704
|
seanhalle@0
|
705 /*Fn singleton uses ID as index into array of singleton structs held in the
|
seanhalle@0
|
706 * semantic environment.
|
seanhalle@0
|
707 */
|
seanhalle@0
|
708 void
|
seanhalle@3
|
709 VSs__start_fn_singleton( int32 singletonID, SlaveVP *animSlv )
|
seanhalle@0
|
710 {
|
seanhalle@2
|
711 VSsSemReq reqData;
|
seanhalle@0
|
712
|
seanhalle@0
|
713 //
|
seanhalle@0
|
714 reqData.reqType = singleton_fn_start;
|
seanhalle@0
|
715 reqData.singletonID = singletonID;
|
seanhalle@0
|
716
|
seanhalle@3
|
717 VMS_WL__send_sem_request( &reqData, animSlv );
|
seanhalle@3
|
718 if( animSlv->dataRetFromReq ) //will be 0 or addr of label in end singleton
|
seanhalle@0
|
719 {
|
seanhalle@3
|
720 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv );
|
seanhalle@0
|
721 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
|
seanhalle@0
|
722 }
|
seanhalle@0
|
723 }
|
seanhalle@0
|
724
|
seanhalle@0
|
725 /*Data singleton hands addr of loc holding a pointer to a singleton struct.
|
seanhalle@0
|
726 * The start_data_singleton makes the structure and puts its addr into the
|
seanhalle@0
|
727 * location.
|
seanhalle@0
|
728 */
|
seanhalle@0
|
729 void
|
seanhalle@3
|
730 VSs__start_data_singleton( VSsSingleton **singletonAddr, SlaveVP *animSlv )
|
seanhalle@0
|
731 {
|
seanhalle@2
|
732 VSsSemReq reqData;
|
seanhalle@0
|
733
|
seanhalle@0
|
734 if( *singletonAddr && (*singletonAddr)->hasFinished )
|
seanhalle@0
|
735 goto JmpToEndSingleton;
|
seanhalle@0
|
736
|
seanhalle@0
|
737 reqData.reqType = singleton_data_start;
|
seanhalle@0
|
738 reqData.singletonPtrAddr = singletonAddr;
|
seanhalle@0
|
739
|
seanhalle@3
|
740 VMS_WL__send_sem_request( &reqData, animSlv );
|
seanhalle@3
|
741 if( animSlv->dataRetFromReq ) //either 0 or end singleton's return addr
|
seanhalle@0
|
742 { //Assembly code changes the return addr on the stack to the one
|
seanhalle@0
|
743 // saved into the singleton by the end-singleton-fn
|
seanhalle@0
|
744 //The return addr is at 0x4(%%ebp)
|
seanhalle@0
|
745 JmpToEndSingleton:
|
seanhalle@0
|
746 asm_write_ret_from_singleton(*singletonAddr);
|
seanhalle@0
|
747 }
|
seanhalle@0
|
748 //now, simply return
|
seanhalle@0
|
749 //will exit either from the start singleton call or the end-singleton call
|
seanhalle@0
|
750 }
|
seanhalle@0
|
751
|
seanhalle@0
|
752 /*Uses ID as index into array of flags. If flag already set, resumes from
|
seanhalle@0
|
753 * end-label. Else, sets flag and resumes normally.
|
seanhalle@0
|
754 *
|
seanhalle@0
|
755 *Note, this call cannot be inlined because the instr addr at the label
|
seanhalle@0
|
756 * inside is shared by all invocations of a given singleton ID.
|
seanhalle@0
|
757 */
|
seanhalle@0
|
758 void
|
seanhalle@3
|
759 VSs__end_fn_singleton( int32 singletonID, SlaveVP *animSlv )
|
seanhalle@0
|
760 {
|
seanhalle@2
|
761 VSsSemReq reqData;
|
seanhalle@0
|
762
|
seanhalle@0
|
763 //don't need this addr until after at least one singleton has reached
|
seanhalle@0
|
764 // this function
|
seanhalle@3
|
765 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv );
|
seanhalle@0
|
766 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
|
seanhalle@0
|
767
|
seanhalle@0
|
768 reqData.reqType = singleton_fn_end;
|
seanhalle@0
|
769 reqData.singletonID = singletonID;
|
seanhalle@0
|
770
|
seanhalle@3
|
771 VMS_WL__send_sem_request( &reqData, animSlv );
|
seanhalle@0
|
772
|
nengel@20
|
773 //EndSingletonInstrAddr:
|
seanhalle@0
|
774 return;
|
seanhalle@0
|
775 }
|
seanhalle@0
|
776
|
seanhalle@0
|
777 void
|
seanhalle@3
|
778 VSs__end_data_singleton( VSsSingleton **singletonPtrAddr, SlaveVP *animSlv )
|
seanhalle@0
|
779 {
|
seanhalle@2
|
780 VSsSemReq reqData;
|
seanhalle@0
|
781
|
seanhalle@0
|
782 //don't need this addr until after singleton struct has reached
|
seanhalle@0
|
783 // this function for first time
|
seanhalle@0
|
784 //do assembly that saves the return addr of this fn call into the
|
seanhalle@0
|
785 // data singleton -- that data-singleton can only be given to exactly
|
seanhalle@0
|
786 // one instance in the code of this function. However, can use this
|
seanhalle@0
|
787 // function in different places for different data-singletons.
|
seanhalle@0
|
788 // (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr;
|
seanhalle@0
|
789
|
seanhalle@0
|
790
|
seanhalle@0
|
791 asm_save_ret_to_singleton(*singletonPtrAddr);
|
seanhalle@0
|
792
|
seanhalle@0
|
793 reqData.reqType = singleton_data_end;
|
seanhalle@0
|
794 reqData.singletonPtrAddr = singletonPtrAddr;
|
seanhalle@0
|
795
|
seanhalle@3
|
796 VMS_WL__send_sem_request( &reqData, animSlv );
|
seanhalle@0
|
797 }
|
seanhalle@0
|
798
|
seanhalle@0
|
799 /*This executes the function in the masterVP, so it executes in isolation
|
seanhalle@0
|
800 * from any other copies -- only one copy of the function can ever execute
|
seanhalle@0
|
801 * at a time.
|
seanhalle@0
|
802 *
|
seanhalle@0
|
803 *It suspends to the master, and the request handler takes the function
|
seanhalle@0
|
804 * pointer out of the request and calls it, then resumes the VP.
|
seanhalle@0
|
805 *Only very short functions should be called this way -- for longer-running
|
seanhalle@0
|
806 * isolation, use transaction-start and transaction-end, which run the code
|
seanhalle@0
|
807 * between as work-code.
|
seanhalle@0
|
808 */
|
seanhalle@0
|
809 void
|
seanhalle@2
|
810 VSs__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
|
seanhalle@3
|
811 void *data, SlaveVP *animSlv )
|
seanhalle@0
|
812 {
|
seanhalle@2
|
813 VSsSemReq reqData;
|
seanhalle@0
|
814
|
seanhalle@0
|
815 //
|
seanhalle@0
|
816 reqData.reqType = atomic;
|
seanhalle@0
|
817 reqData.fnToExecInMaster = ptrToFnToExecInMaster;
|
seanhalle@0
|
818 reqData.dataForFn = data;
|
seanhalle@0
|
819
|
seanhalle@3
|
820 VMS_WL__send_sem_request( &reqData, animSlv );
|
seanhalle@0
|
821 }
|
seanhalle@0
|
822
|
seanhalle@0
|
823
|
seanhalle@0
|
824 /*This suspends to the master.
|
seanhalle@0
|
825 *First, it looks at the VP's data, to see the highest transactionID that VP
|
seanhalle@0
|
826 * already has entered. If the current ID is not larger, it throws an
|
seanhalle@0
|
827 * exception stating a bug in the code. Otherwise it puts the current ID
|
seanhalle@0
|
828 * there, and adds the ID to a linked list of IDs entered -- the list is
|
seanhalle@0
|
829 * used to check that exits are properly ordered.
|
seanhalle@0
|
830 *Next it is uses transactionID as index into an array of transaction
|
seanhalle@0
|
831 * structures.
|
seanhalle@0
|
832 *If the "VP_currently_executing" field is non-null, then put requesting VP
|
seanhalle@0
|
833 * into queue in the struct. (At some point a holder will request
|
seanhalle@0
|
834 * end-transaction, which will take this VP from the queue and resume it.)
|
seanhalle@0
|
835 *If NULL, then write requesting into the field and resume.
|
seanhalle@0
|
836 */
|
seanhalle@0
|
837 void
|
seanhalle@3
|
838 VSs__start_transaction( int32 transactionID, SlaveVP *animSlv )
|
seanhalle@0
|
839 {
|
seanhalle@2
|
840 VSsSemReq reqData;
|
seanhalle@0
|
841
|
seanhalle@0
|
842 //
|
seanhalle@3
|
843 reqData.callingSlv = animSlv;
|
seanhalle@0
|
844 reqData.reqType = trans_start;
|
seanhalle@0
|
845 reqData.transID = transactionID;
|
seanhalle@0
|
846
|
seanhalle@3
|
847 VMS_WL__send_sem_request( &reqData, animSlv );
|
seanhalle@0
|
848 }
|
seanhalle@0
|
849
|
seanhalle@0
|
850 /*This suspends to the master, then uses transactionID as index into an
|
seanhalle@0
|
851 * array of transaction structures.
|
seanhalle@0
|
852 *It looks at VP_currently_executing to be sure it's same as requesting VP.
|
seanhalle@0
|
853 * If different, throws an exception, stating there's a bug in the code.
|
seanhalle@0
|
854 *Next it looks at the queue in the structure.
|
seanhalle@0
|
855 *If it's empty, it sets VP_currently_executing field to NULL and resumes.
|
seanhalle@0
|
856 *If something in, gets it, sets VP_currently_executing to that VP, then
|
seanhalle@0
|
857 * resumes both.
|
seanhalle@0
|
858 */
|
seanhalle@0
|
859 void
|
seanhalle@3
|
860 VSs__end_transaction( int32 transactionID, SlaveVP *animSlv )
|
seanhalle@0
|
861 {
|
seanhalle@2
|
862 VSsSemReq reqData;
|
seanhalle@0
|
863
|
seanhalle@0
|
864 //
|
seanhalle@3
|
865 reqData.callingSlv = animSlv;
|
seanhalle@0
|
866 reqData.reqType = trans_end;
|
seanhalle@0
|
867 reqData.transID = transactionID;
|
seanhalle@0
|
868
|
seanhalle@3
|
869 VMS_WL__send_sem_request( &reqData, animSlv );
|
seanhalle@0
|
870 }
|
seanhalle@7
|
871
|
seanhalle@7
|
872 //======================== Internal ==================================
|
seanhalle@7
|
873 /*
|
seanhalle@7
|
874 */
|
seanhalle@7
|
875 SlaveVP *
|
seanhalle@7
|
876 VSs__create_slave_with( TopLevelFnPtr fnPtr, void *initData,
|
seanhalle@7
|
877 SlaveVP *creatingSlv )
|
seanhalle@7
|
878 { VSsSemReq reqData;
|
seanhalle@7
|
879
|
seanhalle@7
|
880 //the semantic request data is on the stack and disappears when this
|
seanhalle@7
|
881 // call returns -- it's guaranteed to remain in the VP's stack for as
|
seanhalle@7
|
882 // long as the VP is suspended.
|
seanhalle@7
|
883 reqData.reqType = 0; //know type because in a VMS create req
|
seanhalle@7
|
884 reqData.coreToAssignOnto = -1; //means round-robin assign
|
seanhalle@7
|
885 reqData.fnPtr = fnPtr;
|
seanhalle@7
|
886 reqData.initData = initData;
|
seanhalle@7
|
887 reqData.callingSlv = creatingSlv;
|
seanhalle@7
|
888
|
seanhalle@7
|
889 VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv );
|
seanhalle@7
|
890
|
seanhalle@7
|
891 return creatingSlv->dataRetFromReq;
|
seanhalle@7
|
892 }
|
seanhalle@7
|
893
|
seanhalle@7
|
894 SlaveVP *
|
seanhalle@7
|
895 VSs__create_slave_with_affinity( TopLevelFnPtr fnPtr, void *initData,
|
seanhalle@7
|
896 SlaveVP *creatingSlv, int32 coreToAssignOnto )
|
seanhalle@7
|
897 { VSsSemReq reqData;
|
seanhalle@7
|
898
|
seanhalle@7
|
899 //the semantic request data is on the stack and disappears when this
|
seanhalle@7
|
900 // call returns -- it's guaranteed to remain in the VP's stack for as
|
seanhalle@7
|
901 // long as the VP is suspended.
|
seanhalle@7
|
902 reqData.reqType = create_slave_w_aff; //not used, May 2012
|
seanhalle@7
|
903 reqData.coreToAssignOnto = coreToAssignOnto;
|
seanhalle@7
|
904 reqData.fnPtr = fnPtr;
|
seanhalle@7
|
905 reqData.initData = initData;
|
seanhalle@7
|
906 reqData.callingSlv = creatingSlv;
|
seanhalle@7
|
907
|
seanhalle@7
|
908 VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv );
|
seanhalle@7
|
909
|
seanhalle@7
|
910 return creatingSlv->dataRetFromReq;
|
seanhalle@7
|
911 }
|
seanhalle@7
|
912
|