view VMS.h @ 25:c556193f7211

Linux Version -- first set of mods changing from win to linux
author Me
date Sat, 24 Jul 2010 08:58:47 -0700
parents 2b161e1a50ee
children 668278fa7a63
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)
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;
112 void *semanticEnv;
113 void *OSEventStruc; //for future, when add I/O to BLIS
115 void *coreLoopShutDownPt; //addr to jump to to shut down a coreLoop
117 int setupComplete;
118 pthread_mutex_t suspend_mutex;
119 pthread_cond_t suspend_cond;
120 }
121 MasterEnv;
124 //==========================================================
126 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
127 void masterLoop( void *initData, VirtProcr *masterPr );
130 //===================== Global Vars ===================
133 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
134 ThdParams *coreLoopThdParams[ NUM_CORES ];
136 volatile MasterEnv *_VMSMasterEnv;
138 //workQ is global, static, and volatile so that core loop has its location
139 // hard coded, and reloads every time through the loop -- that way don't
140 // need to save any regs used by core loop
141 volatile CASQueueStruc *_VMSWorkQ;
143 //==========================
144 void
145 VMS__init();
147 void
148 VMS__start_the_work_then_wait_until_done();
150 VirtProcr *
151 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
153 VirtProcr *
154 VMS__create_the_shutdown_procr();
156 //==========================
157 inline void
158 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
160 void
161 VMS__send_register_new_procr_request( VirtProcr *newPrToRegister,
162 VirtProcr *reqstingPr );
164 void
165 VMS__free_request( VMSReqst *req );
167 void
168 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
170 VMSReqst *
171 VMS__take_top_request_from( VirtProcr *reqstingPr );
173 inline void *
174 VMS__take_sem_reqst_from( VMSReqst *req );
176 inline int
177 VMS__isSemanticReqst( VMSReqst *req );
179 inline int
180 VMS__isDissipateReqst( VMSReqst *req );
182 inline int
183 VMS__isCreateReqst( VMSReqst *req );
185 //==========================
187 void
188 VMS__suspend_procr( VirtProcr *callingPr );
190 void
191 VMS__dissipate_procr( VirtProcr *prToDissipate );
193 void
194 VMS__shutdown();
196 //============================= Statistics ==================================
198 typedef unsigned long long TSCount;
200 //Frequency of TS counts
201 //TODO: change freq for each machine
202 #define TSCOUNT_FREQ 3180000000
204 #define saveTimeStampCountInto(low, high) \
205 asm volatile("RDTSC; \
206 movl %%eax, %0; \
207 movl %%edx, %1;" \
208 /* outputs */ : "=m" (low), "=m" (high)\
209 /* inputs */ : \
210 /* clobber */ : "%eax", "%edx" \
211 );
213 inline TSCount getTSCount();
215 //===================== Debug ==========================
216 int numProcrsCreated;
219 #endif /* _VMS_H */