JP2012226709A - Exclusive control device and microcomputer - Google Patents
Exclusive control device and microcomputer Download PDFInfo
- Publication number
- JP2012226709A JP2012226709A JP2011096418A JP2011096418A JP2012226709A JP 2012226709 A JP2012226709 A JP 2012226709A JP 2011096418 A JP2011096418 A JP 2011096418A JP 2011096418 A JP2011096418 A JP 2011096418A JP 2012226709 A JP2012226709 A JP 2012226709A
- Authority
- JP
- Japan
- Prior art keywords
- priority
- thread
- lock
- register
- core
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Landscapes
- Multi Processors (AREA)
Abstract
Description
本発明は、共有リソースの排他制御が可能な排他制御装置に関し、特に、複数のプロセッサエレメントが実行時間内に共有リソースを使用した処理を行うことを可能にする排他制御装置に関する。 The present invention relates to an exclusive control device capable of exclusive control of a shared resource, and more particularly to an exclusive control device that allows a plurality of processor elements to perform processing using a shared resource within an execution time.
マルチコアプロセッサがいくつかのスレッドを並行に実行する際、複数のコアが共有リソースを使用することがあり、従来から、各種の共有リソースの排他制御の手法が知られている。 When a multi-core processor executes several threads in parallel, a plurality of cores may use shared resources. Conventionally, a method for exclusive control of various shared resources is known.
一般的な手法はフラグを使用するものである。共有リソースに共通の1つのフラグを設け、スレッドAは共有リソースを使用する前にフラグの状態をチェックし、フラグが解放されている場合はフラグをオンにすることで他のスレッドBが共有リソースを使用することを禁止し、この共有リソースを使用する。このように、共有リソースを占有することをロックという。 A common approach is to use flags. A common flag is provided for the shared resource, and the thread A checks the state of the flag before using the shared resource. If the flag is released, the thread A turns on the flag so that the other thread B can share the shared resource. Prohibit the use of and use this shared resource. Thus, occupying a shared resource is called a lock.
スレッドAは共有リソースを使用し終わると、フラグをオフにして共有リソースを解放する。これにより、スレッドBは共有リソースを使用可能になる。このようなロックの処理は、OS等の共有リソースの競合を調停するソフトウェアが受け持つことが一般的である。 When thread A finishes using the shared resource, it turns off the flag and releases the shared resource. As a result, the thread B can use the shared resource. Such lock processing is generally handled by software that arbitrates contention for a shared resource such as an OS.
スレッドBは、スレッドAが共有リソースをロックして使用中、解放されるまで待機する。スレッドBが共有リソースの解放を待つ態様の1つに、スレッドBがフラグの状態のチェックを繰り返すスピンロック方式がある。スピンロック方式ではスレッドBはロックを取得するまでフラグの監視のためだけに実行中になる。また、スレッドBにとって、いつになったらスレッドAがロックを解放するかも不明である。このため、コアがスレッドBを実行しても何ら処理結果が得られず、また、スレッドBの最悪実行時間を保証することができないという状況が生じうる。 Thread B waits until thread A locks the shared resource and is used and released. One mode in which thread B waits for the release of a shared resource is a spin lock system in which thread B repeatedly checks the flag state. In the spin lock method, thread B is executing only for flag monitoring until a lock is acquired. It is also unclear for thread B when thread A will release the lock. For this reason, even if the core executes the thread B, no processing result can be obtained, and the worst execution time of the thread B cannot be guaranteed.
そこで、スピン時間を短縮する技術が提案されている(例えば、特許文献1参照。)。特許文献1には、情報処理手段がロック獲得に失敗したときに、先行するロック獲得情報処理手段のロック継続時間を判定閾値時間と比較し、その比較結果に応じてロック待ち動作を選択する技術が開示されている。 Therefore, a technique for shortening the spin time has been proposed (see, for example, Patent Document 1). In Patent Document 1, when the information processing unit fails to acquire the lock, the lock continuation time of the preceding lock acquisition information processing unit is compared with the determination threshold time, and the lock waiting operation is selected according to the comparison result. Is disclosed.
しかしながら、特許文献1のような手法はソフトウェアを必要とするという不都合がある。すなわち、スピンロックをソフトウェアで実現するにはアトミック命令が必要になるが、全てのCPUがアトミック命令を実行可能とは限らない。これは、アトミック命令の実装にはハード側(CPU側)が対応している必要があり、具体的にはアトミック命令に対応した複雑なバス機構が必要なので、コスト高となるためである。このため、CPUによってはソフト的にスピンロックを実現できない場合がある。 However, the technique as in Patent Document 1 has a disadvantage that it requires software. In other words, although an atomic instruction is required to realize spin lock by software, not all CPUs can execute the atomic instruction. This is because the hardware side (CPU side) needs to correspond to the implementation of the atomic instruction, and more specifically, a complicated bus mechanism corresponding to the atomic instruction is required, which increases the cost. For this reason, some CPUs may not be able to realize a spin lock in software.
そこで、マルチコアシステムでは、最悪実行時間を保証すると共に、アトミック命令を実装していないCPUにおいてもスピンロックを実現するための専用のハードウェアが要請される。 Therefore, a multi-core system is required to have a dedicated hardware for guaranteeing the worst execution time and realizing a spin lock even in a CPU not mounting an atomic instruction.
図1は、スピンロックハードウェアの構成図の一例を示す。スピンロックハードウェアは、コア毎に専用の優先度レジスタ、各優先度レジスタに設定された優先度の比較回路、及び、比較結果に基づきロックを取得したコアを指定するコア毎に専用のロック取得フラグを有する。 FIG. 1 shows an example of a configuration diagram of spin lock hardware. Spinlock hardware has a dedicated priority register for each core, a priority comparison circuit set in each priority register, and a dedicated lock acquisition for each core that specifies the core that acquired the lock based on the comparison result Has a flag.
このスピンロックハードウェアは、各コアが優先度レジスタに優先度を設定することで、各コアが共有リソースをロックできるまでスピンロックする、優先度順の待ち行列(キューイング)になっている。このようなスピンロックハードウェアをキューイングスピンロックハードウェアという場合がある。 The spin lock hardware is a queue in order of priority (queuing) in which each core spins until each core can lock the shared resource by setting the priority in the priority register. Such spin lock hardware is sometimes referred to as queuing spin lock hardware.
しかしながら、図1のようなスピンロックハードウェアでは、以下のような不都合がある。
(1)スレッドの優先度の継承が困難
図2はスレッドの優先度を説明する図の一例である。例えば、コア0が、アプリケーション0が有するスレッドAとスレッドAから呼び出されるスレッドaを実行し、コア1が、アプリケーション1が有するスレッドBを実行している。スレッドAは共有リソースR1を使用し、スレッドaとスレッドBは共有リソースR2を使用する。スレッド間の優先順位は次のようになっている。
スレッドA>スレッドB>スレッドa
コア0がスレッドAの優先度を優先度レジスタに設定すると、スレッドAは他のスレッドよりも優先度が高いので共有リソースR1をロックできる。この後、コア0がスレッドaを実行するため、コア0がスレッドaの優先度を優先度レジスタに設定し、コア1がスレッドBを実行するため、コア1がスレッドBの優先度を優先度レジスタに設定する場合がある。共有リソースR2が解放されていれば、スレッドaとスレッドBの優先度が比較されるが、スレッドBの方が、スレッドaよりも優先度が高いので、スレッドBが共有リソースR2をロックしてしまう。
However, the spin lock hardware as shown in FIG. 1 has the following disadvantages.
(1) Inheritance of thread priority is difficult FIG. 2 is an example of a diagram illustrating thread priority. For example, the
Thread A> Thread B> Thread a
When the
すなわち、スレッドAは処理のためにスレッドaの実行結果を必要とするが、スレッドBの方がスレッドaよりも優先度が高いため、スレッドAが優先度の低いスレッドBの処理を待たなければならない。このような優先度の逆転現象は、共有リソースR1の最高優先度のコアを特定し、共有リソースR2の優先度に承継する仕組みがないために生じる。しかし、スピンロックハードウェアでは優先度を継承する仕組みがないため、優先度が高いスレッドAの最悪実行時間を保証できない場合が生じうる。上記のようにソフトウェアを組み合わせれば実現可能だが、優先度の承継が可能なスピンロックを実現するためのソフト上のオーバーヘッドが大きいため現実的には実現が困難である。 That is, the thread A needs the execution result of the thread a for processing. However, since the thread B has a higher priority than the thread a, the thread A must wait for the processing of the thread B having a lower priority. Don't be. Such a priority inversion phenomenon occurs because there is no mechanism for specifying the highest priority core of the shared resource R1 and succeeding to the priority of the shared resource R2. However, since there is no mechanism for inheriting the priority in the spin lock hardware, the worst execution time of the thread A having a high priority may not be guaranteed. This can be realized by combining software as described above, but it is practically difficult to realize because the software overhead for realizing the spin lock capable of inheriting the priority is large.
(2)特定のコアを優先する仕組みがない
優先度レジスタには、例えば、スレッドが優先度を設定し、各スレッドの優先度が比較される。このため、原則的には設定された優先度の大きいコア(又は小さいコア)から順に共有リソースをロックできる。
(2) No mechanism for prioritizing a specific core In the priority register, for example, a thread sets a priority, and the priority of each thread is compared. For this reason, in principle, the shared resources can be locked in order from the set cores with higher priorities (or smaller cores).
しかしながら、あるコアが実行するスレッドが緊急時にのみ起動するような特殊なスレッドの場合、そのスレッドを実行するコアは一般のアプリケーションのスレッドを実行するコアよりも優先されることが好ましい場合がある。このような場合に、図1のスピンロックハードウェアは特定のコアを優先することが困難である。 However, when a thread executed by a certain core is a special thread that is activated only in an emergency, it may be preferable that the core executing the thread has priority over the core executing the thread of a general application. In such a case, it is difficult for the spin lock hardware of FIG. 1 to prioritize a specific core.
本発明は、上記課題に鑑み、スレッド間の優先度の逆転現象を極力低減し、又は、特定のコアを優先することが可能な排他制御装置を提供することを目的とする。 In view of the above problems, an object of the present invention is to provide an exclusive control device capable of reducing the priority inversion phenomenon between threads as much as possible or giving priority to a specific core.
本発明は、複数のプロセッサエレメントに対応づけて配置された優先度レジスタと、前記優先度レジスタ毎に配置されたフラグ状態保持手段と、前記優先度レジスタに設定された優先度を比較し、最も高い優先度が設定された前記優先度レジスタに対応する前記フラグ状態保持手段にロック状態を設定する優先度比較回路と、前記優先度レジスタに設定された優先度のうち最高の優先度を格納する最高優先度レジスタと、を有する排他制御装置を提供する。 The present invention compares a priority register arranged in association with a plurality of processor elements, a flag state holding unit arranged for each of the priority registers, and a priority set in the priority register. A priority comparison circuit for setting a lock state in the flag state holding means corresponding to the priority register for which a high priority is set, and the highest priority among the priorities set in the priority register are stored An exclusive controller having a highest priority register is provided.
スレッド間の優先度の逆転現象を極力低減し、又は、特定のコアを優先することが可能な排他制御装置を提供できる。 It is possible to provide an exclusive control device capable of reducing the priority inversion phenomenon between threads as much as possible or giving priority to a specific core.
以下、本発明を実施するための形態について図面を参照しながら説明する。 Hereinafter, embodiments for carrying out the present invention will be described with reference to the drawings.
図3は、マイコンのハードウェア構成図の一例を示す。マイコン200はワンチップマイコン、基板上でCPU等が別チップになっているマイコンなど実装形態はどのような状態でもよい。
FIG. 3 shows an example of a hardware configuration diagram of the microcomputer. The
図示するマイコン200は、ECU(Electronic Control Unit)に搭載されることが想定されているがその用途は車両に限定されない。なお、ECUには、マイコン200の他、センサの信号を受け付ける入力チャネル及びそのドライバ、マイコン200の監視IC、電源IC等が搭載される。
The illustrated
車載されるECUには、その主要な機能により、エンジンECU、ブレーキECU、ボディECU、ナビゲーションECU(AV・情報処理ECU)、ゲートウェイECU等の種類がある。本実施例のマイコン200はECUの機能の違いに影響されず搭載されることが可能である。また、近年、複数の機能を1つのECUに統合する試みがなされているので、マイコン200の搭載先のECUを機能により区別する必要性も低い。
There are various types of ECUs mounted on the vehicle, such as an engine ECU, a brake ECU, a body ECU, a navigation ECU (AV / information processing ECU), and a gateway ECU, depending on main functions. The
マイコン200は、バスに接続されたCPU11、ROM12、スピンロックハードウェア100、INTC13、RAM14、DMAC15、並びに、I/Oブリッジ16を有し、I/Oブリッジ16にはADC17及びCANコントローラ18が接続されている。
The
CPU11は複数のコア0〜nを有し、図にはコア0及びコア1が図示されているが、3つ以上のコアを有していてもよい。コア0、1はそれぞれローカルRAM0,1を作業メモリに使用する。なお、マルチコア型でなく1つのCPUが、レジスタや演算器を切り換えながら並列的に命令を実行することで複数のCPUが存在するように見せるヴァーチャルCPUを有していてもよい。また、チップとして独立した複数のCPUが搭載されていてもよい。複数のコアや複数の独立したCPUをプロセッサエレメントという場合がある。
The
ROM12はフラッシュメモリなどの不揮発メモリであり、CPU11が実行するプログラムや静的なデータを記憶している。プログラムは、コア0が実行するアプリケーション0、コア1が実行するアプリケーション1、及び、OSやデバイスドライバが記憶されている。アプリケーションをより小さい粒度に区分したスレッドやタスクという概念があり、本実施形態でも適宜、アプリケーションからスレッドやタスクを抽出して説明する。なお、説明を容易にするため、各アプリケーションと各コアの関係は固定であるとするが、例えば、OS等がコアにアプリケーションを動的に割り当てることも可能である。この場合、OSはコアとアプリケーションの対応を記憶しているので、OSにとって各アプリケーションと各コアの関係が固定であるか否かによる不都合は少ない。
The
INTC13はIRQやその他の割り込み端子を介して周辺機器から入力された割り込み要求を、周辺機器の優先順位に基づき調停してCPU11に通知する。これによりCPU11は、割り込みした周辺機器に応じて決まった処理を実行する。
The
RAM14は、CPU11がプログラムを実行するための作業領域である。CPU11はメモリバスを介してROM(またはプログラムをSDRAMに移動して実行する場合はSDRAM)12からプログラムを読み込み、また、必要であればデータバスを介してRAM14からデータを読み出しプログラムを実行する。
The
DMAC15は、CPU11からの指示によりRAM14からI/Oブリッジ16を介して周辺機器にデータを送信し、周辺機器から割り込みされたCPU11から指示を受けて、I/Oブリッジ16を介して周辺機器からデータを受け取り、RAM14に書き込む。
The
I/Oブリッジ16は、マルチプレクサ又はブリッジ回路であり、チャネル毎にADC17、及び、CANコントローラ18とそれぞれ接続されており、これらの周辺機器とデータを送受信する。ADC(analog to digital converter)17は、センサが検出したアナログ信号をデジタル信号に変換する。ADC17にはΔΣ型、逐次比較型、二重積分型などがあるがどのような変換原理で変換してもよい。なお、ADC17もINTC13を介して変換の終了をCPU11に通知する。
The I / O bridge 16 is a multiplexer or a bridge circuit, and is connected to the
CANコントローラ18は、車載ネットワークを介して接続された他のECUと通信するための通信装置である。CANコントローラ18は、CPU11から通信データの送信要求を受け付けるとフレームの各フィールドにIDやデータを格納しCANバスに出力する。また、CANコントローラ18は、受信すべきIDの通信データを検出するとそれを取り込みCPU11に割り込んで通知する。
The
図3において、アプリケーションが使用する周辺機器のうち、複数のアプリケーションが使用する周辺機器が共有リソースである。例えば、ADC17とCANコントローラ18が、それぞれ共有リソースR1,R2であるとする。
In FIG. 3, among peripheral devices used by applications, peripheral devices used by a plurality of applications are shared resources. For example, it is assumed that the
スピンロックハードウェア100(以下、区別する場合スピンロックハードウェア1,2…という)は、この共有リソース毎に配置される。すなわち、スピンロックハードウェア1はADC用(共有リソースR1)、スピンロックハードウェア2はCANコントローラ18用(共有リソースR2)、スピンロックハードウェア3は…、のようにロック対象の共有リソースとスピンロックハードウェアが対応づけられている。コアが共有リソースを使用するためには、スピンロックハードウェア1により共有リソースR1を、スピンロックハードウェア2により共有リソースR2を、それぞれロックしなければならない。 The spin lock hardware 100 (hereinafter referred to as “spin lock hardware 1, 2... When distinguished”) is arranged for each shared resource. That is, the spin lock hardware 1 is for the ADC (shared resource R1), the spin lock hardware 2 is for the CAN controller 18 (shared resource R2), the spin lock hardware 3 is ... Lock hardware is associated. In order for the core to use the shared resource, the shared resource R1 must be locked by the spin lock hardware 1, and the shared resource R2 must be locked by the spin lock hardware 2.
図4は、本実施例のスピンロックハードウェア100の構成図の一例を示す。このスピンロックハードウェア100は、ネスト構造のスレッドの優先度を継承可能な点に特徴の1つがある。
FIG. 4 shows an example of a configuration diagram of the
まず、スピンロックハードウェア100は、コア毎に専用の優先度レジスタ21(区別する場合、優先度レジスタ0、1…nという)、各優先度レジスタ21に設定された優先度の比較回路22、比較結果に基づきロックを取得したコアを指定するコア毎に専用のロック取得フラグ23(区別する場合、ロック取得フラグ0、1…nという)、及び、最高優先度レジスタ24を有する。それぞれの優先度レジスタ21には各コアが実行するスレッドの優先度が設定される。また、それぞれの優先度レジスタ21は比較回路22に接続されている。比較回路22は各ロック取得フラグ23に接続されると共に、最高優先度レジスタ24に接続されている。ロック取得フラグ23の状態及び最高優先度レジスタ24の内容は外部から読み取れるようになっている。
First, the
比較回路22は、全ての優先度レジスタ0〜nのうち最も高い優先度が設定された優先度レジスタを特定する。本実施例では数値が大きいほど優先度が高いとするが、逆でもよい。比較回路22は、最も高い優先度が設定された優先度レジスタ0〜nに対応するロック取得フラグ0〜nに“1”を設定する。したがって、“1”が設定されたロック取得フラグ0〜nに対応したコア0〜nが、スピンロックハードウェア100がロックする共有リソースをロックできたこと(使用権を得たこと)になる。
The
また、比較回路22は、優先度レジスタ0〜nのうち最も高い優先度が設定された優先度レジスタ21の値を最高優先度レジスタ24に設定する。最高優先度レジスタ24は、このスピンロックハードウェア100における最高の優先度を常に格納している。
Further, the
図5はスピンロックハードウェア100の作用を説明する図の一例である。図5(a)に示すように、コア0の優先度が“00001111”、コア1の優先度が“00000011”であるとする。設定される優先度は、例えばタイムスタンプとして扱われるカウンタの値である。数値が高い方が優先度が高い場合、カウンタはある設定値から一様に減少する。また、数値が低い方が優先度が高い場合、カウンタは一様に増大する。したがって、いずれの場合も、より早くカウンタから数値を読み出して優先度を設定したコアが優先されるようになる。また、優先度を先に設定したコアが優先されるので、スピンロックハードウェア100はFIFO型の待ち行列(キューイング)になる。
FIG. 5 is an example of a diagram for explaining the operation of the
比較回路22は、最も大きい優先度が設定されたコア0のロック取得フラグ0を“1”にセットする。比較回路22は、コア0以外のコア1のロック取得フラグ1を“0”にクリアする。ロック取得フラグ0〜nのうち、“1”を出力するのは1つだけである。また、比較回路22は、コア0、1の優先度のうち最も高い優先度である“00001111”を取得して最高優先度レジスタ24に格納する。
The
次に、コア0が共有リソースを使用する処理を終え、優先度レジスタ1にゼロを設定する。これにより、比較回路22は、最も大きい優先度が設定されたコア1のロック取得フラグ1を“1”にセットし、コア0のロック取得フラグ0を“0”にクリアする。比較回路22は、コア0、1の優先度のうち最も高い優先度である“00000011”を取得して最高優先度レジスタ24に格納する。
Next, the
スピンロックハードウェア100のこのような作用により、OSは共有リソースをロックすべきコアを特定でき、さらに、スレッドが2段以上のネスト構造になっている場合、2段目以降のスレッドに優先度を承継させることができる。
With this action of the
図6は、スピンロックハードウェア100を操作する各機能の機能ブロック図の一例である。各アプリケーション1,2がスピンロックハードウェア100を自由に操作すると、この時点で競合が生じるので、一般にはOS等の特定のソフトウェアが(例えば、特権モードで)スピンロックハードウェア100を操作する。
FIG. 6 is an example of a functional block diagram of each function for operating the
コア0がアプリケーション0を、コア1がアプリケーション1を、それぞれスレッド単位で実行するものとする。アプリケーション0,1は、それぞれロック要求部31、リソース対応処理部32、及び、ロック解放要求部33を有する。
Assume that
各スレッドは、共有リソースR1、R2を使用する際、共有リソースR1又はR2を獲得(ロック)するため、決まったコマンドを実行する。すなわち、OSにロックを要求する。どのようなコマンドかはCPU11の命令セットによって異なるが、例えば、「get_resorce リソース名」などが知られている。ロック要求部31は、共有リソースR1,R2を使用する直前にこのようなコマンドを発行する。なお、このようなコマンドはOSを呼び出すシステムコールの一種である。この後、ロック要求したコアは、ロックを取得できるまでスピンロック状態になる。
Each thread executes a predetermined command in order to acquire (lock) the shared resource R1 or R2 when using the shared resource R1 or R2. That is, it requests the OS to lock. What kind of command is different depending on the instruction set of the
ロックを取得したコアはスピンロック状態が終了し、ロックを取得したコアのリソース対応処理部32は、共有リソースR1又はR2を使用した処理を実行する。リソース対応処理部32が共有リソースR1又はR2を使用した処理の実行を終了すると、ロック解放要求部33は、コアがロックしている共有リソースR1を解放(アンロック)するため、決まったコマンドを実行する。どのようなコマンドかは命令セットによって異なるが、例えば、「release_resorce リソース名」などが知られている。この後、ロックの解放を要求したコアは、プログラムに沿って処理を実行する。
The core that has acquired the lock ends the spin lock state, and the
OSは優先度設定部35、ネスト判定部36、フラグ読み込み部37、及び、最高優先度レジスタ読み込み部38を有する。優先度設定部35は、ロック要求部31からロックの要求を受け付けると、コア0〜nに対応する優先度レジスタ0〜nに優先度を設定する。優先度は、スレッドが指定する場合、スレッド毎に決まっている場合、又は、OSがスレッドを考慮して動的に決定する場合等がある。本実施例では、スレッドが指定するものとする。よって、優先度設定部35は、ロックを要求したスレッドが指定する優先度を、このスレッドを実行するコア0〜nに対応した優先度レジスタ0〜nに設定する。
The OS includes a
なお、優先度設定部35は、ロック解放要求部33が共有リソースR1又はR2のアンロックを要求すると、アンロックを要求したコア0〜nに対応した優先度レジスタ0〜nに最も優先度が小さい値(例えば、ゼロ)を設定する。これにより、共有リソースのロックがアンロックされる。
When the lock
フラグ読み込み部37はロック変数を更新する。図示するようにロック変数は、コア0〜n毎、かつ、共有リソースR1、R2毎に設けられている。フラグ読み込み部37は、スピンロックハードウェアの別により共有リソースR1又はR2を特定し、“1”を出力したロック取得フラグ0〜nに対応したコア0〜nのロック変数を“1”に設定する。また、フラグ読み込み部37は、“1”に設定したコア以外のロック変数を全て“0”に設定する。このようにロック変数が“1”になるのは、1つの共有リソースで1つだけである。リソース対応処理部32は、スレッドを実行するコアのロック変数が“1”の場合にのみ、共有リソースを使用し、ロック変数が“0”の場合、スピンロックする。
The flag reading unit 37 updates the lock variable. As shown in the figure, the lock variable is provided for each of the
ネスト判定部36は、ロック要求部31が要求したロック要求が、2段以上にネストされたスレッドのロック要求か否かを判定する。なお、ネストとは入れ子を意味し、あるスレッドやルーチンの中に、別のスレッドやルーチンがはめ込まれることをいう。具体的には図2のスレッドAはネスト構造を有し、スレッドaはスレッドAのネスト(入れ子)になっている。2段以上にネストされたスレッドはここではスレッドaが相当する。
The nest determination unit 36 determines whether the lock request requested by the
スレッドAを実行するコアが共有リソースR1をロックした後、ネストになっているスレッドaのため、別の共有リソースR2のロックを要求する場合がある。例えば、スレッドAが、スレッドaの処理結果を利用するなどの密接な関係があり、スレッドAとスレッドaが異なる共有リソースR1,R2を使用する場合に生じ得る。ネスト判定部36はこのスレッドaが要求するロック要求を検出する。 After the core executing the thread A locks the shared resource R1, there is a case where another core resource R2 is requested to be locked because of the nested thread a. For example, this may occur when the thread A has a close relationship such as using the processing result of the thread a, and the thread A and the thread a use different shared resources R1 and R2. The nest determination unit 36 detects a lock request requested by the thread a.
例えば、ネスト判定部36は、ロック要求を受け付けると、ロック要求された共有リソースR2を特定する。そして、ロック要求された共有リソースR2のスピンロックハードウェア2以外で、ロック要求したコア0〜nに対応するロック取得フラグ0〜nに“1”が設定されているか否かを判定する。ロック取得フラグ0〜nに“1”が設定されていることは、リソースR2のロック要求したコアと同じコアが別の共有リソースR1をすでにロックしていることになる。このような状況は、2段以上のネストのスレッドaのロック要求があった可能性が高い。
For example, when receiving the lock request, the nest determination unit 36 specifies the shared resource R2 that has been requested to be locked. Then, it is determined whether “1” is set in the
なお、ネスト判定部36は、ロック要求部31からの明示的な2段以上にネストされたスレッドaのロック要求であるというロック要求に基づき、2段以上にネストされたスレッドaのロック要求であることを判定してもよい。
Note that the nest determination unit 36 receives a lock request for a thread a nested in two or more levels based on a lock request from the
ネスト判定部36は、以上のようにして判定した判定結果を最高優先度レジスタ読み込み部38に通知する。
The nest determination unit 36 notifies the highest priority
最高優先度レジスタ読み込み部38は、ロック要求された共有リソースのスピンロックハードウェア以外で、ロック要求したコア0〜nに対応するロック取得フラグ0〜nに“1”が設定されているスピンロックハードウェア1の最高優先度レジスタ24の値を読み出す。これにより、ロック要求したコア0〜nが設定した優先度(このスピンロックハードウェア1において最も高い最高優先度)を取得できたことになる。
The highest priority
最高優先度レジスタ読み込み部38は、優先度設定部35にスピンロックハードウェア1の最高優先度を通知する。優先度設定部35は、スレッドaがロック要求した共有リソースR2のスピンロックハードウェア2のコア0〜nに対応する優先度レジスタ0〜nに、最高優先度を設定する。すなわち、スレッドaがロック要求と共にOSに通知した優先度に代えて、最高優先度を設定する。スレッドaがロック要求と共に要求した優先度でなく、最高優先度を2段目のスピンロックハードウェア2の優先度レジスタ21に設定することで、コアが実行しているスレッドAの優先度を、スレッドaの優先度として承継できたことになる。
The highest priority
〔動作手順〕
図7は、主にOSがスピンロックハードウェア100を操作する手順を示すフローチャート図の一例である。
[Operation procedure]
FIG. 7 is an example of a flowchart diagram illustrating a procedure in which the OS mainly operates the
まず、優先度設定部35は、アプリケーション0のスレッドAのロック要求部31から、共有リソースAの指定と共に、ロック要求と優先度を取得する(S10)。実際にはまず、ネスト判定部36が、2段以上にネストされたスレッドaのロック要求であるか否かを最初に判定するが、ここでは省略している。
First, the
次に、優先度設定部35は、共有リソースR1に対応したスピンロックハードウェア1の、ロック要求したコア0〜nに対応する優先度レジスタ0〜nに優先度を設定する(S20)。
Next, the
この後、フラグ読み込み部37は、スピンロックハードウェア1のロック取得フラグ0〜nを監視して、スレッドAを実行しているコアがロックを取得したか否かを判定する(S30)。例えば、すでに別のコアが共有リソースR1をロックしていた場合、この別のコアが実行するスレッドを終了するなどして共有リソースR1を解放するまで、ロック要求したコアはスピンロックする。
Thereafter, the flag reading unit 37 monitors the
スレッドAがロックを取得した場合(S30のYes)、最高優先度レジスタ読み込み部38は、最高優先度レジスタ24の値を読み取る(S40)。ロックを取得するコアが変われば、最高優先度レジスタ24の値も変わるので、最高優先度レジスタ24の値が更新されるなどのタイミングで最高優先度を取得すればよい。最高優先度レジスタ24の値によりスレッドAの優先度の承継が可能になる。
When the thread A acquires the lock (Yes in S30), the highest priority
次に、スレッドAの実行中、スレッドAにネストされたスレッドaが実行される。スレッドaは共有リソースR2を必要とするため、スレッドaのロック要求部31は共有リソースR2の指定と共に、ロック要求と優先度を優先度設定部35に通知する。これにより、優先度設定部35は、共有リソースR2の指定と共に、ロック要求と優先度を取得する。
Next, during execution of thread A, thread a nested in thread A is executed. Since the thread a requires the shared resource R2, the
ここで、ネスト判定部36は、ロック要求された共有リソースR2のスピンロックハードウェア2以外で、ロック要求したコアに対応するロック取得フラグ0〜nに“1”が設定されているか否かを判定することで、優先度を承継するか否かを判定する。
Here, the nest determination unit 36 determines whether or not “1” is set in the
優先度を承継すべき場合、優先度設定部35は、最高優先度レジスタ読み込み部38が読み取った最高優先度レジスタ24の値を、スピンロックハードウェア2のスレッドaを実行するコアに対応する優先度レジスタ21に設定する(S50)。こうすることでスレッドaの優先度がスレッドAと同じになる。
When the priority should be inherited, the
フラグ読み込み部37は、スピンロックハードウェア2のロック取得フラグ0〜nを監視して、スレッドaを実行しているコアがロックを取得したか否かを判定する(S60)。取得できない場合は、スレッドAよりも優先度の高いスレッドが共有リソースR2を使用していることになるので、スレッドaを実行しているコアはスピンロックする。このため、処理はステップS40に戻る。
The flag reading unit 37 monitors the
スレッドaを実行しているコアが共有リソースR2のロックを取得した場合(S60)、フラグ読み込み部37は、スレッドaを実行するコアの共有リソースR2のロック変数のみを“1”にして、他を“0”に設定する。これにより、スレッドaは共有リソースR2を排他的に使用することができる(S70)。 When the core executing the thread a acquires the lock of the shared resource R2 (S60), the flag reading unit 37 sets only the lock variable of the shared resource R2 of the core executing the thread a to “1”, and the like. Is set to “0”. As a result, the thread a can exclusively use the shared resource R2 (S70).
以上説明したように、本実施例のスピンロックハードウェア100は、CPU11がアトミック命令を有していない場合でも、ハード的にスピンロックを実現できる。また、スレッドがネスト構造を有していても、2段目のスレッドが1段目のスレッドの優先度を承継できるので、ネスト構造を有するスレッドの最悪実行時間を保証できる。
As described above, the
本実施例では、さらにコア0〜nのいずれかを選択的に優先できるスピンロックハードウェア100について説明する。
In the present embodiment, a
図8(a)は、本実施例のスピンロックハードウェア100の構成図の一例を示す。図8において図4と同一部には同一の符号を付しその説明は省略する。このスピンロックハードウェア100は、コア毎にローカル優先ビットを有し、特定のコアを優先可能な点に特徴の1つがある。
FIG. 8A shows an example of a configuration diagram of the
図8(b)はローカル優先ビットの一例を示す図である。ローカル優先ビットは、優先度レジスタ21の先頭の1ビットとする。すなわち、優先度レジスタ21のビット数が8であれば、優先度レジスタ21の下位7ビットに優先度が設定され、MSB(most significant bit)にローカル優先ビットが割り当てられる。
FIG. 8B shows an example of local priority bits. The local priority bit is the first bit of the
比較回路22は、実施例1と同様に、各コア0〜nの「ローカル優先ビット+優先度」を比較して、最も大きい値のコアのロック取得フラグ0〜nを“1”にセットする。これにより、スピンロックハードウェア100は以下のように作用する。
・コア0〜nが優先的に共有リソースをロックするのでなければ、ローカル優先ビットは“0”なので、実施例1と同様に、最も高い優先度を設定したコア0〜nが優先的に共有リソースを使用できる。
・コア0〜nのいずれか1つのコアが、優先的に共有リソースをロックする場合、1つの優先度レジスタ21のローカル優先ビットだけが“1”なので、ローカル優先ビットを“1”に設定したコアが優先的に共有リソースを使用できる。
・コア0〜nのいずれか2つ以上のコアが、優先的に共有リソースをロックする場合、複数のローカル優先ビットが“1”になる。この場合、ローカル優先ビットを“1”に設定した複数のコアのうち、優先度レジスタの下位7ビットに最も高い優先度を設定したコアが優先的に共有リソースを使用できる。
As in the first embodiment, the
Unless the
When one of the
When any two or more of the
〔ローカル優先ビットの必要性〕
コア0〜nが優先的に共有リソースを使用する必要がある場合、換言すると、あるコア0〜nに優先的に共有リソースを使用させてよい場合とは、例えば、異常検出時のフェールセーフ処理、優先度の高い割り込み処理、OSなど管理用ソフトの特定処理などである。
[Necessity of local priority bit]
When the
また、例えば、一定時間以上、共有リソースが解放されるまで待機している(スピンしている)スレッドが、ローカル優先ビットを“1”に設定することができてもよい。この設定は、OSの優先度設定部35が、スピンロックしているコアを監視して、一定時間以上経過すると自律的に設定することが好ましい。
In addition, for example, a thread that is waiting (spinning) until the shared resource is released for a certain time or more may be able to set the local priority bit to “1”. This setting is preferably set autonomously when the
しかし、各スレッドがローカル優先ビットを“1”に設定することが許可されていても、下位7ビットにより優先度が比較されるので、各スレッドがローカル優先ビットを“1”に設定しても優先度が逆転することはない。 However, even if each thread is allowed to set the local priority bit to “1”, the priority is compared by the lower 7 bits, so even if each thread sets the local priority bit to “1”. The priority will never be reversed.
〔動作手順〕
図9(a)は、ローカル優先ビットに“0”が設定された場合のOSの処理手順の一例を、図9(b)は、ローカル優先ビットに“1”が設定された場合のOSの処理手順の一例を、それぞれ示すフローチャート図である。
[Operation procedure]
FIG. 9A shows an example of the OS processing procedure when the local priority bit is set to “0”, and FIG. 9B shows the OS processing procedure when the local priority bit is set to “1”. It is a flowchart figure which shows an example of a process procedure, respectively.
図9(a)において、優先度設定部35は、スレッドAのロック要求部31から、共有リソースAの指定と共に、ロック要求と優先度を取得する(S10)。
In FIG. 9A, the
次に、優先度設定部35は、共有リソースR1に対応したスピンロックハードウェア1の、ロック要求したコア0〜nに対応する優先度レジスタ0〜nに優先度を設定する(S20)。ここでは、ローカル優先ビットは“0”である。
Next, the
この後、フラグ読み込み部37は、スピンロックハードウェア1のロック取得フラグ0〜nを監視して、スレッドAを実行しているコアがロックを取得したか否かを判定する(S30)。
Thereafter, the flag reading unit 37 monitors the
取得できない場合は、スレッドAよりも優先度の高いスレッドが共有リソースR1を使用していることになるので、スレッドAを実行しているコアはスピンロックする。このため、処理はステップS30に戻る。 If it cannot be acquired, a thread having a higher priority than the thread A uses the shared resource R1, and the core executing the thread A spin-locks. For this reason, a process returns to step S30.
スレッドAがロックを取得した場合(S30のYes)、スレッドAは排他的に共有リソースR1を使用して処理することができる(S70)。 When the thread A acquires the lock (Yes in S30), the thread A can exclusively process using the shared resource R1 (S70).
続いて、図9(b)において優先度設定部35は、アプリケーション0のスレッドAのロック要求部31から、共有リソースAの指定と共に、ロック要求と優先度を取得する(S10)。
Subsequently, in FIG. 9B, the
次に、優先度設定部35は、共有リソースR1に対応したスピンロックハードウェア1の、ロック要求したコアに対応する優先度レジスタに優先度を設定する(S22)。ここでは、スレッドA又はOSがローカル優先ビットを“1”に設定したものとする。これにより、スレッドAは優先的に共有リソースR1をロックできる可能性が高くなる。
Next, the
この後、フラグ読み込み部37は、スピンロックハードウェア1のロック取得フラグ0〜nを監視して、スレッドaを実行しているコアがロックを取得したか否かを判定する(S30)。
Thereafter, the flag reading unit 37 monitors the
取得できない場合は、スレッドAよりも優先度の高いスレッドがローカル優先ビットを“1”に設定して共有リソースR1を使用していることになるので、スレッドAを実行しているコアはスピンロックする。このため、処理はステップS30に戻る。 If it cannot be obtained, the thread having higher priority than the thread A uses the shared resource R1 with the local priority bit set to “1”, so the core executing the thread A is spin-locked. To do. For this reason, a process returns to step S30.
スレッドAがロックを取得した場合(S30のYes)、スレッドAは排他的に共有リソースR1を使用して処理することができる(S70)。 When the thread A acquires the lock (Yes in S30), the thread A can exclusively process using the shared resource R1 (S70).
なお、図9(b)の処理はネストがない(1段目のみ)処理であるが、2段以上のネストがある場合も同様である。すなわち、1段目のスレッドAがローカル優先ビットを“1”に設定すれば、2段目のスレッドaもこの優先度を承継できる。1段目のスレッドAがローカル優先ビットを“0”に設定した場合に、2段目のスレッドaがローカル優先ビットを“1”に設定した場合も(このような優先度の関係は通常は生じない)、優先度設定部35は2段目のスレッドaの優先度を優先度レジスタ21に設定しないので、1段目のスレッドAの優先度が承継される。
The process of FIG. 9B is a process without nests (only the first stage), but the same applies when there are two or more levels of nests. That is, if the first-stage thread A sets the local priority bit to “1”, the second-stage thread a can also inherit this priority. When the first-stage thread A sets the local priority bit to “0”, and the second-stage thread a sets the local priority bit to “1” (the relationship between such priorities is usually The
以上説明したように、本実施例のスピンロックハードウェアは、実施例1の効果に加え、特定のコアに優先的に共有リソースをロックさせ処理を実行させることができる。 As described above, in addition to the effects of the first embodiment, the spin lock hardware of this embodiment can cause a specific core to preferentially lock a shared resource and execute processing.
11 CPU
12 ROM
13 INTC
17 ADC
18 CANコントローラ
21 優先度レジスタ
22 比較回路
23 ロック取得フラグ
24 最高優先度レジスタ
100 スピンロックハードウェア
200 マイコン
11 CPU
12 ROM
13 INTC
17 ADC
18
Claims (7)
前記優先度レジスタ毎に配置されたフラグ状態保持手段と、
前記優先度レジスタに設定された優先度を比較し、最も高い優先度が設定された前記優先度レジスタに対応する前記フラグ状態保持手段にロック状態を設定する優先度比較回路と、
前記優先度レジスタに設定された優先度のうち最高の優先度を格納する最高優先度レジスタと、を有する排他制御装置。 A priority register arranged in association with a plurality of processor elements;
Flag state holding means arranged for each of the priority registers;
A priority comparison circuit that compares the priority set in the priority register and sets a lock state in the flag state holding unit corresponding to the priority register in which the highest priority is set;
An exclusive control device comprising: a highest priority register for storing the highest priority among the priorities set in the priority register.
ことを特徴とする請求項1記載の排他制御装置。 The priority register has a reserved bit, and the priority of the priority register in which a predetermined value is set in the reserved bit is higher than the priority of the priority register in which the predetermined value is not set.
The exclusive control apparatus according to claim 1.
ことを特徴とする請求項1〜3いずれか1項記載の排他制御装置。 The highest priority stored in the highest priority register is set in the priority register associated with the processor element that has set the highest priority of another exclusive control device.
The exclusive control apparatus according to any one of claims 1 to 3, wherein
複数の周辺機器と、
前記周辺機器に対応して配置された請求項1〜4いずれか1項に記載の複数の排他制御装置と、
を有するマイコン。 Multiple processor elements;
Multiple peripherals,
A plurality of exclusive control devices according to any one of claims 1 to 4, arranged corresponding to the peripheral devices,
A microcomputer having
を有する請求項5記載のマイコン。 Lock permission means for allowing the processor element associated with the flag state holding means in the locked state to lock the shared resource corresponding to the exclusive control device provided with the flag state holding means;
The microcomputer according to claim 5, comprising:
前記所定のプロセッサエレメントが第2の排他制御装置の前記優先度レジスタに優先度を設定する場合、
第1の排他制御装置の前記最高優先度レジスタに格納された最高の優先度を、第2の排他制御装置の前記所定のプロセッサエレメントに対応づけられた前記優先度レジスタに設定する優先度設定手段、を有する、
請求項5又は6記載のマイコン。
The priority set by the predetermined processor element in the priority register of the first exclusive control device is stored in the highest priority register,
When the predetermined processor element sets a priority in the priority register of the second exclusive control device,
Priority setting means for setting the highest priority stored in the highest priority register of the first exclusive control device in the priority register associated with the predetermined processor element of the second exclusive control device Having
The microcomputer according to claim 5 or 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2011096418A JP2012226709A (en) | 2011-04-22 | 2011-04-22 | Exclusive control device and microcomputer |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2011096418A JP2012226709A (en) | 2011-04-22 | 2011-04-22 | Exclusive control device and microcomputer |
Publications (1)
Publication Number | Publication Date |
---|---|
JP2012226709A true JP2012226709A (en) | 2012-11-15 |
Family
ID=47276767
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2011096418A Pending JP2012226709A (en) | 2011-04-22 | 2011-04-22 | Exclusive control device and microcomputer |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP2012226709A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2017056172A1 (en) * | 2015-09-29 | 2017-04-06 | 株式会社日立製作所 | Computer system which performs exclusive access control of memory region |
CN110147269A (en) * | 2019-05-09 | 2019-08-20 | 腾讯科技(上海)有限公司 | A kind of event-handling method, device, equipment and storage medium |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2009205585A (en) * | 2008-02-29 | 2009-09-10 | Seiko Epson Corp | Information processor, control method of information processor, and control program |
-
2011
- 2011-04-22 JP JP2011096418A patent/JP2012226709A/en active Pending
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2009205585A (en) * | 2008-02-29 | 2009-09-10 | Seiko Epson Corp | Information processor, control method of information processor, and control program |
Non-Patent Citations (6)
Title |
---|
CSNG200200112018; 王 才棟: '優先度継承スピンロックアルゴリズムとその評価' 情報処理学会論文誌 第38巻,第11号, 19971115, p.2262-2273, 社団法人情報処理学会 Information Processing Socie * |
CSNG201000487048; 一場 利幸: '中断可能なキューイングスピンロックのハードウェア実装と評価' 情報処理学会研究報告 2010-SLDM-144巻,第61号, 20100415, p.1-8, 社団法人情報処理学会 * |
CSNG201000919007; 一場 利幸: '中断可能な優先度継承キューイングスピンロックのハードウェア実装と評価' 組込みシステムシンポジウム2010論文集 第2010巻, 20101020, p.55-64, 一般社団法人情報処理学会 * |
JPN6014024701; 一場 利幸: '中断可能なキューイングスピンロックのハードウェア実装と評価' 情報処理学会研究報告 2010-SLDM-144巻,第61号, 20100415, p.1-8, 社団法人情報処理学会 * |
JPN6014024702; 王 才棟: '優先度継承スピンロックアルゴリズムとその評価' 情報処理学会論文誌 第38巻,第11号, 19971115, p.2262-2273, 社団法人情報処理学会 Information Processing Socie * |
JPN6014024703; 一場 利幸: '中断可能な優先度継承キューイングスピンロックのハードウェア実装と評価' 組込みシステムシンポジウム2010論文集 第2010巻, 20101020, p.55-64, 一般社団法人情報処理学会 * |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2017056172A1 (en) * | 2015-09-29 | 2017-04-06 | 株式会社日立製作所 | Computer system which performs exclusive access control of memory region |
CN110147269A (en) * | 2019-05-09 | 2019-08-20 | 腾讯科技(上海)有限公司 | A kind of event-handling method, device, equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US6389449B1 (en) | Interstream control and communications for multi-streaming digital processors | |
US8572626B2 (en) | Symmetric multi-processor system | |
US8707315B2 (en) | Method and system for implementing realtime spinlocks | |
JP5745868B2 (en) | Multiprocessor system | |
US10261926B2 (en) | Semaphore for multi-core processor | |
US11782720B2 (en) | Processor architecture with micro-threading control by hardware-accelerated kernel thread | |
WO2010067492A1 (en) | Multiprocessor system and multiprocessor exclusive control adjustment method | |
KR100902977B1 (en) | Hardware sharing system and method | |
US7103631B1 (en) | Symmetric multi-processor system | |
US7398378B2 (en) | Allocating lower priority interrupt for processing to slave processor via master processor currently processing higher priority interrupt through special interrupt among processors | |
US8769546B2 (en) | Busy-wait time for threads | |
JPH1115793A (en) | Protection method for resource maintainability | |
KR100850387B1 (en) | Processing architecture having passive threads and active semaphores | |
JP2008033893A (en) | Multiprocessor system and access right setting method in multiprocessor system | |
JP2013152636A (en) | Information processing device and task scheduling method | |
JP2012226709A (en) | Exclusive control device and microcomputer | |
US11301304B2 (en) | Method and apparatus for managing kernel services in multi-core system | |
JP2010092101A (en) | Information processor | |
WO2007049543A1 (en) | Calculating apparatus | |
JP2019128711A (en) | Electronic control device | |
JP2023091314A (en) | Semiconductor device, control method of semiconductor device, and program | |
JP2009230466A (en) | Information processor, control method of information processor, and control program |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
A621 | Written request for application examination |
Free format text: JAPANESE INTERMEDIATE CODE: A621 Effective date: 20131122 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A821 Effective date: 20131122 |
|
A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20140611 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20140617 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20140807 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A821 Effective date: 20140807 |
|
A02 | Decision of refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A02 Effective date: 20141209 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20150311 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A821 Effective date: 20150311 |