view VMS.h @ 26:668278fa7a63

Sequential -- just starting to add sequential version
author Me
date Mon, 26 Jul 2010 15:25:53 -0700
parents c556193f7211
children 8b9e4c333fe6
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 0x10000
27 #define SUCCESS 0
29 #define writeVMSQ writePThdQ
30 #define readVMSQ readPThdQ
31 #define makeVMSQ makePThdQ
32 #define VMSQueueStruc PThdQueueStruc
34 //#define thdAttrs NULL //For PThreads
36 typedef struct _SchedSlot SchedSlot;
37 typedef struct _VMSReqst VMSReqst;
38 typedef struct _VirtProcr VirtProcr;
40 typedef VirtProcr * (*SlaveScheduler) ( void * ); //semEnv
41 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
42 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
43 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
45 typedef struct
46 {
47 void *endThdPt;
48 unsigned int coreNum;
49 // void *framePtr;
50 // void *stackPtr;
51 }
52 ThdParams;
55 struct _SchedSlot
56 {
57 int workIsDone;
58 int needsProcrAssigned;
59 VirtProcr *procrAssignedToSlot;
60 };
61 //SchedSlot
63 enum ReqstType
64 {
65 semantic = 1,
66 dissipate,
67 regCreated,
68 IO
69 };
71 struct _VMSReqst
72 {
73 // VirtProcr *virtProcrFrom;
74 enum ReqstType reqType;//used for dissipate and in future for IO requests
75 void *semReqData;
77 VMSReqst *nextReqst;
78 };
79 //VMSReqst
81 struct _VirtProcr
82 { int procrID; //for debugging -- count up each time create
83 int coreAnimatedBy;
84 void *startOfStack;
85 void *stackPtr;
86 void *framePtr;
87 void *nextInstrPt;
89 void *coreLoopStartPt; //allows proto-runtime to be linked later
90 void *coreLoopFramePtr; //restore before jmp back to core loop
91 void *coreLoopStackPtr; //restore before jmp back to core loop
93 void *initialData;
95 SchedSlot *schedSlot;
96 VMSReqst *requests;
98 void *semanticData;
99 };
100 //VirtProcr
104 typedef struct
105 {
106 SlaveScheduler slaveScheduler;
107 RequestHandler requestHandler;
109 SchedSlot **schedSlots;
110 SchedSlot **filledSlots;
111 int numToPrecede;
113 volatile int stillRunning;
115 VirtProcr *masterVirtPr;
117 void *semanticEnv;
118 void *OSEventStruc; //for future, when add I/O to BLIS
120 void *coreLoopShutDownPt; //addr to jump to to shut down a coreLoop
122 int setupComplete;
123 }
124 MasterEnv;
127 //==========================================================
129 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
130 void masterLoop( void *initData, VirtProcr *masterPr );
133 //===================== Global Vars ===================
136 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
137 ThdParams *coreLoopThdParams [ NUM_CORES ];
138 pthread_mutex_t suspendLock;
139 pthread_cond_t suspend_cond;
141 volatile MasterEnv *_VMSMasterEnv;
143 //workQ is global, static, and volatile so that core loop has its location
144 // hard coded, and reloads every time through the loop -- that way don't
145 // need to save any regs used by core loop
146 volatile VMSQueueStruc *_VMSWorkQ;
148 //==========================
149 void
150 VMS__init();
152 void
153 VMS__start_the_work_then_wait_until_done();
155 VirtProcr *
156 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
158 VirtProcr *
159 VMS__create_the_shutdown_procr();
161 //==========================
162 inline void
163 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
165 void
166 VMS__send_register_new_procr_request( VirtProcr *newPrToRegister,
167 VirtProcr *reqstingPr );
169 void
170 VMS__free_request( VMSReqst *req );
172 void
173 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
175 VMSReqst *
176 VMS__take_top_request_from( VirtProcr *reqstingPr );
178 inline void *
179 VMS__take_sem_reqst_from( VMSReqst *req );
181 inline int
182 VMS__isSemanticReqst( VMSReqst *req );
184 inline int
185 VMS__isDissipateReqst( VMSReqst *req );
187 inline int
188 VMS__isCreateReqst( VMSReqst *req );
190 //==========================
192 void
193 VMS__suspend_procr( VirtProcr *callingPr );
195 void
196 VMS__dissipate_procr( VirtProcr *prToDissipate );
198 void
199 VMS__shutdown();
201 //============================= Statistics ==================================
203 typedef unsigned long long TSCount;
205 //Frequency of TS counts
206 //TODO: change freq for each machine
207 #define TSCOUNT_FREQ 3180000000
209 #define saveTimeStampCountInto(low, high) \
210 asm volatile("RDTSC; \
211 movl %%eax, %0; \
212 movl %%edx, %1;" \
213 /* outputs */ : "=m" (low), "=m" (high)\
214 /* inputs */ : \
215 /* clobber */ : "%eax", "%edx" \
216 );
218 inline TSCount getTSCount();
220 //===================== Debug ==========================
221 int numProcrsCreated;
224 #endif /* _VMS_H */