annotate user/menikon/thesis.md @ 67:a4f167def66b

backup 2021-05-26
author autobackup
date Wed, 26 May 2021 00:10:03 +0900
parents b6c284fd5ae4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 # CbC による xv6 の FileSystem の書き換え
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
2 - 並列信頼研
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
4 - 坂本昂弘
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 ## 研究目的
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 - OSに対し高い信頼性を実現させたい
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 - そのために当研究室ではContinuation based C (CbC)を用いたGearsOSを設計中である
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 - 前段階としてシンプルであるが基本的な機能を揃えたOSであるxv6をCbCで書き換える
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
12 - xv6のFilleSystemをCbCで記述し、なるべく処理を細分化実装してやる
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
13
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
14 ---
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
15
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
16 # Continuation based C
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
17 - 状態遷移ベースで記述できる言語(以下CbC)
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
18 - C の関数呼び出しとは異なり、stack に値を積まない
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
19 - Code Gear
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
20 - 基本的な処理の単位
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
21 - goto 文で遷移する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
22 - Data Gear
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
23 - Code Gear からアクセスできるデータの単位
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
24 - 引数など
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
25
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
26
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
27 ---
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
28 # Code Gear による継続
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
29 - Code Gear の処理の間を goto によって遷移していく
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
30 - __code CodeGear名 で定義
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
31 ![](https://i.imgur.com/etfQund.png)
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
32
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
33
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
34 ---
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
35
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
36 # Data Gear の受け渡し
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
37 - Code Gear からアクセスできるデータ
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
38 - Code Gear の計算の入力と、計算の出力が存在する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
39
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
40 ![](https://i.imgur.com/3E0DGWA.png)
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
41
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
42
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
43 ---
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
44
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
45 # Data Gear の一種であるContext
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
47 - Contextには実行するプログラムの全てのData Gear と Code Gear が登録されている
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
48 - ユーザープロセスに対応して1つのcontextが存在する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
49 - CodeGearの入出力は、一度Contextに書き込まれる
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
50 - Contextは実行している処理の状態を保持している
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
51 - そのためContextを見れば、実行中の処理がわかる
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
52 ![](http://ie.u-ryukyu.ac.jp/~e165723/context.pdf)
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
53
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
54 ---
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
55
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
56 # Xv6
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
57 - MIT の講義用教材として作られたOS
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
58 - xv6 は Unix の基本的な構造を持っている。
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
59 - プロセス
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
60 - 仮想メモリ
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
61 - ファイルシステム
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
62 - Xv6 をCbCで書き換える
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
64 ---
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
65
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
66 # Xv6のFileSystem
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
67 - FileSystem は コンピュータの資源を操作するための OS が持つ機能である
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
68 - xv6 の FileSystem は、デバイスやプロセス、カーネル内の処理をする際の情報などをファイルとして扱う
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
69 - inodeを用いファイルの管理や操作を行う
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
70 - inodeはディスク上にブロックを持つ木構造のデータ構造
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
71 ---
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
72
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
73 # Xv6の書き換え方針
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
74 - 段階的に書き換えていきたい
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
75 - FileSystem を書き換える理由
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
76 - FileSystem は状態が複雑に変化するため、信頼性を保証する必要がある
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
77 - インターフェースを定義、実装する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
78 - 状態遷移ベースにしてやる
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
79
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
80 ---
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
82 # インターフェースの導入
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
83 - CbC のモジュール化の方法
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
84 - Javaのインターフェースと同様
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
85 - インターフェースによるメリット
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
86 - 複雑な状態の解消
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
87 - 入力の切り替えによる実装の入れ替え
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
88 - 実装は別で定義し、呼び出す
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
89 - 後ほど説明
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
90
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
91 ---
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
92
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
93 # インターフェースの定義
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
94 - Xv6 の FileSystem の インターフェース
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
95 - typedef struct の直後にインターフェース名(fs)を書く
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
96 - fs で使う Code Gear を登録する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
97 - Code Gear は __code CodeGear名(引数); で記述する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
98 - 引数が Data Gear に相当する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
99 - 第1引数の Impl* fs がインターフェースの実装の型になる
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
100 - privateな実装側のヘッダーファイルも インターフェース と同じように用意する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
101 ``` c
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
102 typedef struct fs<Type,Impl> {
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
103 __code readsb(Impl* fs, uint dev, struct superblock* sb, __code next(...));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
104 __code iinit(Impl* fs, __code next(...));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
105 __code ialloc(Impl* fs, uint dev, short type, __code next(...));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
106 __code iupdate(Impl* fs, struct inode* ip, __code next(...));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
107 __code idup(Impl* fs, struct inode* ip, __code next(...));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
108 ....
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
109 } fs;
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
110 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
111 ---
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
112
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
113
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
114 # インターフェース実装内の CbC
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
115 - for文やif文がある場合はさらに実装を分ける
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
116 - Basic Block をもとに状態遷移ベースで記述することを目標とする
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
117 - インターフェースは外から呼び出されるAPI
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
118 - それに対してインターフェースの実装の Code Gearから明示的に呼び出される Code Gearは、Java の private メソッドのように扱われる。
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
119 - 実際に書き換えた一部の例として fs.c の ialloc の実装を分けた記述を説明する
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
121 ![](https://ie.u-ryukyu.ac.jp/~e165723/seni.pdf)
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
122 ```clike
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
123 __code iallocfs_impl(struct fs_impl* fs, uint dev, short type, __code next(...)) {
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
124 goto allocinode(fs, dev, sb, next(...));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
125 }
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
126 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
127 - 関数が呼び出されるとprivate実装に遷移する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
128
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
129 ---
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
130
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
131 # ialloc の CbCによる書き換え
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
132 - FileSystemの代表的なAPIであるiallocをCbCで書き直した
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
133 - ialloc
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
134 - inodeにi-numberという番号を割り当てている
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
136 ## 元ソースコード
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
137 - ialloc のソースコードの一部
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
138 - for文の中でif文の処理が行われ、複雑である
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
139 - for文とif文を切り分けてやる
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
140 ```clike
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
141 for (inum = 1; inum < sb.ninodes; inum++) {
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
142 bp = bread(dev, IBLOCK(inum));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
143 dip = (struct dinode*) bp->data + inum % IPB;
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
145 if (dip->type == 0) {
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
146 memset(dip, 0, sizeof(*dip));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
147 dip->type = type;
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
148 log_write(bp);
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
149 brelse(bp);
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
150 return iget(dev, inum);
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
151 }
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
152 ....
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
153 }
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
154 panic("ialloc: no inodes");
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
155
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
156 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
157
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
158 ## iallocの処理の流れ
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
159 ![](https://ie.u-ryukyu.ac.jp/~e165723/iallocloop.pdf)
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
160
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
161 ## CbCで書き換えたiallc
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
162 ### 書き換え前
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
163 - まずfor文のループするかどうか、条件を確認する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
164 ```clike
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
165 for (inum = 1; inum < sb.ninodes; inum++) {
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
166 ....
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 }
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 ```
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
169 ### 書き換え後
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
170 - ループの条件に合うかどうかを確認するためのCodeGearに遷移する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
171 ```clike
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
172 __code allocinode(struct fs_impl* fs_impl, uint dev, struct superblock* sb, __code next(...)){ //:skip
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
173 ....
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
174 goto allocinode_loopcheck(fs_impl, inum, dev, sb, bp, dip, next(...));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
175 }
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
176 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
177 - allocinode_loopcheckに遷移しループの条件の確認を行う
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
178 ```clike
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
179 __code allocinode_loopcheck(struct fs_impl* fs_impl, uint inum, uint dev, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(...)){ //:skip
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
180 if( inum < sb->ninodes){
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
181 goto allocinode_loop(fs_impl, inum, dev, type, sb, bp, dip, next(...));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
182 }
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
183 ....
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
184 }
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
185 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
186 - ループ文の条件に当てはまらなかった場合panicへ遷移し処理が終わる
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
187 ```clike
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
188 __code allocinode_loopcheck(struct fs_impl* fs_impl, uint inum, uint dev, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(...)){ //:skip
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
189 ....
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
190 char* msg = "failed allocinode...";
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
191 struct Err* err = createKernelError(&proc->cbc_context);
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
192 Gearef(cbc_context, Err)->msg = msg;
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
193 goto meta(cbc_context, err->panic);
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
194 }
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
195 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
196 ### 書き換え前
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
197 - for文の中で処理が行われているif文
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
198 - ループを抜けるか確認
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
199 ```clike
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
200 if (dip->type == 0) {
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
201 ....
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
202 }
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
203 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
204 ### 書き換え後
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
205 - ループから抜けるかどうかを確認する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
206 - 抜ける場合はallocinode_noloopへ遷移する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
207 ```clike
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
208 __code allocinode_loop(struct fs_impl* fs_impl, uint inum, uint dev, short type, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(...)){ //:skip
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
209 ....
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
210 if(dip->type = 0){
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
211 goto allocinode_noloop(fs_impl, inum, dev, sb, bp, dip, next(...));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
212 }
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
213 ....
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
214 }
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
215 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
216 - ループから抜けなかった場合
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
217 - inumの値をインクリメント
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
218 - 再びallocinode_loopcheckへと遷移する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
219 ```clike
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
220 __code allocinode_loop(struct fs_impl* fs_impl, uint inum, uint dev, short type, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(...)){ //:skip
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
221 ....
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
222 inum++;
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
223 goto allocinode_loopcheck(fs_impl, inum, dev, type, sb, bp, dip, next(...));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
224 }
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
225 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
226 ### 書き換え前
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
227 - 処理が抜けた場合
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
228 - 変更された値などを更新
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
229 - logに書き込んでやり保持していた値解放
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
230 - returnでigetを返し終了
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
231 ```clike
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
232 memset(dip, 0, sizeof(*dip));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
233 dip->type = type;
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
234 log_write(bp);
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
235 brelse(bp);
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
236 return iget(dev, inum);
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
237 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
238 ### 書き換え後
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
239 - 処理を抜けた場合allocinode_noloopへ遷移
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
240 - 処理を行い値を返し終了
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
241 ```clike
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
242 __code allocinode_noloop(struct fs_impl* fs_impl, uint inum, uint dev, short type, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(int ret, ...)){ //:skip
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
243 memset(dip, 0, sizeof(*dip));
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
244 dip->type = type;
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
245 log_write(bp);
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
246 brelse(bp);
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
247 ret = iget(dev, inum);
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
248 goto next(ret, ...);
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
249 }
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 ```
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
253 ---
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
254 # 書き換えの評価
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
255 - 今回はfor文やif文がある場合切り出してやり、Basic Block 単位に書き換えることができた
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
256 - Basic Block 単位に書き換えたことによって、組み合わせを変え処理の改善などに利用可能
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 ## まとめと今後の方針
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
260 - OS 内部で CbC インターフェースを扱えるようになった
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
261 - CbC の書き換えが完了すれば、継続の入力と出力を検査することで OS の信頼性を保証したり、インターフェースの実装の入れ替えが可能になり拡張性が実現可能
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
262 - デバックをまだ行っていないため正常に動くかどうか確認することが求められる
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
263
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
264
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
265