view VMS.h @ 37:d6367cd40e21

Change in a comment from VMSHW to SSR
author Me
date Wed, 01 Sep 2010 09:18:40 -0700
parents 0e008278fe3c
children e69579a0e797
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
11 #define __USE_GNU
13 #include "VMS_primitive_data_types.h"
14 #include "Queue_impl/BlockingQueue.h"
15 #include <pthread.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)
23 #define NUM_SCHED_SLOTS 3
25 // 8K stack
26 #define VIRT_PROCR_STACK_SIZE 0x20000
28 //256M of total memory for VMS application to VMS__malloc
29 #define MASSIVE_MALLOC_SIZE 0x10000000
31 #define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem);
33 #define SUCCESS 0
35 #define writeVMSQ writeCASQ
36 #define readVMSQ readCASQ
37 #define makeVMSQ makeCASQ
38 #define VMSQueueStruc CASQueueStruc
40 //#define thdAttrs NULL //For PThreads
42 typedef struct _SchedSlot SchedSlot;
43 typedef struct _VMSReqst VMSReqst;
44 typedef struct _VirtProcr VirtProcr;
46 typedef VirtProcr * (*SlaveScheduler) ( void * ); //semEnv
47 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
48 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
49 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
51 typedef struct
52 {
53 void *endThdPt;
54 unsigned int coreNum;
55 // void *framePtr;
56 // void *stackPtr;
57 }
58 ThdParams;
61 struct _SchedSlot
62 {
63 int workIsDone;
64 int needsProcrAssigned;
65 VirtProcr *procrAssignedToSlot;
66 };
67 //SchedSlot
69 enum ReqstType
70 {
71 semantic = 1,
72 dissipate,
73 regCreated,
74 IO
75 };
77 struct _VMSReqst
78 {
79 // VirtProcr *virtProcrFrom;
80 enum ReqstType reqType;//used for dissipate and in future for IO requests
81 void *semReqData;
83 VMSReqst *nextReqst;
84 };
85 //VMSReqst
87 struct _VirtProcr
88 { int procrID; //for debugging -- count up each time create
89 int coreAnimatedBy;
90 void *startOfStack;
91 void *stackPtr;
92 void *framePtr;
93 void *nextInstrPt;
95 void *coreLoopStartPt; //allows proto-runtime to be linked later
96 void *coreLoopFramePtr; //restore before jmp back to core loop
97 void *coreLoopStackPtr; //restore before jmp back to core loop
99 void *initialData;
101 SchedSlot *schedSlot;
102 VMSReqst *requests;
104 void *semanticData;
105 };
106 //VirtProcr
110 typedef struct
111 {
112 SlaveScheduler slaveScheduler;
113 RequestHandler requestHandler;
115 SchedSlot **schedSlots;
116 SchedSlot **filledSlots;
117 int numToPrecede;
119 volatile int stillRunning;
121 VirtProcr *masterVirtPr;
123 void *semanticEnv;
124 void *OSEventStruc; //for future, when add I/O to BLIS
126 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
128 int setupComplete;
130 void *mallocChunk;
131 }
132 MasterEnv;
135 //==========================================================
137 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
138 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
139 void masterLoop( void *initData, VirtProcr *masterPr );
142 //===================== Global Vars ===================
145 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
146 ThdParams *coreLoopThdParams [ NUM_CORES ];
147 pthread_mutex_t suspendLock;
148 pthread_cond_t suspend_cond;
150 volatile MasterEnv *_VMSMasterEnv;
152 //workQ is global, static, and volatile so that core loop has its location
153 // hard coded, and reloads every time through the loop -- that way don't
154 // need to save any regs used by core loop
155 volatile VMSQueueStruc *_VMSWorkQ;
157 //==========================
158 void
159 VMS__init();
161 void
162 VMS__init_Seq();
164 void
165 VMS__start_the_work_then_wait_until_done();
167 void
168 VMS__start_the_work_then_wait_until_done_Seq();
170 VirtProcr *
171 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
173 VirtProcr *
174 VMS__create_the_shutdown_procr();
176 //==========================
177 inline void
178 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
180 void
181 VMS__send_register_new_procr_request( VirtProcr *newPrToRegister,
182 VirtProcr *reqstingPr );
184 void
185 VMS__free_request( VMSReqst *req );
187 void
188 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
190 VMSReqst *
191 VMS__take_top_request_from( VirtProcr *reqstingPr );
193 inline void *
194 VMS__take_sem_reqst_from( VMSReqst *req );
196 inline int
197 VMS__isSemanticReqst( VMSReqst *req );
199 inline int
200 VMS__isDissipateReqst( VMSReqst *req );
202 inline int
203 VMS__isCreateReqst( VMSReqst *req );
205 //==========================
207 void
208 VMS__suspend_procr( VirtProcr *callingPr );
210 void
211 VMS__dissipate_procr( VirtProcr *prToDissipate );
213 void
214 VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate );
216 void
217 VMS__cleanup_after_shutdown();
219 //============================= Statistics ==================================
221 typedef unsigned long long TSCount;
223 //Frequency of TS counts
224 //TODO: change freq for each machine
225 #define TSCOUNT_FREQ 3180000000
227 #define saveTimeStampCountInto(low, high) \
228 asm volatile("RDTSC; \
229 movl %%eax, %0; \
230 movl %%edx, %1;" \
231 /* outputs */ : "=m" (low), "=m" (high)\
232 /* inputs */ : \
233 /* clobber */ : "%eax", "%edx" \
234 );
236 inline TSCount getTSCount();
238 //===================== Debug ==========================
239 int numProcrsCreated;
242 #endif /* _VMS_H */