SlideShare a Scribd company logo
RTOS入門
タスク
2016-09-09 三輪
タスクとは
• タスクとは、複数の処理を並行処理(※)するためのもの。
• 優先度によってどのタスクを実行するか制御される。
• より高優先度のタスクが実行される。
• OS の制御によりタスクが実行される(ディスパッチと呼ぶ)。
並行/並列
並行処理: 1つのCPU上で複数タスクが動作すること
並列処理: 複数のCPU上で複数タスクが同時に動作すること
一般的な定義は無いので、ここでは以下のように定義する。
タスクA タスクB タスクC タスクA タスクB タスクC
タスクA
タスクA
タスクA
タスク状態遷移
• タスクは複数の状態がある
• READY <=> RUNNING は OS によって遷移される
• RUNNING => WAITING => READY は タスクがみずから状
態遷移させる
• RUNNING => DORMANT も然り
自タスクによる待ち
slp_tsk
セマフォ取得待ち
イベント取得待ち
sus_tsk
自タスクによる終了
ext_tsk
他タスクや割り込みハンドラによる起動
cre_tsk
他タスクや割り込みハンドラによる待ち解除
slp_tsk完了
セマフォ取得完了
イベント取得完了
rsm_tsk
http://www.kumikomi.net/archives/2008/12/32rtos.php?page=6
ディスパッチ
AF
ライブビュー
TFT
タッチパネル
優先度高
実行状態
実行可能状態
待機状態
優先度が高いタスクが実行される。タスクは実行状態、実行可能状態、待機状態など状態
遷移を持つ。
ディスパッチ
ディスパッチ
ディスパッチ
タスクエントリーに注意
• OS がディスパッチするとタスクエントリーが呼ばれる。
• READY→RUNNING と状態遷移する
• タスクエントリー内では(長時間)CPUを占有するようなことを
してはいけない
• for(;;){ レジスタ読んで確認 } のようなことをしてはいけない。
• 他のタスクが CPU を使えなくなる。
• 迅速に処理しとっとと終了すべし
AF
ライブビュー
TFT
タッチパネル
優先度高
実行状態
実行可能状態
待機状態
タスクが実行状態のままだと、より低優先度のタスクがディスパッチされない(高優先度
のタスクはディスパッチされる)
CPU専有しちゃダメ
低優先度のタスクがディ
スパッチされない
タスク優先度に注意
• ハードウェアに近いタスクほど高優先度
• そうでないタスクが低優先度
• システム全体を考慮して優先度が決定されるので、勝手に優先
度を設定しないこと。
タッチパネル
ライブビュー
TFT
AF
優先度高
実行状態
実行可能状態
待機状態
タスクの優先度はシステム全体の設計を考えて決定すべき。何も考えずに優先度を変更し
てはいけない。
ディスパッチ
ディスパッチ
ディスパッチ
優先度を勝手に変更しちゃダメ
スタックサイズに注意
• スタックサイズはタスクが利用できるメモリ
• 自動変数や関数呼び出しの引数を記憶したりする
• 大きすぎる自動変数(配列とか)を作ったり、関数呼び出しが深
すぎるとスタックオーバーフローする
• 原因調査しづらい非常に厄介な現象となるので注意
スタックサイズに注意
タスクBのスタック
4096バイト
char a[5000];
タスクAのスタック
4096バイト
タスクAのスタック
4096バイト
5000バイト
スタックを破壊

More Related Content

What's hot

NGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX: High Performance Load Balancing
NGINX: High Performance Load Balancing
NGINX, Inc.
 
その ionice、ほんとに効いてますか?
その ionice、ほんとに効いてますか?その ionice、ほんとに効いてますか?
その ionice、ほんとに効いてますか?
Narimichi Takamura
 
Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops)
Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops) Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops)
Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops)
Joël Séguillon
 
10GbE時代のネットワークI/O高速化
10GbE時代のネットワークI/O高速化10GbE時代のネットワークI/O高速化
10GbE時代のネットワークI/O高速化
Takuya ASADA
 
The Forefront of the Development for NVDIMM on Linux Kernel (Linux Plumbers c...
The Forefront of the Development for NVDIMM on Linux Kernel (Linux Plumbers c...The Forefront of the Development for NVDIMM on Linux Kernel (Linux Plumbers c...
The Forefront of the Development for NVDIMM on Linux Kernel (Linux Plumbers c...
Yasunori Goto
 
젠킨스 설치 및 설정
젠킨스 설치 및 설정젠킨스 설치 및 설정
젠킨스 설치 및 설정
중선 곽
 
Understanding Monorepos
Understanding MonoreposUnderstanding Monorepos
Understanding Monorepos
Benjamin Cabanes
 
SOA vs Microservices vs SBA
SOA vs Microservices vs SBASOA vs Microservices vs SBA
SOA vs Microservices vs SBA
Michael Sukachev
 
ネットワーク自動化、なに使う? ~自動化ツール紹介~(2017/08/18追加開催)
ネットワーク自動化、なに使う? ~自動化ツール紹介~(2017/08/18追加開催) ネットワーク自動化、なに使う? ~自動化ツール紹介~(2017/08/18追加開催)
ネットワーク自動化、なに使う? ~自動化ツール紹介~(2017/08/18追加開催)
akira6592
 
CyberAgent における OSS の CI/CD 基盤開発 myshoes #CICD2021
CyberAgent における OSS の CI/CD 基盤開発 myshoes #CICD2021CyberAgent における OSS の CI/CD 基盤開発 myshoes #CICD2021
CyberAgent における OSS の CI/CD 基盤開発 myshoes #CICD2021
whywaita
 
Quarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java frameworkQuarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java framework
SVDevOps
 
Rootless Containers
Rootless ContainersRootless Containers
Rootless Containers
Akihiro Suda
 
[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep Dive[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep Dive
Akihiro Suda
 
3GPP TS 38.300-100まとめ
3GPP TS 38.300-100まとめ3GPP TS 38.300-100まとめ
3GPP TS 38.300-100まとめ
Tetsuya Hasegawa
 
Kvm
KvmKvm
Fluentdのお勧めシステム構成パターン
Fluentdのお勧めシステム構成パターンFluentdのお勧めシステム構成パターン
Fluentdのお勧めシステム構成パターン
Kentaro Yoshida
 
Cloud run - Serverless Containers Done Right
Cloud run - Serverless Containers Done RightCloud run - Serverless Containers Done Right
Cloud run - Serverless Containers Done Right
mfazal
 
Fuchsia概略その1
Fuchsia概略その1Fuchsia概略その1
Fuchsia概略その1
l_b__
 
Installing and Configuring NGINX Open Source
Installing and Configuring NGINX Open SourceInstalling and Configuring NGINX Open Source
Installing and Configuring NGINX Open Source
NGINX, Inc.
 
ZabbixのAPIを使って運用を楽しくする話
ZabbixのAPIを使って運用を楽しくする話ZabbixのAPIを使って運用を楽しくする話
ZabbixのAPIを使って運用を楽しくする話
Masahito Zembutsu
 

What's hot (20)

NGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX: High Performance Load Balancing
NGINX: High Performance Load Balancing
 
その ionice、ほんとに効いてますか?
その ionice、ほんとに効いてますか?その ionice、ほんとに効いてますか?
その ionice、ほんとに効いてますか?
 
Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops)
Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops) Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops)
Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops)
 
10GbE時代のネットワークI/O高速化
10GbE時代のネットワークI/O高速化10GbE時代のネットワークI/O高速化
10GbE時代のネットワークI/O高速化
 
The Forefront of the Development for NVDIMM on Linux Kernel (Linux Plumbers c...
The Forefront of the Development for NVDIMM on Linux Kernel (Linux Plumbers c...The Forefront of the Development for NVDIMM on Linux Kernel (Linux Plumbers c...
The Forefront of the Development for NVDIMM on Linux Kernel (Linux Plumbers c...
 
젠킨스 설치 및 설정
젠킨스 설치 및 설정젠킨스 설치 및 설정
젠킨스 설치 및 설정
 
Understanding Monorepos
Understanding MonoreposUnderstanding Monorepos
Understanding Monorepos
 
SOA vs Microservices vs SBA
SOA vs Microservices vs SBASOA vs Microservices vs SBA
SOA vs Microservices vs SBA
 
ネットワーク自動化、なに使う? ~自動化ツール紹介~(2017/08/18追加開催)
ネットワーク自動化、なに使う? ~自動化ツール紹介~(2017/08/18追加開催) ネットワーク自動化、なに使う? ~自動化ツール紹介~(2017/08/18追加開催)
ネットワーク自動化、なに使う? ~自動化ツール紹介~(2017/08/18追加開催)
 
CyberAgent における OSS の CI/CD 基盤開発 myshoes #CICD2021
CyberAgent における OSS の CI/CD 基盤開発 myshoes #CICD2021CyberAgent における OSS の CI/CD 基盤開発 myshoes #CICD2021
CyberAgent における OSS の CI/CD 基盤開発 myshoes #CICD2021
 
Quarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java frameworkQuarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java framework
 
Rootless Containers
Rootless ContainersRootless Containers
Rootless Containers
 
[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep Dive[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep Dive
 
3GPP TS 38.300-100まとめ
3GPP TS 38.300-100まとめ3GPP TS 38.300-100まとめ
3GPP TS 38.300-100まとめ
 
Kvm
KvmKvm
Kvm
 
Fluentdのお勧めシステム構成パターン
Fluentdのお勧めシステム構成パターンFluentdのお勧めシステム構成パターン
Fluentdのお勧めシステム構成パターン
 
Cloud run - Serverless Containers Done Right
Cloud run - Serverless Containers Done RightCloud run - Serverless Containers Done Right
Cloud run - Serverless Containers Done Right
 
Fuchsia概略その1
Fuchsia概略その1Fuchsia概略その1
Fuchsia概略その1
 
Installing and Configuring NGINX Open Source
Installing and Configuring NGINX Open SourceInstalling and Configuring NGINX Open Source
Installing and Configuring NGINX Open Source
 
ZabbixのAPIを使って運用を楽しくする話
ZabbixのAPIを使って運用を楽しくする話ZabbixのAPIを使って運用を楽しくする話
ZabbixのAPIを使って運用を楽しくする話
 

More from miwarin

GoF デザインパターン 2009
GoF デザインパターン 2009GoF デザインパターン 2009
GoF デザインパターン 2009
miwarin
 
RTOS入門 割り込み制御
RTOS入門 割り込み制御RTOS入門 割り込み制御
RTOS入門 割り込み制御
miwarin
 
RTOS入門 タスク間同期通信
RTOS入門 タスク間同期通信RTOS入門 タスク間同期通信
RTOS入門 タスク間同期通信
miwarin
 
リーンスタートアップとは
リーンスタートアップとはリーンスタートアップとは
リーンスタートアップとはmiwarin
 
マーケティングとは
マーケティングとはマーケティングとは
マーケティングとはmiwarin
 
スクラムとは
スクラムとはスクラムとは
スクラムとはmiwarin
 
Clangとは
ClangとはClangとは
Clangとはmiwarin
 
NetBSDとは
NetBSDとはNetBSDとは
NetBSDとはmiwarin
 
リーンキャンバステンプレ
リーンキャンバステンプレリーンキャンバステンプレ
リーンキャンバステンプレmiwarin
 

More from miwarin (9)

GoF デザインパターン 2009
GoF デザインパターン 2009GoF デザインパターン 2009
GoF デザインパターン 2009
 
RTOS入門 割り込み制御
RTOS入門 割り込み制御RTOS入門 割り込み制御
RTOS入門 割り込み制御
 
RTOS入門 タスク間同期通信
RTOS入門 タスク間同期通信RTOS入門 タスク間同期通信
RTOS入門 タスク間同期通信
 
リーンスタートアップとは
リーンスタートアップとはリーンスタートアップとは
リーンスタートアップとは
 
マーケティングとは
マーケティングとはマーケティングとは
マーケティングとは
 
スクラムとは
スクラムとはスクラムとは
スクラムとは
 
Clangとは
ClangとはClangとは
Clangとは
 
NetBSDとは
NetBSDとはNetBSDとは
NetBSDとは
 
リーンキャンバステンプレ
リーンキャンバステンプレリーンキャンバステンプレ
リーンキャンバステンプレ
 

RTOS入門 タスク概要