changeset 86:765449889623

fix translate interface routine
author anatofuz
date Tue, 15 Oct 2019 20:03:48 +0900
parents d33e6b5adb57
children add5e775339c
files src/CMakeLists.txt src/console.cbc src/context.h src/gearsTools/pmake.pl src/origin-context.h src/usr/CMakeLists.txt
diffstat 6 files changed, 525 insertions(+), 523 deletions(-) [+]
line wrap: on
line diff
--- a/src/CMakeLists.txt	Tue Oct 15 16:14:18 2019 +0900
+++ b/src/CMakeLists.txt	Tue Oct 15 20:03:48 2019 +0900
@@ -22,7 +22,7 @@
 
 if (${USE_CUDA})
     include_directories("/usr/local/cuda/include")
-    include_directories(${CMAKE_SOURCE_DIR})
+    #include_directories(${CMAKE_SOURCE_DIR})
     set(NVCCFLAG "-std=c++11" "-g" "-O0" )
     if (UNIX AND NOT APPLE) # LINUX
         set(CUDA_LINK_FLAGS "-L/usr/local/cuda/lib64 -lcuda -lcudart")
@@ -77,16 +77,19 @@
 
     #target_link_libraries(syslib)
     file(COPY "${CMAKE_SOURCE_DIR}/interface/" DESTINATION ${CMAKE_KERNEL_DIR_C})
-    file(COPY "${CMAKE_SOURCE_DIR}/context.h" DESTINATION ${CMAKE_KERNEL_DIR_C})
+    file(COPY "${CMAKE_SOURCE_DIR}/origin-context.h" DESTINATION ${CMAKE_KERNEL_DIR_C})
+    file(RENAME "${CMAKE_KERNEL_DIR_C}/origin-context.h" "${CMAKE_KERNEL_DIR_C}/context.h")
     add_custom_command (
-          OUTPUT    ${CMAKE_KERNEL_DIR}/c/${_Gears_TARGET}-context.c
+          OUTPUT    ${CMAKE_KERNEL_DIR_C}/c/${_Gears_TARGET}-context.c
           DEPENDS   ${_Gears_CBC_SOURCES} fs.img initcode
           COMMAND  "cd" "CMakeFiles/kernel.dir" ";" "perl" "${CMAKE_SOURCE_DIR}/gearsTools/generate_context.pl" "-o" ${_Gears_TARGET} ${_Gears_CBC_SOURCES}
     )
     # add_executable(${_Gears_TARGET} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} ${CMAKE_KERNEL_DIR}/c/${_Gears_TARGET}-context.c )
-    include_directories(${_Gears_TARGET} PUBLIC ".")
-    include_directories(${_Gears_TARGET} PUBLIC ${CMAKE_KERNEL_DIR_C})
-    add_executable(${_Gears_TARGET} ${CMAKE_KERNEL_DIR_C} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} ${CMAKE_KERNEL_DIR}/c/${_Gears_TARGET}-context.c )
+    include_directories(${CMAKE_KERNEL_DIR_C})
+    file(GLOB XV6_HEADERS "${CMAKE_SOURCE_DIR}/*.h")
+    file(COPY ${XV6_HEADERS} DESTINATION ${CMAKE_KERNEL_DIR_C})
+    file(COPY "${CMAKE_SOURCE_DIR}/device" DESTINATION "${CMAKE_KERNEL_DIR_C}")
+    add_executable(${_Gears_TARGET} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} ${CMAKE_KERNEL_DIR_C}/c/${_Gears_TARGET}-context.c )
     #  target_link_libraries(${_Gears_TARGET} m pthread)
 endmacro()
 
--- a/src/console.cbc	Tue Oct 15 16:14:18 2019 +0900
+++ b/src/console.cbc	Tue Oct 15 20:03:48 2019 +0900
@@ -13,8 +13,6 @@
 #include "proc.h"
 
 
-#include "../context.h"
-
 #define __ncode __code
 
 __ncode cbc_consoleread1 ();
--- a/src/context.h	Tue Oct 15 16:14:18 2019 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,511 +0,0 @@
-/* Context definition for llrb example */
-// #ifdef CBC_CONTEXT_H  does not work well
-#define CBC_CONTEXT_H
-// #include <stdlib.h>
-// #include <pthread.h>
-#ifdef USE_CUDAWorker
-#include <cuda.h>
-#include <driver_types.h>
-#include <cuda_runtime.h>
-#include "helper_cuda.h"
-#endif
-
-#include "types.h"
-#include "use_context_numbers.h"
-#include "fs.h"
-#include "defs.h"
-
-#ifdef XV6KERNEL
-#define calloc(a,b)  kmalloc((a)*(b))
-#define free(a)  kfree(a)
-#else
-#define calloc(a,b)  malloc((a)*(b))
-#define free(a)  free(a)
-#endif
-
-#define ALLOCATE_SIZE 20000000
-#define NEW(type) (type*)(calloc(1, sizeof(type)))
-#define NEWN(n, type) (type*)(calloc(n, sizeof(type)))
-
-#define ALLOC_DATA(cbc_context, dseg) ({\
-    Meta* meta = (Meta*)cbc_context->heap;\
-    meta->type = D_##dseg;\
-    meta->size = sizeof(dseg);\
-    meta->len = 1;\
-    cbc_context->heap += sizeof(Meta);\
-    cbc_context->data[D_##dseg] = cbc_context->heap; cbc_context->heap += sizeof(dseg); (dseg *)cbc_context->data[D_##dseg]; })
-
-#define ALLOC_DATA_TYPE(cbc_context, dseg, t) ({\
-    Meta* meta = (Meta*)cbc_context->heap;\
-    meta->type = D_##t;\
-    meta->size = sizeof(t);\
-    meta->len = 1;\
-    cbc_context->heap += sizeof(Meta);\
-    cbc_context->data[D_##dseg] = cbc_context->heap; cbc_context->heap += sizeof(t); (t *)cbc_context->data[D_##dseg]; })
-
-#define ALLOCATE(cbc_context, t) ({ \
-    Meta* meta = (Meta*)cbc_context->heap;\
-    cbc_context->heap += sizeof(Meta);\
-    union Data* data = cbc_context->heap; \
-    cbc_context->heap += sizeof(t); \
-    meta->type = D_##t; \
-    meta->size = sizeof(t);     \
-    meta->len = 1;\
-    data; })
-
-#define ALLOCATE_ARRAY(cbc_context, t, length) ({ \
-    Meta* meta = (Meta*)cbc_context->heap;\
-    cbc_context->heap += sizeof(Meta);\
-    union Data* data = cbc_context->heap; \
-    cbc_context->heap += sizeof(t)*length; \
-    meta->type = D_##t; \
-    meta->size = sizeof(t)*length; \
-    meta->len = length; \
-    data;   })
-
-#define ALLOCATE_PTR_ARRAY(cbc_context, dseg, length) ({\
-    Meta* meta = (Meta*)cbc_context->heap;\
-    cbc_context->heap += sizeof(Meta);\
-    union Data* data = cbc_context->heap; \
-    cbc_context->heap += sizeof(dseg *)*length; \
-    meta->type = D_##dseg; \
-    meta->size = sizeof(dseg *)*length; \
-    meta->len = length; \
-    data; })
-
-#define ALLOCATE_DATA_GEAR(cbc_context, t) ({ \
-        union Data* data = ALLOCATE(cbc_context, t); \
-        Meta* meta = GET_META(data); \
-        meta->wait = createSynchronizedQueue(cbc_context); \
-        data; })
-
-#define ALLOC(cbc_context, t) (&ALLOCATE(cbc_context, t)->t)
-
-#define GET_META(dseg) ((Meta*)(((void*)dseg) - sizeof(Meta)))
-#define GET_TYPE(dseg) (GET_META(dseg)->type)
-#define GET_SIZE(dseg) (GET_META(dseg)->size)
-#define GET_LEN(dseg) (GET_META(dseg)->len)
-#define GET_WAIT_LIST(dseg) (GET_META(dseg)->wait)
-
-#define Gearef(cbc_context, t) (&(cbc_context)->data[D_##t]->t)
-
-// (SingleLinkedStack *)cbc_context->data[D_Stack]->Stack.stack->Stack.stack
-
-#define GearImpl(cbc_context, intf, name) (Gearef(cbc_context, intf)->name->intf.name)
-
-#include "c/enumCode.h"
-
-enum Relational {
-    EQ,
-    GT,
-    LT,
-};
-
-#include "c/enumData.h"
-#define NDIRECT 12 //fs.h
-
-struct Context {
-    enum Code next;
-    struct Worker* worker;
-    struct TaskManager* taskManager;
-    int codeNum;
-    __code (**code) (struct Context*);
-    union Data **data;
-    void* heapStart;
-    void* heap;
-    long heapLimit;
-    int dataNum;
-
-    // task parameter
-    int idgCount; //number of waiting dataGear
-    int idg;
-    int maxIdg;
-    int odg;
-    int maxOdg;
-    int gpu; // GPU task
-    struct Context* task;
-    struct Element* taskList;
-#ifdef USE_CUDAWorker
-    int num_exec;
-    CUmodule module;
-    CUfunction function;
-#endif
-    /* multi dimension parameter */
-    int iterate;
-    struct Iterator* iterator;
-    enum Code before;
-};
-
-typedef int Int;
-#ifndef USE_CUDAWorker
-typedef unsigned long long CUdeviceptr;
-#endif
-union Data {
-    struct Meta {
-        enum DataType type;
-        long size;
-        long len;
-        struct Queue* wait; // tasks waiting this dataGear
-    } Meta;
-    struct Context Context;
-    struct Timer {
-        union Data* timer;
-        enum Code start;
-        enum Code end;
-        enum Code next;
-    } Timer;
-    struct TimerImpl {
-        double time;
-    } TimerImpl;
-    struct LoopCounter {
-        int i;
-    } LoopCounter;
-    struct TaskManager {
-        union Data* taskManager;
-        enum Code spawn;      // start NEW cbc_context on the worker
-        enum Code spawnTasks; // start NEW tasks on the worker
-        enum Code shutdown;
-        enum Code incrementTaskCount;
-        enum Code decrementTaskCount;
-        enum Code next;
-        enum Code next1;
-        enum Code setWaitTask;
-        struct Context* task;
-        struct Element* taskList;
-        union Data* data;
-    } TaskManager;
-    struct TaskManagerImpl {
-        enum Code next;
-        int numWorker;
-        int sendCPUWorkerIndex;
-        int sendGPUWorkerIndex;
-        int taskCount;
-        // pthread_mutex_t mutex;
-        struct Queue* activeQueue;
-        struct Worker** workers;
-        struct Element* taskList;
-        int loopCounter;
-        int cpu;
-        int gpu;
-        int io;
-        int maxCPU;
-    } TaskManagerImpl;
-    struct Worker {
-        union Data* worker;
-        enum Code taskReceive;
-        enum Code shutdown;
-        enum Code next;
-        struct Queue* tasks;
-        // pthread_t thread;
-        struct TaskManager* taskManager;
-        struct Context* task;
-    } Worker;
-    struct CPUWorker {
-        // pthread_mutex_t mutex;
-        // pthread_cond_t cond;
-        struct Context* cbc_context;
-        int id;
-        int loopCounter;
-    } CPUWorker;
-#ifdef USE_CUDAWorker
-    struct CUDAWorker {
-        CUdevice device;
-        CUcbc_context cuCtx;
-        struct Context* cbc_context;
-        int id;
-        int loopCounter;
-        int deviceNum;
-        struct Queue* tasks;
-        int runFlag;
-        enum Code next;
-        int numStream;
-        struct Executor* executor;
-        CUstream *stream;
-    } CUDAWorker;
-#else
-    struct CUDAWorker {
-    } CUDAWorker;
-#endif
-    struct Main {
-        enum Code code;
-        enum Code next;
-        struct Queue* args;
-    } Main;
-    // Queue Interface
-    struct Queue {
-        union Data* queue;
-        union Data* data;
-        enum Code whenEmpty;
-        enum Code clear;
-        enum Code put;
-        enum Code take;
-        enum Code isEmpty;
-        enum Code next;
-    } Queue;
-    struct SingleLinkedQueue {
-        struct Element* top;
-        struct Element* last;
-    } SingleLinkedQueue;
-    struct SynchronizedQueue {
-        struct Element* top;
-        struct Element* last;
-        struct Atomic* atomic;
-    } SynchronizedQueue;
-    // Stack Interface
-    struct Stack {
-        union Data* stack;
-        union Data* data;
-        union Data* data1;
-        enum Code whenEmpty;
-        enum Code clear;
-        enum Code push;
-        enum Code pop;
-        enum Code pop2;
-        enum Code isEmpty;
-        enum Code get;
-        enum Code get2;
-        enum Code next;
-    } Stack;
-    // Stack implementations
-    struct SingleLinkedStack {
-        struct Element* top;
-    } SingleLinkedStack;
-    struct ArrayStack {
-        int size;
-        int limit;
-        struct Element* array;
-    } ArrayStack;
-    // Stack implementation end
-    struct Element {
-        union Data* data;
-        struct Element* next;
-    } Element;
-    struct Array {
-        int prefix;
-        Int* array;
-    } Array;
-    struct Tree {
-        union Data* tree;
-        struct Node* node;
-        enum Code put;
-        enum Code get;
-        enum Code remove;
-        enum Code clear;
-        enum Code next;
-    } Tree;
-    struct RedBlackTree {
-        struct Node* root;
-        struct Node* current; // reading node of original tree
-        struct Node* previous; // parent of reading node of original tree
-        struct Node* newNode; // writing node of new tree
-        struct Node* parent;
-        struct Node* grandparent;
-        struct Stack* nodeStack;
-        enum Code findNodeNext;
-        int result;
-    } RedBlackTree;
-    struct RotateTree {
-        enum Code next;
-        struct RedBlackTree* traverse;
-        struct Tree* tree;
-    } RotateTree;
-    struct Node {
-        int key; // comparable data segment
-        union Data* value;
-        struct Node* left;
-        struct Node* right;
-        // need to balancing
-        enum Color {
-            Red,
-            Black,
-            // Red eq 0,Black eq 1. enum name convert intager.
-        } color;
-    } Node;
-    struct Atomic {
-        union Data* atomic;
-        union Data** ptr;
-        union Data* oldData;
-        union Data* newData;
-        enum Code checkAndSet;
-        enum Code next;
-        enum Code fail;
-    } Atomic;
-    struct AtomicReference {
-    } AtomicReference;
-    struct Semaphore {
-        union Data* semaphore;
-        enum Code p;
-        enum Code v;
-        enum Code next;
-    } Semaphore;
-    struct SemaphoreImpl {
-        int value;
-        struct Lock* lock;
-        struct Queue* waitThreadQueue;
-    } SemaphoreImpl;
-    struct Allocate {
-        enum Code next;
-        long size;
-    } Allocate;
-    struct Integer {
-        int value;
-    } Integer;
-    struct SortArray {
-        struct Integer *array; //Array arrayじゃできない?
-        int loopCounter;
-        int block;
-        int first;
-        int prefix;
-    } SortArray;
-    struct Iterator {
-        union Data* iterator;
-        struct Context* task;
-        int numGPU;
-        enum Code exec;
-        enum Code barrier;
-        enum Code whenWait;
-        enum Code next;
-    } Iterator;
-    struct MultiDimIterator {
-        int x;
-        int y;
-        int z;
-        int count;
-        int counterX;
-        int counterY;
-        int counterZ;
-    } MultiDimIterator;
-    struct MultiDim {
-        int x;
-        int y;
-        int z;
-    } MultiDim;
-    struct Executor {
-        union Data* executor;
-        struct Context* task;
-        enum Code read;
-        enum Code exec;
-        enum Code write;
-        enum Code next;
-    } Executor;
-#ifdef USE_CUDAWorker
-    struct CUDAExecutor {
-        CUdeviceptr** kernelParams;
-        struct CUDABuffer* buffer;
-        int maxThreadPerBlock;
-        int maxThreadPerBlockX;
-        int maxThreadPerBlockY;
-        int maxThreadPerBlockZ;
-        struct Timer* timer;
-    } CUDAExecutor;
-    struct CUDABuffer {
-        int inputLen;
-        int outputLen;
-        union Data** inputData;
-        union Data** outputData;
-    } CUDABuffer;
-    CUdeviceptr CUdeviceptr;
-#else
-    struct CUDAExecutor {
-    } CUDAExecutor;
-    struct CUDABuffer {
-    } CUDABuffer;
-    CUdeviceptr CUdeviceptr;
-#endif
-    Int Int;
-    struct Memory {
-        union Data* adr;
-        int length;
-        union Data* body;
-        int hash;
-    } Memory;
-    struct Buffer {
-        union Data* buffer;
-        union Data* data;
-        enum Code put;
-        enum Code take;
-        enum Code next;
-    } Buffer;
-    struct BoundedBuffer {
-        struct Element* top;
-        struct Element* last;
-        struct Semaphore* fullCount;
-        struct Semaphore* emptyCount;
-        struct Semaphore* lock;
-    } BoundedBuffer;
-    struct Lock {
-        union Data* lock;
-        enum Code doLock;
-        enum Code doUnlock;
-        enum Code next;
-    } Lock;
-    struct LockImpl {
-        Int* lock;
-        struct Queue* waitThreadQueue;
-        struct Atomic* atomic;
-        struct Context* lockContext;
-    } LockImpl;
-    struct SpinLock {
-        volatile Int* lock;
-        struct Atomic* atomic;
-        struct Context* lockContext;
-    } SpinLock;
-    /* CbCxv6 cbc_context*/
-    struct Inode {
-      uint    dev;        // Device number
-      uint    inum;       // Inode number
-      int     ref;        // Reference count
-      int     flags;      // I_BUSY, I_VALID
-
-      short   type;       // copy of disk inode
-      short   major;
-      short   minor;
-      short   nlink;
-      uint    size;
-      uint    addrs[NDIRECT+1];       
-    } Inode;
-    struct Uinteger {
-        uint value;
-    } Uinteger;
-    struct Short {
-       short value;
-    } Short;
-    struct String {
-      char* string;
-    } String;
-    // fs.h ---
-    struct SuperBlock {
-      uint    size;           // Size of file system image (blocks)
-      uint    nblocks;        // Number of data blocks
-      uint    ninodes;        // Number of inodes.
-      uint    nlog;           // Number of log blocks
-    } SuperBlock;
-    struct Dinode {
-      short   type;       // copy of disk inode
-      short   major;
-      short   minor;
-      short   nlink;
-      uint    size;
-      uint    addrs[NDIRECT+1];       
-    } Dinode;
-    struct Dirent {
-      ushort inum;
-      char   name[DIRSIZ];
-    } Dirent;
-    // --- fs.h
-}; // union Data end       this is necessary for cbc_context generator
-
-typedef union Data Data;
-
-#include "c/typedefData.h"
-
-#include "c/extern.h"
-
-extern __code start_code(struct Context* cbc_context);
-extern __code exit_code(struct Context* cbc_context);
-extern __code meta(struct Context* cbc_context, enum Code next);
-//extern __code par_meta(struct Context* cbc_context, enum Code spawns, enum Code next);
-extern __code parGotoMeta(struct Context* cbc_context, enum Code next);
-extern void initContext(struct Context* cbc_context);
-
-// #endif
--- a/src/gearsTools/pmake.pl	Tue Oct 15 16:14:18 2019 +0900
+++ b/src/gearsTools/pmake.pl	Tue Oct 15 20:03:48 2019 +0900
@@ -18,16 +18,16 @@
     $cc     = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-gcc';
     $asm    = $cc;
     $cflags = qq|-B/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-  
-             -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -I. -g -O0|;
+             -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall  -g -O0|;
     $ld     = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-ld';
     chomp($libgcc = `$cc --print-libgcc-file-name`);
     $cmake  .= 3;
     $ldflags = " -L. -T kernel-cmake.ld";
-    $kernel_cflags   = '-march=armv6 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -I. -g -O0 -iquote ../   -c';
+    $kernel_cflags   = '-march=armv6 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -g -O0 -iquote ../   -c';
     # -DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags  -o kernel.elf <OBJECTS> $libgcc   -b binary initcode usr/fs.img\"
     $kernel_ld_flags =  ' -L. -N -e main -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>  -L ../ /mnt/dalmore-home/one/src/gcc-arm-none-eabi-6-2017-q2-update/bin/../lib/gcc/arm-none-eabi/6.3.1/libgcc.a';
     $kernel_ld_command = "$ld $kernel_ld_flags";
-    $initcode_cflags = '-march=armv6   -nostdinc -I. -c';
+    $initcode_cflags = '-march=armv6   -nostdinc  -c';
     $initcode_ld_command = "$ld -L.  -N -e start -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>";
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/origin-context.h	Tue Oct 15 20:03:48 2019 +0900
@@ -0,0 +1,511 @@
+/* Context definition for llrb example */
+// #ifdef CBC_CONTEXT_H  does not work well
+#define CBC_CONTEXT_H
+// #include <stdlib.h>
+// #include <pthread.h>
+#ifdef USE_CUDAWorker
+#include <cuda.h>
+#include <driver_types.h>
+#include <cuda_runtime.h>
+#include "helper_cuda.h"
+#endif
+
+#include "types.h"
+#include "use_context_numbers.h"
+#include "fs.h"
+#include "defs.h"
+
+#ifdef XV6KERNEL
+#define calloc(a,b)  kmalloc((a)*(b))
+#define free(a)  kfree(a)
+#else
+#define calloc(a,b)  malloc((a)*(b))
+#define free(a)  free(a)
+#endif
+
+#define ALLOCATE_SIZE 20000000
+#define NEW(type) (type*)(calloc(1, sizeof(type)))
+#define NEWN(n, type) (type*)(calloc(n, sizeof(type)))
+
+#define ALLOC_DATA(cbc_context, dseg) ({\
+    Meta* meta = (Meta*)cbc_context->heap;\
+    meta->type = D_##dseg;\
+    meta->size = sizeof(dseg);\
+    meta->len = 1;\
+    cbc_context->heap += sizeof(Meta);\
+    cbc_context->data[D_##dseg] = cbc_context->heap; cbc_context->heap += sizeof(dseg); (dseg *)cbc_context->data[D_##dseg]; })
+
+#define ALLOC_DATA_TYPE(cbc_context, dseg, t) ({\
+    Meta* meta = (Meta*)cbc_context->heap;\
+    meta->type = D_##t;\
+    meta->size = sizeof(t);\
+    meta->len = 1;\
+    cbc_context->heap += sizeof(Meta);\
+    cbc_context->data[D_##dseg] = cbc_context->heap; cbc_context->heap += sizeof(t); (t *)cbc_context->data[D_##dseg]; })
+
+#define ALLOCATE(cbc_context, t) ({ \
+    Meta* meta = (Meta*)cbc_context->heap;\
+    cbc_context->heap += sizeof(Meta);\
+    union Data* data = cbc_context->heap; \
+    cbc_context->heap += sizeof(t); \
+    meta->type = D_##t; \
+    meta->size = sizeof(t);     \
+    meta->len = 1;\
+    data; })
+
+#define ALLOCATE_ARRAY(cbc_context, t, length) ({ \
+    Meta* meta = (Meta*)cbc_context->heap;\
+    cbc_context->heap += sizeof(Meta);\
+    union Data* data = cbc_context->heap; \
+    cbc_context->heap += sizeof(t)*length; \
+    meta->type = D_##t; \
+    meta->size = sizeof(t)*length; \
+    meta->len = length; \
+    data;   })
+
+#define ALLOCATE_PTR_ARRAY(cbc_context, dseg, length) ({\
+    Meta* meta = (Meta*)cbc_context->heap;\
+    cbc_context->heap += sizeof(Meta);\
+    union Data* data = cbc_context->heap; \
+    cbc_context->heap += sizeof(dseg *)*length; \
+    meta->type = D_##dseg; \
+    meta->size = sizeof(dseg *)*length; \
+    meta->len = length; \
+    data; })
+
+#define ALLOCATE_DATA_GEAR(cbc_context, t) ({ \
+        union Data* data = ALLOCATE(cbc_context, t); \
+        Meta* meta = GET_META(data); \
+        meta->wait = createSynchronizedQueue(cbc_context); \
+        data; })
+
+#define ALLOC(cbc_context, t) (&ALLOCATE(cbc_context, t)->t)
+
+#define GET_META(dseg) ((Meta*)(((void*)dseg) - sizeof(Meta)))
+#define GET_TYPE(dseg) (GET_META(dseg)->type)
+#define GET_SIZE(dseg) (GET_META(dseg)->size)
+#define GET_LEN(dseg) (GET_META(dseg)->len)
+#define GET_WAIT_LIST(dseg) (GET_META(dseg)->wait)
+
+#define Gearef(cbc_context, t) (&(cbc_context)->data[D_##t]->t)
+
+// (SingleLinkedStack *)cbc_context->data[D_Stack]->Stack.stack->Stack.stack
+
+#define GearImpl(cbc_context, intf, name) (Gearef(cbc_context, intf)->name->intf.name)
+
+#include "c/enumCode.h"
+
+enum Relational {
+    EQ,
+    GT,
+    LT,
+};
+
+#include "c/enumData.h"
+#define NDIRECT 12 //fs.h
+
+struct Context {
+    enum Code next;
+    struct Worker* worker;
+    struct TaskManager* taskManager;
+    int codeNum;
+    __code (**code) (struct Context*);
+    union Data **data;
+    void* heapStart;
+    void* heap;
+    long heapLimit;
+    int dataNum;
+
+    // task parameter
+    int idgCount; //number of waiting dataGear
+    int idg;
+    int maxIdg;
+    int odg;
+    int maxOdg;
+    int gpu; // GPU task
+    struct Context* task;
+    struct Element* taskList;
+#ifdef USE_CUDAWorker
+    int num_exec;
+    CUmodule module;
+    CUfunction function;
+#endif
+    /* multi dimension parameter */
+    int iterate;
+    struct Iterator* iterator;
+    enum Code before;
+};
+
+typedef int Int;
+#ifndef USE_CUDAWorker
+typedef unsigned long long CUdeviceptr;
+#endif
+union Data {
+    struct Meta {
+        enum DataType type;
+        long size;
+        long len;
+        struct Queue* wait; // tasks waiting this dataGear
+    } Meta;
+    struct Context Context;
+    struct Timer {
+        union Data* timer;
+        enum Code start;
+        enum Code end;
+        enum Code next;
+    } Timer;
+    struct TimerImpl {
+        double time;
+    } TimerImpl;
+    struct LoopCounter {
+        int i;
+    } LoopCounter;
+    struct TaskManager {
+        union Data* taskManager;
+        enum Code spawn;      // start NEW cbc_context on the worker
+        enum Code spawnTasks; // start NEW tasks on the worker
+        enum Code shutdown;
+        enum Code incrementTaskCount;
+        enum Code decrementTaskCount;
+        enum Code next;
+        enum Code next1;
+        enum Code setWaitTask;
+        struct Context* task;
+        struct Element* taskList;
+        union Data* data;
+    } TaskManager;
+    struct TaskManagerImpl {
+        enum Code next;
+        int numWorker;
+        int sendCPUWorkerIndex;
+        int sendGPUWorkerIndex;
+        int taskCount;
+        // pthread_mutex_t mutex;
+        struct Queue* activeQueue;
+        struct Worker** workers;
+        struct Element* taskList;
+        int loopCounter;
+        int cpu;
+        int gpu;
+        int io;
+        int maxCPU;
+    } TaskManagerImpl;
+    struct Worker {
+        union Data* worker;
+        enum Code taskReceive;
+        enum Code shutdown;
+        enum Code next;
+        struct Queue* tasks;
+        // pthread_t thread;
+        struct TaskManager* taskManager;
+        struct Context* task;
+    } Worker;
+    struct CPUWorker {
+        // pthread_mutex_t mutex;
+        // pthread_cond_t cond;
+        struct Context* cbc_context;
+        int id;
+        int loopCounter;
+    } CPUWorker;
+#ifdef USE_CUDAWorker
+    struct CUDAWorker {
+        CUdevice device;
+        CUcbc_context cuCtx;
+        struct Context* cbc_context;
+        int id;
+        int loopCounter;
+        int deviceNum;
+        struct Queue* tasks;
+        int runFlag;
+        enum Code next;
+        int numStream;
+        struct Executor* executor;
+        CUstream *stream;
+    } CUDAWorker;
+#else
+    struct CUDAWorker {
+    } CUDAWorker;
+#endif
+    struct Main {
+        enum Code code;
+        enum Code next;
+        struct Queue* args;
+    } Main;
+    // Queue Interface
+    struct Queue {
+        union Data* queue;
+        union Data* data;
+        enum Code whenEmpty;
+        enum Code clear;
+        enum Code put;
+        enum Code take;
+        enum Code isEmpty;
+        enum Code next;
+    } Queue;
+    struct SingleLinkedQueue {
+        struct Element* top;
+        struct Element* last;
+    } SingleLinkedQueue;
+    struct SynchronizedQueue {
+        struct Element* top;
+        struct Element* last;
+        struct Atomic* atomic;
+    } SynchronizedQueue;
+    // Stack Interface
+    struct Stack {
+        union Data* stack;
+        union Data* data;
+        union Data* data1;
+        enum Code whenEmpty;
+        enum Code clear;
+        enum Code push;
+        enum Code pop;
+        enum Code pop2;
+        enum Code isEmpty;
+        enum Code get;
+        enum Code get2;
+        enum Code next;
+    } Stack;
+    // Stack implementations
+    struct SingleLinkedStack {
+        struct Element* top;
+    } SingleLinkedStack;
+    struct ArrayStack {
+        int size;
+        int limit;
+        struct Element* array;
+    } ArrayStack;
+    // Stack implementation end
+    struct Element {
+        union Data* data;
+        struct Element* next;
+    } Element;
+    struct Array {
+        int prefix;
+        Int* array;
+    } Array;
+    struct Tree {
+        union Data* tree;
+        struct Node* node;
+        enum Code put;
+        enum Code get;
+        enum Code remove;
+        enum Code clear;
+        enum Code next;
+    } Tree;
+    struct RedBlackTree {
+        struct Node* root;
+        struct Node* current; // reading node of original tree
+        struct Node* previous; // parent of reading node of original tree
+        struct Node* newNode; // writing node of new tree
+        struct Node* parent;
+        struct Node* grandparent;
+        struct Stack* nodeStack;
+        enum Code findNodeNext;
+        int result;
+    } RedBlackTree;
+    struct RotateTree {
+        enum Code next;
+        struct RedBlackTree* traverse;
+        struct Tree* tree;
+    } RotateTree;
+    struct Node {
+        int key; // comparable data segment
+        union Data* value;
+        struct Node* left;
+        struct Node* right;
+        // need to balancing
+        enum Color {
+            Red,
+            Black,
+            // Red eq 0,Black eq 1. enum name convert intager.
+        } color;
+    } Node;
+    struct Atomic {
+        union Data* atomic;
+        union Data** ptr;
+        union Data* oldData;
+        union Data* newData;
+        enum Code checkAndSet;
+        enum Code next;
+        enum Code fail;
+    } Atomic;
+    struct AtomicReference {
+    } AtomicReference;
+    struct Semaphore {
+        union Data* semaphore;
+        enum Code p;
+        enum Code v;
+        enum Code next;
+    } Semaphore;
+    struct SemaphoreImpl {
+        int value;
+        struct Lock* lock;
+        struct Queue* waitThreadQueue;
+    } SemaphoreImpl;
+    struct Allocate {
+        enum Code next;
+        long size;
+    } Allocate;
+    struct Integer {
+        int value;
+    } Integer;
+    struct SortArray {
+        struct Integer *array; //Array arrayじゃできない?
+        int loopCounter;
+        int block;
+        int first;
+        int prefix;
+    } SortArray;
+    struct Iterator {
+        union Data* iterator;
+        struct Context* task;
+        int numGPU;
+        enum Code exec;
+        enum Code barrier;
+        enum Code whenWait;
+        enum Code next;
+    } Iterator;
+    struct MultiDimIterator {
+        int x;
+        int y;
+        int z;
+        int count;
+        int counterX;
+        int counterY;
+        int counterZ;
+    } MultiDimIterator;
+    struct MultiDim {
+        int x;
+        int y;
+        int z;
+    } MultiDim;
+    struct Executor {
+        union Data* executor;
+        struct Context* task;
+        enum Code read;
+        enum Code exec;
+        enum Code write;
+        enum Code next;
+    } Executor;
+#ifdef USE_CUDAWorker
+    struct CUDAExecutor {
+        CUdeviceptr** kernelParams;
+        struct CUDABuffer* buffer;
+        int maxThreadPerBlock;
+        int maxThreadPerBlockX;
+        int maxThreadPerBlockY;
+        int maxThreadPerBlockZ;
+        struct Timer* timer;
+    } CUDAExecutor;
+    struct CUDABuffer {
+        int inputLen;
+        int outputLen;
+        union Data** inputData;
+        union Data** outputData;
+    } CUDABuffer;
+    CUdeviceptr CUdeviceptr;
+#else
+    struct CUDAExecutor {
+    } CUDAExecutor;
+    struct CUDABuffer {
+    } CUDABuffer;
+    CUdeviceptr CUdeviceptr;
+#endif
+    Int Int;
+    struct Memory {
+        union Data* adr;
+        int length;
+        union Data* body;
+        int hash;
+    } Memory;
+    struct Buffer {
+        union Data* buffer;
+        union Data* data;
+        enum Code put;
+        enum Code take;
+        enum Code next;
+    } Buffer;
+    struct BoundedBuffer {
+        struct Element* top;
+        struct Element* last;
+        struct Semaphore* fullCount;
+        struct Semaphore* emptyCount;
+        struct Semaphore* lock;
+    } BoundedBuffer;
+    struct Lock {
+        union Data* lock;
+        enum Code doLock;
+        enum Code doUnlock;
+        enum Code next;
+    } Lock;
+    struct LockImpl {
+        Int* lock;
+        struct Queue* waitThreadQueue;
+        struct Atomic* atomic;
+        struct Context* lockContext;
+    } LockImpl;
+    struct SpinLock {
+        volatile Int* lock;
+        struct Atomic* atomic;
+        struct Context* lockContext;
+    } SpinLock;
+    /* CbCxv6 cbc_context*/
+    struct Inode {
+      uint    dev;        // Device number
+      uint    inum;       // Inode number
+      int     ref;        // Reference count
+      int     flags;      // I_BUSY, I_VALID
+
+      short   type;       // copy of disk inode
+      short   major;
+      short   minor;
+      short   nlink;
+      uint    size;
+      uint    addrs[NDIRECT+1];       
+    } Inode;
+    struct Uinteger {
+        uint value;
+    } Uinteger;
+    struct Short {
+       short value;
+    } Short;
+    struct String {
+      char* string;
+    } String;
+    // fs.h ---
+    struct SuperBlock {
+      uint    size;           // Size of file system image (blocks)
+      uint    nblocks;        // Number of data blocks
+      uint    ninodes;        // Number of inodes.
+      uint    nlog;           // Number of log blocks
+    } SuperBlock;
+    struct Dinode {
+      short   type;       // copy of disk inode
+      short   major;
+      short   minor;
+      short   nlink;
+      uint    size;
+      uint    addrs[NDIRECT+1];       
+    } Dinode;
+    struct Dirent {
+      ushort inum;
+      char   name[DIRSIZ];
+    } Dirent;
+    // --- fs.h
+}; // union Data end       this is necessary for cbc_context generator
+
+typedef union Data Data;
+
+#include "c/typedefData.h"
+
+#include "c/extern.h"
+
+extern __code start_code(struct Context* cbc_context);
+extern __code exit_code(struct Context* cbc_context);
+extern __code meta(struct Context* cbc_context, enum Code next);
+//extern __code par_meta(struct Context* cbc_context, enum Code spawns, enum Code next);
+extern __code parGotoMeta(struct Context* cbc_context, enum Code next);
+extern void initContext(struct Context* cbc_context);
+
+// #endif
--- a/src/usr/CMakeLists.txt	Tue Oct 15 16:14:18 2019 +0900
+++ b/src/usr/CMakeLists.txt	Tue Oct 15 20:03:48 2019 +0900
@@ -43,7 +43,8 @@
             list(APPEND _Gears_CBC_SOURCES ${j})
         else()
             set(j ${i})
-            file(COPY "${CMAKE_SOURCE_DIR}/context.h" DESTINATION "${CMAKE_BINARY_DIR}/usr/${_Gears_TARGET}.dir")
+            file(COPY "${CMAKE_SOURCE_DIR}/origin-context.h" DESTINATION "${CMAKE_BINARY_DIR}/usr/${_Gears_TARGET}.dir")
+            file(RENAME "${CMAKE_BINARY_DIR}/usr/${_Gears_TARGET}.dir/origin-context.h" "${CMAKE_BINARY_DIR}/usr/${_Gears_TARGET}.dir/context.h")
             list(APPEND _Gears_CSOURCES ${j})
         endif()
     endforeach(i)