annotate slide/slide.md @ 63:eaa7a127027b

add asm
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Wed, 03 Feb 2021 13:30:03 +0900
parents 53fb09da2319
children 2c2767e29244
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 ---
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 marp: true
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 title: GearsOSのメタ計算
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 paginate: true
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 ---
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 # <!--fit--> GearsOSのメタ計算
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 - 清水 隆博
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 - 198584B
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 - 河野研
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 ---
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 # 研究目的
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 - アプリケーションの信頼性を向上させたい
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 - その為には土台となる OS 自体の信頼性が重要である
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 - OSそのものも巨大なプログラム
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 - 並列並行処理など起因するバグや、そもそもOSを構成する処理が巨大
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 - テストコードで信頼性を保証しきれない
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 - 形式手法を用いて信頼性を保証したい
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 - モデル検査
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 ---
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 # ノーマルレベルとメタレベルを用いた信頼性の向上
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 - プログラムの実行部分は以下の2つからなる
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 - 入力と出力の関係を決める計算(ノーマルレベル)
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 - プログラムを実行したり、 信頼性を保証するために必要な計算(メタレベル)
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 - メタレベルの例
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 - メモリやCPUの資源管理
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 - システムコールの動作(副作用)
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 - 並行実行(他のプロセスとの干渉)
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 - モデル検査(可能な実行を列挙する方式の実行)
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 - 証明(入力時と出力時の論理的な条件)、(invariant)
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 - メタレベルの計算として信頼性を保証する
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 ---
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 # モデル検査
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 - 実際に想定されるパターンを全て動かして検証する
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 - デッドロック発生の検知
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 - JavaPathFinderなど
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 - 状態爆発が問題になる
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 - Spinを用いる方法では、 promelaという言語で実装し直す必要がある
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 ---
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 # 定理証明支援系
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 - 論理学的なモデルに変更して証明する
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 - Agda
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 - Coq
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 - HoareLogicを用いる
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 - PreCondition -> Statement -> PostCondition
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 - 従来の方法ではStatementには限られたコマンドしか使えない
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 - ループは不変条件を使うが、 条件を見つけることが一般的には困難
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 - 実装言語と同じ記述で証明をすることはできない
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 ---
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 # GearsOSでの信頼性の保証
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 - メタレベルのみで信頼性の保証を行う
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 - ノーマルレベルでの記述は変更しない
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 - Continuation Based C(CbC)をつかって、ノーマルレベルとメタレベルの分離を行う
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 - C言語の下位言語であり、 いくつかのCコンパイラ上で実装している
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 - C言語の構文は使用可能だが、 関数呼び出しの他に軽量継続を持つ
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 - 関数呼び出し時のスタックの操作を行わず`jmp`命令で次の処理に移動する
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 - schemaなどと違い環境を持たず継続するために軽量継続と呼ぶ
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 ---
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 # GearsOSでの信頼性の保証
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 - デフォルトのメタレベルの計算は自動生成される
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 - 資源管理あるいは検証用のメタ計算は必要に応じて挿入する
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 - これにより大きなコード変更が無くモデル検査や定理証明を行うことができる
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 - モデル検査や定理証明の困難さはメタレベルのプログラミングとして吸収する
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 - 例えばOSで使用するデータ構造に合わせたモデル検査用の状態圧縮
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 - OSの検証に利用できるinvariantの提供
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 - CbCを用いたOSであるGearsOSを開発している
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 ---
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 # CbCとCodeGear(ノーマルレベル)
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 - 軽量継続で表現する単位をCodeGearと呼ぶ
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 - CodeGearはCの関数とアセンブラの中間の様に使える
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 - CodeGearは返り値の型の代わりに`__code`で宣言する
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 ```
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 __code cbc_read(__code (*next)(int ret)){
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 struct file *f;
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 int n;
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 char *p;
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &p, n) < 0) {
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 goto next(-1);
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 }
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 goto cbc_fileread(f, p, n, next);
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 }
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 ```
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 - cbcで書き直したxv6の`read`システムコールの例
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 ---
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 # CbCとCodeGear(メタレベル)
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 - `cbc_read_stub`内で必要な引数をcontextから取り出す
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 - 取得するものがなければノーマルレベルのCodeGearに継続する
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 ```c
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 __code cbc_read_stub(struct Context* cbc_context, enum Code next) {
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 goto cbc_read(cbc_context, next);
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 }
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 ```
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 ---
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 # cbcで書き直したシステムコールディスパッチの例
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 - CbCは`goto`文で呼び出す
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 - 受け取ったシステムコール番号に対応するCodeGearに継続する
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 ```c
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 void syscall(void)
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 {
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 int num;
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 int ret;
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 if((num >= NELEM(syscalls)) && (num <= NELEM(cbccodes)) && cbccodes[num]) {
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 proc->cbc_arg.cbc_console_arg.num = num;
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 goto (cbccodes[num])(cbc_ret);
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 }
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 ```
657784b3bae1 add slide
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134