comparison VMS.c @ 71:5ff1631c26ed

working O3 version
author Merten Sach <msach@mailbox.tu-berlin.de>
date Mon, 30 May 2011 18:28:41 +0200
parents 11bfe9d136ed
children f6990e1ba998
comparison
equal deleted inserted replaced
36:053256974df1 38:90a67c3d0e5d
9 #include <string.h> 9 #include <string.h>
10 #include <malloc.h> 10 #include <malloc.h>
11 #include <sys/time.h> 11 #include <sys/time.h>
12 12
13 #include "VMS.h" 13 #include "VMS.h"
14 #include "SwitchAnimators.h"
14 #include "Queue_impl/BlockingQueue.h" 15 #include "Queue_impl/BlockingQueue.h"
15 #include "Histogram/Histogram.h" 16 #include "Histogram/Histogram.h"
16 17
17 18
18 #define thdAttrs NULL 19 #define thdAttrs NULL
74 { 75 {
75 create_masterEnv(); 76 create_masterEnv();
76 create_the_coreLoop_OS_threads(); 77 create_the_coreLoop_OS_threads();
77 } 78 }
78 79
80 #ifdef SEQUENTIAL
81
79 /*To initialize the sequential version, just don't create the threads 82 /*To initialize the sequential version, just don't create the threads
80 */ 83 */
81 void 84 void
82 VMS__init_Seq() 85 VMS__init_Seq()
83 { 86 {
84 create_masterEnv(); 87 create_masterEnv();
85 } 88 }
89
90 #endif
86 91
87 void 92 void
88 create_masterEnv() 93 create_masterEnv()
89 { MasterEnv *masterEnv; 94 { MasterEnv *masterEnv;
90 VMSQueueStruc **readyToAnimateQs; 95 VMSQueueStruc **readyToAnimateQs;
259 //NOTE: do not clean up VMS env here -- semantic layer has to have 264 //NOTE: do not clean up VMS env here -- semantic layer has to have
260 // a chance to clean up its environment first, then do a call to free 265 // a chance to clean up its environment first, then do a call to free
261 // the Master env and rest of VMS locations 266 // the Master env and rest of VMS locations
262 } 267 }
263 268
269 #ifdef SEQUENTIAL
264 /*Only difference between version with an OS thread pinned to each core and 270 /*Only difference between version with an OS thread pinned to each core and
265 * the sequential version of VMS is VMS__init_Seq, this, and coreLoop_Seq. 271 * the sequential version of VMS is VMS__init_Seq, this, and coreLoop_Seq.
266 */ 272 */
267 void 273 void
268 VMS__start_the_work_then_wait_until_done_Seq() 274 VMS__start_the_work_then_wait_until_done_Seq()
270 //Instead of un-suspending threads, just call the one and only 276 //Instead of un-suspending threads, just call the one and only
271 // core loop (sequential version), in the main thread. 277 // core loop (sequential version), in the main thread.
272 coreLoop_Seq( NULL ); 278 coreLoop_Seq( NULL );
273 279
274 } 280 }
275 281 #endif
276
277 282
278 /*Create stack, then create __cdecl structure on it and put initialData and 283 /*Create stack, then create __cdecl structure on it and put initialData and
279 * pointer to the new structure instance into the parameter positions on 284 * pointer to the new structure instance into the parameter positions on
280 * the stack 285 * the stack
281 *Then put function pointer into nextInstrPt -- the stack is setup in std 286 *Then put function pointer into nextInstrPt -- the stack is setup in std
376 381
377 //The request to master will cause this suspended virt procr to get 382 //The request to master will cause this suspended virt procr to get
378 // scheduled again at some future point -- to resume, core loop jumps 383 // scheduled again at some future point -- to resume, core loop jumps
379 // to the resume point (below), which causes restore of saved regs and 384 // to the resume point (below), which causes restore of saved regs and
380 // "return" from this call. 385 // "return" from this call.
381 animatingPr->nextInstrPt = &&ResumePt; 386 //animatingPr->nextInstrPt = &&ResumePt;
382 387
383 //return ownership of the virt procr and sched slot to Master virt pr 388 //return ownership of the virt procr and sched slot to Master virt pr
384 animatingPr->schedSlot->workIsDone = TRUE; 389 animatingPr->schedSlot->workIsDone = TRUE;
385 390
386 //=========================== Measurement stuff ======================== 391 //=========================== Measurement stuff ========================
388 //record time stamp: compare to time-stamp recorded below 393 //record time stamp: compare to time-stamp recorded below
389 saveLowTimeStampCountInto( animatingPr->preSuspTSCLow ); 394 saveLowTimeStampCountInto( animatingPr->preSuspTSCLow );
390 #endif 395 #endif
391 //======================================================================= 396 //=======================================================================
392 397
393 /* VirtProcr offsets: 398 switchToCoreLoop(animatingPr);
394 * 0xc stackPtr 399 flushRegisters();
395 * 0x10 framePtr
396 * 0x14 nextInstrPt
397 * 0x1c coreLoopFramePtr
398 * 0x20 coreLoopStackPtr
399 *
400 * _VMSMasterEnv offsets:
401 * 0x24 coreLoopStartPt
402 * 0x28 coreLoopEndPt
403 * 0x30 masterLock
404 */
405 // SwitchToCoreLoop( animatingPr )
406 asm volatile("movl %0, %%ebx; \
407 movl %1, %%ecx; \
408 movl %%esp, 0x0c(%%ecx); \
409 movl %%ebp, 0x10(%%ecx); \
410 movl 0x24(%%ebx), %%eax; \
411 movl 0x20(%%ecx), %%esp; \
412 movl 0x1c(%%ecx), %%ebp; \
413 jmp %%eax" \
414 /* outputs */ : \
415 /* inputs */ : "g"(_VMSMasterEnv), "g"(animatingPr) \
416 /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
417 );
418
419 // asm volatile("mov %0,%%ebx; \
420 mov %%ebx, %%eax; \
421 add $0xc, %%eax; \
422 movl %%esp, (%%eax); \
423 mov %%ebx, %%eax; \
424 add $0x10, %%eax; \
425 movl %%ebp, (%%eax); \
426 movl %1, %%eax; \
427 movl %2, %%esp; \
428 movl %3, %%ebp; \
429 jmp %%eax" \
430 /* outputs */ : \
431 /* inputs */ : "g"(animatingPr), "g" (jmpPt), "g" (coreLoopStackPtr), \
432 "g" (coreLoopFramePtr) \
433 /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
434 );
435 400
436 //======================================================================= 401 //=======================================================================
437 ResumePt: 402
438 #ifdef MEAS__TIME_STAMP_SUSP 403 #ifdef MEAS__TIME_STAMP_SUSP
439 //NOTE: only take low part of count -- do sanity check when take diff 404 //NOTE: only take low part of count -- do sanity check when take diff
440 saveLowTimeStampCountInto( animatingPr->postSuspTSCLow ); 405 saveLowTimeStampCountInto( animatingPr->postSuspTSCLow );
441 #endif 406 #endif
442 407
736 * to core loop function -- note that this slices out a level of virtual 701 * to core loop function -- note that this slices out a level of virtual
737 * processors). 702 * processors).
738 */ 703 */
739 void 704 void
740 endOSThreadFn( void *initData, VirtProcr *animatingPr ) 705 endOSThreadFn( void *initData, VirtProcr *animatingPr )
741 { void *jmpPt, *coreLoopStackPtr, *coreLoopFramePtr; 706 {
742 707 asmTerminateCoreLoop(animatingPr);
743 jmpPt = _VMSMasterEnv->coreLoopEndPt;
744 coreLoopStackPtr = animatingPr->coreLoopStackPtr;
745 coreLoopFramePtr = animatingPr->coreLoopFramePtr;
746
747
748 asm volatile("movl %0, %%eax; \
749 movl %1, %%esp; \
750 movl %2, %%ebp; \
751 jmp %%eax " \
752 /* outputs */ : \
753 /* inputs */ : "m" (jmpPt), "m"(coreLoopStackPtr), "m"(coreLoopFramePtr)\
754 /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi" \
755 );
756 } 708 }
757 709
758 710
759 /*This is called from the startup & shutdown 711 /*This is called from the startup & shutdown
760 */ 712 */