view VMS.h @ 24:2b161e1a50ee

1st working version -- as far as can tell due to SEH bugs
author Me
date Wed, 07 Jul 2010 13:15:54 -0700
parents aa634ef7cc35
children c556193f7211
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 _VMSReqst 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 regCreated,
63 IO
64 };
66 struct _VMSReqst
67 {
68 // VirtProcr *virtProcrFrom;
69 enum ReqstType reqType;//used for dissipate and in future for IO requests
70 void *semReqData;
72 VMSReqst *nextReqst;
73 };
74 //VMSReqst
76 struct _VirtProcr
77 { int procrID; //for debugging -- count up each time create
78 int coreAnimatedBy;
79 void *startOfStack;
80 void *stackPtr;
81 void *framePtr;
82 void *nextInstrPt;
84 void *coreLoopStartPt; //allows proto-runtime to be linked later
85 void *coreLoopFramePtr; //restore before jmp back to core loop
86 void *coreLoopStackPtr; //restore before jmp back to core loop
88 void *initialData;
90 SchedSlot *schedSlot;
91 VMSReqst *requests;
93 void *semanticData;
94 };
95 //VirtProcr
99 typedef struct
100 {
101 SlaveScheduler slaveScheduler;
102 RequestHandler requestHandler;
104 SchedSlot **schedSlots;
105 SchedSlot **filledSlots;
106 int numFilled;
108 int stillRunning;
110 VirtProcr *masterVirtPr;
111 void *semanticEnv;
112 void *OSEventStruc; //for future, when add I/O to BLIS
114 void *coreLoopShutDownPt; //addr to jump to to shut down a coreLoop
115 }
116 MasterEnv;
119 //==========================================================
121 DWORD WINAPI coreLoop( LPVOID paramsIn );
122 //void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
123 void masterLoop( void *initData, VirtProcr *masterPr );
126 //===================== Global Vars ===================
129 HANDLE coreLoopThdHandles[ NUM_CORES ]; //windows handle to thread
130 ThdParams *coreLoopThdParams[ NUM_CORES ];
131 DWORD coreLoopThdIds[ NUM_CORES ];
133 //TODO: Debug: figure out if need to be volatile or not
134 volatile MasterEnv *_VMSMasterEnv;
136 //workQ is global, static, and volatile so that core loop has its location
137 // hard coded, and reloads every time through the loop -- that way don't
138 // need to save any regs used by core loop (will see if this really works)
139 volatile CASQueueStruc *_VMSWorkQ;
141 //==========================
142 void
143 VMS__init();
145 void
146 VMS__start_the_work_then_wait_until_done();
148 VirtProcr *
149 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
151 VirtProcr *
152 VMS__create_the_shutdown_procr();
154 //==========================
155 inline void
156 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
158 void
159 VMS__send_register_new_procr_request( VirtProcr *newPrToRegister,
160 VirtProcr *reqstingPr );
162 void
163 VMS__free_request( VMSReqst *req );
165 void
166 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
168 VMSReqst *
169 VMS__take_top_request_from( VirtProcr *reqstingPr );
171 inline void *
172 VMS__take_sem_reqst_from( VMSReqst *req );
174 inline int
175 VMS__isSemanticReqst( VMSReqst *req );
177 inline int
178 VMS__isDissipateReqst( VMSReqst *req );
180 inline int
181 VMS__isCreateReqst( VMSReqst *req );
183 //==========================
185 void
186 VMS__suspend_procr( VirtProcr *callingPr );
188 void
189 VMS__dissipate_procr( VirtProcr *prToDissipate );
191 void
192 VMS__shutdown();
194 //============================= Statistics ==================================
196 typedef unsigned long long TSCount;
198 #define saveTimeStampCountInto(low, high) \
199 asm volatile("RDTSC; \
200 movl %%eax, %0; \
201 movl %%edx, %1;" \
202 /* outputs */ : "=m" (low), "=m" (high)\
203 /* inputs */ : \
204 /* clobber */ : "%eax", "%edx" \
205 );
207 inline TSCount getTSCount();
209 //===================== Debug ==========================
210 int numProcrsCreated;
213 #endif /* _VMS_H */