view VMS.h @ 23:aa634ef7cc35

Full VMS test -- works
author Me
date Wed, 30 Jun 2010 13:11:06 -0700
parents c3e6c3fda84e
children 2b161e1a50ee
line source
1 /*
2 * Copyright 2009 OpenSourceStewardshipFoundation.org
3 * Licensed under GNU General Public License version 2
4 *
5 * Author: seanhalle@yahoo.com
6 *
7 */
9 #ifndef _VMS_H
10 #define _VMS_H
12 #include "VMS_primitive_data_types.h"
13 #include "Queue_impl/BlockingQueue.h"
14 #include <windows.h>
15 #include <winbase.h>
17 //This value is the number of hardware threads in the shared memory
18 // machine
19 #define NUM_CORES 4
21 // make double-num-cores scheduling slots, plus extra for master
22 #define NUM_SCHED_SLOTS (2 * NUM_CORES + 1)
24 //128K stack.. compromise, want 10K virtPr
25 #define VIRT_PROCR_STACK_SIZE 0x100000
27 #define SUCCESS 0
29 //#define thdAttrs NULL //For PThreads
31 typedef struct _SchedSlot SchedSlot;
32 typedef struct _SlaveReqst VMSReqst;
33 typedef struct _VirtProcr VirtProcr;
35 typedef VirtProcr * (*SlaveScheduler) ( void * ); //semEnv
36 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
37 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
38 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
40 typedef struct
41 {
42 void *endThdPt;
43 unsigned int coreNum;
44 // void *framePtr;
45 // void *stackPtr;
46 }
47 ThdParams;
50 struct _SchedSlot
51 {
52 int workIsDone;
53 int needsProcrAssigned;
54 VirtProcr *procrAssignedToSlot;
55 };
56 //SchedSlot
58 enum ReqstType
59 {
60 semantic = 1,
61 dissipate,
62 IO
63 };
65 struct _SlaveReqst
66 {
67 // VirtProcr *virtProcrFrom;
68 enum ReqstType reqType; //used for dissipate and in future for IO requests
69 void *semReqData;
71 VMSReqst *nextReqst;
72 };
73 //SlaveReqst
75 struct _VirtProcr
76 { int procrID; //for debugging -- count up each time create
77 int coreAnimatedBy;
78 void *startOfStack;
79 void *stackPtr;
80 void *framePtr;
81 void *nextInstrPt;
83 void *coreLoopStartPt; //allows proto-runtime to be linked later
84 void *coreLoopFramePtr; //restore before jmp back to core loop
85 void *coreLoopStackPtr; //restore before jmp back to core loop
87 void *initialData;
89 SchedSlot *schedSlot;
90 VMSReqst *requests;
92 void *semanticData;
93 };
94 //VirtProcr
98 typedef struct
99 {
100 SlaveScheduler slaveScheduler;
101 RequestHandler requestHandler;
103 SchedSlot **schedSlots;
104 SchedSlot **filledSlots;
105 int numFilled;
107 int stillRunning;
109 VirtProcr *masterVirtPr;
110 void *semanticEnv;
111 void *OSEventStruc; //for future, when add I/O to BLIS
113 void *coreLoopShutDownPt; //addr to jump to to shut down a coreLoop
114 }
115 MasterEnv;
118 //==========================================================
120 DWORD WINAPI coreLoop( LPVOID paramsIn );
121 //void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
122 void masterLoop( void *initData, VirtProcr *masterPr );
125 //===================== Global Vars ===================
128 HANDLE coreLoopThdHandles[ NUM_CORES ]; //windows handle to thread
129 ThdParams *coreLoopThdParams[ NUM_CORES ];
130 DWORD coreLoopThdIds[ NUM_CORES ];
132 //TODO: Debug: figure out if need to be volatile or not
133 volatile MasterEnv *_VMSMasterEnv;
135 //workQ is global, static, and volatile so that core loop has its location
136 // hard coded, and reloads every time through the loop -- that way don't
137 // need to save any regs used by core loop (will see if this really works)
138 volatile CASQueueStruc *_VMSWorkQ;
140 //==========================
141 void
142 VMS__init();
144 void
145 VMS__start();
147 VirtProcr *
148 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
150 VirtProcr *
151 VMS__create_the_shutdown_procr();
153 inline void
154 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
156 void
157 VMS__send_dissipate_request( VirtProcr *procrToDissipate );
159 void
160 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
162 void
163 VMS__suspend_procr( VirtProcr *callingPr );
165 void
166 VMS__dissipate_procr( VirtProcr *prToDissipate );
168 void
169 VMS__shutdown();
171 //============================= Statistics ==================================
173 typedef unsigned long long TSCount;
175 #define saveTimeStampCountInto(low, high) \
176 asm volatile("RDTSC; \
177 movl %%eax, %0; \
178 movl %%edx, %1;" \
179 /* outputs */ : "=m" (low), "=m" (high)\
180 /* inputs */ : \
181 /* clobber */ : "%eax", "%edx" \
182 );
184 inline TSCount getTSCount();
186 //===================== Debug ==========================
187 int numProcrsCreated;
190 #endif /* _VMS_H */