JP2012226709A - Exclusive control device and microcomputer - Google Patents

Exclusive control device and microcomputer Download PDF

Info

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
Application number
JP2011096418A
Other languages
Japanese (ja)
Inventor
Kazuhiro Kajio
和弘 梶尾
Masahide Sakano
将秀 坂野
Hiroaki Takada
広章 高田
Shinya Honda
晋也 本田
Yutaka Matsubara
豊 松原
Ayumu Sugiyama
歩 杉山
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nagoya University NUC
Toyota Motor Corp
Original Assignee
Nagoya University NUC
Toyota Motor Corp
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Nagoya University NUC, Toyota Motor Corp filed Critical Nagoya University NUC
Priority to JP2011096418A priority Critical patent/JP2012226709A/en
Publication of JP2012226709A publication Critical patent/JP2012226709A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Multi Processors (AREA)

Abstract

PROBLEM TO BE SOLVED: To provide an exclusive control device capable of reducing priority inversion among threads to the minimum or capable of giving priority to a specific core.SOLUTION: There is provided an exclusive control device 100 which includes priority registers 21 which are disposed being associated with plural processor elements, flag state holding means 23 which are disposed to each of the priority registers, a priority comparison circuit 22 that compares the priority set to the priority registers and locks the flag state holding means corresponding to the priority register to which the highest priority is set, and a highest priority register 24 that stores the highest priority in the priorities set to the priority registers.

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.

特開2010−191575号公報JP 2010-191575 A

しかしながら、特許文献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 core 0 executes the thread A included in the application 0 and the thread a called from the thread A, and the core 1 executes the thread B included in the application 1. Thread A uses shared resource R1, and thread a and thread B use shared resource R2. The priority among threads is as follows.
Thread A> Thread B> Thread a
When the core 0 sets the priority of the thread A in the priority register, since the thread A has a higher priority than the other threads, the shared resource R1 can be locked. Thereafter, since core 0 executes thread a, core 0 sets the priority of thread a in the priority register, and core 1 executes thread B. Therefore, core 1 sets the priority of thread B to priority. May be set in registers. If the shared resource R2 is released, the priorities of the thread a and the thread B are compared. However, since the thread B has a higher priority than the thread a, the thread B locks the shared resource R2. End up.

すなわち、スレッド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.

スピンロックハードウェアの構成図の一例である。It is an example of the block diagram of a spin lock hardware. スレッドの優先度を説明する図の一例である。It is an example of the figure explaining the priority of a thread. マイコンのハードウェア構成図の一例である。It is an example of the hardware block diagram of a microcomputer. スピンロックハードウェアの構成図の一例である。It is an example of the block diagram of a spin lock hardware. スピンロックハードウェアの作用を説明する図の一例である。It is an example of the figure explaining the effect | action of a spin lock hardware. スピンロックハードウェアを操作する各機能の機能ブロック図の一例である。It is an example of the functional block diagram of each function which operates spin lock hardware. 主にOSがスピンロックハードウェアを操作する手順を示すフローチャート図の一例である。FIG. 10 is an example of a flowchart showing a procedure for operating the spin lock hardware mainly by the OS. スピンロックハードウェアの構成図の一例である(実施例2)。FIG. 3 is an example of a configuration diagram of spin lock hardware (Example 2); ローカル優先ビットに“1”が設定された場合のOSの処理手順の一例を示すフローチャート図である。FIG. 10 is a flowchart illustrating an example of an OS processing procedure when “1” is set in a local priority bit.

以下、本発明を実施するための形態について図面を参照しながら説明する。   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 microcomputer 200 may be mounted in any state, such as a one-chip microcomputer, a microcomputer in which a CPU or the like is on a separate chip on the substrate.

図示するマイコン200は、ECU(Electronic Control Unit)に搭載されることが想定されているがその用途は車両に限定されない。なお、ECUには、マイコン200の他、センサの信号を受け付ける入力チャネル及びそのドライバ、マイコン200の監視IC、電源IC等が搭載される。   The illustrated microcomputer 200 is assumed to be mounted on an ECU (Electronic Control Unit), but its application is not limited to a vehicle. In addition to the microcomputer 200, the ECU is mounted with an input channel for receiving sensor signals and its driver, a monitoring IC for the microcomputer 200, a power supply IC, and the like.

車載される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 microcomputer 200 of the present embodiment can be mounted without being affected by the difference in ECU functions. Further, in recent years, attempts have been made to integrate a plurality of functions into one ECU, so that the necessity of distinguishing the ECU on which the microcomputer 200 is mounted by function is low.

マイコン200は、バスに接続されたCPU11、ROM12、スピンロックハードウェア100、INTC13、RAM14、DMAC15、並びに、I/Oブリッジ16を有し、I/Oブリッジ16にはADC17及びCANコントローラ18が接続されている。   The microcomputer 200 includes a CPU 11, a ROM 12, a spin lock hardware 100, an INTC 13, a RAM 14, a DMAC 15, and an I / O bridge 16 connected to a bus, and an ADC 17 and a CAN controller 18 are connected to the I / O bridge 16. Has been.

CPU11は複数のコア0〜nを有し、図にはコア0及びコア1が図示されているが、3つ以上のコアを有していてもよい。コア0、1はそれぞれローカルRAM0,1を作業メモリに使用する。なお、マルチコア型でなく1つのCPUが、レジスタや演算器を切り換えながら並列的に命令を実行することで複数のCPUが存在するように見せるヴァーチャルCPUを有していてもよい。また、チップとして独立した複数のCPUが搭載されていてもよい。複数のコアや複数の独立したCPUをプロセッサエレメントという場合がある。   The CPU 11 includes a plurality of cores 0 to n, and the core 0 and the core 1 are illustrated in the drawing, but may include three or more cores. The cores 0 and 1 use the local RAMs 0 and 1 as work memories, respectively. Note that, instead of the multi-core type, one CPU may have a virtual CPU that makes it appear that a plurality of CPUs exist by executing instructions in parallel while switching registers and arithmetic units. A plurality of independent CPUs may be mounted as chips. A plurality of cores and a plurality of independent CPUs may be referred to as processor elements.

ROM12はフラッシュメモリなどの不揮発メモリであり、CPU11が実行するプログラムや静的なデータを記憶している。プログラムは、コア0が実行するアプリケーション0、コア1が実行するアプリケーション1、及び、OSやデバイスドライバが記憶されている。アプリケーションをより小さい粒度に区分したスレッドやタスクという概念があり、本実施形態でも適宜、アプリケーションからスレッドやタスクを抽出して説明する。なお、説明を容易にするため、各アプリケーションと各コアの関係は固定であるとするが、例えば、OS等がコアにアプリケーションを動的に割り当てることも可能である。この場合、OSはコアとアプリケーションの対応を記憶しているので、OSにとって各アプリケーションと各コアの関係が固定であるか否かによる不都合は少ない。   The ROM 12 is a nonvolatile memory such as a flash memory, and stores programs executed by the CPU 11 and static data. The program stores an application 0 executed by the core 0, an application 1 executed by the core 1, and an OS and a device driver. There is a concept of a thread or task in which an application is divided into smaller granularities. In this embodiment, a thread or task is extracted from the application as appropriate. For ease of explanation, the relationship between each application and each core is assumed to be fixed. However, for example, an OS or the like can dynamically assign an application to a core. In this case, since the OS stores the correspondence between the core and the application, there is little inconvenience for the OS depending on whether or not the relationship between each application and each core is fixed.

INTC13はIRQやその他の割り込み端子を介して周辺機器から入力された割り込み要求を、周辺機器の優先順位に基づき調停してCPU11に通知する。これによりCPU11は、割り込みした周辺機器に応じて決まった処理を実行する。   The INTC 13 arbitrates based on the priority of the peripheral device and notifies the CPU 11 of the interrupt request input from the peripheral device via the IRQ or other interrupt terminal. As a result, the CPU 11 executes processing determined according to the interrupted peripheral device.

RAM14は、CPU11がプログラムを実行するための作業領域である。CPU11はメモリバスを介してROM(またはプログラムをSDRAMに移動して実行する場合はSDRAM)12からプログラムを読み込み、また、必要であればデータバスを介してRAM14からデータを読み出しプログラムを実行する。   The RAM 14 is a work area for the CPU 11 to execute a program. The CPU 11 reads the program from the ROM (or SDRAM when the program is moved to the SDRAM for execution) via the memory bus, and reads the data from the RAM 14 via the data bus if necessary and executes the program.

DMAC15は、CPU11からの指示によりRAM14からI/Oブリッジ16を介して周辺機器にデータを送信し、周辺機器から割り込みされたCPU11から指示を受けて、I/Oブリッジ16を介して周辺機器からデータを受け取り、RAM14に書き込む。   The DMAC 15 transmits data from the RAM 14 to the peripheral device via the I / O bridge 16 according to an instruction from the CPU 11, receives an instruction from the CPU 11 interrupted by the peripheral device, and receives data from the peripheral device via the I / O bridge 16. Data is received and written to the RAM 14.

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 ADC 17 and the CAN controller 18 for each channel, and transmits / receives data to / from these peripheral devices. An ADC (analog to digital converter) 17 converts an analog signal detected by the sensor into a digital signal. The ADC 17 includes a ΔΣ type, a successive approximation type, a double integration type, and the like, but may be converted by any conversion principle. The ADC 17 also notifies the CPU 11 of the end of conversion via the INTC 13.

CANコントローラ18は、車載ネットワークを介して接続された他のECUと通信するための通信装置である。CANコントローラ18は、CPU11から通信データの送信要求を受け付けるとフレームの各フィールドにIDやデータを格納しCANバスに出力する。また、CANコントローラ18は、受信すべきIDの通信データを検出するとそれを取り込みCPU11に割り込んで通知する。   The CAN controller 18 is a communication device for communicating with other ECUs connected via an in-vehicle network. When receiving a communication data transmission request from the CPU 11, the CAN controller 18 stores the ID and data in each field of the frame and outputs them to the CAN bus. Further, when the CAN controller 18 detects the communication data of the ID to be received, it captures it and interrupts it to notify the CPU 11.

図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 ADC 17 and the CAN controller 18 are shared resources R1 and R2, respectively.

スピンロックハードウェア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 spin lock hardware 100 of the present embodiment. The spin lock hardware 100 is characterized in that it can inherit the priority of a nested thread.

まず、スピンロックハードウェア100は、コア毎に専用の優先度レジスタ21(区別する場合、優先度レジスタ0、1…nという)、各優先度レジスタ21に設定された優先度の比較回路22、比較結果に基づきロックを取得したコアを指定するコア毎に専用のロック取得フラグ23(区別する場合、ロック取得フラグ0、1…nという)、及び、最高優先度レジスタ24を有する。それぞれの優先度レジスタ21には各コアが実行するスレッドの優先度が設定される。また、それぞれの優先度レジスタ21は比較回路22に接続されている。比較回路22は各ロック取得フラグ23に接続されると共に、最高優先度レジスタ24に接続されている。ロック取得フラグ23の状態及び最高優先度レジスタ24の内容は外部から読み取れるようになっている。   First, the spin lock hardware 100 includes a dedicated priority register 21 for each core (priority registers 0, 1,..., N when distinguished), a priority comparison circuit 22 set in each priority register 21, Each core that designates the core that has acquired the lock based on the comparison result has a dedicated lock acquisition flag 23 (in the case of distinction, the lock acquisition flags 0, 1,... N), and the highest priority register 24. The priority of each thread executed by each core is set in each priority register 21. Each priority register 21 is connected to a comparison circuit 22. The comparison circuit 22 is connected to each lock acquisition flag 23 and also connected to the highest priority register 24. The state of the lock acquisition flag 23 and the contents of the highest priority register 24 can be read from the outside.

比較回路22は、全ての優先度レジスタ0〜nのうち最も高い優先度が設定された優先度レジスタを特定する。本実施例では数値が大きいほど優先度が高いとするが、逆でもよい。比較回路22は、最も高い優先度が設定された優先度レジスタ0〜nに対応するロック取得フラグ0〜nに“1”を設定する。したがって、“1”が設定されたロック取得フラグ0〜nに対応したコア0〜nが、スピンロックハードウェア100がロックする共有リソースをロックできたこと(使用権を得たこと)になる。   The comparison circuit 22 specifies the priority register in which the highest priority is set among all the priority registers 0 to n. In this embodiment, the higher the numerical value, the higher the priority, but the reverse may be possible. The comparison circuit 22 sets “1” to the lock acquisition flags 0 to n corresponding to the priority registers 0 to n for which the highest priority is set. Therefore, the cores 0 to n corresponding to the lock acquisition flags 0 to n in which “1” is set can lock the shared resource locked by the spin lock hardware 100 (the use right has been obtained).

また、比較回路22は、優先度レジスタ0〜nのうち最も高い優先度が設定された優先度レジスタ21の値を最高優先度レジスタ24に設定する。最高優先度レジスタ24は、このスピンロックハードウェア100における最高の優先度を常に格納している。   Further, the comparison circuit 22 sets the value of the priority register 21 in which the highest priority among the priority registers 0 to n is set in the highest priority register 24. The highest priority register 24 always stores the highest priority in the spin lock hardware 100.

図5はスピンロックハードウェア100の作用を説明する図の一例である。図5(a)に示すように、コア0の優先度が“00001111”、コア1の優先度が“00000011”であるとする。設定される優先度は、例えばタイムスタンプとして扱われるカウンタの値である。数値が高い方が優先度が高い場合、カウンタはある設定値から一様に減少する。また、数値が低い方が優先度が高い場合、カウンタは一様に増大する。したがって、いずれの場合も、より早くカウンタから数値を読み出して優先度を設定したコアが優先されるようになる。また、優先度を先に設定したコアが優先されるので、スピンロックハードウェア100はFIFO型の待ち行列(キューイング)になる。   FIG. 5 is an example of a diagram for explaining the operation of the spin lock hardware 100. As shown in FIG. 5A, it is assumed that the priority of the core 0 is “00001111” and the priority of the core 1 is “00000011”. The priority set is, for example, a counter value that is treated as a time stamp. If the higher the numerical value, the higher the priority, the counter decreases uniformly from a certain set value. Further, when the priority is higher when the numerical value is lower, the counter increases uniformly. Therefore, in any case, the core whose value is set by reading the numerical value from the counter earlier is given priority. In addition, since the core whose priority is set first is given priority, the spinlock hardware 100 becomes a FIFO type queue (queuing).

比較回路22は、最も大きい優先度が設定されたコア0のロック取得フラグ0を“1”にセットする。比較回路22は、コア0以外のコア1のロック取得フラグ1を“0”にクリアする。ロック取得フラグ0〜nのうち、“1”を出力するのは1つだけである。また、比較回路22は、コア0、1の優先度のうち最も高い優先度である“00001111”を取得して最高優先度レジスタ24に格納する。   The comparison circuit 22 sets the lock acquisition flag 0 of the core 0 set with the highest priority to “1”. The comparison circuit 22 clears the lock acquisition flag 1 of the cores 1 other than the core 0 to “0”. Of the lock acquisition flags 0 to n, only one outputs “1”. Further, the comparison circuit 22 acquires “000011111” which is the highest priority among the priorities of the cores 0 and 1 and stores it in the highest priority register 24.

次に、コア0が共有リソースを使用する処理を終え、優先度レジスタ1にゼロを設定する。これにより、比較回路22は、最も大きい優先度が設定されたコア1のロック取得フラグ1を“1”にセットし、コア0のロック取得フラグ0を“0”にクリアする。比較回路22は、コア0、1の優先度のうち最も高い優先度である“00000011”を取得して最高優先度レジスタ24に格納する。   Next, the core 0 finishes the process of using the shared resource, and sets zero in the priority register 1. As a result, the comparison circuit 22 sets the lock acquisition flag 1 of the core 1 with the highest priority set to “1”, and clears the lock acquisition flag 0 of the core 0 to “0”. The comparison circuit 22 acquires “00000011” which is the highest priority among the priorities of the cores 0 and 1 and stores it in the highest priority register 24.

スピンロックハードウェア100のこのような作用により、OSは共有リソースをロックすべきコアを特定でき、さらに、スレッドが2段以上のネスト構造になっている場合、2段目以降のスレッドに優先度を承継させることができる。   With this action of the spin lock hardware 100, the OS can specify the core to which the shared resource should be locked, and if the thread has a nested structure of two or more stages, the priority is given to the second and subsequent threads. Can be inherited.

図6は、スピンロックハードウェア100を操作する各機能の機能ブロック図の一例である。各アプリケーション1,2がスピンロックハードウェア100を自由に操作すると、この時点で競合が生じるので、一般にはOS等の特定のソフトウェアが(例えば、特権モードで)スピンロックハードウェア100を操作する。   FIG. 6 is an example of a functional block diagram of each function for operating the spin lock hardware 100. When each of the applications 1 and 2 freely operates the spin lock hardware 100, a conflict occurs at this point, and therefore, specific software such as an OS generally operates the spin lock hardware 100 (for example, in a privileged mode).

コア0がアプリケーション0を、コア1がアプリケーション1を、それぞれスレッド単位で実行するものとする。アプリケーション0,1は、それぞれロック要求部31、リソース対応処理部32、及び、ロック解放要求部33を有する。   Assume that core 0 executes application 0 and core 1 executes application 1 in units of threads. Each of the applications 0 and 1 includes a lock request unit 31, a resource handling processing unit 32, and a lock release request unit 33.

各スレッドは、共有リソース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 CPU 11, for example, “get_resorce resource name” is known. The lock request unit 31 issues such a command immediately before using the shared resources R1 and R2. Such a command is a kind of system call for calling the OS. Thereafter, the core that requested the lock enters a spin lock state until the lock can be acquired.

ロックを取得したコアはスピンロック状態が終了し、ロックを取得したコアのリソース対応処理部32は、共有リソースR1又はR2を使用した処理を実行する。リソース対応処理部32が共有リソースR1又はR2を使用した処理の実行を終了すると、ロック解放要求部33は、コアがロックしている共有リソースR1を解放(アンロック)するため、決まったコマンドを実行する。どのようなコマンドかは命令セットによって異なるが、例えば、「release_resorce リソース名」などが知られている。この後、ロックの解放を要求したコアは、プログラムに沿って処理を実行する。   The core that has acquired the lock ends the spin lock state, and the resource handling unit 32 of the core that has acquired the lock executes processing using the shared resource R1 or R2. When the resource handling processing unit 32 finishes executing the processing using the shared resource R1 or R2, the lock release requesting unit 33 releases (unlocks) the shared resource R1 locked by the core. Run. The type of command differs depending on the instruction set. For example, “release_resorce resource name” is known. Thereafter, the core that has requested the release of the lock executes processing according to the program.

OSは優先度設定部35、ネスト判定部36、フラグ読み込み部37、及び、最高優先度レジスタ読み込み部38を有する。優先度設定部35は、ロック要求部31からロックの要求を受け付けると、コア0〜nに対応する優先度レジスタ0〜nに優先度を設定する。優先度は、スレッドが指定する場合、スレッド毎に決まっている場合、又は、OSがスレッドを考慮して動的に決定する場合等がある。本実施例では、スレッドが指定するものとする。よって、優先度設定部35は、ロックを要求したスレッドが指定する優先度を、このスレッドを実行するコア0〜nに対応した優先度レジスタ0〜nに設定する。   The OS includes a priority setting unit 35, a nest determination unit 36, a flag reading unit 37, and a highest priority register reading unit 38. When receiving a lock request from the lock request unit 31, the priority setting unit 35 sets the priority in the priority registers 0 to n corresponding to the cores 0 to n. The priority may be specified by a thread, determined for each thread, or dynamically determined by the OS in consideration of the thread. In this embodiment, it is assumed that a thread specifies. Therefore, the priority setting unit 35 sets the priority specified by the thread that requested the lock in the priority registers 0 to n corresponding to the cores 0 to n executing the thread.

なお、優先度設定部35は、ロック解放要求部33が共有リソースR1又はR2のアンロックを要求すると、アンロックを要求したコア0〜nに対応した優先度レジスタ0〜nに最も優先度が小さい値(例えば、ゼロ)を設定する。これにより、共有リソースのロックがアンロックされる。   When the lock release requesting unit 33 requests the shared resource R1 or R2 to be unlocked, the priority setting unit 35 has the highest priority in the priority registers 0 to n corresponding to the cores 0 to n that requested the unlocking. Set a small value (eg, zero). As a result, the lock of the shared resource is unlocked.

フラグ読み込み部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 cores 0 to n and for each of the shared resources R1 and R2. The flag reading unit 37 identifies the shared resource R1 or R2 depending on the spin lock hardware, and sets the lock variable of the cores 0 to n corresponding to the lock acquisition flags 0 to n that output “1” to “1”. To do. In addition, the flag reading unit 37 sets all lock variables other than the core set to “1” to “0”. In this way, only one lock variable is set to “1” for one shared resource. The resource handling unit 32 uses the shared resource only when the lock variable of the core executing the thread is “1”, and spin-locks when the lock variable is “0”.

ネスト判定部36は、ロック要求部31が要求したロック要求が、2段以上にネストされたスレッドのロック要求か否かを判定する。なお、ネストとは入れ子を意味し、あるスレッドやルーチンの中に、別のスレッドやルーチンがはめ込まれることをいう。具体的には図2のスレッドAはネスト構造を有し、スレッドaはスレッドAのネスト(入れ子)になっている。2段以上にネストされたスレッドはここではスレッドaが相当する。   The nest determination unit 36 determines whether the lock request requested by the lock request unit 31 is a lock request for a thread nested in two or more stages. Nesting means nesting, and another thread or routine is inserted into one thread or routine. Specifically, the thread A in FIG. 2 has a nested structure, and the thread a is nested in the thread A. Here, the thread nested in two or more levels corresponds to the thread a.

スレッド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 lock acquisition flags 0 to n corresponding to the cores 0 to n requested to be locked other than the spin lock hardware 2 of the shared resource R2 requested to be locked. The fact that “1” is set in the lock acquisition flags 0 to n means that the same core as that requested to lock the resource R2 has already locked another shared resource R1. In such a situation, there is a high possibility that there is a lock request for the thread a having two or more levels of nesting.

なお、ネスト判定部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 lock request unit 31 that is explicitly locked in two or more levels. You may determine that there is.

ネスト判定部36は、以上のようにして判定した判定結果を最高優先度レジスタ読み込み部38に通知する。   The nest determination unit 36 notifies the highest priority register reading unit 38 of the determination result determined as described above.

最高優先度レジスタ読み込み部38は、ロック要求された共有リソースのスピンロックハードウェア以外で、ロック要求したコア0〜nに対応するロック取得フラグ0〜nに“1”が設定されているスピンロックハードウェア1の最高優先度レジスタ24の値を読み出す。これにより、ロック要求したコア0〜nが設定した優先度(このスピンロックハードウェア1において最も高い最高優先度)を取得できたことになる。   The highest priority register reading unit 38 is a spin lock in which “1” is set in the lock acquisition flags 0 to n corresponding to the cores 0 to n requested to be locked other than the spin lock hardware of the shared resource requested to be locked. The value of the highest priority register 24 of the hardware 1 is read. As a result, the priority set by the cores 0 to n that requested the lock (the highest highest priority in the spin lock hardware 1) can be acquired.

最高優先度レジスタ読み込み部38は、優先度設定部35にスピンロックハードウェア1の最高優先度を通知する。優先度設定部35は、スレッドaがロック要求した共有リソースR2のスピンロックハードウェア2のコア0〜nに対応する優先度レジスタ0〜nに、最高優先度を設定する。すなわち、スレッドaがロック要求と共にOSに通知した優先度に代えて、最高優先度を設定する。スレッドaがロック要求と共に要求した優先度でなく、最高優先度を2段目のスピンロックハードウェア2の優先度レジスタ21に設定することで、コアが実行しているスレッドAの優先度を、スレッドaの優先度として承継できたことになる。   The highest priority register reading unit 38 notifies the priority setting unit 35 of the highest priority of the spin lock hardware 1. The priority setting unit 35 sets the highest priority in the priority registers 0 to n corresponding to the cores 0 to n of the spin lock hardware 2 of the shared resource R2 requested to be locked by the thread a. That is, the highest priority is set instead of the priority notified to the OS together with the lock request by the thread a. By setting the highest priority in the priority register 21 of the second-stage spinlock hardware 2 instead of the priority requested by the thread a together with the lock request, the priority of the thread A being executed by the core is It is succeeded as the priority of the thread a.

〔動作手順〕
図7は、主にOSがスピンロックハードウェア100を操作する手順を示すフローチャート図の一例である。
[Operation procedure]
FIG. 7 is an example of a flowchart diagram illustrating a procedure in which the OS mainly operates the spin lock hardware 100.

まず、優先度設定部35は、アプリケーション0のスレッドAのロック要求部31から、共有リソースAの指定と共に、ロック要求と優先度を取得する(S10)。実際にはまず、ネスト判定部36が、2段以上にネストされたスレッドaのロック要求であるか否かを最初に判定するが、ここでは省略している。   First, the priority setting unit 35 acquires a lock request and priority together with the designation of the shared resource A from the lock request unit 31 of the thread A of the application 0 (S10). Actually, first, the nest determination unit 36 first determines whether or not it is a lock request for the thread a nested in two or more stages, but this is omitted here.

次に、優先度設定部35は、共有リソースR1に対応したスピンロックハードウェア1の、ロック要求したコア0〜nに対応する優先度レジスタ0〜nに優先度を設定する(S20)。   Next, the priority setting unit 35 sets priorities in the priority registers 0 to n corresponding to the cores 0 to n requested to be locked in the spin lock hardware 1 corresponding to the shared resource R1 (S20).

この後、フラグ読み込み部37は、スピンロックハードウェア1のロック取得フラグ0〜nを監視して、スレッドAを実行しているコアがロックを取得したか否かを判定する(S30)。例えば、すでに別のコアが共有リソースR1をロックしていた場合、この別のコアが実行するスレッドを終了するなどして共有リソースR1を解放するまで、ロック要求したコアはスピンロックする。   Thereafter, the flag reading unit 37 monitors the lock acquisition flags 0 to n of the spin lock hardware 1, and determines whether or not the core executing the thread A has acquired the lock (S30). For example, if another core has already locked the shared resource R1, the core that requested the lock is spin-locked until the shared resource R1 is released by terminating a thread executed by the other core.

スレッドAがロックを取得した場合(S30のYes)、最高優先度レジスタ読み込み部38は、最高優先度レジスタ24の値を読み取る(S40)。ロックを取得するコアが変われば、最高優先度レジスタ24の値も変わるので、最高優先度レジスタ24の値が更新されるなどのタイミングで最高優先度を取得すればよい。最高優先度レジスタ24の値によりスレッドAの優先度の承継が可能になる。   When the thread A acquires the lock (Yes in S30), the highest priority register reading unit 38 reads the value of the highest priority register 24 (S40). If the core from which the lock is acquired changes, the value of the highest priority register 24 also changes. Therefore, the highest priority may be acquired at a timing such as when the value of the highest priority register 24 is updated. The value of the highest priority register 24 allows the priority of the thread A to be inherited.

次に、スレッド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 lock request unit 31 of the thread a notifies the priority setting unit 35 of the lock request and the priority together with the designation of the shared resource R2. Thereby, the priority setting unit 35 acquires the lock request and the priority together with the designation of the shared resource R2.

ここで、ネスト判定部36は、ロック要求された共有リソースR2のスピンロックハードウェア2以外で、ロック要求したコアに対応するロック取得フラグ0〜nに“1”が設定されているか否かを判定することで、優先度を承継するか否かを判定する。   Here, the nest determination unit 36 determines whether or not “1” is set in the lock acquisition flags 0 to n corresponding to the core that requested the lock, other than the spinlock hardware 2 of the shared resource R2 that is requested to be locked. By determining, it is determined whether to inherit the priority.

優先度を承継すべき場合、優先度設定部35は、最高優先度レジスタ読み込み部38が読み取った最高優先度レジスタ24の値を、スピンロックハードウェア2のスレッドaを実行するコアに対応する優先度レジスタ21に設定する(S50)。こうすることでスレッドaの優先度がスレッドAと同じになる。   When the priority should be inherited, the priority setting unit 35 sets the value of the highest priority register 24 read by the highest priority register reading unit 38 to the priority corresponding to the core executing the thread a of the spinlock hardware 2. The degree register 21 is set (S50). By doing so, the priority of the thread a becomes the same as that of the thread A.

フラグ読み込み部37は、スピンロックハードウェア2のロック取得フラグ0〜nを監視して、スレッドaを実行しているコアがロックを取得したか否かを判定する(S60)。取得できない場合は、スレッドAよりも優先度の高いスレッドが共有リソースR2を使用していることになるので、スレッドaを実行しているコアはスピンロックする。このため、処理はステップS40に戻る。   The flag reading unit 37 monitors the lock acquisition flags 0 to n of the spin lock hardware 2, and determines whether or not the core executing the thread a has acquired the lock (S60). If it cannot be acquired, a thread having a higher priority than the thread A uses the shared resource R2, and the core executing the thread a spin-locks. Therefore, the process returns to step S40.

スレッド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 spin lock hardware 100 according to the present embodiment can realize the spin lock in hardware even when the CPU 11 does not have an atomic instruction. Even if the thread has a nested structure, the second-stage thread can take over the priority of the first-stage thread, so that the worst execution time of the thread having the nested structure can be guaranteed.

本実施例では、さらにコア0〜nのいずれかを選択的に優先できるスピンロックハードウェア100について説明する。   In the present embodiment, a spin lock hardware 100 that can selectively give priority to any of the cores 0 to n will be described.

図8(a)は、本実施例のスピンロックハードウェア100の構成図の一例を示す。図8において図4と同一部には同一の符号を付しその説明は省略する。このスピンロックハードウェア100は、コア毎にローカル優先ビットを有し、特定のコアを優先可能な点に特徴の1つがある。   FIG. 8A shows an example of a configuration diagram of the spin lock hardware 100 of the present embodiment. In FIG. 8, the same parts as those in FIG. The spin lock hardware 100 has a local priority bit for each core, and is characterized in that a specific core can be prioritized.

図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 priority register 21. That is, if the number of bits of the priority register 21 is 8, the priority is set to the lower 7 bits of the priority register 21, and the local priority bit is assigned to the most significant bit (MSB).

比較回路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 comparison circuit 22 compares the “local priority bit + priority” of each of the cores 0 to n and sets the lock acquisition flags 0 to n of the cores with the largest value to “1”. . As a result, the spin lock hardware 100 operates as follows.
Unless the cores 0 to n preferentially lock the shared resource, the local priority bit is “0”, so that the cores 0 to n having the highest priority are preferentially shared as in the first embodiment. Resources can be used.
When one of the cores 0 to n preferentially locks the shared resource, the local priority bit is set to “1” because only the local priority bit of one priority register 21 is “1”. The core can use shared resources preferentially.
When any two or more of the cores 0 to n preferentially lock the shared resource, a plurality of local priority bits become “1”. In this case, among the plurality of cores having the local priority bit set to “1”, the core having the highest priority set in the lower 7 bits of the priority register can preferentially use the shared resource.

〔ローカル優先ビットの必要性〕
コア0〜nが優先的に共有リソースを使用する必要がある場合、換言すると、あるコア0〜nに優先的に共有リソースを使用させてよい場合とは、例えば、異常検出時のフェールセーフ処理、優先度の高い割り込み処理、OSなど管理用ソフトの特定処理などである。
[Necessity of local priority bit]
When the cores 0 to n need to use the shared resource preferentially, in other words, the case where the certain cores 0 to n may preferentially use the shared resource is, for example, a fail-safe process when an abnormality is detected High-priority interrupt processing, OS specific management software processing, and the like.

また、例えば、一定時間以上、共有リソースが解放されるまで待機している(スピンしている)スレッドが、ローカル優先ビットを“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 priority setting unit 35 of the OS monitors a core that is spin-locked and a certain time or more has elapsed.

しかし、各スレッドがローカル優先ビットを“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 priority setting unit 35 acquires the lock request and priority together with the designation of the shared resource A from the lock request unit 31 of the thread A (S10).

次に、優先度設定部35は、共有リソースR1に対応したスピンロックハードウェア1の、ロック要求したコア0〜nに対応する優先度レジスタ0〜nに優先度を設定する(S20)。ここでは、ローカル優先ビットは“0”である。   Next, the priority setting unit 35 sets priorities in the priority registers 0 to n corresponding to the cores 0 to n requested to be locked in the spin lock hardware 1 corresponding to the shared resource R1 (S20). Here, the local priority bit is “0”.

この後、フラグ読み込み部37は、スピンロックハードウェア1のロック取得フラグ0〜nを監視して、スレッドAを実行しているコアがロックを取得したか否かを判定する(S30)。   Thereafter, the flag reading unit 37 monitors the lock acquisition flags 0 to n of the spin lock hardware 1, and determines whether or not the core executing the thread A has acquired the lock (S30).

取得できない場合は、スレッド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 priority setting unit 35 acquires the lock request and the priority along with the designation of the shared resource A from the lock request unit 31 of the thread A of the application 0 (S10).

次に、優先度設定部35は、共有リソースR1に対応したスピンロックハードウェア1の、ロック要求したコアに対応する優先度レジスタに優先度を設定する(S22)。ここでは、スレッドA又はOSがローカル優先ビットを“1”に設定したものとする。これにより、スレッドAは優先的に共有リソースR1をロックできる可能性が高くなる。   Next, the priority setting unit 35 sets the priority in the priority register corresponding to the core that requested the lock of the spin lock hardware 1 corresponding to the shared resource R1 (S22). Here, it is assumed that the thread A or OS sets the local priority bit to “1”. This increases the possibility that the thread A can preferentially lock the shared resource R1.

この後、フラグ読み込み部37は、スピンロックハードウェア1のロック取得フラグ0〜nを監視して、スレッドaを実行しているコアがロックを取得したか否かを判定する(S30)。   Thereafter, the flag reading unit 37 monitors the lock acquisition flags 0 to n of the spin lock hardware 1, and determines whether or not the core executing the thread a has acquired the lock (S30).

取得できない場合は、スレッド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 priority setting unit 35 does not set the priority of the second-stage thread a in the priority register 21, so the priority of the first-stage thread A is inherited.

以上説明したように、本実施例のスピンロックハードウェアは、実施例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 CAN controller 21 priority register 22 comparison circuit 23 lock acquisition flag 24 highest priority register 100 spin lock hardware 200 microcomputer


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.
前記優先度レジスタの前記予約ビットは最上位ビットである、ことを特徴とする請求項2記載の排他制御装置。   3. The exclusive control apparatus according to claim 2, wherein the reserved bit of the priority register is a most significant bit. 前記最高優先度レジスタが格納する最高の優先度は、別の排他制御装置の、前記最高の優先度を設定したプロセッサエレメントに対応づけられた前記優先度レジスタに設定される、
ことを特徴とする請求項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:
所定のプロセッサエレメントが第1の排他制御装置の前記優先度レジスタに設定した優先度が、前記最高優先度レジスタに格納された場合であって、
前記所定のプロセッサエレメントが第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.
JP2011096418A 2011-04-22 2011-04-22 Exclusive control device and microcomputer Pending JP2012226709A (en)

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)

* Cited by examiner, † Cited by third party
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)

* Cited by examiner, † Cited by third party
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

Patent Citations (1)

* Cited by examiner, † Cited by third party
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)

* Cited by examiner, † Cited by third party
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)

* Cited by examiner, † Cited by third party
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