| rev |
line source |
|
Me@0
|
1 /*
|
|
Me@38
|
2 * Copyright 2010 OpenSourceStewardshipFoundation
|
|
Me@0
|
3 *
|
|
Me@0
|
4 * Licensed under BSD
|
|
Me@0
|
5 */
|
|
Me@0
|
6
|
|
Me@0
|
7 #include <stdio.h>
|
|
Me@0
|
8 #include <stdlib.h>
|
|
Me@50
|
9 #include <string.h>
|
|
Me@0
|
10 #include <malloc.h>
|
|
Me@50
|
11 #include <sys/time.h>
|
|
Me@0
|
12
|
|
Me@0
|
13 #include "VMS.h"
|
|
Me@0
|
14 #include "Queue_impl/BlockingQueue.h"
|
|
Me@38
|
15 #include "Histogram/Histogram.h"
|
|
Me@0
|
16
|
|
Me@0
|
17
|
|
Me@26
|
18 #define thdAttrs NULL
|
|
Me@26
|
19
|
|
Me@22
|
20 //===========================================================================
|
|
Me@22
|
21 void
|
|
Me@22
|
22 shutdownFn( void *dummy, VirtProcr *dummy2 );
|
|
Me@22
|
23
|
|
Me@31
|
24 SchedSlot **
|
|
Me@31
|
25 create_sched_slots();
|
|
Me@22
|
26
|
|
Me@28
|
27 void
|
|
Me@28
|
28 create_masterEnv();
|
|
Me@28
|
29
|
|
Me@28
|
30 void
|
|
Me@28
|
31 create_the_coreLoop_OS_threads();
|
|
Me@28
|
32
|
|
Me@50
|
33 MallocProlog *
|
|
Me@50
|
34 create_free_list();
|
|
Me@50
|
35
|
|
Me@53
|
36 void
|
|
Me@53
|
37 endOSThreadFn( void *initData, VirtProcr *animatingPr );
|
|
Me@50
|
38
|
|
Me@26
|
39 pthread_mutex_t suspendLock = PTHREAD_MUTEX_INITIALIZER;
|
|
Me@26
|
40 pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER;
|
|
Me@26
|
41
|
|
Me@22
|
42 //===========================================================================
|
|
Me@22
|
43
|
|
Me@0
|
44 /*Setup has two phases:
|
|
Me@0
|
45 * 1) Semantic layer first calls init_VMS, which creates masterEnv, and puts
|
|
Me@8
|
46 * the master virt procr into the work-queue, ready for first "call"
|
|
Me@8
|
47 * 2) Semantic layer then does its own init, which creates the seed virt
|
|
Me@8
|
48 * procr inside the semantic layer, ready to schedule it when
|
|
Me@0
|
49 * asked by the first run of the masterLoop.
|
|
Me@0
|
50 *
|
|
Me@0
|
51 *This part is bit weird because VMS really wants to be "always there", and
|
|
Me@0
|
52 * have applications attach and detach.. for now, this VMS is part of
|
|
Me@0
|
53 * the app, so the VMS system starts up as part of running the app.
|
|
Me@0
|
54 *
|
|
Me@8
|
55 *The semantic layer is isolated from the VMS internals by making the
|
|
Me@8
|
56 * semantic layer do setup to a state that it's ready with its
|
|
Me@8
|
57 * initial virt procrs, ready to schedule them to slots when the masterLoop
|
|
Me@0
|
58 * asks. Without this pattern, the semantic layer's setup would
|
|
Me@8
|
59 * have to modify slots directly to assign the initial virt-procrs, and put
|
|
Me@31
|
60 * them into the readyToAnimateQ itself, breaking the isolation completely.
|
|
Me@0
|
61 *
|
|
Me@0
|
62 *
|
|
Me@8
|
63 *The semantic layer creates the initial virt procr(s), and adds its
|
|
Me@8
|
64 * own environment to masterEnv, and fills in the pointers to
|
|
Me@0
|
65 * the requestHandler and slaveScheduler plug-in functions
|
|
Me@8
|
66 */
|
|
Me@8
|
67
|
|
Me@8
|
68 /*This allocates VMS data structures, populates the master VMSProc,
|
|
Me@0
|
69 * and master environment, and returns the master environment to the semantic
|
|
Me@0
|
70 * layer.
|
|
Me@0
|
71 */
|
|
Me@8
|
72 void
|
|
Me@8
|
73 VMS__init()
|
|
Me@28
|
74 {
|
|
Me@28
|
75 create_masterEnv();
|
|
Me@28
|
76 create_the_coreLoop_OS_threads();
|
|
Me@28
|
77 }
|
|
Me@28
|
78
|
|
Me@28
|
79 /*To initialize the sequential version, just don't create the threads
|
|
Me@28
|
80 */
|
|
Me@28
|
81 void
|
|
Me@28
|
82 VMS__init_Seq()
|
|
Me@28
|
83 {
|
|
Me@28
|
84 create_masterEnv();
|
|
Me@28
|
85 }
|
|
Me@28
|
86
|
|
Me@28
|
87 void
|
|
Me@28
|
88 create_masterEnv()
|
|
Me@31
|
89 { MasterEnv *masterEnv;
|
|
Me@55
|
90 VMSQueueStruc **readyToAnimateQs;
|
|
Me@31
|
91 int coreIdx;
|
|
Me@31
|
92 VirtProcr **masterVPs;
|
|
Me@31
|
93 SchedSlot ***allSchedSlots; //ptr to array of ptrs
|
|
Me@53
|
94
|
|
Me@53
|
95
|
|
Me@31
|
96 //Make the master env, which holds everything else
|
|
Me@1
|
97 _VMSMasterEnv = malloc( sizeof(MasterEnv) );
|
|
Me@53
|
98
|
|
Me@53
|
99 //Very first thing put into the master env is the free-list, seeded
|
|
Me@53
|
100 // with a massive initial chunk of memory.
|
|
Me@53
|
101 //After this, all other mallocs are VMS__malloc.
|
|
Me@53
|
102 _VMSMasterEnv->freeListHead = VMS_ext__create_free_list();
|
|
Me@53
|
103
|
|
Me@65
|
104
|
|
Me@65
|
105 //============================= MEASUREMENT STUFF ========================
|
|
Me@65
|
106 #ifdef MEAS__TIME_MALLOC
|
|
Me@68
|
107 _VMSMasterEnv->mallocTimeHist = makeFixedBinHistExt( 50, 0, 100,
|
|
Me@65
|
108 "malloc time hist");
|
|
Me@68
|
109 _VMSMasterEnv->freeTimeHist = makeFixedBinHistExt( 50, 0, 100,
|
|
Me@65
|
110 "free time hist");
|
|
Me@65
|
111 #endif
|
|
Me@68
|
112 #ifdef MEAS__TIME_PLUGIN
|
|
Me@68
|
113 _VMSMasterEnv->reqHdlrLowTimeHist = makeFixedBinHistExt( 50, 0, 10,
|
|
Me@68
|
114 "plugin low time hist");
|
|
Me@68
|
115 _VMSMasterEnv->reqHdlrHighTimeHist = makeFixedBinHistExt( 50, 0, 100,
|
|
Me@68
|
116 "plugin high time hist");
|
|
Me@68
|
117 #endif
|
|
Me@65
|
118 //========================================================================
|
|
Me@65
|
119
|
|
Me@53
|
120 //===================== Only VMS__malloc after this ====================
|
|
Me@1
|
121 masterEnv = _VMSMasterEnv;
|
|
Me@31
|
122
|
|
Me@31
|
123 //Make a readyToAnimateQ for each core loop
|
|
Me@55
|
124 readyToAnimateQs = VMS__malloc( NUM_CORES * sizeof(VMSQueueStruc *) );
|
|
Me@53
|
125 masterVPs = VMS__malloc( NUM_CORES * sizeof(VirtProcr *) );
|
|
Me@0
|
126
|
|
Me@31
|
127 //One array for each core, 3 in array, core's masterVP scheds all
|
|
Me@53
|
128 allSchedSlots = VMS__malloc( NUM_CORES * sizeof(SchedSlot *) );
|
|
Me@0
|
129
|
|
Me@53
|
130 _VMSMasterEnv->numProcrsCreated = 0; //used by create procr
|
|
Me@31
|
131 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
|
|
Me@53
|
132 {
|
|
Me@55
|
133 readyToAnimateQs[ coreIdx ] = makeVMSQ();
|
|
Me@31
|
134
|
|
Me@50
|
135 //Q: should give masterVP core-specific info as its init data?
|
|
Me@53
|
136 masterVPs[ coreIdx ] = VMS__create_procr( &masterLoop, masterEnv );
|
|
Me@31
|
137 masterVPs[ coreIdx ]->coreAnimatedBy = coreIdx;
|
|
Me@31
|
138 allSchedSlots[ coreIdx ] = create_sched_slots(); //makes for one core
|
|
Me@53
|
139 _VMSMasterEnv->numMasterInARow[ coreIdx ] = 0;
|
|
Me@55
|
140 _VMSMasterEnv->workStealingGates[ coreIdx ] = NULL;
|
|
Me@31
|
141 }
|
|
Me@31
|
142 _VMSMasterEnv->readyToAnimateQs = readyToAnimateQs;
|
|
Me@31
|
143 _VMSMasterEnv->masterVPs = masterVPs;
|
|
Me@50
|
144 _VMSMasterEnv->masterLock = UNLOCKED;
|
|
Me@31
|
145 _VMSMasterEnv->allSchedSlots = allSchedSlots;
|
|
Me@55
|
146 _VMSMasterEnv->workStealingLock = UNLOCKED;
|
|
Me@28
|
147
|
|
Me@12
|
148
|
|
Me@31
|
149 //Aug 19, 2010: no longer need to place initial masterVP into queue
|
|
Me@31
|
150 // because coreLoop now controls -- animates its masterVP when no work
|
|
Me@31
|
151
|
|
Me@30
|
152
|
|
Me@50
|
153 //============================= MEASUREMENT STUFF ========================
|
|
Me@50
|
154 #ifdef STATS__TURN_ON_PROBES
|
|
Me@50
|
155 _VMSMasterEnv->dynIntervalProbesInfo =
|
|
Me@53
|
156 makePrivDynArrayOfSize( &(_VMSMasterEnv->intervalProbes), 200);
|
|
Me@30
|
157
|
|
Me@53
|
158 _VMSMasterEnv->probeNameHashTbl = makeHashTable( 1000, &VMS__free );
|
|
Me@53
|
159
|
|
Me@53
|
160 //put creation time directly into master env, for fast retrieval
|
|
Me@50
|
161 struct timeval timeStamp;
|
|
Me@50
|
162 gettimeofday( &(timeStamp), NULL);
|
|
Me@50
|
163 _VMSMasterEnv->createPtInSecs =
|
|
Me@50
|
164 timeStamp.tv_sec +(timeStamp.tv_usec/1000000.0);
|
|
Me@50
|
165 #endif
|
|
Me@65
|
166 #ifdef MEAS__TIME_MASTER_LOCK
|
|
Me@65
|
167 _VMSMasterEnv->masterLockLowTimeHist = makeFixedBinHist( 50, 0, 2,
|
|
Me@65
|
168 "master lock low time hist");
|
|
Me@68
|
169 _VMSMasterEnv->masterLockHighTimeHist = makeFixedBinHist( 50, 0, 100,
|
|
Me@65
|
170 "master lock high time hist");
|
|
Me@65
|
171 #endif
|
|
Me@68
|
172
|
|
Me@68
|
173 MakeTheMeasHists
|
|
Me@50
|
174 //========================================================================
|
|
Me@38
|
175
|
|
Me@0
|
176 }
|
|
Me@0
|
177
|
|
Me@31
|
178 SchedSlot **
|
|
Me@31
|
179 create_sched_slots()
|
|
Me@31
|
180 { SchedSlot **schedSlots;
|
|
Me@0
|
181 int i;
|
|
Me@0
|
182
|
|
Me@53
|
183 schedSlots = VMS__malloc( NUM_SCHED_SLOTS * sizeof(SchedSlot *) );
|
|
Me@8
|
184
|
|
Me@1
|
185 for( i = 0; i < NUM_SCHED_SLOTS; i++ )
|
|
Me@0
|
186 {
|
|
Me@53
|
187 schedSlots[i] = VMS__malloc( sizeof(SchedSlot) );
|
|
Me@8
|
188
|
|
Me@1
|
189 //Set state to mean "handling requests done, slot needs filling"
|
|
Me@8
|
190 schedSlots[i]->workIsDone = FALSE;
|
|
Me@8
|
191 schedSlots[i]->needsProcrAssigned = TRUE;
|
|
Me@0
|
192 }
|
|
Me@31
|
193 return schedSlots;
|
|
Me@31
|
194 }
|
|
Me@31
|
195
|
|
Me@31
|
196
|
|
Me@31
|
197 void
|
|
Me@31
|
198 freeSchedSlots( SchedSlot **schedSlots )
|
|
Me@31
|
199 { int i;
|
|
Me@31
|
200 for( i = 0; i < NUM_SCHED_SLOTS; i++ )
|
|
Me@31
|
201 {
|
|
Me@53
|
202 VMS__free( schedSlots[i] );
|
|
Me@31
|
203 }
|
|
Me@53
|
204 VMS__free( schedSlots );
|
|
Me@0
|
205 }
|
|
Me@0
|
206
|
|
Me@8
|
207
|
|
Me@28
|
208 void
|
|
Me@28
|
209 create_the_coreLoop_OS_threads()
|
|
Me@28
|
210 {
|
|
Me@28
|
211 //========================================================================
|
|
Me@28
|
212 // Create the Threads
|
|
Me@28
|
213 int coreIdx, retCode;
|
|
Me@28
|
214
|
|
Me@28
|
215 //Need the threads to be created suspended, and wait for a signal
|
|
Me@28
|
216 // before proceeding -- gives time after creating to initialize other
|
|
Me@28
|
217 // stuff before the coreLoops set off.
|
|
Me@28
|
218 _VMSMasterEnv->setupComplete = 0;
|
|
Me@28
|
219
|
|
Me@28
|
220 //Make the threads that animate the core loops
|
|
Me@28
|
221 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
|
|
Me@53
|
222 { coreLoopThdParams[coreIdx] = VMS__malloc( sizeof(ThdParams) );
|
|
Me@28
|
223 coreLoopThdParams[coreIdx]->coreNum = coreIdx;
|
|
Me@28
|
224
|
|
Me@28
|
225 retCode =
|
|
Me@28
|
226 pthread_create( &(coreLoopThdHandles[coreIdx]),
|
|
Me@28
|
227 thdAttrs,
|
|
Me@28
|
228 &coreLoop,
|
|
Me@28
|
229 (void *)(coreLoopThdParams[coreIdx]) );
|
|
Me@50
|
230 if(retCode){printf("ERROR creating thread: %d\n", retCode); exit(1);}
|
|
Me@28
|
231 }
|
|
Me@28
|
232 }
|
|
Me@28
|
233
|
|
Me@0
|
234 /*Semantic layer calls this when it want the system to start running..
|
|
Me@0
|
235 *
|
|
Me@24
|
236 *This starts the core loops running then waits for them to exit.
|
|
Me@0
|
237 */
|
|
Me@12
|
238 void
|
|
Me@24
|
239 VMS__start_the_work_then_wait_until_done()
|
|
Me@12
|
240 { int coreIdx;
|
|
Me@24
|
241 //Start the core loops running
|
|
Me@25
|
242
|
|
Me@25
|
243 //tell the core loop threads that setup is complete
|
|
Me@25
|
244 //get lock, to lock out any threads still starting up -- they'll see
|
|
Me@25
|
245 // that setupComplete is true before entering while loop, and so never
|
|
Me@25
|
246 // wait on the condition
|
|
Me@26
|
247 pthread_mutex_lock( &suspendLock );
|
|
Me@25
|
248 _VMSMasterEnv->setupComplete = 1;
|
|
Me@26
|
249 pthread_mutex_unlock( &suspendLock );
|
|
Me@26
|
250 pthread_cond_broadcast( &suspend_cond );
|
|
Me@25
|
251
|
|
Me@25
|
252
|
|
Me@24
|
253 //wait for all to complete
|
|
Me@8
|
254 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
|
|
Me@8
|
255 {
|
|
Me@25
|
256 pthread_join( coreLoopThdHandles[coreIdx], NULL );
|
|
Me@24
|
257 }
|
|
Me@25
|
258
|
|
Me@24
|
259 //NOTE: do not clean up VMS env here -- semantic layer has to have
|
|
Me@24
|
260 // a chance to clean up its environment first, then do a call to free
|
|
Me@24
|
261 // the Master env and rest of VMS locations
|
|
Me@8
|
262 }
|
|
Me@0
|
263
|
|
Me@28
|
264 /*Only difference between version with an OS thread pinned to each core and
|
|
Me@28
|
265 * the sequential version of VMS is VMS__init_Seq, this, and coreLoop_Seq.
|
|
Me@28
|
266 */
|
|
Me@28
|
267 void
|
|
Me@28
|
268 VMS__start_the_work_then_wait_until_done_Seq()
|
|
Me@28
|
269 {
|
|
Me@28
|
270 //Instead of un-suspending threads, just call the one and only
|
|
Me@28
|
271 // core loop (sequential version), in the main thread.
|
|
Me@28
|
272 coreLoop_Seq( NULL );
|
|
Me@28
|
273
|
|
Me@28
|
274 }
|
|
Me@28
|
275
|
|
Me@0
|
276
|
|
Me@0
|
277
|
|
Me@8
|
278 /*Create stack, then create __cdecl structure on it and put initialData and
|
|
Me@8
|
279 * pointer to the new structure instance into the parameter positions on
|
|
Me@8
|
280 * the stack
|
|
Me@8
|
281 *Then put function pointer into nextInstrPt -- the stack is setup in std
|
|
Me@8
|
282 * call structure, so jumping to function ptr is same as a GCC generated
|
|
Me@8
|
283 * function call
|
|
Me@8
|
284 *No need to save registers on old stack frame, because there's no old
|
|
Me@8
|
285 * animator state to return to --
|
|
Me@8
|
286 *
|
|
Me@8
|
287 */
|
|
Me@50
|
288 inline VirtProcr *
|
|
Me@50
|
289 create_procr_helper( VirtProcr *newPr, VirtProcrFnPtr fnPtr,
|
|
Me@50
|
290 void *initialData, char *stackLocs )
|
|
Me@50
|
291 {
|
|
Me@50
|
292 char *stackPtr;
|
|
Me@8
|
293
|
|
Me@53
|
294 newPr->startOfStack = stackLocs;
|
|
Me@53
|
295 newPr->procrID = _VMSMasterEnv->numProcrsCreated++;
|
|
Me@53
|
296 newPr->nextInstrPt = fnPtr;
|
|
Me@53
|
297 newPr->initialData = initialData;
|
|
Me@53
|
298 newPr->requests = NULL;
|
|
Me@53
|
299 newPr->schedSlot = NULL;
|
|
Me@8
|
300
|
|
Me@14
|
301 //fnPtr takes two params -- void *initData & void *animProcr
|
|
Me@8
|
302 //alloc stack locations, make stackPtr be the highest addr minus room
|
|
Me@14
|
303 // for 2 params + return addr. Return addr (NULL) is in loc pointed to
|
|
Me@14
|
304 // by stackPtr, initData at stackPtr + 4 bytes, animatingPr just above
|
|
Me@22
|
305 stackPtr = ( (char *)stackLocs + VIRT_PROCR_STACK_SIZE - 0x10 );
|
|
Me@50
|
306
|
|
Me@8
|
307 //setup __cdecl on stack -- coreloop will switch to stackPtr before jmp
|
|
Me@22
|
308 *( (int *)stackPtr + 2 ) = (int) newPr; //rightmost param -- 32bit pointer
|
|
Me@14
|
309 *( (int *)stackPtr + 1 ) = (int) initialData; //next param to left
|
|
Me@8
|
310 newPr->stackPtr = stackPtr; //core loop will switch to this, then
|
|
Me@8
|
311 newPr->framePtr = stackPtr; //suspend loop will save new stack & frame ptr
|
|
Me@8
|
312
|
|
Me@50
|
313 //============================= MEASUREMENT STUFF ========================
|
|
Me@50
|
314 #ifdef STATS__TURN_ON_PROBES
|
|
Me@50
|
315 struct timeval timeStamp;
|
|
Me@50
|
316 gettimeofday( &(timeStamp), NULL);
|
|
Me@54
|
317 newPr->createPtInSecs = timeStamp.tv_sec +(timeStamp.tv_usec/1000000.0) -
|
|
Me@54
|
318 _VMSMasterEnv->createPtInSecs;
|
|
Me@50
|
319 #endif
|
|
Me@50
|
320 //========================================================================
|
|
Me@50
|
321
|
|
Me@8
|
322 return newPr;
|
|
Me@8
|
323 }
|
|
Me@8
|
324
|
|
Me@50
|
325 inline VirtProcr *
|
|
Me@50
|
326 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData )
|
|
Me@50
|
327 { VirtProcr *newPr;
|
|
Me@50
|
328 char *stackLocs;
|
|
Me@50
|
329
|
|
Me@50
|
330 newPr = VMS__malloc( sizeof(VirtProcr) );
|
|
Me@50
|
331 stackLocs = VMS__malloc( VIRT_PROCR_STACK_SIZE );
|
|
Me@50
|
332 if( stackLocs == 0 )
|
|
Me@50
|
333 { perror("VMS__malloc stack"); exit(1); }
|
|
Me@50
|
334
|
|
Me@50
|
335 return create_procr_helper( newPr, fnPtr, initialData, stackLocs );
|
|
Me@50
|
336 }
|
|
Me@50
|
337
|
|
Me@50
|
338 /* "ext" designates that it's for use outside the VMS system -- should only
|
|
Me@50
|
339 * be called from main thread or other thread -- never from code animated by
|
|
Me@50
|
340 * a VMS virtual processor.
|
|
Me@50
|
341 */
|
|
Me@50
|
342 inline VirtProcr *
|
|
Me@50
|
343 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData )
|
|
Me@50
|
344 { VirtProcr *newPr;
|
|
Me@50
|
345 char *stackLocs;
|
|
Me@50
|
346
|
|
Me@50
|
347 newPr = malloc( sizeof(VirtProcr) );
|
|
Me@50
|
348 stackLocs = malloc( VIRT_PROCR_STACK_SIZE );
|
|
Me@50
|
349 if( stackLocs == 0 )
|
|
Me@50
|
350 { perror("malloc stack"); exit(1); }
|
|
Me@50
|
351
|
|
Me@50
|
352 return create_procr_helper( newPr, fnPtr, initialData, stackLocs );
|
|
Me@50
|
353 }
|
|
Me@50
|
354
|
|
Me@8
|
355
|
|
Me@64
|
356 /*Anticipating multi-tasking
|
|
Me@64
|
357 */
|
|
Me@64
|
358 void *
|
|
Me@64
|
359 VMS__give_sem_env_for( VirtProcr *animPr )
|
|
Me@64
|
360 {
|
|
Me@64
|
361 return _VMSMasterEnv->semanticEnv;
|
|
Me@64
|
362 }
|
|
Me@64
|
363 //===========================================================================
|
|
Me@26
|
364 /*there is a label inside this function -- save the addr of this label in
|
|
Me@0
|
365 * the callingPr struc, as the pick-up point from which to start the next
|
|
Me@0
|
366 * work-unit for that procr. If turns out have to save registers, then
|
|
Me@0
|
367 * save them in the procr struc too. Then do assembly jump to the CoreLoop's
|
|
Me@0
|
368 * "done with work-unit" label. The procr struc is in the request in the
|
|
Me@0
|
369 * slave that animated the just-ended work-unit, so all the state is saved
|
|
Me@0
|
370 * there, and will get passed along, inside the request handler, to the
|
|
Me@0
|
371 * next work-unit for that procr.
|
|
Me@0
|
372 */
|
|
Me@8
|
373 void
|
|
Me@38
|
374 VMS__suspend_procr( VirtProcr *animatingPr )
|
|
Me@55
|
375 {
|
|
Me@0
|
376
|
|
Me@14
|
377 //The request to master will cause this suspended virt procr to get
|
|
Me@14
|
378 // scheduled again at some future point -- to resume, core loop jumps
|
|
Me@14
|
379 // to the resume point (below), which causes restore of saved regs and
|
|
Me@14
|
380 // "return" from this call.
|
|
Me@38
|
381 animatingPr->nextInstrPt = &&ResumePt;
|
|
Me@1
|
382
|
|
Me@1
|
383 //return ownership of the virt procr and sched slot to Master virt pr
|
|
Me@38
|
384 animatingPr->schedSlot->workIsDone = TRUE;
|
|
Me@1
|
385
|
|
Me@41
|
386 //=========================== Measurement stuff ========================
|
|
Me@38
|
387 #ifdef MEAS__TIME_STAMP_SUSP
|
|
Me@41
|
388 //record time stamp: compare to time-stamp recorded below
|
|
Me@38
|
389 saveLowTimeStampCountInto( animatingPr->preSuspTSCLow );
|
|
Me@38
|
390 #endif
|
|
Me@41
|
391 //=======================================================================
|
|
Me@38
|
392
|
|
Me@62
|
393 /* VirtProcr offsets:
|
|
Me@62
|
394 * 0xc stackPtr
|
|
Me@62
|
395 * 0x10 framePtr
|
|
Me@62
|
396 * 0x14 nextInstrPt
|
|
Me@62
|
397 * 0x1c coreLoopFramePtr
|
|
Me@62
|
398 * 0x20 coreLoopStackPtr
|
|
Me@62
|
399 *
|
|
Me@62
|
400 * _VMSMasterEnv offsets:
|
|
Me@62
|
401 * 0x24 coreLoopStartPt
|
|
Me@62
|
402 * 0x28 coreLoopEndPt
|
|
Me@62
|
403 * 0x30 masterLock
|
|
Me@62
|
404 */
|
|
Me@62
|
405 // SwitchToCoreLoop( animatingPr )
|
|
Me@62
|
406 asm volatile("movl %0, %%ebx; \
|
|
Me@62
|
407 movl %1, %%ecx; \
|
|
Me@62
|
408 movl %%esp, 0x0c(%%ecx); \
|
|
Me@62
|
409 movl %%ebp, 0x10(%%ecx); \
|
|
Me@62
|
410 movl 0x24(%%ebx), %%eax; \
|
|
Me@62
|
411 movl 0x20(%%ecx), %%esp; \
|
|
Me@62
|
412 movl 0x1c(%%ecx), %%ebp; \
|
|
Me@62
|
413 jmp %%eax" \
|
|
Me@62
|
414 /* outputs */ : \
|
|
Me@62
|
415 /* inputs */ : "g"(_VMSMasterEnv), "g"(animatingPr) \
|
|
Me@62
|
416 /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
|
|
Me@62
|
417 );
|
|
Me@1
|
418
|
|
Me@62
|
419 // asm volatile("mov %0,%%ebx; \
|
|
Me@62
|
420 mov %%ebx, %%eax; \
|
|
Me@62
|
421 add $0xc, %%eax; \
|
|
Me@62
|
422 movl %%esp, (%%eax); \
|
|
Me@62
|
423 mov %%ebx, %%eax; \
|
|
Me@62
|
424 add $0x10, %%eax; \
|
|
Me@62
|
425 movl %%ebp, (%%eax); \
|
|
Me@62
|
426 movl %1, %%eax; \
|
|
Me@62
|
427 movl %2, %%esp; \
|
|
Me@62
|
428 movl %3, %%ebp; \
|
|
Me@62
|
429 jmp %%eax" \
|
|
Me@62
|
430 /* outputs */ : \
|
|
Me@62
|
431 /* inputs */ : "g"(animatingPr), "g" (jmpPt), "g" (coreLoopStackPtr), \
|
|
Me@62
|
432 "g" (coreLoopFramePtr) \
|
|
Me@62
|
433 /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
|
|
Me@62
|
434 );
|
|
Me@55
|
435
|
|
Me@55
|
436 //=======================================================================
|
|
Me@1
|
437 ResumePt:
|
|
Me@38
|
438 #ifdef MEAS__TIME_STAMP_SUSP
|
|
Me@41
|
439 //NOTE: only take low part of count -- do sanity check when take diff
|
|
Me@38
|
440 saveLowTimeStampCountInto( animatingPr->postSuspTSCLow );
|
|
Me@38
|
441 #endif
|
|
Me@38
|
442
|
|
Me@0
|
443 return;
|
|
Me@0
|
444 }
|
|
Me@0
|
445
|
|
Me@22
|
446
|
|
Me@22
|
447
|
|
Me@50
|
448 /*For this implementation of VMS, it may not make much sense to have the
|
|
Me@50
|
449 * system of requests for creating a new processor done this way.. but over
|
|
Me@50
|
450 * the scope of single-master, multi-master, mult-tasking, OS-implementing,
|
|
Me@50
|
451 * distributed-memory, and so on, this gives VMS implementation a chance to
|
|
Me@50
|
452 * do stuff before suspend, in the AppVP, and in the Master before the plugin
|
|
Me@50
|
453 * is called, as well as in the lang-lib before this is called, and in the
|
|
Me@50
|
454 * plugin. So, this gives both VMS and language implementations a chance to
|
|
Me@50
|
455 * intercept at various points and do order-dependent stuff.
|
|
Me@50
|
456 *Having a standard VMSNewPrReqData struc allows the language to create and
|
|
Me@50
|
457 * free the struc, while VMS knows how to get the newPr if it wants it, and
|
|
Me@50
|
458 * it lets the lang have lang-specific data related to creation transported
|
|
Me@50
|
459 * to the plugin.
|
|
Me@50
|
460 */
|
|
Me@50
|
461 void
|
|
Me@50
|
462 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr )
|
|
Me@50
|
463 { VMSReqst req;
|
|
Me@50
|
464
|
|
Me@50
|
465 req.reqType = createReq;
|
|
Me@50
|
466 req.semReqData = semReqData;
|
|
Me@50
|
467 req.nextReqst = reqstingPr->requests;
|
|
Me@50
|
468 reqstingPr->requests = &req;
|
|
Me@50
|
469
|
|
Me@50
|
470 VMS__suspend_procr( reqstingPr );
|
|
Me@50
|
471 }
|
|
Me@50
|
472
|
|
Me@22
|
473
|
|
Me@38
|
474 /*
|
|
Me@22
|
475 *This adds a request to dissipate, then suspends the processor so that the
|
|
Me@22
|
476 * request handler will receive the request. The request handler is what
|
|
Me@22
|
477 * does the work of freeing memory and removing the processor from the
|
|
Me@22
|
478 * semantic environment's data structures.
|
|
Me@22
|
479 *The request handler also is what figures out when to shutdown the VMS
|
|
Me@22
|
480 * system -- which causes all the core loop threads to die, and returns from
|
|
Me@22
|
481 * the call that started up VMS to perform the work.
|
|
Me@22
|
482 *
|
|
Me@22
|
483 *This form is a bit misleading to understand if one is trying to figure out
|
|
Me@22
|
484 * how VMS works -- it looks like a normal function call, but inside it
|
|
Me@22
|
485 * sends a request to the request handler and suspends the processor, which
|
|
Me@22
|
486 * jumps out of the VMS__dissipate_procr function, and out of all nestings
|
|
Me@22
|
487 * above it, transferring the work of dissipating to the request handler,
|
|
Me@22
|
488 * which then does the actual work -- causing the processor that animated
|
|
Me@22
|
489 * the call of this function to disappear and the "hanging" state of this
|
|
Me@22
|
490 * function to just poof into thin air -- the virtual processor's trace
|
|
Me@22
|
491 * never returns from this call, but instead the virtual processor's trace
|
|
Me@22
|
492 * gets suspended in this call and all the virt processor's state disap-
|
|
Me@22
|
493 * pears -- making that suspend the last thing in the virt procr's trace.
|
|
Me@8
|
494 */
|
|
Me@8
|
495 void
|
|
Me@53
|
496 VMS__send_dissipate_req( VirtProcr *procrToDissipate )
|
|
Me@50
|
497 { VMSReqst req;
|
|
Me@22
|
498
|
|
Me@50
|
499 req.reqType = dissipate;
|
|
Me@50
|
500 req.nextReqst = procrToDissipate->requests;
|
|
Me@50
|
501 procrToDissipate->requests = &req;
|
|
Me@50
|
502
|
|
Me@22
|
503 VMS__suspend_procr( procrToDissipate );
|
|
Me@50
|
504 }
|
|
Me@50
|
505
|
|
Me@50
|
506
|
|
Me@50
|
507 /* "ext" designates that it's for use outside the VMS system -- should only
|
|
Me@50
|
508 * be called from main thread or other thread -- never from code animated by
|
|
Me@50
|
509 * a VMS virtual processor.
|
|
Me@50
|
510 *
|
|
Me@50
|
511 *Use this version to dissipate VPs created outside the VMS system.
|
|
Me@50
|
512 */
|
|
Me@50
|
513 void
|
|
Me@50
|
514 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate )
|
|
Me@50
|
515 {
|
|
Me@50
|
516 //NOTE: initialData was given to the processor, so should either have
|
|
Me@50
|
517 // been alloc'd with VMS__malloc, or freed by the level above animPr.
|
|
Me@50
|
518 //So, all that's left to free here is the stack and the VirtProcr struc
|
|
Me@50
|
519 // itself
|
|
Me@50
|
520 //Note, should not stack-allocate initial data -- no guarantee, in
|
|
Me@50
|
521 // general that creating processor will outlive ones it creates.
|
|
Me@50
|
522 free( procrToDissipate->startOfStack );
|
|
Me@50
|
523 free( procrToDissipate );
|
|
Me@50
|
524 }
|
|
Me@50
|
525
|
|
Me@22
|
526
|
|
Me@22
|
527
|
|
Me@53
|
528 /*This call's name indicates that request is malloc'd -- so req handler
|
|
Me@53
|
529 * has to free any extra requests tacked on before a send, using this.
|
|
Me@53
|
530 *
|
|
Me@53
|
531 * This inserts the semantic-layer's request data into standard VMS carrier
|
|
Me@53
|
532 * request data-struct that is mallocd. The sem request doesn't need to
|
|
Me@53
|
533 * be malloc'd if this is called inside the same call chain before the
|
|
Me@53
|
534 * send of the last request is called.
|
|
Me@53
|
535 *
|
|
Me@53
|
536 *The request handler has to call VMS__free_VMSReq for any of these
|
|
Me@22
|
537 */
|
|
Me@22
|
538 inline void
|
|
Me@53
|
539 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData,
|
|
Me@53
|
540 VirtProcr *callingPr )
|
|
Me@53
|
541 { VMSReqst *req;
|
|
Me@22
|
542
|
|
Me@53
|
543 req = VMS__malloc( sizeof(VMSReqst) );
|
|
Me@53
|
544 req->reqType = semantic;
|
|
Me@53
|
545 req->semReqData = semReqData;
|
|
Me@53
|
546 req->nextReqst = callingPr->requests;
|
|
Me@53
|
547 callingPr->requests = req;
|
|
Me@22
|
548 }
|
|
Me@22
|
549
|
|
Me@50
|
550 /*This inserts the semantic-layer's request data into standard VMS carrier
|
|
Me@50
|
551 * request data-struct is allocated on stack of this call & ptr to it sent
|
|
Me@50
|
552 * to plugin
|
|
Me@50
|
553 *Then it does suspend, to cause request to be sent.
|
|
Me@50
|
554 */
|
|
Me@50
|
555 inline void
|
|
Me@50
|
556 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr )
|
|
Me@50
|
557 { VMSReqst req;
|
|
Me@22
|
558
|
|
Me@50
|
559 req.reqType = semantic;
|
|
Me@50
|
560 req.semReqData = semReqData;
|
|
Me@50
|
561 req.nextReqst = callingPr->requests;
|
|
Me@50
|
562 callingPr->requests = &req;
|
|
Me@50
|
563
|
|
Me@50
|
564 VMS__suspend_procr( callingPr );
|
|
Me@50
|
565 }
|
|
Me@50
|
566
|
|
Me@50
|
567
|
|
Me@50
|
568 inline void
|
|
Me@50
|
569 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr )
|
|
Me@50
|
570 { VMSReqst req;
|
|
Me@50
|
571
|
|
Me@50
|
572 req.reqType = VMSSemantic;
|
|
Me@50
|
573 req.semReqData = semReqData;
|
|
Me@50
|
574 req.nextReqst = callingPr->requests; //gab any other preceeding
|
|
Me@50
|
575 callingPr->requests = &req;
|
|
Me@50
|
576
|
|
Me@50
|
577 VMS__suspend_procr( callingPr );
|
|
Me@50
|
578 }
|
|
Me@50
|
579
|
|
Me@50
|
580
|
|
Me@50
|
581 /*
|
|
Me@38
|
582 */
|
|
Me@24
|
583 VMSReqst *
|
|
Me@50
|
584 VMS__take_next_request_out_of( VirtProcr *procrWithReq )
|
|
Me@31
|
585 { VMSReqst *req;
|
|
Me@31
|
586
|
|
Me@31
|
587 req = procrWithReq->requests;
|
|
Me@38
|
588 if( req == NULL ) return NULL;
|
|
Me@31
|
589
|
|
Me@31
|
590 procrWithReq->requests = procrWithReq->requests->nextReqst;
|
|
Me@50
|
591 return req;
|
|
Me@24
|
592 }
|
|
Me@22
|
593
|
|
Me@24
|
594
|
|
Me@24
|
595 inline void *
|
|
Me@24
|
596 VMS__take_sem_reqst_from( VMSReqst *req )
|
|
Me@24
|
597 {
|
|
Me@24
|
598 return req->semReqData;
|
|
Me@24
|
599 }
|
|
Me@24
|
600
|
|
Me@24
|
601
|
|
Me@24
|
602
|
|
Me@50
|
603 /* This is for OS requests and VMS infrastructure requests, such as to create
|
|
Me@50
|
604 * a probe -- a probe is inside the heart of VMS-core, it's not part of any
|
|
Me@50
|
605 * language -- but it's also a semantic thing that's triggered from and used
|
|
Me@50
|
606 * in the application.. so it crosses abstractions.. so, need some special
|
|
Me@50
|
607 * pattern here for handling such requests.
|
|
Me@52
|
608 * Doing this just like it were a second language sharing VMS-core.
|
|
Me@52
|
609 *
|
|
Me@50
|
610 * This is called from the language's request handler when it sees a request
|
|
Me@50
|
611 * of type VMSSemReq
|
|
Me@52
|
612 *
|
|
Me@52
|
613 * TODO: Later change this, to give probes their own separate plugin & have
|
|
Me@52
|
614 * VMS-core steer the request to appropriate plugin
|
|
Me@52
|
615 * Do the same for OS calls -- look later at it..
|
|
Me@50
|
616 */
|
|
Me@50
|
617 void inline
|
|
Me@50
|
618 VMS__handle_VMSSemReq( VMSReqst *req, VirtProcr *requestingPr, void *semEnv,
|
|
Me@50
|
619 ResumePrFnPtr resumePrFnPtr )
|
|
Me@50
|
620 { VMSSemReq *semReq;
|
|
Me@50
|
621 IntervalProbe *newProbe;
|
|
Me@50
|
622 int32 nameLen;
|
|
Me@24
|
623
|
|
Me@50
|
624 semReq = req->semReqData;
|
|
Me@24
|
625
|
|
Me@50
|
626 newProbe = VMS__malloc( sizeof(IntervalProbe) );
|
|
Me@65
|
627 newProbe->nameStr = VMS__strDup( semReq->nameStr );
|
|
Me@50
|
628 newProbe->hist = NULL;
|
|
Me@50
|
629 newProbe->schedChoiceWasRecorded = FALSE;
|
|
Me@53
|
630
|
|
Me@53
|
631 //This runs in masterVP, so no race-condition worries
|
|
Me@50
|
632 newProbe->probeID =
|
|
Me@50
|
633 addToDynArray( newProbe, _VMSMasterEnv->dynIntervalProbesInfo );
|
|
Me@50
|
634
|
|
Me@53
|
635 requestingPr->dataRetFromReq = newProbe;
|
|
Me@50
|
636
|
|
Me@50
|
637 (*resumePrFnPtr)( requestingPr, semEnv );
|
|
Me@22
|
638 }
|
|
Me@22
|
639
|
|
Me@22
|
640
|
|
Me@22
|
641
|
|
Me@24
|
642 /*This must be called by the request handler plugin -- it cannot be called
|
|
Me@24
|
643 * from the semantic library "dissipate processor" function -- instead, the
|
|
Me@50
|
644 * semantic layer has to generate a request, and the plug-in calls this
|
|
Me@24
|
645 * function.
|
|
Me@24
|
646 *The reason is that this frees the virtual processor's stack -- which is
|
|
Me@24
|
647 * still in use inside semantic library calls!
|
|
Me@24
|
648 *
|
|
Me@24
|
649 *This frees or recycles all the state owned by and comprising the VMS
|
|
Me@24
|
650 * portion of the animating virtual procr. The request handler must first
|
|
Me@24
|
651 * free any semantic data created for the processor that didn't use the
|
|
Me@24
|
652 * VMS_malloc mechanism. Then it calls this, which first asks the malloc
|
|
Me@24
|
653 * system to disown any state that did use VMS_malloc, and then frees the
|
|
Me@24
|
654 * statck and the processor-struct itself.
|
|
Me@24
|
655 *If the dissipated processor is the sole (remaining) owner of VMS__malloc'd
|
|
Me@24
|
656 * state, then that state gets freed (or sent to recycling) as a side-effect
|
|
Me@24
|
657 * of dis-owning it.
|
|
Me@24
|
658 */
|
|
Me@24
|
659 void
|
|
Me@53
|
660 VMS__dissipate_procr( VirtProcr *animatingPr )
|
|
Me@24
|
661 {
|
|
Me@24
|
662 //dis-own all locations owned by this processor, causing to be freed
|
|
Me@24
|
663 // any locations that it is (was) sole owner of
|
|
Me@29
|
664 //TODO: implement VMS__malloc system, including "give up ownership"
|
|
Me@24
|
665
|
|
Me@24
|
666
|
|
Me@24
|
667 //NOTE: initialData was given to the processor, so should either have
|
|
Me@24
|
668 // been alloc'd with VMS__malloc, or freed by the level above animPr.
|
|
Me@24
|
669 //So, all that's left to free here is the stack and the VirtProcr struc
|
|
Me@24
|
670 // itself
|
|
Me@50
|
671 //Note, should not stack-allocate initial data -- no guarantee, in
|
|
Me@50
|
672 // general that creating processor will outlive ones it creates.
|
|
Me@50
|
673 VMS__free( animatingPr->startOfStack );
|
|
Me@50
|
674 VMS__free( animatingPr );
|
|
Me@24
|
675 }
|
|
Me@24
|
676
|
|
Me@24
|
677
|
|
Me@53
|
678 //TODO: look at architecting cleanest separation between request handler
|
|
Me@29
|
679 // and master loop, for dissipate, create, shutdown, and other non-semantic
|
|
Me@29
|
680 // requests. Issue is chain: one removes requests from AppVP, one dispatches
|
|
Me@29
|
681 // on type of request, and one handles each type.. but some types require
|
|
Me@29
|
682 // action from both request handler and master loop -- maybe just give the
|
|
Me@29
|
683 // request handler calls like: VMS__handle_X_request_type
|
|
Me@24
|
684
|
|
Me@29
|
685
|
|
Me@29
|
686 /*This is called by the semantic layer's request handler when it decides its
|
|
Me@29
|
687 * time to shut down the VMS system. Calling this causes the core loop OS
|
|
Me@29
|
688 * threads to exit, which unblocks the entry-point function that started up
|
|
Me@29
|
689 * VMS, and allows it to grab the result and return to the original single-
|
|
Me@29
|
690 * threaded application.
|
|
Me@22
|
691 *
|
|
Me@29
|
692 *The _VMSMasterEnv is needed by this shut down function, so the create-seed-
|
|
Me@29
|
693 * and-wait function has to free a bunch of stuff after it detects the
|
|
Me@29
|
694 * threads have all died: the masterEnv, the thread-related locations,
|
|
Me@29
|
695 * masterVP any AppVPs that might still be allocated and sitting in the
|
|
Me@29
|
696 * semantic environment, or have been orphaned in the _VMSWorkQ.
|
|
Me@29
|
697 *
|
|
Me@53
|
698 *NOTE: the semantic plug-in is expected to use VMS__malloc to get all the
|
|
Me@29
|
699 * locations it needs, and give ownership to masterVP. Then, they will be
|
|
Me@53
|
700 * automatically freed.
|
|
Me@22
|
701 *
|
|
Me@29
|
702 *In here,create one core-loop shut-down processor for each core loop and put
|
|
Me@31
|
703 * them all directly into the readyToAnimateQ.
|
|
Me@29
|
704 *Note, this function can ONLY be called after the semantic environment no
|
|
Me@29
|
705 * longer cares if AppVPs get animated after the point this is called. In
|
|
Me@29
|
706 * other words, this can be used as an abort, or else it should only be
|
|
Me@29
|
707 * called when all AppVPs have finished dissipate requests -- only at that
|
|
Me@29
|
708 * point is it sure that all results have completed.
|
|
Me@22
|
709 */
|
|
Me@22
|
710 void
|
|
Me@53
|
711 VMS__shutdown()
|
|
Me@8
|
712 { int coreIdx;
|
|
Me@14
|
713 VirtProcr *shutDownPr;
|
|
Me@22
|
714
|
|
Me@29
|
715 //create the shutdown processors, one for each core loop -- put them
|
|
Me@31
|
716 // directly into the Q -- each core will die when gets one
|
|
Me@8
|
717 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
|
|
Me@50
|
718 { //Note, this is running in the master
|
|
Me@29
|
719 shutDownPr = VMS__create_procr( &endOSThreadFn, NULL );
|
|
Me@55
|
720 writeVMSQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] );
|
|
Me@8
|
721 }
|
|
Me@22
|
722
|
|
Me@12
|
723 }
|
|
Me@12
|
724
|
|
Me@12
|
725
|
|
Me@29
|
726 /*Am trying to be cute, avoiding IF statement in coreLoop that checks for
|
|
Me@29
|
727 * a special shutdown procr. Ended up with extra-complex shutdown sequence.
|
|
Me@29
|
728 *This function has the sole purpose of setting the stack and framePtr
|
|
Me@29
|
729 * to the coreLoop's stack and framePtr.. it does that then jumps to the
|
|
Me@29
|
730 * core loop's shutdown point -- might be able to just call Pthread_exit
|
|
Me@30
|
731 * from here, but am going back to the pthread's stack and setting everything
|
|
Me@29
|
732 * up just as if it never jumped out, before calling pthread_exit.
|
|
Me@29
|
733 *The end-point of core loop will free the stack and so forth of the
|
|
Me@29
|
734 * processor that animates this function, (this fn is transfering the
|
|
Me@29
|
735 * animator of the AppVP that is in turn animating this function over
|
|
Me@29
|
736 * to core loop function -- note that this slices out a level of virtual
|
|
Me@29
|
737 * processors).
|
|
Me@29
|
738 */
|
|
Me@29
|
739 void
|
|
Me@29
|
740 endOSThreadFn( void *initData, VirtProcr *animatingPr )
|
|
Me@29
|
741 { void *jmpPt, *coreLoopStackPtr, *coreLoopFramePtr;
|
|
Me@29
|
742
|
|
Me@29
|
743 jmpPt = _VMSMasterEnv->coreLoopEndPt;
|
|
Me@29
|
744 coreLoopStackPtr = animatingPr->coreLoopStackPtr;
|
|
Me@29
|
745 coreLoopFramePtr = animatingPr->coreLoopFramePtr;
|
|
Me@29
|
746
|
|
Me@29
|
747
|
|
Me@29
|
748 asm volatile("movl %0, %%eax; \
|
|
Me@29
|
749 movl %1, %%esp; \
|
|
Me@29
|
750 movl %2, %%ebp; \
|
|
Me@29
|
751 jmp %%eax " \
|
|
Me@29
|
752 /* outputs */ : \
|
|
Me@29
|
753 /* inputs */ : "m" (jmpPt), "m"(coreLoopStackPtr), "m"(coreLoopFramePtr)\
|
|
Me@29
|
754 /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi" \
|
|
Me@29
|
755 );
|
|
Me@29
|
756 }
|
|
Me@29
|
757
|
|
Me@29
|
758
|
|
Me@53
|
759 /*This is called from the startup & shutdown
|
|
Me@24
|
760 */
|
|
Me@24
|
761 void
|
|
Me@53
|
762 VMS__cleanup_at_end_of_shutdown()
|
|
Me@31
|
763 {
|
|
Me@55
|
764 VMSQueueStruc **readyToAnimateQs;
|
|
Me@31
|
765 int coreIdx;
|
|
Me@31
|
766 VirtProcr **masterVPs;
|
|
Me@31
|
767 SchedSlot ***allSchedSlots; //ptr to array of ptrs
|
|
Me@31
|
768
|
|
Me@65
|
769 //Before getting rid of everything, print out any measurements made
|
|
Me@68
|
770 forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, &printHist );
|
|
Me@68
|
771 //forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, &freeHistExt );
|
|
Me@65
|
772 #ifdef MEAS__TIME_PLUGIN
|
|
Me@68
|
773 printHist( _VMSMasterEnv->reqHdlrLowTimeHist );
|
|
Me@68
|
774 printHist( _VMSMasterEnv->reqHdlrHighTimeHist );
|
|
Me@68
|
775 freeHistExt( _VMSMasterEnv->reqHdlrLowTimeHist );
|
|
Me@68
|
776 freeHistExt( _VMSMasterEnv->reqHdlrHighTimeHist );
|
|
Me@65
|
777 #endif
|
|
Me@65
|
778 #ifdef MEAS__TIME_MALLOC
|
|
Me@65
|
779 printHist( _VMSMasterEnv->mallocTimeHist );
|
|
Me@65
|
780 printHist( _VMSMasterEnv->freeTimeHist );
|
|
Me@65
|
781 freeHistExt( _VMSMasterEnv->mallocTimeHist );
|
|
Me@65
|
782 freeHistExt( _VMSMasterEnv->freeTimeHist );
|
|
Me@65
|
783 #endif
|
|
Me@65
|
784 #ifdef MEAS__TIME_MASTER_LOCK
|
|
Me@65
|
785 printHist( _VMSMasterEnv->masterLockLowTimeHist );
|
|
Me@65
|
786 printHist( _VMSMasterEnv->masterLockHighTimeHist );
|
|
Me@65
|
787 #endif
|
|
Me@65
|
788 #ifdef MEAS__TIME_MASTER
|
|
Me@65
|
789 printHist( _VMSMasterEnv->pluginTimeHist );
|
|
Me@65
|
790 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
|
|
Me@65
|
791 {
|
|
Me@65
|
792 freeVMSQ( readyToAnimateQs[ coreIdx ] );
|
|
Me@65
|
793 //master VPs were created external to VMS, so use external free
|
|
Me@65
|
794 VMS__dissipate_procr( masterVPs[ coreIdx ] );
|
|
Me@65
|
795
|
|
Me@65
|
796 freeSchedSlots( allSchedSlots[ coreIdx ] );
|
|
Me@65
|
797 }
|
|
Me@65
|
798 #endif
|
|
Me@65
|
799 #ifdef MEAS__TIME_STAMP_SUSP
|
|
Me@65
|
800 printHist( _VMSMasterEnv->pluginTimeHist );
|
|
Me@65
|
801 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
|
|
Me@65
|
802 {
|
|
Me@65
|
803 freeVMSQ( readyToAnimateQs[ coreIdx ] );
|
|
Me@65
|
804 //master VPs were created external to VMS, so use external free
|
|
Me@65
|
805 VMS__dissipate_procr( masterVPs[ coreIdx ] );
|
|
Me@65
|
806
|
|
Me@65
|
807 freeSchedSlots( allSchedSlots[ coreIdx ] );
|
|
Me@65
|
808 }
|
|
Me@65
|
809 #endif
|
|
Me@65
|
810
|
|
Me@53
|
811 //All the environment data has been allocated with VMS__malloc, so just
|
|
Me@53
|
812 // free its internal big-chunk and all inside it disappear.
|
|
Me@53
|
813 /*
|
|
Me@31
|
814 readyToAnimateQs = _VMSMasterEnv->readyToAnimateQs;
|
|
Me@31
|
815 masterVPs = _VMSMasterEnv->masterVPs;
|
|
Me@31
|
816 allSchedSlots = _VMSMasterEnv->allSchedSlots;
|
|
Me@31
|
817
|
|
Me@31
|
818 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
|
|
Me@24
|
819 {
|
|
Me@55
|
820 freeVMSQ( readyToAnimateQs[ coreIdx ] );
|
|
Me@50
|
821 //master VPs were created external to VMS, so use external free
|
|
Me@53
|
822 VMS__dissipate_procr( masterVPs[ coreIdx ] );
|
|
Me@31
|
823
|
|
Me@31
|
824 freeSchedSlots( allSchedSlots[ coreIdx ] );
|
|
Me@24
|
825 }
|
|
Me@31
|
826
|
|
Me@53
|
827 VMS__free( _VMSMasterEnv->readyToAnimateQs );
|
|
Me@53
|
828 VMS__free( _VMSMasterEnv->masterVPs );
|
|
Me@53
|
829 VMS__free( _VMSMasterEnv->allSchedSlots );
|
|
Me@50
|
830
|
|
Me@50
|
831 //============================= MEASUREMENT STUFF ========================
|
|
Me@50
|
832 #ifdef STATS__TURN_ON_PROBES
|
|
Me@53
|
833 freeDynArrayDeep( _VMSMasterEnv->dynIntervalProbesInfo, &VMS__free_probe);
|
|
Me@50
|
834 #endif
|
|
Me@50
|
835 //========================================================================
|
|
Me@53
|
836 */
|
|
Me@53
|
837 //These are the only two that use system free
|
|
Me@53
|
838 VMS_ext__free_free_list( _VMSMasterEnv->freeListHead );
|
|
Me@53
|
839 free( (void *)_VMSMasterEnv );
|
|
Me@24
|
840 }
|
|
Me@24
|
841
|
|
Me@54
|
842
|
|
Me@54
|
843 //================================
|
|
Me@54
|
844
|
|
Me@54
|
845
|
|
Me@54
|
846 /*Later, improve this -- for now, just exits the application after printing
|
|
Me@54
|
847 * the error message.
|
|
Me@54
|
848 */
|
|
Me@54
|
849 void
|
|
Me@54
|
850 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData )
|
|
Me@54
|
851 {
|
|
Me@54
|
852 printf(msgStr);
|
|
Me@54
|
853 fflush(stdin);
|
|
Me@54
|
854 exit(1);
|
|
Me@54
|
855 }
|
|
Me@54
|
856
|