view 2017/2017_02_07/slide.md @ 22:bf593e6958b1

Update
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Tue, 21 Mar 2017 23:58:48 +0900
parents
children
line wrap: on
line source

title: Gears OS
author: Tatsuki IHA
profile:
lang: Japanese
code-engine: coderay

## 研究目的
- 当研究室では  処理の単位を Code Gear、 データの単位を Data Gear を用いて 信頼性が高い並列処理を行う Gears OS を開発している
- Gears OS では Task を Code Gear と実行するときに必要な Input Data Gear と出力するための Output Data Gear の組で表現される。 Input Data Gear/Output Data Gear によって依存関係が決定し、それにそって並列実行を行う.
- 依存関係の解決やモデル検査等の本論の計算を行うためのメタな計算を Meta Code Gear で行う.
- 現在の Gears では Stack や Queue の operatation の API が存在しなため, 記述が困難になっている. そのため, この研究では Gears OS における API の記述方法を設計し, 実装する


## 今週
- semaphore を作りました
- Synchornized Queue の 中身の数を semaphore で管理する
- odg_commit のコードを軽く書きました
- torqueを動かしました

## semaphore の data Gearの構成
- Cerium の Sem.c を参考に

``` c
struct Semaphore {
    union Data* semaphore;
    enum Code p;
    enum Code v;
    enum Code next;
} Semaphore;
struct SemaphoreImpl {
    int value;
    pthread_mutex_t mutex;
    pthread_cond_t cond;
} SemaphoreImpl;
```

## semaphore の実装
- p命令は wait でループする必要があるため ループ用の cgも作る
- generate_stub でちゃんとstubが生成される形

``` c
Semaphore* createSemaphoreImpl(struct Context* context, int n) {
    ....
}

__code pOperationSemaphoreImpl(struct SemaphoreImpl* semaphore, __code next(...)) {
    pthread_mutex_lock(&semaphore->mutex);
    goto meta(context, C_pOperationSemaphoreImpl1);
}

__code pOperationSemaphoreImpl1(struct SemaphoreImpl* semaphore, __code next(...)) {
    if(semaphore->value == 0) {
        pthread_cond_wait(&semaphore->cond, &semaphore->mutex);
        goto meta(context, C_pOperationSemaphoreImpl1);
    }
    semaphore->value--;
    pthread_mutex_unlock(&semaphore->mutex);
    goto next(...);
}

__code vOperationSemaphoreImpl(struct SemaphoreImpl* semaphore, __code next(...)) {
    pthread_mutex_lock(&semaphore->mutex);
    semaphore->value++;
    pthread_cond_signal(&semaphore->cond);
    pthread_mutex_unlock(&semaphore->mutex);
    goto next(...);
}
```


## twice スピードが出ない
- 単純にtime だとcpuを増やしてもスピードが出ない
- length の量を結構増やすと一応は早くなる