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