ESP-IDFを使ってみる
タスクのスケジューリングルール
マルチコアの環境で、タスクを複数同時に起動したときのコアの決め方をEspressifの開発者に教えてもらいました。
なんか難しいことが書いてありますが、せっかく教えてもらったので公開します。
* When creating a task with no affinity (i.e. calling
`xTaskCreate()`), the preemption rules are as follows:
* If the task has higher priority than the current priority
of both cores, it will preempt the core with the lower priority.
* If the both cores have a equal current priority that is
lower than the created task, the task will prefer to preempt the
current core (i.e. the core that called `xTaskCreate()`)
* If the created task has equal priority to the current
priority of one or both cores, the created task will round robin on
the next tick.
* When creating a task with affinity (i.e. calling
`xTaskCreatePinnedToCore()`), the preemption rules are simpler
* If the current priority of the target core is lower than
that of the created task, the task will preempt the core
* If the current priority of the target core is equal to that
of the created task, the task will round robin with that core
* If the current priority of the target core is higher than
that of the created task, the task will not run preempt or round
robin
*アフィニティなしでタスクを作成する(つまり、 `xTaskCreate()`を呼び出す)場合、プリエンプションルールは次のとおりです:
*タスクが両方のコアの現在の優先度よりも高い優先度を持っている場合、それは低い優先度のタスクからコアを横取りします。
つまり、
作成したタスクの優先度=5
Core1で実行中のタスクの優先度=3
Core2で実行中のタスクの優先度=4
の場合、Core1の実行権を横取ります。
*両方のコアの現在の優先度が等しく、作成されたタスクよりも低い場合、タスクは現在のコア(つまり
`xTaskCreate()`を呼び出したコア)を横取りします。
つまり、
作成したタスクの優先度=5
Core1で実行中のタスクの優先度=3
Core2で実行中のタスクの優先度=3
の場合、xTaskCreateを呼び出した(呼び出し元のタスクが動いている)コアの実行権を横取ります。
*作成したタスクが現在のコアの優先順位と同じ優先順位である場合、作成したタスクは次のティックでラウンドロビンします。
*アフィニティを使用してタスクを作成する(すなわち
`xTaskCreatePinnedToCore()`を呼び出す)場合、プリエンプションルールはより単純です
*ターゲットコアの現在の優先度が作成されたタスクの優先度より低い場合、タスクはコアを横取りします。
*ターゲットコアの現在の優先度が作成されたタスクの優先度と等しい場合、タスクはそのコアでラウンドロビンします。
*ターゲットコアの現在の優先度が作成されたタスクの優先度よりも高い場合、タスクは横取りもラウンドロビンもしません。
続く....