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