view VMS.h @ 14:65c8fb2821ee

Forgot to commit after had working test -- changed stack & frame ptrs in thd params to be instead in virt procr struc -- stopped working! Saving now, then going back to way had it..
author Me
date Tue, 22 Jun 2010 11:52:41 -0700
parents f96e4b3b35c7
children c3e6c3fda84e
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 -- make double that number scheduling slots, plus extra for master
19 #define NUM_CORES 4
20 #define NUM_SCHED_SLOTS 9
22 #define SUCCESS 0
24 //#define thdAttrs NULL //For PThreads
26 typedef struct _WorkUnit WorkUnit;
27 typedef struct _VirtProcr VirtProcr;
28 typedef struct _SlaveReqst SlaveReqst;
29 typedef struct _SchedSlot SchedSlot;
31 typedef bool8 (*SlaveScheduler) ( SchedSlot *, void * );
32 typedef void (*RequestHandler) ( SlaveReqst * );
33 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * );
34 typedef void VirtProcrFn( void *, VirtProcr * );
36 typedef struct
37 {
38 void *endThdPt;
39 unsigned int coreNum;
40 }
41 ThdParams;
43 struct _SchedSlot
44 {
45 int workIsDone;
46 int needsProcrAssigned;
47 VirtProcr *procrAssignedToSlot;
48 };
51 struct _VirtProcr
52 { int procrID; //for debugging -- count up each time create
53 void *stackPtr;
54 void *framePtr;
55 void *nextInstrPt;
56 void *coreLoopStartPt; //allows proto-runtime to be linked later
58 void *initialData;
60 SchedSlot *schedSlot;
61 SlaveReqst *requests;
63 void *semanticData;
64 };
67 //When optimize make a separate flat array in here for each flag in SchedSlot
68 //So that polling done flags is fast.. not sure even worth it, though..
69 typedef struct
70 {
71 SlaveScheduler slaveScheduler;
72 RequestHandler requestHandler;
74 SchedSlot **schedSlots;
75 SchedSlot **filledSlots;
76 int numFilled;
78 int stillRunning;
80 VirtProcr *masterVirtPr;
81 void *semanticEnv;
82 void *OSEventStruc; //for future, when add I/O to BLIS
83 }
84 MasterEnv;
88 struct _SlaveReqst
89 {
90 VirtProcr *slaveFrom;
91 int reqType; //for future when have I/O and OS services
92 void *semReqData;
94 SlaveReqst *nextRequest;
95 };
98 DWORD WINAPI coreLoop( LPVOID paramsIn );
99 //void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
100 void masterLoop( void *initData, VirtProcr *masterPr );
103 //===================== Global Vars ===================
106 HANDLE coreLoopThdHandles[ NUM_CORES ]; //windows handle to thread
107 ThdParams *coreLoopThdParams[ NUM_CORES ];
108 DWORD coreLoopThdIds[ NUM_CORES ];
110 //TODO: Debug: figure out if need to be volatile or not
111 volatile MasterEnv *_VMSMasterEnv;
113 //workQ is global, static, and volatile so that core loop has its location
114 // hard coded, and reloads every time through the loop -- that way don't
115 // need to save any regs used by core loop (will see if this really works)
116 volatile CASQueueStruc *_VMSWorkQ;
118 //==========================
119 void
120 VMS__init();
122 void
123 VMS__start();
125 VirtProcr *
126 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
128 inline void
129 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
131 void
132 VMS__suspend_processor( VirtProcr *callingPr );
134 //============================= Statistics ==================================
136 typedef unsigned long long TSCount;
138 #define saveTimeStampCountInto(low, high) \
139 asm volatile("RDTSC; \
140 movl %%eax, %0; \
141 movl %%edx, %1;" \
142 /* outputs */ : "=m" (low), "=m" (high)\
143 /* inputs */ : \
144 /* clobber */ : "%eax", "%edx" \
145 );
147 inline TSCount getTSCount();
149 int numProcrsCreated;
151 #endif /* _VMS_H */