Mercurial > hg > Members > menikon > CbC_xv6
comparison src/context.h @ 52:214d21c891c7
rename to cbc
__ncode is not handled as interfaces
author | kono |
---|---|
date | Mon, 03 Jun 2019 18:12:44 +0900 |
parents | fadfd62d6b14 |
children | 435bfab09924 |
comparison
equal
deleted
inserted
replaced
51:fadfd62d6b14 | 52:214d21c891c7 |
---|---|
1 /* Context definition for llrb example */ | 1 /* Context definition for llrb example */ |
2 #ifdef CONTEXT_H | 2 // #ifdef CBC_CONTEXT_H does not work well |
3 #define CONTEXT_H | 3 #define CBC_CONTEXT_H |
4 #include <stdlib.h> | 4 // #include <stdlib.h> |
5 #include <pthread.h> | 5 // #include <pthread.h> |
6 #ifdef USE_CUDAWorker | 6 #ifdef USE_CUDAWorker |
7 #include <cuda.h> | 7 #include <cuda.h> |
8 #include <driver_types.h> | 8 #include <driver_types.h> |
9 #include <cuda_runtime.h> | 9 #include <cuda_runtime.h> |
10 #include "helper_cuda.h" | 10 #include "helper_cuda.h" |
11 #endif | 11 #endif |
12 | 12 |
13 #include "use_context_numbers.h" | 13 // #include "use_context_numbers.h" |
14 | 14 |
15 #define ALLOCATE_SIZE 20000000 | 15 #define ALLOCATE_SIZE 20000000 |
16 #define NEW(type) (type*)(calloc(1, sizeof(type))) | 16 #define NEW(type) (type*)(calloc(1, sizeof(type))) |
17 #define NEWN(n, type) (type*)(calloc(n, sizeof(type))) | 17 #define NEWN(n, type) (type*)(calloc(n, sizeof(type))) |
18 | 18 |
19 #define ALLOC_DATA(context, dseg) ({\ | 19 #define ALLOC_DATA(cbc_context, dseg) ({\ |
20 Meta* meta = (Meta*)context->heap;\ | 20 Meta* meta = (Meta*)cbc_context->heap;\ |
21 meta->type = D_##dseg;\ | 21 meta->type = D_##dseg;\ |
22 meta->size = sizeof(dseg);\ | 22 meta->size = sizeof(dseg);\ |
23 meta->len = 1;\ | 23 meta->len = 1;\ |
24 context->heap += sizeof(Meta);\ | 24 cbc_context->heap += sizeof(Meta);\ |
25 context->data[D_##dseg] = context->heap; context->heap += sizeof(dseg); (dseg *)context->data[D_##dseg]; }) | 25 cbc_context->data[D_##dseg] = cbc_context->heap; cbc_context->heap += sizeof(dseg); (dseg *)cbc_context->data[D_##dseg]; }) |
26 | 26 |
27 #define ALLOC_DATA_TYPE(context, dseg, t) ({\ | 27 #define ALLOC_DATA_TYPE(cbc_context, dseg, t) ({\ |
28 Meta* meta = (Meta*)context->heap;\ | 28 Meta* meta = (Meta*)cbc_context->heap;\ |
29 meta->type = D_##t;\ | 29 meta->type = D_##t;\ |
30 meta->size = sizeof(t);\ | 30 meta->size = sizeof(t);\ |
31 meta->len = 1;\ | 31 meta->len = 1;\ |
32 context->heap += sizeof(Meta);\ | 32 cbc_context->heap += sizeof(Meta);\ |
33 context->data[D_##dseg] = context->heap; context->heap += sizeof(t); (t *)context->data[D_##dseg]; }) | 33 cbc_context->data[D_##dseg] = cbc_context->heap; cbc_context->heap += sizeof(t); (t *)cbc_context->data[D_##dseg]; }) |
34 | 34 |
35 #define ALLOCATE(context, t) ({ \ | 35 #define ALLOCATE(cbc_context, t) ({ \ |
36 Meta* meta = (Meta*)context->heap;\ | 36 Meta* meta = (Meta*)cbc_context->heap;\ |
37 context->heap += sizeof(Meta);\ | 37 cbc_context->heap += sizeof(Meta);\ |
38 union Data* data = context->heap; \ | 38 union Data* data = cbc_context->heap; \ |
39 context->heap += sizeof(t); \ | 39 cbc_context->heap += sizeof(t); \ |
40 meta->type = D_##t; \ | 40 meta->type = D_##t; \ |
41 meta->size = sizeof(t); \ | 41 meta->size = sizeof(t); \ |
42 meta->len = 1;\ | 42 meta->len = 1;\ |
43 data; }) | 43 data; }) |
44 | 44 |
45 #define ALLOCATE_ARRAY(context, t, length) ({ \ | 45 #define ALLOCATE_ARRAY(cbc_context, t, length) ({ \ |
46 Meta* meta = (Meta*)context->heap;\ | 46 Meta* meta = (Meta*)cbc_context->heap;\ |
47 context->heap += sizeof(Meta);\ | 47 cbc_context->heap += sizeof(Meta);\ |
48 union Data* data = context->heap; \ | 48 union Data* data = cbc_context->heap; \ |
49 context->heap += sizeof(t)*length; \ | 49 cbc_context->heap += sizeof(t)*length; \ |
50 meta->type = D_##t; \ | 50 meta->type = D_##t; \ |
51 meta->size = sizeof(t)*length; \ | 51 meta->size = sizeof(t)*length; \ |
52 meta->len = length; \ | 52 meta->len = length; \ |
53 data; }) | 53 data; }) |
54 | 54 |
55 #define ALLOCATE_PTR_ARRAY(context, dseg, length) ({\ | 55 #define ALLOCATE_PTR_ARRAY(cbc_context, dseg, length) ({\ |
56 Meta* meta = (Meta*)context->heap;\ | 56 Meta* meta = (Meta*)cbc_context->heap;\ |
57 context->heap += sizeof(Meta);\ | 57 cbc_context->heap += sizeof(Meta);\ |
58 union Data* data = context->heap; \ | 58 union Data* data = cbc_context->heap; \ |
59 context->heap += sizeof(dseg *)*length; \ | 59 cbc_context->heap += sizeof(dseg *)*length; \ |
60 meta->type = D_##dseg; \ | 60 meta->type = D_##dseg; \ |
61 meta->size = sizeof(dseg *)*length; \ | 61 meta->size = sizeof(dseg *)*length; \ |
62 meta->len = length; \ | 62 meta->len = length; \ |
63 data; }) | 63 data; }) |
64 | 64 |
65 #define ALLOCATE_DATA_GEAR(context, t) ({ \ | 65 #define ALLOCATE_DATA_GEAR(cbc_context, t) ({ \ |
66 union Data* data = ALLOCATE(context, t); \ | 66 union Data* data = ALLOCATE(cbc_context, t); \ |
67 Meta* meta = GET_META(data); \ | 67 Meta* meta = GET_META(data); \ |
68 meta->wait = createSynchronizedQueue(context); \ | 68 meta->wait = createSynchronizedQueue(cbc_context); \ |
69 data; }) | 69 data; }) |
70 | 70 |
71 #define ALLOC(context, t) (&ALLOCATE(context, t)->t) | 71 #define ALLOC(cbc_context, t) (&ALLOCATE(cbc_context, t)->t) |
72 | 72 |
73 #define GET_META(dseg) ((Meta*)(((void*)dseg) - sizeof(Meta))) | 73 #define GET_META(dseg) ((Meta*)(((void*)dseg) - sizeof(Meta))) |
74 #define GET_TYPE(dseg) (GET_META(dseg)->type) | 74 #define GET_TYPE(dseg) (GET_META(dseg)->type) |
75 #define GET_SIZE(dseg) (GET_META(dseg)->size) | 75 #define GET_SIZE(dseg) (GET_META(dseg)->size) |
76 #define GET_LEN(dseg) (GET_META(dseg)->len) | 76 #define GET_LEN(dseg) (GET_META(dseg)->len) |
77 #define GET_WAIT_LIST(dseg) (GET_META(dseg)->wait) | 77 #define GET_WAIT_LIST(dseg) (GET_META(dseg)->wait) |
78 | 78 |
79 #define Gearef(context, t) (&(context)->data[D_##t]->t) | 79 #define Gearef(cbc_context, t) (&(cbc_context)->data[D_##t]->t) |
80 | 80 |
81 // (SingleLinkedStack *)context->data[D_Stack]->Stack.stack->Stack.stack | 81 // (SingleLinkedStack *)cbc_context->data[D_Stack]->Stack.stack->Stack.stack |
82 | 82 |
83 #define GearImpl(context, intf, name) (Gearef(context, intf)->name->intf.name) | 83 #define GearImpl(cbc_context, intf, name) (Gearef(cbc_context, intf)->name->intf.name) |
84 | 84 |
85 #include "c/enumCode.h" | 85 #include "c/enumCode.h" |
86 | 86 |
87 enum Relational { | 87 enum Relational { |
88 EQ, | 88 EQ, |
149 struct LoopCounter { | 149 struct LoopCounter { |
150 int i; | 150 int i; |
151 } LoopCounter; | 151 } LoopCounter; |
152 struct TaskManager { | 152 struct TaskManager { |
153 union Data* taskManager; | 153 union Data* taskManager; |
154 enum Code spawn; // start NEW context on the worker | 154 enum Code spawn; // start NEW cbc_context on the worker |
155 enum Code spawnTasks; // start NEW tasks on the worker | 155 enum Code spawnTasks; // start NEW tasks on the worker |
156 enum Code shutdown; | 156 enum Code shutdown; |
157 enum Code incrementTaskCount; | 157 enum Code incrementTaskCount; |
158 enum Code decrementTaskCount; | 158 enum Code decrementTaskCount; |
159 enum Code next; | 159 enum Code next; |
167 enum Code next; | 167 enum Code next; |
168 int numWorker; | 168 int numWorker; |
169 int sendCPUWorkerIndex; | 169 int sendCPUWorkerIndex; |
170 int sendGPUWorkerIndex; | 170 int sendGPUWorkerIndex; |
171 int taskCount; | 171 int taskCount; |
172 pthread_mutex_t mutex; | 172 // pthread_mutex_t mutex; |
173 struct Queue* activeQueue; | 173 struct Queue* activeQueue; |
174 struct Worker** workers; | 174 struct Worker** workers; |
175 struct Element* taskList; | 175 struct Element* taskList; |
176 int loopCounter; | 176 int loopCounter; |
177 int cpu; | 177 int cpu; |
183 union Data* worker; | 183 union Data* worker; |
184 enum Code taskReceive; | 184 enum Code taskReceive; |
185 enum Code shutdown; | 185 enum Code shutdown; |
186 enum Code next; | 186 enum Code next; |
187 struct Queue* tasks; | 187 struct Queue* tasks; |
188 pthread_t thread; | 188 // pthread_t thread; |
189 struct TaskManager* taskManager; | 189 struct TaskManager* taskManager; |
190 struct Context* task; | 190 struct Context* task; |
191 } Worker; | 191 } Worker; |
192 struct CPUWorker { | 192 struct CPUWorker { |
193 pthread_mutex_t mutex; | 193 // pthread_mutex_t mutex; |
194 pthread_cond_t cond; | 194 // pthread_cond_t cond; |
195 struct Context* context; | 195 struct Context* cbc_context; |
196 int id; | 196 int id; |
197 int loopCounter; | 197 int loopCounter; |
198 } CPUWorker; | 198 } CPUWorker; |
199 #ifdef USE_CUDAWorker | 199 #ifdef USE_CUDAWorker |
200 struct CUDAWorker { | 200 struct CUDAWorker { |
201 CUdevice device; | 201 CUdevice device; |
202 CUcontext cuCtx; | 202 CUcbc_context cuCtx; |
203 struct Context* context; | 203 struct Context* cbc_context; |
204 int id; | 204 int id; |
205 int loopCounter; | 205 int loopCounter; |
206 int deviceNum; | 206 int deviceNum; |
207 struct Queue* tasks; | 207 struct Queue* tasks; |
208 int runFlag; | 208 int runFlag; |
437 struct SpinLock { | 437 struct SpinLock { |
438 volatile Int* lock; | 438 volatile Int* lock; |
439 struct Atomic* atomic; | 439 struct Atomic* atomic; |
440 struct Context* lockContext; | 440 struct Context* lockContext; |
441 } SpinLock; | 441 } SpinLock; |
442 /* CbCxv6 context*/ | 442 /* CbCxv6 cbc_context*/ |
443 struct Inode { | 443 struct Inode { |
444 uint dev; // Device number | 444 uint dev; // Device number |
445 uint inum; // Inode number | 445 uint inum; // Inode number |
446 int ref; // Reference count | 446 int ref; // Reference count |
447 int flags; // I_BUSY, I_VALID | 447 int flags; // I_BUSY, I_VALID |
480 struct Dirent { | 480 struct Dirent { |
481 ushort inum; | 481 ushort inum; |
482 char name[DIRSIZ]; | 482 char name[DIRSIZ]; |
483 } Dirent; | 483 } Dirent; |
484 // --- fs.h | 484 // --- fs.h |
485 }; // union Data end this is necessary for context generator | 485 }; // union Data end this is necessary for cbc_context generator |
486 | 486 |
487 typedef union Data Data; | 487 typedef union Data Data; |
488 | 488 |
489 #include "c/typedefData.h" | 489 #include "c/typedefData.h" |
490 | 490 |
491 #include "c/extern.h" | 491 #include "c/extern.h" |
492 | 492 |
493 extern __code start_code(struct Context* context); | 493 extern __code start_code(struct Context* cbc_context); |
494 extern __code exit_code(struct Context* context); | 494 extern __code exit_code(struct Context* cbc_context); |
495 extern __code meta(struct Context* context, enum Code next); | 495 extern __code meta(struct Context* cbc_context, enum Code next); |
496 //extern __code par_meta(struct Context* context, enum Code spawns, enum Code next); | 496 //extern __code par_meta(struct Context* cbc_context, enum Code spawns, enum Code next); |
497 extern __code parGotoMeta(struct Context* context, enum Code next); | 497 extern __code parGotoMeta(struct Context* cbc_context, enum Code next); |
498 extern void initContext(struct Context* context); | 498 extern void initContext(struct Context* cbc_context); |
499 | 499 |
500 #endif | 500 // #endif |