view VMS.h @ 18:734c665500e4

Kinda have test working -- assembly looks right for saving core loop frame and stack and restoring them But have a bug that looks timing-related, so thinking maybe some threads are going to completion? The whole test isn't quite right yet -- it throws exception because the suspended virtual processors never have a continuation put back into the workQ (is this right? Is that why it throws exception?) Want to move to full code to finish debugging
author Me
date Tue, 22 Jun 2010 12:37:43 -0700
parents 4b58b9a2527b
children aa634ef7cc35
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 _SchedSlot SchedSlot;
27 typedef struct _SlaveReqst SlaveReqst;
28 typedef struct _VirtProcr VirtProcr;
30 typedef bool8 (*SlaveScheduler) ( SchedSlot *, void * );
31 typedef void (*RequestHandler) ( SlaveReqst * );
32 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * );
33 typedef void VirtProcrFn( void *, VirtProcr * );
36 typedef struct
37 {
38 void *endThdPt;
39 unsigned int coreNum;
40 // void *framePtr;
41 // void *stackPtr;
42 }
43 ThdParams;
46 struct _SchedSlot
47 {
48 int workIsDone;
49 int needsProcrAssigned;
50 VirtProcr *procrAssignedToSlot;
51 };
52 //SchedSlot
55 struct _SlaveReqst
56 {
57 VirtProcr *slaveFrom;
58 int reqType; //for future when have I/O and OS services
59 void *semReqData;
61 SlaveReqst *nextRequest;
62 };
63 //SlaveReqst
65 struct _VirtProcr
66 { int procrID; //for debugging -- count up each time create
67 int coreAnimatedBy;
68 void *stackPtr;
69 void *framePtr;
70 void *nextInstrPt;
72 void *coreLoopStartPt; //allows proto-runtime to be linked later
73 void *coreLoopFramePtr; //restore before jmp back to core loop
74 void *coreLoopStackPtr; //restore before jmp back to core loop
76 void *initialData;
78 SchedSlot *schedSlot;
79 SlaveReqst *requests;
81 void *semanticData;
82 };
83 //VirtProcr
87 typedef struct
88 {
89 SlaveScheduler slaveScheduler;
90 RequestHandler requestHandler;
92 SchedSlot **schedSlots;
93 SchedSlot **filledSlots;
94 int numFilled;
96 int stillRunning;
98 VirtProcr *masterVirtPr;
99 void *semanticEnv;
100 void *OSEventStruc; //for future, when add I/O to BLIS
102 void *coreLoopShutDownPt; //addr to jump to to shut down a coreLoop
103 }
104 MasterEnv;
107 //==========================================================
109 DWORD WINAPI coreLoop( LPVOID paramsIn );
110 //void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
111 void masterLoop( void *initData, VirtProcr *masterPr );
114 //===================== Global Vars ===================
117 HANDLE coreLoopThdHandles[ NUM_CORES ]; //windows handle to thread
118 ThdParams *coreLoopThdParams[ NUM_CORES ];
119 DWORD coreLoopThdIds[ NUM_CORES ];
121 //TODO: Debug: figure out if need to be volatile or not
122 volatile MasterEnv *_VMSMasterEnv;
124 //workQ is global, static, and volatile so that core loop has its location
125 // hard coded, and reloads every time through the loop -- that way don't
126 // need to save any regs used by core loop (will see if this really works)
127 volatile CASQueueStruc *_VMSWorkQ;
129 //==========================
130 void
131 VMS__init();
133 void
134 VMS__start();
136 VirtProcr *
137 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
139 inline void
140 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
142 void
143 VMS__suspend_processor( VirtProcr *callingPr );
145 //============================= Statistics ==================================
147 typedef unsigned long long TSCount;
149 #define saveTimeStampCountInto(low, high) \
150 asm volatile("RDTSC; \
151 movl %%eax, %0; \
152 movl %%edx, %1;" \
153 /* outputs */ : "=m" (low), "=m" (high)\
154 /* inputs */ : \
155 /* clobber */ : "%eax", "%edx" \
156 );
158 inline TSCount getTSCount();
160 int numProcrsCreated;
162 #endif /* _VMS_H */