A hardware semaphore device and a multi-core system

By introducing a hardware semaphore device that supports three operating modes in a multi-core system, the problem of the single hardware semaphore mode in the prior art is solved, and flexible and efficient inter-core communication is realized.

CN117331879BActive Publication Date: 2026-11-17SHANDONG YUNHAI GUOCHUANG CLOUD COMPUTING EQUIP IND INNOVATION CENT CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311271345.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-28
Publication Date
2026-11-17
Estimated Expiration
2043-09-28

AI Technical Summary

Technical Problem

In existing multi-core systems, hardware semaphores only support a single mutex semaphore working mode, resulting in insufficient flexibility and an inability to meet the needs of different business scenarios.

Method used

A hardware semaphore device is provided, including a mutex semaphore module and a message management module, supporting three working modes: polling mode, interrupt mode and message mode. By storing the authorization result in the register and generating corresponding request signals and messages, flexible inter-core communication is achieved.

Benefits of technology

It enables flexible selection of mutex semaphores in different modes, improves the communication efficiency and adaptability of multi-core systems, and meets the needs of various business scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117331879B_ABST
    Figure CN117331879B_ABST
Patent Text Reader

Abstract

This invention relates to the field of computers and discloses a hardware semaphore device and a multi-core system, comprising: a mutex semaphore module, used to store the authorization result of the mutex semaphore to the core in a register corresponding to the mutex semaphore when the mutex semaphore is operating in polling mode, interrupt mode, or message mode; and used to generate a first request signal corresponding to the mutex semaphore and send the first request signal to a message management module when the mutex semaphore is operating in message mode; the message management module is used to generate a first message using first sequence number information corresponding to the first request signal and write the first message into the memory area of ​​the corresponding core; the first sequence number information includes the mutex semaphore sequence number and the core sequence number. In this invention, the mutex semaphore has three operating modes: polling mode, interrupt mode, and message mode, offering diverse operating options and allowing for flexible selection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computers, and in particular to a hardware semaphore device and a multi-core system. Background Technology

[0002] A semaphore, also known as a semaphore, is a facility used in a multithreaded environment to prevent two or more critical code sections from being accessed concurrently. Before entering a critical code section, a thread must acquire a semaphore; once the critical code section is complete, the thread must release the semaphore. Other threads wishing to enter the critical code section must wait until the first thread releases the semaphore.

[0003] In modern multi-core systems, hardware semaphores can be used to achieve inter-core communication. Currently, only mutex semaphores are available, and they only support one working mode: interrupt. This single working mode is not flexible enough.

[0004] Therefore, how to solve the above-mentioned technical problems should be a key focus for those skilled in the art. Summary of the Invention

[0005] The purpose of this invention is to provide a hardware semaphore device and a multi-core system. The mutex semaphore has three working modes, with a variety of working types, and the working mode can be flexibly selected.

[0006] To solve the above-mentioned technical problems, the present invention provides a hardware semaphore device, comprising:

[0007] The mutex semaphore module is used to store the authorization result of the mutex semaphore to the core into the register corresponding to the mutex semaphore when the mutex semaphore is working in polling mode, interrupt mode, or message mode; when the mutex semaphore is working in message mode, it is also used to generate a first request signal corresponding to the mutex semaphore and send the first request signal to the message management module.

[0008] The message management module is used to generate a first message using the first sequence number information corresponding to the first request signal, and write the first message into the memory area of ​​the corresponding core; the first sequence number information includes a mutex semaphore sequence number and a core sequence number.

[0009] As one possible implementation, when the number of the mutual exclusion semaphore modules is two or more, it further includes:

[0010] An interrupt management module is used to aggregate all first authorized interrupt signals for the same core, generate a first aggregated authorized interrupt signal, and send the first aggregated authorized interrupt signal to the corresponding core; correspondingly, a mutex semaphore module is used to send the first authorized interrupt signal to the interrupt management module.

[0011] As one possible implementation, the message management module includes a message generation sub-module and a message sending sub-module;

[0012] The message generation submodule is used to generate a first message using the first sequence number information and send the first message to the sending submodule;

[0013] The sending sub-module is used to send the first message to the memory area of ​​the corresponding core.

[0014] As one possible implementation, the message generation submodule includes a message buffer for storing the first message. When the number of first messages in the message buffer reaches a preset threshold, the first message is sent to the sending submodule.

[0015] As one possible implementation, the sending sub-module is further configured to send a first feedback signal to the message generation sub-module; the message generation sub-module includes a counter; the counter corresponds one-to-one with a core;

[0016] The counter is used to increment the first count value of the first message by one when the message generation submodule receives the first feedback signal to obtain a new first count value; when the message generation submodule receives the first message subtraction value signal, subtract the value corresponding to the first message subtraction value signal from the count value to obtain a new first count value; and send the new first count value to the interrupt management module.

[0017] Correspondingly, the interrupt management module is also used to generate a first message interrupt signal and send the first message interrupt signal to the corresponding core when the new first count value is greater than or equal to the message value of the first preset configuration that generates an interrupt.

[0018] As one possible implementation, when the new first count value obtained by the counter is equal to the maximum number of first messages that can be stored in the core, and the sending sub-module sends a new first message to the core again, the message generation sub-module is also used to generate a first error signal and send the first error signal to the interrupt management module, so that the interrupt management module generates a first error interrupt signal and sends the first error interrupt signal to the corresponding core.

[0019] When the new first count value obtained by the counter is equal to the maximum number of first messages that can be stored in the core, and the sending sub-module sends a new first message to the core again, the message generation sub-module is also used to discard the new first message;

[0020] When the counter obtains a new first count value equal to zero, and the message generation submodule receives the first message subtraction value signal again, the counter keeps the new first count value fixed. The message generation submodule is also used to generate a first error signal and send the first error signal to the interrupt management module, so that the interrupt management module generates a first error interrupt signal and sends the first error interrupt signal to the corresponding core.

[0021] As one possible implementation, when the number of the mutual exclusion semaphore modules is two or more, it further includes:

[0022] A polling arbitrator module is used to arbitrate all first request signals to obtain a first target request signal; and to send the first target request signal to the message management module.

[0023] Accordingly, the mutex semaphore module is used to send the first request signal to the polling arbitrator module.

[0024] As one possible implementation, it also includes:

[0025] A configuration module is used to send a first semaphore request signal and a first semaphore resource count increase signal to the mutex semaphore module.

[0026] As one possible implementation, it also includes:

[0027] A counting semaphore module is used to: when the counting semaphore is operating in polling mode, store the authorization result of the counting semaphore to the core in the register corresponding to the counting semaphore; when the counting semaphore is operating in interrupt mode, store the authorization result of the counting semaphore to the core in the register corresponding to the counting semaphore, generate a second authorization interrupt signal to the core, and send the second authorization interrupt signal to the corresponding core; when the counting semaphore is operating in message mode, store the authorization result of the counting semaphore to the core in the register corresponding to the counting semaphore, generate a second request signal corresponding to the counting semaphore, and send the second request signal to the message management module.

[0028] Accordingly, the message management module is also used to generate a second message using the second sequence number information corresponding to the second request signal, and write the second message into the memory area of ​​the corresponding core; the second sequence number information includes a counting semaphore sequence number and a core sequence number.

[0029] As one possible implementation, when the counting semaphore operates in message mode, the authorization mode of the counting semaphore module to the core is serial authorization; when the counting semaphore operates in polling mode or interrupt mode, the authorization mode of the counting semaphore module to the core includes serial authorization and parallel authorization.

[0030] The present invention also provides a multi-core system including any of the hardware semaphore devices described above.

[0031] The present invention provides a hardware semaphore device, comprising: a mutex semaphore module, used to store the authorization result of the mutex semaphore to the core in a register corresponding to the mutex semaphore when the mutex semaphore is operating in polling mode, interrupt mode, or message mode; and used to generate a first request signal corresponding to the mutex semaphore and send the first request signal to a message management module when the mutex semaphore is operating in message mode; the message management module is used to generate a first message using first sequence number information corresponding to the first request signal and write the first message into the memory area of ​​the corresponding core; the first sequence number information includes the mutex semaphore sequence number and the core sequence number.

[0032] As can be seen, the mutex semaphore in this invention can operate in three modes: polling, interrupt, and message. This variety of modes allows for flexible selection based on the business scenario, enabling efficient and flexible multi-core communication. In polling mode, the mutex semaphore module stores the authorization result of the mutex semaphore to the core in a register. In message mode, the mutex semaphore module not only stores the authorization result of the mutex semaphore to the core in a register but also generates a first request signal, which is then sent to the message management module. The message management module then generates a first message and sends it to the corresponding core's memory area, allowing the core to read the message from the memory area.

[0033] Furthermore, the present invention also provides a multi-core system with the above-mentioned advantages. Attached Figure Description

[0034] To more clearly illustrate the technical solutions of the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0035] Figure 1 A schematic diagram of a hardware semaphore device provided in an embodiment of the present invention. Figure 1 ;

[0036] Figure 2 This is a schematic diagram illustrating the format of a first message provided in an embodiment of the present invention;

[0037] Figure 3 A schematic diagram of a hardware semaphore device provided in an embodiment of the present invention. Figure 2 ;

[0038] Figure 4 A schematic diagram of a hardware semaphore device provided in an embodiment of the present invention. Figure 3 ;

[0039] Figure 5 A schematic diagram of a hardware semaphore device provided in an embodiment of the present invention. Figure 4 ;

[0040] Figure 6 A schematic diagram of a hardware semaphore device provided in an embodiment of the present invention. Figure 5 ;

[0041] Figure 7 This is a flowchart illustrating the operation of a mutex semaphore provided in an embodiment of the present invention.

[0042] Figure 8 This is a flowchart illustrating the operation of a counting semaphore provided in an embodiment of the present invention. Detailed Implementation

[0043] To enable those skilled in the art to better understand the present invention, the invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are merely some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0044] As described in the background section, current hardware semaphores only include mutex semaphores, which only support one working mode: interrupt. This single working mode is not flexible enough.

[0045] In view of this, the present invention provides a hardware semaphore device, please refer to... Figure 1 ,include:

[0046] The mutex semaphore module 1 is used to store the authorization result of the mutex semaphore to the core 3 into the register corresponding to the mutex semaphore when the mutex semaphore is working in polling mode, interrupt mode, or message mode; when the mutex semaphore is working in message mode, it is also used to generate a first request signal corresponding to the mutex semaphore and send the first request signal to the message management module 2.

[0047] The message management module 2 is used to generate a first message using the first sequence number information corresponding to the first request signal, and write the first message into the memory area of ​​the corresponding core 3; the first sequence number information includes the mutex semaphore sequence number and the core sequence number.

[0048] When the mutex semaphore is operating in interrupt mode, the authorization result of the mutex semaphore to core 3 is stored in the register corresponding to the mutex semaphore, the first authorization interrupt signal to core 3 is generated, and the first authorization interrupt signal is sent to the corresponding core 3.

[0049] The authorization result of the mutex semaphore to core 3 is that the mutex semaphore is authorized to core 3, which in turn produces three different behaviors according to three different working modes.

[0050] The number of mutually exclusive semaphore modules 1 can be one or more, both of which are within the protection scope of this invention.

[0051] A mutex semaphore can only be authorized to one core at a time.

[0052] When a mutex semaphore operates in polling mode, the grant result is stored in the register of the mutex semaphore corresponding to that core 3. At this time, the register is set to 1. Cores 3 that request the mutex semaphore periodically poll their own registers. If the corresponding register is set, then that core 3 runs the corresponding software service.

[0053] When a mutex semaphore operates in interrupt mode, the authorization result is stored in the register of the mutex semaphore corresponding to core 3. Simultaneously, a first authorization interrupt signal, Func_int, is generated for core 3. When the authorized core 3 receives this first authorization interrupt signal, it executes the corresponding interrupt service routine. After the authorized core 3 completes its software execution, it releases the mutex semaphore via `put`. The register value of the corresponding mutex semaphore is cleared. Only after core 3 releases the mutex semaphore can other cores 3 acquire it.

[0054] When the mutex semaphore is working in message mode, on the one hand, the authorization result is stored in the register of the mutex semaphore corresponding to the core 3, and on the other hand, a first request signal Req is generated for the message management module 2.

[0055] In the first sequence number information, the core sequence number refers to the sequence number of the authorized core 3.

[0056] As one possible implementation, the message management module 2 includes a message generation sub-module 21 and a message sending sub-module 22;

[0057] The message generation submodule 21 is used to generate a first message using the first sequence number information and send the first message to the sending submodule;

[0058] The sending sub-module 22 is used to send the first message to the corresponding core 3.

[0059] Each core 3 has a separate ring buffer configuration register, including the base address of the message and the size of the memory area to store the message. The sending sub-module 22 sends the first message to the corresponding core 3's memory area, i.e., writes the first message to the memory area. The first message can be written to the memory area via a bus, such as the AHB bus (Advanced High Performance Bus) or the AXI (Advanced Extensible Interface) bus. When a core receives a message interrupt, it reads the first message from the memory area and performs the corresponding business processing.

[0060] The first message includes the mutex semaphore number `Semaphore_num`, the core number `Core_num`, the data flip bit `Flip_bit`, and the reserved segment `RSV`. The reserved segment is used to align with the data width of the memory area; the data flip bit is flipped during each round of filling the memory area of ​​core 3 to distinguish between old and new data. The format of the first message is as follows: Figure 2 As shown, from left to right, they are reserved segment, data flip bit, mutex semaphore number, and core number.

[0061] In this invention, the form in which the message sub-module sends the first message is not limited and depends on the situation. For example, each time the sending sub-module 22 receives a first message, it writes the first message into the memory area of ​​core 3. Alternatively, the message generation sub-module 21 includes a message buffer for storing the first messages, and when the number of first messages in the message buffer reaches a preset threshold, the first message is sent to the sending sub-module.

[0062] The message buffer can be a FIFO (first in first out) buffer, where messages are only sent when the number of messages reaches a preset threshold, thus improving bus utilization efficiency. The preset threshold can be set by the user and is not limited in this invention.

[0063] In this embodiment, the mutex semaphore can operate in three modes: polling, interrupt, and message. This variety of modes allows for flexible selection based on the business scenario. In polling mode, mutex semaphore module 1 stores the authorization result of the mutex semaphore to core 3 in a register. In interrupt mode, mutex semaphore module 1 not only stores the authorization result of the mutex semaphore to core 3 in a register but also generates a first authorization interrupt signal. When the authorized core 3 receives the first authorization interrupt signal, it runs the corresponding interrupt service routine. In message mode, mutex semaphore module 1 not only stores the authorization result of the mutex semaphore to core 3 in a register but also generates a first request signal, which is then sent to message management module 2. Message management module 2 then generates a first message and sends it to the memory area of ​​the corresponding core 3, allowing the core to read the message from the memory area.

[0064] Based on the above embodiments, in one embodiment of the present invention, such as Figure 3 As shown, when the number of mutual exclusion semaphore modules 1 is more than two, it also includes:

[0065] Interrupt management module 4 is used to aggregate all first authorized interrupt signals for the same core 3, generate a first aggregated authorized interrupt signal, and send the first aggregated authorized interrupt signal to the corresponding core 3;

[0066] Correspondingly, the mutex semaphore module 1 is used to send the first authorized interrupt signal to the interrupt management module 4.

[0067] When there are more than two mutex semaphore modules 1, multiple first authorized interrupt signals may be authorized to the same core 3. The interrupt management module 4 aggregates the first authorized interrupt signals and generates a first aggregated authorized interrupt signal granted_int, which is then sent to the corresponding core 3.

[0068] Please refer to Figure 3 In one embodiment of the present invention, the sending sub-module 22 is further configured to send a first feedback signal Send Response to the message generation sub-module 21; the message generation sub-module 21 includes a counter 211; the counter 211 corresponds one-to-one with the core 3;

[0069] The counter 211 is used to increment the first count value of the first message by one when the message generation submodule 21 receives the first feedback signal, to obtain a new first count value; when the message generation submodule 21 receives the first message subtraction value signal, it subtracts the value corresponding to the first message subtraction value signal from the count value to obtain a new first count value; and sends the new first count value to the interrupt management module 4.

[0070] Correspondingly, the interrupt management module 4 is also used to generate a first message interrupt signal and send the first message interrupt signal to the corresponding core 3 when the new first count value is greater than or equal to the message value of the first preset configuration that generates an interrupt.

[0071] Each core 3 has a separate counter 211. The message value for the interrupt generated by the first preset configuration can be set by the user and is not limited in this invention.

[0072] Once the first message is sent, the sending sub-module 22 sends a first feedback signal to the message generation sub-module 21 so that the counter 211 can count.

[0073] The first message subtraction signal (Msg_sub_val signal) is sent from configuration module 6 to message generation submodule 21. The first message subtraction signal includes the value to be subtracted; the count value subtracted by counter 211 can be either equal to or greater than 1. Counter 211 determines a new first count value, Msg_cnt. When the new first count value, Msg_cnt, is greater than the preset configuration interrupt message value, Msg_cfg, the new first count value, Msg_cnt, is sent to interrupt management module 4.

[0074] Correspondingly, interrupt management module 4 is also used to generate message interrupt signals msg_int. When core 3 receives the message interrupt signal msg_int, core 3 runs the interrupt service function. It can read multiple messages from the memory area at once, process the messages in batches, and run related business logic.

[0075] In other embodiments of the present invention, when the new first count value obtained by the counter 211 is equal to the maximum number of first messages that can be stored in the core 3, and the sending sub-module 22 sends a new first message to the core 3 again, the message generation sub-module 21 is also used to generate a first error signal and send the first error signal to the interrupt management module 4, so that the interrupt management module 4 generates a first error interrupt signal and sends the first error interrupt signal to the corresponding core 3.

[0076] When the new first count value obtained by counter 211 is equal to the maximum number of first messages that can be stored in core 3, and the sending sub-module 22 sends a new first message to core 3 again, the message generation sub-module 21 is also used to discard the new first message.

[0077] When the new first count value obtained by counter 211 is equal to zero, and the message generation submodule 21 receives the first message subtraction value signal again, counter 211 keeps the new first count value fixed, and the message generation submodule 21 is also used to generate a first error signal and send the first error signal to the interrupt management module 4, so that the interrupt management module 4 generates a first error interrupt signal and sends the first error interrupt signal to the corresponding core 3.

[0078] When the number of first messages sent by the sending submodule 22 has already equaled the maximum amount that the memory area in core 3 can store, an overflow occurs when the first message is sent to the memory area again. At this time, the first error signal err is generated and sent to the interrupt management module 4. At the same time, the newly generated first message is discarded.

[0079] When core 3 initiates a subtraction operation, if the number of the first message stored in core 3 overflows, that is, the number of the first message stored is already zero and cannot be reduced further, counter 211 keeps the number of the first message sent by the sending sub-module 22 to core 3 fixed, that is, keeps the number zero. At this time, an error signal err is also generated and sent to the interrupt management module 4.

[0080] Correspondingly, interrupt management module 4 is also used to generate an error interrupt signal err_int and send it to the corresponding core 3.

[0081] like Figure 4 As shown, based on any of the above embodiments, in one embodiment of the present invention, when the number of mutual exclusion semaphore modules 1 is two or more, the hardware semaphore device further includes:

[0082] Polling arbitrator module 5 is used to arbitrate all first request signals to obtain a first target request signal; and send the first target request signal to message management module 2.

[0083] Correspondingly, the mutex semaphore module 1 is used to send the first request signal to the polling arbitrator module 5.

[0084] When the mutex semaphore module 1 is working in message mode, and there are more than two mutex semaphore modules 1, multiple mutex semaphore modules 1 may need to send the first message. Therefore, it is necessary to arbitrate multiple first request signals and select one first request signal as the first target request signal.

[0085] It should be noted that the method for arbitrating the first target request signal from the first request signal in this invention is not limited and can be determined as appropriate. For example, it can be selected based on the polling priority of the first request signals, with the highest priority first request signal selected as the first target request signal each time; or it can be selected based on the fixed priority of the first request signals, with the highest priority first request signal selected as the first target request signal each time. Polling priority means that the priority of the first request signals is not fixed each time, and the priorities of the various first request signals rotate; fixed priority means that the priority of the first request signals remains unchanged.

[0086] Please refer to Figure 5Based on any of the above embodiments, in one embodiment of the present invention, the hardware semaphore device includes:

[0087] The mutex semaphore module 1 is used to store the authorization result of the mutex semaphore to core 3 in the register corresponding to the mutex semaphore when the mutex semaphore is working in polling mode; when the mutex semaphore is working in interrupt mode, it stores the authorization result of the mutex semaphore to core 3 in the register corresponding to the mutex semaphore, generates a first authorization interrupt signal for core 3, and sends the first authorization interrupt signal to the corresponding core 3; when the mutex semaphore is working in message mode, it stores the authorization result of the mutex semaphore to core 3 in the register corresponding to the mutex semaphore, generates a first request signal corresponding to the mutex semaphore, and sends the first request signal to message management module 2.

[0088] The message management module 2 is used to generate a first message using the first sequence number information corresponding to the first request signal, and write the first message into the memory area of ​​the corresponding core 3; the first sequence number information includes the mutex semaphore sequence number and the core sequence number;

[0089] Configuration module 6 is used to send a first semaphore request signal and a first semaphore resource count increase signal to the mutex semaphore module 1.

[0090] Core 3 sends a first semaphore request signal (get) to the mutex semaphore module 1 via configuration module 6. When one or more cores 3 need to acquire a mutex semaphore, each core 3 can request the mutex semaphore via get and wait for authorization. Core 3 also sends a first semaphore resource increment signal (put) to the mutex semaphore module 1 via configuration module 6, indicating that core 3 is releasing the mutex semaphore. Core 3 and configuration module 6 communicate via a bus.

[0091] Please refer to Figure 6 Based on the above embodiments, in one embodiment of the present invention, the hardware semaphore device includes:

[0092] Configuration module 6 is used to send a first semaphore request signal and a first semaphore resource count increment signal to the mutex-type semaphore module 1; and to send a second semaphore request signal and a second semaphore resource count increment signal to the counting-type semaphore module 7.

[0093] The mutex semaphore module 1 is used to store the authorization result of the mutex semaphore to core 3 into the register corresponding to the mutex semaphore when the mutex semaphore is working in polling mode; when the mutex semaphore is working in interrupt mode, it stores the authorization result of the mutex semaphore to core 3 into the register corresponding to the mutex semaphore, generates a first authorization interrupt signal for core 3, and sends the first authorization interrupt signal to interrupt management module 4; when the mutex semaphore is working in message mode, it stores the authorization result of the mutex semaphore to core 3 into the register corresponding to the mutex semaphore, generates a first request signal corresponding to the mutex semaphore, and sends the first request signal to polling arbitrator module 5.

[0094] The counting semaphore module 7 is used to store the authorization result of the counting semaphore to core 3 into the register corresponding to the counting semaphore when the counting semaphore is working in polling mode; when the counting semaphore is working in interrupt mode, it stores the authorization result of the counting semaphore to core 3 into the register corresponding to the counting semaphore, generates a second authorization interrupt signal for core 3, and sends the second authorization interrupt signal to the interrupt management module 4; when the counting semaphore is working in message mode, it stores the authorization result of the counting semaphore to core 3 into the register corresponding to the counting semaphore, generates a second request signal corresponding to the counting semaphore, and sends the second request signal to the polling arbitrator module 5.

[0095] The polling arbitrator module 5 is used to arbitrate all first request signals to obtain a first target request signal; send the first target request signal to the message management module 2; arbitrate all second request signals to obtain a second target request signal; and send the second target request signal to the message management module 2.

[0096] The message management module 2 includes a message generation sub-module 21 and a sending sub-module 22. The message generation sub-module 21 is used to generate a first message using first sequence number information and send the first message to the sending sub-module; it is also used to generate a second message using second sequence number information and send the second message to the sending sub-module; the first sequence number information and the second sequence number information correspond to the first target request signal and the second target request signal, respectively.

[0097] The sending sub-module 22 is used to send the first message to the memory area of ​​the corresponding core 3; and to send the second message to the memory area of ​​the corresponding core 3.

[0098] Interrupt management module 4 is used to aggregate all first authorized interrupt signals for the same core 3, generate a first aggregated authorized interrupt signal, and send the first aggregated authorized interrupt signal to the corresponding core 3; aggregate all second authorized interrupt signals for the same core 3, generate a second aggregated authorized interrupt signal, and send the second aggregated authorized interrupt signal to the corresponding core 3.

[0099] The sending sub-module 22 is also used to send a first feedback signal to the message generation sub-module 21; send a second feedback signal to the message generation sub-module 21; the message generation sub-module 21 includes a counter 211; the counter 211 corresponds one-to-one with the core 3;

[0100] Counter 211 is used to increment the first count value of the first message by one when the message generation submodule 21 receives the first feedback signal, to obtain a new first count value; and to subtract the value corresponding to the first message subtraction value signal from the count value when the message generation submodule 21 receives the first message subtraction value signal, to obtain a new first count value; and to send the new first count value to the interrupt management module 4. It is also used to increment the second count value of the second message by one when the message generation submodule 21 receives the second feedback signal, to obtain a new second count value; and to subtract the value corresponding to the second message subtraction value signal from the count value when the message generation submodule 21 receives the second message subtraction value signal, to obtain a new second count value; and to send the new second count value to the interrupt management module 4.

[0101] The interrupt management module 4 is used to generate a first message interrupt signal and send the first message interrupt signal to the corresponding core 3 when the new first count value is greater than or equal to the message value of the first preset configuration that generates an interrupt; and to generate a second message interrupt signal and send the second message interrupt signal to the corresponding core 3 when the new second count value is greater than or equal to the message value of the second preset configuration that generates an interrupt.

[0102] When the new first count value equals the maximum number of first messages that can be stored in core 3, and the sending sub-module 22 sends a new first message to core 3 again, the message generation sub-module 21 is also used to generate a first error signal and send the first error signal to the interrupt management module 4, so that the interrupt management module 4 generates a first error interrupt signal and sends the first error interrupt signal to the corresponding core 3; at the same time, the message generation sub-module 21 is also used to discard the new first message;

[0103] When the new first count value obtained by counter 211 is equal to zero, and the message generation submodule 21 receives the first message subtraction value signal again, counter 211 keeps the new first count value fixed, and the message generation submodule 21 is also used to generate a first error signal and send the first error signal to the interrupt management module 4, so that the interrupt management module 4 generates a first error interrupt signal and sends the first error interrupt signal to the corresponding core 3;

[0104] When the new second count value equals the maximum number of second messages that can be stored in core 3, and the sending sub-module 22 sends a new second message to core 3 again, the message generation sub-module 21 is also used to generate a second error signal and send the second error signal to the interrupt management module 4, so that the interrupt management module 4 generates a second error interrupt signal and sends the second error interrupt signal to the corresponding core 3; at the same time, the message generation sub-module 21 is also used to discard the new second message;

[0105] When the counter 211 obtains a new second count value equal to zero, and the message generation submodule 21 receives the second message subtraction value signal again, the counter 211 maintains the new second count value. The message generation submodule 21 also generates a second error signal and sends it to the interrupt management module 4, so that the interrupt management module 4 generates a second error interrupt signal and sends it to the corresponding core 3.

[0106] When there are more than two counting semaphore modules 7, multiple second authorized interrupt signals may be authorized to the same core 3. The interrupt management module 4 aggregates the second authorized interrupt signals and generates a second aggregated authorized interrupt signal granted_int, which is then sent to the corresponding core 3.

[0107] The value of the interrupt message generated by the second preset configuration can be set by the user and is not limited in this invention.

[0108] After the second message is sent, the sending sub-module 22 sends a second feedback signal to the message generation sub-module 21 so that the counter 211 can count. The second message subtraction value signal is sent by the configuration module 6 to the message generation sub-module 21. The second message subtraction value signal includes the value to be subtracted, and the count value subtracted by the counter 211 can be equal to 1 or greater than 1.

[0109] When the number of second messages sent by the sending submodule 22 is equal to the maximum number that can be stored in the memory area of ​​core 3, an overflow occurs when the second message is sent to the memory area again. At this time, a second error signal err is generated and sent to the interrupt management module 4.

[0110] When core 3 initiates a subtraction operation, if the number of second messages stored in core 3 underflows, meaning the number of second messages stored is already zero and cannot be reduced further, counter 211 keeps the number of second messages sent by the sending sub-module 22 to core 3 fixed, i.e., keeps the number zero. At this time, an error signal err is also generated and sent to the interrupt management module 4.

[0111] In this embodiment, the number of at least one mutual exclusion semaphore module 1 and counting semaphore module 7 is more than two. When the number of mutual exclusion semaphore module 1 and counting semaphore module 7 is one, the interrupt management module 4 and the polling arbiter module 5 may not be included.

[0112] The three operating modes of counting semaphores are the same as the three operating modes of mutex semaphores.

[0113] When operating in polling mode, the authorization result is stored in the register of the counting semaphore corresponding to that core 3. At this time, the register is set to 1. Core 3 requesting the counting semaphore periodically polls its own register. If the corresponding register is set, then that core 3 runs the corresponding software service.

[0114] When operating in interrupt mode, the authorization result is stored in the register of the counting semaphore corresponding to core 3. Simultaneously, a second authorization interrupt signal, Func_int, is generated for core 3. When the authorized core 3 receives this second authorization interrupt signal, it executes the corresponding interrupt service routine. After the authorized core 3 completes its software execution, it releases the counting semaphore via `put`, clearing the register value of the corresponding counting semaphore. Only after core 3 releases the counting semaphore can other cores 3 acquire it.

[0115] When operating in message mode, on the one hand, the authorization result is stored in the register of the counting semaphore corresponding to the core 3, and on the other hand, a second request signal Req is generated for the message management module 2.

[0116] In the second sequence number information, the core sequence number refers to the sequence number of the authorized core 3.

[0117] The second message includes the counting semaphore number Semaphore_num, the core number Core_num, the data flip bit Flip_bit, and the reserved segment Rsv.

[0118] In this invention, the form in which the message sub-module sends the second message is not limited and depends on the situation. For example, each time the sending sub-module 22 receives a second message, it writes the second message into the memory area of ​​core 3. Alternatively, the message generation sub-module 21 includes a message buffer for storing second messages, and when the number of second messages in the message buffer reaches a preset threshold, the second message is sent to the sending sub-module.

[0119] It should be noted that the method for arbitrating the second target request signal from the second request signal in this invention is not limited and can be determined as appropriate. For example, it can be selected based on the polling priority of the second request signals, with the second request signal having the highest priority selected each time; or it can be selected based on the fixed priority of the second request signals, with the second request signal having the highest priority selected each time. Polling priority means that the priority of the second request signals is not fixed each time, and the priorities of the various second request signals rotate; fixed priority means that the priority of the second request signals remains constant.

[0120] In this embodiment, core 3 sends a second semaphore request signal (get) to the counting semaphore module 7 via configuration module 6. When one or more cores 3 need to acquire a counting semaphore, each core 3 can request the counting semaphore via get and wait for authorization. Core 3 also sends a second semaphore resource increment signal (put) and put_value to the counting semaphore module 7 via configuration module 6, indicating that core 3 is releasing the counting semaphore.

[0121] The total number of resources is the maximum number that can be authorized by the counting semaphore. The number of authorized cores (3) is subtracted from the total number of resources. When there is a request and the total number of resources is 0, authorization cannot be granted until the number of resources is not 0. When one or more cores (3) need to acquire a counting semaphore, each core (3) can request the counting semaphore through the `get` function and wait for authorization. Authorization is performed according to the configured authorization mode. When the counting semaphore is operating in message mode, the authorization mode of the counting semaphore module 7 for cores (3) is serial authorization; when the counting semaphore is operating in polling mode or interrupt mode, the authorization mode of the counting semaphore module 7 for cores (3) includes both serial authorization and parallel authorization.

[0122] When the authorization mode is serial authorization, only one core 3 can be authorized at a time if resources are available. When the authorization mode is parallel authorization, if the total number of resources is greater than the request, all core 3 requests can be authorized at once. If the number of resources is less than the number of core 3 requests, all resources can be authorized at once. Unauthorized core 3 will only have the opportunity to be authorized when the total number of resources is greater than 0.

[0123] The hardware semaphore device in this embodiment includes two types: counting semaphore module 7 and mutex semaphore module 1. That is, it supports two types of semaphores: mutex semaphores and counting semaphores. Each type of semaphore has three working modes to choose from. Users can select the semaphore type and working mode according to their business scenarios to flexibly and efficiently realize multi-core 3 communication.

[0124] The following is based on Figure 6Taking the hardware semaphore device shown as an example, the working process of mutex semaphores and counting semaphores will be described respectively.

[0125] The flowchart of a mutex semaphore is as follows: Figure 7 As shown, the core requests a mutex semaphore via a first semaphore request signal. When granted permission for the mutex semaphore, the grant result is stored in the register corresponding to the mutex semaphore. It then determines whether the mutex semaphore is in interrupt mode. If it is, a first grant interrupt signal is generated for the core and sent to the interrupt management module. The interrupt management module sends the generated first aggregate grant interrupt signal `granted_int` to the corresponding core, and the core releases the mutex semaphore. If it is not in interrupt mode, it determines whether it is in message mode. If it is not in message mode, the core releases the mutex semaphore. If it is in message mode, a polling arbitration is performed to select a semaphore, and a first message `Msg` is generated and sent to the core's memory area. It then determines whether the new count value `Msg_cnt` is greater than or equal to the preset configuration message value `Msg_cfg` that generates the interrupt. If it is greater than or equal to `Msg_cfg`, a message interrupt signal `msg_int` is generated, and the core releases the mutex semaphore. If it is less than `Msg_cfg`, the process ends directly.

[0126] The flowchart of a counting semaphore is as follows: Figure 8 As shown, the core requests a counting semaphore via the second semaphore request signal; releases the counting semaphore via the second semaphore resource increment signal; determines whether the counting semaphore is in serial grant mode; if so, the grant result is stored in the register corresponding to the mutex semaphore; otherwise, it is in parallel grant mode, and the grant result is stored in the register corresponding to the mutex semaphore; determines whether it is in interrupt mode; if so, a second grant interrupt signal for the core is generated and sent to the interrupt management module, which then sends the generated second aggregate grant interrupt signal to the corresponding core; if not, it determines whether it is in message mode; if not, the process ends; if so, it performs polling arbitration to select a semaphore, generates a second message Msg, and sends the second message to the core's memory area; determines whether the new count value Msg_cnt is greater than or equal to the preset configuration message value Msg_cfg that generates the interrupt; if it is greater than or equal to Msg_cfg, a message interrupt signal msg_int is generated; if it is less than Msg_cfg, the process ends directly.

[0127] The present invention also provides a multi-core system, including the hardware semaphore device in any of the above embodiments.

[0128] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0129] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0130] The hardware semaphore device and multi-core system provided by this invention have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this invention. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and core ideas of this invention. It should be noted that those skilled in the art can make various improvements and modifications to this invention without departing from its principles, and these improvements and modifications also fall within the protection scope of the claims of this invention.

Claims

1. A hardware semaphore device, characterized in that, include: A mutex semaphore module is used to store the authorization result of the mutex semaphore to the core in the register corresponding to the mutex semaphore when the mutex semaphore is working in polling mode, interrupt mode, or message mode; when the mutex semaphore is working in message mode, it is also used to generate a first request signal corresponding to the mutex semaphore and send the first request signal to the message management module; when the mutex semaphore is working in interrupt mode, it stores the authorization result of the mutex semaphore to the core in the register corresponding to the mutex semaphore, generates a first authorization interrupt signal to the core, and sends the first authorization interrupt signal to the corresponding core; when the mutex semaphore is working in polling mode, it saves the authorization result in the register of the mutex semaphore corresponding to the core, and at this time the register is set. The core requesting the mutex semaphore periodically polls its own core register. If the corresponding register is set, the corresponding core runs the corresponding software service. The message management module is used to generate a first message using the first sequence number information corresponding to the first request signal, and write the first message into the memory area of ​​the corresponding core; the first sequence number information includes a mutex semaphore sequence number and a core sequence number.

2. The hardware semaphore device as described in claim 1, characterized in that, When the number of the mutually exclusive semaphore modules is two or more, it also includes: An interrupt management module is used to aggregate all first authorized interrupt signals for the same core, generate a first aggregated authorized interrupt signal, and send the first aggregated authorized interrupt signal to the corresponding core; correspondingly, a mutex semaphore module is used to send the first authorized interrupt signal to the interrupt management module.

3. The hardware semaphore device as described in claim 2, characterized in that, The message management module includes a message generation sub-module and a message sending sub-module; The message generation sub-module is used to generate a first message using the first sequence number information and send the first message to the sending sub-module; The sending sub-module is used to send the first message to the memory area of ​​the corresponding core.

4. The hardware semaphore device as described in claim 3, characterized in that, The message generation submodule includes a message buffer for storing the first message. When the number of first messages in the message buffer reaches a preset threshold, the first message is sent to the sending submodule.

5. The hardware semaphore device as described in claim 3, characterized in that, The sending sub-module is also used to send a first feedback signal to the message generation sub-module; the message generation sub-module includes a counter; the counter corresponds one-to-one with a core; The counter is used to increment the first count value of the first message by one when the message generation submodule receives the first feedback signal to obtain a new first count value; when the message generation submodule receives the first message subtraction value signal, subtract the value corresponding to the first message subtraction value signal from the count value to obtain a new first count value; and send the new first count value to the interrupt management module. Correspondingly, the interrupt management module is also used to generate a first message interrupt signal and send the first message interrupt signal to the corresponding core when the new first count value is greater than or equal to the message value of the first preset configuration that generates an interrupt.

6. The hardware semaphore device as described in claim 5, characterized in that, When the counter obtains a new first count value equal to the maximum number of first messages that can be stored in the core, and the sending sub-module sends a new first message to the core again, the message generation sub-module is also used to generate a first error signal and send the first error signal to the interrupt management module, so that the interrupt management module generates a first error interrupt signal and sends the first error interrupt signal to the corresponding core. When the new first count value obtained by the counter is equal to the maximum number of first messages that can be stored in the core, and the sending sub-module sends a new first message to the core again, the message generation sub-module is also used to discard the new first message; When the counter obtains a new first count value equal to zero, and the message generation submodule receives the first message subtraction value signal again, the counter keeps the new first count value fixed. The message generation submodule is also used to generate a first error signal and send the first error signal to the interrupt management module, so that the interrupt management module generates a first error interrupt signal and sends the first error interrupt signal to the corresponding core.

7. The hardware semaphore device as described in claim 1, characterized in that, When the number of the mutually exclusive semaphore modules is two or more, it also includes: A polling arbitrator module is used to arbitrate all first request signals to obtain a first target request signal; and to send the first target request signal to the message management module. Accordingly, the mutex semaphore module is used to send the first request signal to the polling arbitrator module.

8. The hardware semaphore device as described in claim 1, characterized in that, Also includes: A configuration module is used to send a first semaphore request signal and a first semaphore resource count increase signal to the mutex semaphore module.

9. The hardware semaphore device according to any one of claims 1 to 8, characterized in that, Also includes: A counting semaphore module is used to: when the counting semaphore is operating in polling mode, store the authorization result of the counting semaphore to the core in the register corresponding to the counting semaphore; when the counting semaphore is operating in interrupt mode, store the authorization result of the counting semaphore to the core in the register corresponding to the counting semaphore, generate a second authorization interrupt signal to the core, and send the second authorization interrupt signal to the corresponding core; when the counting semaphore is operating in message mode, store the authorization result of the counting semaphore to the core in the register corresponding to the counting semaphore, generate a second request signal corresponding to the counting semaphore, and send the second request signal to the message management module. Accordingly, the message management module is further configured to generate a second message using the second sequence number information corresponding to the second request signal, and write the second message into the memory area of ​​the corresponding core; wherein, the second sequence number information includes a counting semaphore sequence number and a core sequence number.

10. The hardware semaphore device as described in claim 9, characterized in that, When the counting semaphore operates in message mode, the authorization mode of the counting semaphore module to the core is serial authorization; when the counting semaphore operates in polling mode or interrupt mode, the authorization mode of the counting semaphore module to the core includes serial authorization and parallel authorization.

11. A multi-core system, characterized in that, Includes the hardware semaphore device as described in any one of claims 1 to 10.

Citation Information

Patent Citations

  • Mutual exclusion and semaphore cell block of multi-core processor satisfying SystemC syntax

    CN101635006A

  • Realization method of real-time operating system of component-based hardware

    CN103440171A