Instruction execution method, shared cache, computer system, and storage medium

By working together with an exclusive monitor and a state machine, the problem of CPU performance degradation caused by excessively long SC instruction commit times was solved, resulting in faster instruction execution and performance improvement.

CN115756608BActive Publication Date: 2026-11-27BEIJING ESWIN COMPUTING TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211448873.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-18
Publication Date
2026-11-27
Estimated Expiration
2042-11-18

AI Technical Summary

Technical Problem

In the RISC-V instruction set, the return value of the SC instruction is written to the physical register at a later time, which affects CPU performance and leads to performance degradation.

Method used

By employing an exclusive monitor and state machine approach, the execution mode of an instruction is determined in response to specific instructions and execution status signals from the processor core. During speculative execution, exclusive access to the shared cache is obtained in advance to execute the write operation of the tag and data corresponding to the instruction.

Benefits of technology

By obtaining exclusive access in advance, the submission time of SC instructions is shortened, thus improving CPU performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115756608B_ABST
    Figure CN115756608B_ABST
Patent Text Reader

Abstract

The embodiment of the application provides an instruction execution method, a shared cache, a computer system and a storage medium, and relates to the technical field of computers. The method comprises the following steps: a unique monitor determines an execution mode of a specific instruction in response to the specific instruction and a signal representing an execution state of the specific instruction from a processor core; a state machine determines to obtain a unique right of a shared cache in response to the execution mode of the specific instruction being speculative execution, and executes a write operation corresponding to a tag and data of the specific instruction in response to the execution state of the specific instruction being determined execution; and the unique monitor returns an instruction completion signal to the processor core after the specific instruction is executed. The embodiment of the application uses the method of speculative execution of the specific instruction to obtain the unique right of the shared cache in advance, can accelerate the submission time of the specific instruction, and further improves the performance of the CPU.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and more specifically, to an instruction execution method, a shared cache, a computer system, and a computer-readable storage medium. Background Technology

[0002] In the Reduced Instruction Set Computer–FIVE (RISC-V) instruction set, Load-Reserved (LR) and Store-Conditional (SC) instructions are exclusive memory access instructions. Generally, a monitor needs to be designed in the cache and Double Data Rate Synchronous Dynamic Random Access Memory (DDR) to implement the function of this instruction pair.

[0003] Because the SC instruction has a return value, in the current design, the SC instruction is only sent to the cache after all other instructions have been committed. This causes the time when the SC instruction return value is written to the physical register to be delayed, which affects subsequent instructions related to SC instruction read-after-write (RAW), and consequently affects the performance of the central processing unit (CPU).

[0004] Therefore, in order to improve CPU performance, how to shorten the SC instruction submission time is an urgent problem to be solved. Summary of the Invention

[0005] This application provides an instruction execution method, a shared cache, a computer system, and a computer-readable storage medium, aiming to solve at least one technical problem in the prior art.

[0006] According to a first aspect of the embodiments of this application, an instruction execution method is provided, the method being applied to a shared cache, the shared cache including an exclusive monitor and a state machine, the method comprising:

[0007] The exclusive monitor responds to a specific instruction from the processor core and a signal characterizing the execution status of the specific instruction to determine the execution mode of the specific instruction, wherein the signal includes a first signal characterizing whether the specific instruction is determined to be executed and a second signal characterizing whether the specific instruction is canceled;

[0008] The state machine responds to the specific instruction by speculative execution, determining to obtain exclusive access to the shared cache, and responds to the specific instruction by deterministic execution, performing the write operation for the tag and data corresponding to the specific instruction.

[0009] After the exclusive monitor has completed the execution of the specific instruction, it returns an instruction completion signal to the processor core.

[0010] In one possible implementation, the exclusive monitor determines the execution status of the specific instruction by one of the following methods:

[0011] Upon receiving a first signal indicating that the execution mode of the specific instruction is speculative execution and a second signal indicating that the specific instruction is not canceled, the execution state of the specific instruction is determined to be speculative execution.

[0012] Upon receiving a first signal indicating that the execution mode of the specific instruction is determined to be executed and a second signal indicating that the specific instruction is not canceled, the execution status of the specific instruction is determined to be executed.

[0013] In yet another possible implementation, the method further includes:

[0014] If the monitor receives a first signal indicating that the execution status of a specific instruction is speculative execution before returning an instruction completion signal to the processor core, it determines that the specific instruction is in a speculative execution state and returns a third signal indicating that the specific instruction has not been completed to the processor core.

[0015] In another possible implementation, the state machine responds to the execution state of the specific instruction as determined execution, and performs the write operation corresponding to the specific instruction for the tag and data, including:

[0016] The state machine writes the data corresponding to the specific instruction into the storage unit of the shared cache in a bypass manner.

[0017] In another possible implementation, the method further includes:

[0018] When the exclusive monitor receives a first signal indicating that the execution mode of the specific instruction is speculative execution and a second signal indicating that the specific instruction has been canceled, it determines that the specific instruction will be re-executed by the processor core.

[0019] In another possible implementation, the method further includes:

[0020] The state machine responds to the execution of the specific instruction by deterministic execution, performing the write operation of the tag and data corresponding to the specific instruction, and writing the data corresponding to the specific instruction into the storage unit of the shared cache by queuing in the data buffer area.

[0021] In another possible implementation, the shared cache is a level 2 cache, and the specific instruction is an SC instruction.

[0022] According to a second aspect of the embodiments of this application, a shared cache is provided, comprising: an exclusive monitor and a state machine, wherein,

[0023] An exclusive monitor is used to respond to specific instructions from a processor core and signals characterizing the execution status of those specific instructions, determine the execution mode of those specific instructions, and return an instruction completion signal to the processor core upon completion of the execution of those specific instructions.

[0024] The signal includes a first signal characterizing the execution mode of the specific instruction and a second signal characterizing whether the specific instruction has been cancelled;

[0025] A state machine is used to determine exclusive access to the shared cache in response to the execution state of the specific instruction being speculative execution, and to execute the write operation for the tag and data corresponding to the specific instruction in response to the execution state of the specific instruction being confirmed execution.

[0026] In one possible implementation, the exclusive monitor determines the execution status of the particular instruction by one of the following methods:

[0027] Upon receiving a first signal indicating that the execution mode of the specific instruction is speculative execution and a second signal indicating that the specific instruction is not canceled, the execution state of the specific instruction is determined to be speculative execution.

[0028] Upon receiving a first signal indicating that the execution mode of the specific instruction is determined to be executed and a second signal indicating that the specific instruction is not canceled, the execution status of the specific instruction is determined to be executed.

[0029] In another possible implementation, the exclusive monitor is further configured to, before returning an instruction completion signal to the processor core, determine that the specific instruction is in a speculative execution state if it receives a first signal indicating that the execution status of the specific instruction is speculative execution, and return a third signal indicating that the specific instruction has not been completed to the processor core.

[0030] In another possible implementation, the exclusive monitor is further configured to determine, upon receiving a first signal indicating that the execution mode of the specific instruction is speculative execution and a second signal indicating that the specific instruction has been cancelled, that the specific instruction will be re-executed by the processor core.

[0031] In another possible implementation, the state machine, which responds to the execution of the specific instruction in a deterministic manner, writes the data corresponding to the specific instruction into the storage unit of the shared cache during the execution of the write operation for the tag and data corresponding to the specific instruction.

[0032] In another possible implementation, the state machine is further configured to, in response to the execution mode of the specific instruction being deterministic, execute the write operation corresponding to the specific instruction for the tag and data, and write the data corresponding to the specific instruction into the storage unit of the shared cache by queuing in the data buffer area.

[0033] In another possible implementation, the shared cache is a level 2 cache, and the specific instruction is an SC instruction.

[0034] According to a third aspect of the embodiments of this application, a computer system is provided, comprising:

[0035] processor;

[0036] A memory, coupled to a processor, stores computer-executable instructions therein for implementing the steps of the instruction execution method described in the first aspect above when executed by the processor.

[0037] According to a fourth aspect of the embodiments of this application, a computer-readable storage medium is provided, wherein when the computer program is executed by a processor, it implements the steps of the instruction execution method shown in the first aspect above.

[0038] The beneficial effects of the technical solutions provided in this application are:

[0039] By responding to specific instructions and signals representing the execution status of those instructions from the processor core via an exclusive monitor, the state machine determines the execution mode of a specific instruction and returns an instruction completion signal to the processor core upon completion. If the execution mode is speculative execution, the state machine determines to acquire exclusive access to the shared cache; if the execution status is confirmed as execution, it performs the write operation on the tag and data corresponding to that specific instruction. By using speculative execution to acquire exclusive access to the shared cache in advance, the state machine can accelerate the commit time of specific instructions, thereby improving CPU performance, especially in scenarios where the instruction has not been canceled. Attached Figure Description

[0040] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below.

[0041] Figure 1 A schematic diagram of a shared cache structure provided in an embodiment of this application;

[0042] Figure 2 A flowchart illustrating an instruction execution method provided in an embodiment of this application;

[0043] Figure 3A flowchart illustrating an instruction execution method according to another embodiment of this application;

[0044] Figure 4 A flowchart illustrating an instruction execution method according to another embodiment of this application;

[0045] Figure 5 A flowchart illustrating an instruction execution method according to another embodiment of this application;

[0046] Figure 6 This is a schematic diagram of the structure of a computer system provided in an embodiment of this application. Detailed Implementation

[0047] The embodiments of this application are described below with reference to the accompanying drawings. It should be understood that the embodiments described below with reference to the accompanying drawings are exemplary descriptions for explaining the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions of the embodiments of this application.

[0048] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0049] In the RISC-V instruction set, the LR / SC instructions require an exclusive monitor in the cache. A simple process involves the processor core issuing an LR instruction. When the LR instruction enters the cache, its address is recorded in the monitor, and the data in the cache is returned to the core. If the return value of the LR instruction matches the expected value, the core issues an SC instruction to modify the data at that address. When the SC instruction arrives in the cache, it first checks if the address is still marked in the monitor. If so, the SC instruction executes successfully, and the core gains exclusive access to the memory. Otherwise, the SC instruction fails, and the core re-initiates the LR / SC instruction.

[0050] For example, if the return value of the LR instruction is 0 and the expected value is 0, the core issues an SC instruction to change it to 1. When the SC instruction arrives at the cache, if the address is marked in the monitor, it means that the address can be locked; otherwise, the core re-initiates the LR / SC instruction.

[0051] If the return value of the LR instruction is not equal to the expected value, the core will re-initiate the LR / SC instruction until the return value of the LR instruction is equal to the expected value.

[0052] Because the SC instruction has a return value, in the current design, the SC instruction is only sent to the cache after all other instructions have been committed. This causes the time when the SC instruction's return value is written to the physical register to be delayed, which affects subsequent instructions that are related to the SC instruction and have read-after-write (RAW) operations, and consequently affects the performance of the central processing unit (CPU).

[0053] Therefore, in order to improve CPU performance, how to shorten the SC instruction submission time is an urgent problem to be solved.

[0054] To address the aforementioned technical problems in the prior art, embodiments of this application provide an instruction execution method, apparatus, and computer-readable storage medium.

[0055] In this application's scheme, the SC instruction does not need to wait for all preceding instructions to be committed; it is sent to the cache in advance. If the SC instruction is not interrupted by snoop requests from other cores before its commit, and no interruption or exception occurs, then the result of the early execution of the SC instruction is correct. If the SC instruction encounters a snoop from another core targeting that address, or if an interruption or exception occurs before its commit, a flush signal is sent to the cache, indicating that the execution result of the current SC instruction is incorrect, and then the core re-initiates the SC instruction to the cache.

[0056] The above design scheme can significantly shorten the SC instruction submission time when the SC instruction is not flushed, thereby improving CPU performance.

[0057] The following section first describes the relevant technologies of the embodiments of this application.

[0058] 1. Cache

[0059] A cache is a small but high-speed buffer located between the CPU and main memory (DRAM, or Dynamic Random Access Memory). It is typically composed of SRAM (Static Random Access Memory). The function of the cache is to improve the CPU's data input / output speed. The CPU's general-purpose registers are much faster than main memory. When the CPU directly accesses data from main memory, it has to wait for a certain period. The cache, however, can store data that the CPU has just used or that is used repeatedly. If the CPU needs to use this data again, it can retrieve it directly from the cache. This avoids repeated data access, reduces CPU waiting time, and thus improves system efficiency.

[0060] Multi-level caches include L1 cache (Level 1 cache), L2 cache (Level 2 cache), and L3 cache (Level 3 cache). L1 cache is primarily integrated within the CPU, while L2 cache is integrated on the motherboard or CPU. L1 cache includes L1I-cache (Level 1 instruction cache) and L1D-cache (Level 1 data cache). L1I-cache stores instructions, while L1D-cache stores data. The difference is that data in L1D-cache can be written back, while data in L1I-cache is read-only.

[0061] 2. RISC-V Instruction Set

[0062] RISC-V is an open-source instruction set architecture based on the principles of Reduced Instruction Set Computer (RISC). Compared to most instruction sets, the RISC-V instruction set is unrestricted in its use, and its design makes it suitable for modern computing devices such as warehouse-scale cloud computers, high-end mobile phones, and tiny embedded systems.

[0063] The RISC-V instruction set includes two special instructions: LR (Load-Reserved) and SC (Store-Conditional). These instructions are used to implement synchronization between different processes. The LR instruction reads data from an address, the size of which can be one or two words, and stores it in the destination register, while setting a reserved bit in this address range. The SC instruction writes data to an address, the size of which can be one or two words, and checks whether the accessed address range has a reserved bit set. If not, it returns a non-zero value indicating failure; if so, it returns 0 to indicate success. If a process's SC instruction succeeds, it can execute the rest of its program. If SC fails, the LR / SC instructions must be re-executed until SC succeeds before the rest of the program can proceed. This is the lock-preemption mechanism between different processes.

[0064] Secondly, the technical solutions of the embodiments of this application and the technical effects produced by the technical solutions of this application will be explained below through the description of several exemplary embodiments. It should be noted that the following embodiments can be referenced, borrowed, or combined with each other, and the same terms, similar features, and similar implementation steps in different embodiments will not be described again.

[0065] Figure 1 This application provides a shared cache for its embodiments. For example... Figure 1As shown, the shared cache includes: an exclusive monitor 301 and a state machine 302. Among them,

[0066] Exclusive monitor 301 is used to respond to specific instructions from the processor core and signals characterizing the execution status of the specific instructions, determine the execution mode of the specific instructions, and return an instruction completion signal to the processor core after the execution of the specific instructions is completed. The signals include a first signal characterizing the execution mode of the specific instructions and a second signal characterizing whether the specific instructions have been canceled.

[0067] State machine 302 is used to determine the exclusive access to the shared cache when the execution state of a specific instruction is speculative execution as determined by the exclusive monitor 301, and to execute the write operation for the tag and data corresponding to the specific instruction when the execution state of the specific instruction is determined execution.

[0068] In one possible implementation, the exclusive monitor 301 is further configured to determine, upon receiving a first signal indicating that the execution mode of a particular instruction is speculative execution and a second signal indicating that the particular instruction has been cancelled, that the particular instruction will be re-executed by the processor core.

[0069] In another possible implementation, the exclusive monitor 301 is also used to determine that the specific instruction is in a speculative execution state if a first signal indicating that the execution status of the specific instruction is speculative execution is received before returning an instruction completion signal to the processor core, and to return a third signal indicating that the specific instruction has not been completed.

[0070] In another possible implementation, state machine 302 responds to specific instructions by executing deterministically. During the execution of the write operation for the tag and data corresponding to the specific instruction, the data corresponding to the specific instruction is written to the storage unit of the shared cache in a bypass manner.

[0071] In another possible implementation, the exclusive monitor 301 determines the execution status of a specific instruction in one of the following ways:

[0072] Upon receiving a first signal indicating that the execution mode of a specific instruction is speculative execution and a second signal indicating that the specific instruction is not canceled, the execution state of the specific instruction is determined to be speculative execution.

[0073] Upon receiving a first signal indicating that the execution mode of a specific instruction is determined to be executed and a second signal indicating that the specific instruction is not canceled, the execution status of the specific instruction is determined to be executed.

[0074] In another possible implementation, state machine 302 is also used to respond to a specific instruction if the execution mode is deterministic, then execute the write operation for the tag and data corresponding to the specific instruction, and write the data corresponding to the specific instruction into the storage unit of the shared cache by queuing in the data buffer.

[0075] The apparatus of this application embodiment can execute the instruction execution method provided in this application embodiment. Its implementation principle and the effect it can achieve are similar. The actions performed by each module in the apparatus of each embodiment of this application correspond to the steps in the method of each embodiment of this application. For detailed functional descriptions of each module of the apparatus, please refer to the description of the instruction execution method below, which will not be repeated here.

[0076] Figure 2 This is a flowchart illustrating an instruction execution method provided in an embodiment of this application. The method is applied to a shared cache, which includes an exclusive monitor and a state machine. Figure 2 The methods shown include:

[0077] S1. The exclusive monitor responds to a specific instruction from the processor core and a signal indicating the execution status of that specific instruction to determine the execution mode of the specific instruction. The signal includes a first signal indicating whether the specific instruction is determined to be executed and a second signal indicating whether the specific instruction is canceled.

[0078] S2. The state machine responds to specific instructions by speculative execution, determining that it has exclusive access to the shared cache, and responds to specific instructions by deterministic execution, executing the write operation for the tag and data corresponding to the specific instruction.

[0079] S3. The exclusive monitor returns an instruction completion signal to the processor core after a specific instruction has been executed.

[0080] Specifically, in this embodiment, if the execution mode of a specific instruction determined by the exclusive monitor is speculative execution, the state machine first obtains exclusive access to the shared cache. Then, when the execution mode of the specific instruction is determined to be deterministic execution, it performs the write operation of the tag and data corresponding to the instruction. After the instruction is executed, the exclusive monitor returns an instruction completion signal to the processor core. Since the exclusive access to the shared cache is obtained in advance by using the method of speculative execution of specific instructions, the submission time of specific instructions can be accelerated, thereby improving the performance of the CPU.

[0081] In one possible implementation, the exclusive monitor determines the execution status of a specific instruction in one of the following ways:

[0082] Upon receiving a first signal indicating that the execution mode of a specific instruction is speculative execution and a second signal indicating that the specific instruction is not canceled, the execution state of the specific instruction is determined to be speculative execution.

[0083] Upon receiving a first signal indicating that the execution mode of a specific instruction is determined to be executed and a second signal indicating that the specific instruction is not canceled, the execution status of the specific instruction is determined to be executed.

[0084] In yet another possible implementation, the above method may also include:

[0085] If the monitor receives a first signal indicating that the execution status of a specific instruction is speculative execution before returning an instruction completion signal to the processor core, it determines that the specific instruction is in a speculative execution state and returns a third signal indicating that the specific instruction has not been completed to the processor core.

[0086] In another possible implementation, in step S2, the state machine responds to the execution state of a specific instruction as determined execution, and performs the write operation for the tag and data corresponding to the specific instruction, including: the state machine writes the data corresponding to the specific instruction into the storage unit of the shared cache in a bypass manner.

[0087] Specifically, in this embodiment, if the execution mode of a specific instruction determined by the exclusive monitor is speculative execution, the state machine first obtains exclusive access to the shared cache. Then, when the execution mode of the specific instruction is determined to be deterministic execution, it performs the write operation of the tag and data corresponding to the instruction. When writing the data corresponding to the instruction to the storage unit of the shared cache, it writes in a bypass manner without queuing in the data cache area.

[0088] In another possible implementation, the above method may also include:

[0089] When the exclusive monitor receives a first signal indicating that the execution mode of a specific instruction is speculative execution and a second signal indicating that the specific instruction has been canceled, it determines that the specific instruction will be re-executed by the processor core.

[0090] In another possible implementation, the above method may also include:

[0091] The state machine responds to specific instructions by executing deterministically, performing write operations on the tag and data corresponding to the specific instruction, and writing the data corresponding to the specific instruction into the shared cache storage unit by queuing in the data buffer area.

[0092] Specifically, in this embodiment, if the execution mode of a specific instruction determined by the exclusive monitor is determined to be executed, the state machine performs the write operation of the tag and data corresponding to the instruction. When writing the data corresponding to the instruction to the storage unit of the shared cache, it is written in a queuing manner in the data cache area.

[0093] The following example uses a shared cache as the L2 cache and SC instructions as specific instructions. Figures 3 to 5 The technical solution of an instruction execution method provided in the embodiments of this application will be described in detail.

[0094] Figure 3 This is a flowchart illustrating an instruction execution method provided in an embodiment of this application. The method can be applied to a Level 2 cache (L2 cache), which includes an exclusive monitor and a state machine. Figure 3 The methods shown include:

[0095] S101, the exclusive monitor determines the execution mode of the SC instruction based on the SC instruction from the processor core and the signals characterizing the execution status of the SC instruction.

[0096] The signals include a first signal indicating whether the SC instruction is determined to be executed and a second signal indicating whether the SC instruction is canceled.

[0097] S102. If the state machine finds that the execution mode of the SC instruction is speculative execution, it determines that it has exclusive access to the L2 cache.

[0098] S103. If the exclusive monitor receives a first signal indicating that the SC instruction is to be executed and a second signal indicating that the SC instruction has not been cancelled, it determines that the SC instruction will be executed.

[0099] S104. If the state machine obtains that the SC instruction is to be executed, it will execute the write operation of the tag and data corresponding to the SC instruction, and after the SC instruction is executed, the exclusive monitor will return an instruction completion signal to the processor core.

[0100] In this embodiment, if the exclusive monitor determines that the execution mode of the SC instruction is speculative execution based on a first signal indicating whether the SC instruction is certain to be executed and a second signal indicating whether the SC instruction has been cancelled, and the state machine obtains that the execution mode of the SC instruction is speculative execution, it determines that it has exclusive access to the L2 cache. Then, if the exclusive monitor receives the first signal indicating that the SC instruction is certain to be executed and the second signal indicating that the SC instruction has not been cancelled, it determines that the SC instruction will be executed. When the state machine obtains that the SC instruction is certain to be executed, it performs the write operation of the tag and data corresponding to the SC instruction, and after the SC instruction is executed, the exclusive monitor returns an instruction completion signal to the processor core. This scheme uses the speculative execution method of the SC instruction to obtain exclusive access to the L2 cache in advance. In the scenario where the SC instruction has not been cancelled, it can speed up the SC instruction submission time, thereby improving CPU performance.

[0101] It should be noted that, in this embodiment, the first signal can be denoted as "proceed". If "proceed = 1", that is, the first signal is high, it indicates that the SC instruction is definitely executed; if "proceed = 0", that is, the first signal is low, it indicates that the SC instruction is speculatively executed. The second signal can be denoted as "flush". If "flush = 1", that is, the second signal is high, it indicates that the SC instruction is canceled; if "flush = 0", that is, the second signal is low, it indicates that the SC instruction is not canceled.

[0102] In some embodiments, step S101 may specifically include: if the exclusive monitor receives a first signal indicating speculative execution of the SC instruction and a second signal indicating that the SC instruction has not been canceled, determining that the execution mode of the SC instruction is speculative execution; if the exclusive monitor receives a first signal indicating deterministic execution of the SC instruction and a second signal indicating that the SC instruction has not been canceled, determining that the execution mode of the SC instruction is deterministic execution.

[0103] Specifically, in this embodiment, if the first signal proceed = 0 and the second signal flush = 0, it indicates that the SC instruction is executed speculatively; if the first signal proceed = 1 and the second signal flush = 0, it indicates that the SC instruction has been submitted in the processor core and is confirmed to be executed.

[0104] This application provides one possible implementation method, such as... Figure 4 As shown, after S102, the above method further includes:

[0105] S105. If the exclusive monitor receives a first signal indicating that the SC instruction is presumably executed and a second signal indicating that the SC instruction has been canceled, it determines that the processor core will re-execute the SC instruction.

[0106] Specifically, in this embodiment, if the exclusive monitor determines that the execution mode of the SC instruction is speculative execution based on a first signal indicating whether the SC instruction is certain to be executed and a second signal indicating whether the SC instruction has been cancelled, and the state machine obtains that the execution mode of the SC instruction is speculative execution, it determines that it has exclusive access to the L2 cache. Then, if the exclusive monitor receives the first signal indicating speculative execution of the SC instruction and the second signal indicating that the SC instruction has been cancelled, it means that the SC instruction was cancelled before commit, and the processor core needs to re-execute the SC instruction.

[0107] In one possible implementation, the method also includes:

[0108] S106 (not shown in the figure) is the exclusive monitor that returns the SC instruction feedback signal to the processor core.

[0109] Specifically, in this embodiment, if the exclusive monitor determines that the execution mode of the SC instruction is speculative execution based on the first signal indicating whether the SC instruction is certain to be executed and the second signal indicating whether the SC instruction has been canceled, when the state machine obtains that the execution mode of the SC instruction is speculative execution, it determines that it has obtained exclusive access to the L2 cache, and the exclusive monitor returns an SC instruction feedback signal to the processor core, for example, returning resp valid = 1, to indicate that the SC instruction feedback information is valid. It can also return a fourth signal indicating whether the SC instruction was executed successfully. For example, the fourth signal can be denoted as fail; if the SC instruction is executed successfully, fail = 0, that is, the fourth signal is low; if the SC instruction fails, fail = 1, that is, the fourth signal is high.

[0110] It should be noted that when resp_valid=1, complete can be 0 or 1, and fail can also be 0 or 1.

[0111] 1. If fail=1, then it must have failed. The processor core needs to re-initiate the LR instruction and then execute the SC instruction.

[0112] 2. If fail=0 and complete=0, it means that the SC instruction "did not fail", and the processor core can continue to "speculate" the execution of subsequent instructions.

[0113] 3. If fail=0 and complete=1, it means the SC instruction was executed successfully. For the processor core, this is the final and definitively successful outcome.

[0114] Then, if the exclusive monitor receives a first signal indicating that the SC instruction has been executed and a second signal indicating that the SC instruction has not been canceled, it determines that the SC instruction will be executed. When the state machine receives confirmation that the SC instruction has been executed, it performs the write operation on the tag and data corresponding to the SC instruction. After the SC instruction is executed, the exclusive monitor returns an instruction completion signal to the processor core. Simultaneously, it can also return an SC instruction feedback signal and a fourth signal indicating whether the SC instruction was executed successfully.

[0115] If the exclusive monitor receives a first signal indicating speculative execution of the SC instruction and a second signal indicating that the SC instruction has been cancelled, it means that the SC instruction was cancelled before committing, and the processor core needs to re-execute the SC instruction. Simultaneously, it can return an SC instruction feedback signal and a fourth signal indicating whether the SC instruction was executed successfully to the processor core.

[0116] It should be noted that the conditions for the SC instruction to fail can be found in the instruction manual, and will not be repeated here for the sake of brevity.

[0117] This application provides a possible implementation method, which further includes:

[0118] S107 (not shown in the figure): If the exclusive monitor receives a signal indicating that the SC instruction is speculatively executed and that the SC instruction has not been canceled before returning the SC instruction feedback signal to the processor core, it determines that the SC instruction is in speculative execution state and returns a third signal indicating that the SC instruction has not been completed to the processor core.

[0119] Specifically, in this embodiment, the third signal can be denoted as `complete`. If `complete` = 1, meaning the third signal is high, it indicates that the SC instruction has been completed. If `complete` = 0, meaning the third signal is low, it indicates that the SC instruction has not been completed. If the exclusive monitor determines that the execution mode of the SC instruction is speculative execution based on the first signal indicating whether the SC instruction is confirmed to be executed and the second signal indicating whether the SC instruction has been canceled, the state machine determines that it has obtained exclusive access to the L2 cache when it obtains that the execution mode of the SC instruction is speculative execution. If `proceed` and `flush` are always 0 before the exclusive monitor returns the SC instruction feedback signal to the processor core, it means that the SC instruction is always in a speculative execution state. At this time, `complete` = 0, indicating that the SC instruction has not actually been completed.

[0120] This application provides one possible implementation method, such as... Figure 5 In S104, during the write operation of the tag and data corresponding to the SC instruction, the data corresponding to the SC instruction is written to the L2 cache storage unit through a bypass method.

[0121] Specifically, in this embodiment, if the SC instruction is executed speculatively from the start to the final execution, the SC data may not be ready during the speculative execution phase. The SC data will only be sent to the L2 cache after the SC instruction is committed. In this case, the bypass value must be 1, so that the SC data does not need to queue in the data buffer during the writing process to the storage unit, thus avoiding deadlock.

[0122] This application provides another possible implementation, such as... Figure 5 As shown, the method also includes:

[0123] S108. If the state machine obtains that the execution mode of the SC instruction is deterministic execution, it will definitely execute the write operation of the tag and data corresponding to the SC instruction, and write the data corresponding to the SC instruction into the storage unit of the L2 cache by queuing in the data buffer area.

[0124] Specifically, in this embodiment, if the exclusive monitor determines that the execution mode of the SC instruction is to be executed based on the first signal indicating whether the SC instruction is to be executed and the second signal indicating whether the SC instruction is to be cancelled, then the write operation of the tag and data corresponding to the SC instruction is performed, and the data corresponding to the SC instruction is written into the storage unit of the L2 cache by queuing in the data buffer area.

[0125] For example, when the SC valid instruction (indicating the current request is an SC instruction) arrives at the exclusive monitor in the L2 cache, proceed = 1 and flush = 0, indicating that the SC instruction has been committed to the core and is confirmed for execution. The exclusive monitor returns resp valid = 1; if the SC instruction indicates failure, then fail = 1; otherwise, fail = 0. Since the SC instruction is confirmed for execution, complete = 1. Because the SC instruction is confirmed for execution, SC data and SC valid arrive at the L2 cache simultaneously. At this point, the data can be processed as ordinary store data, and bypass = 0 (indicating that the current SC data does not need to be bypassed). That is, when the SC instruction is not speculatively executed, no bypass is needed.

[0126] The above describes the process where the SC instruction is not executed in advance. This scenario represents the ideal state, where the CPU pipeline is not blocked.

[0127] In the solution of this application embodiment, if other instructions before the SC instruction have not been successfully submitted, then the SC instruction that follows can be sent to the L2 cache in advance without waiting for submission.

[0128] The specific process of speculative execution using the SC instruction is as follows:

[0129] 1. When the SC valid instruction arrives at the exclusive monitor in the L2 cache, at this time, proceed=0 and flush=0, indicating that the SC instruction is executed speculatively.

[0130] 2. The exclusive monitor returns `resp valid = 1`. If the SC instruction fails, then `fail = 1`. Otherwise, `fail = 0`. If `proceed` and `flush` remain 0 until `resp valid` is returned, it means the SC instruction is in a speculative execution state. In this case, `complete = 0`, indicating that the SC instruction has not actually finished executing.

[0131] 3. If the exclusive monitor subsequently receives Proceed=1 and flush=0, it means the SC command was not flushed before committing, and execution is confirmed. Then, the exclusive monitor returns resp_valid=1, fali=0 / 1, and complete=1 again.

[0132] 4. If the exclusive monitor receives Proceed=0 and flush=1, it means the SC command was flushed before committing, and the core needs to re-execute LR / SC. The exclusive monitor returns resp_valid=1, fali=0 / 1, and complete=1.

[0133] In summary, the solution in this application embodiment uses the method of speculative execution of SC instructions to obtain exclusive access to the L2 cache in advance. In scenarios where SC instructions are not canceled, it can speed up the submission time of SC instructions, thereby improving CPU performance.

[0134] This application also provides a computer system, including:

[0135] processor;

[0136] A memory, coupled to a processor, stores computer-executable instructions for implementing the steps of the instruction execution method provided in this application embodiment when executed by the processor. Compared with the prior art, it can achieve the following: by responding to a specific instruction and a signal representing the execution state of the specific instruction from the processor core via an exclusive monitor, determining the execution mode of the specific instruction, and returning an instruction completion signal to the processor core after the execution of the specific instruction is completed; the state machine determines to obtain exclusive access to the shared cache when the execution mode of the specific instruction is speculative execution, and performs write operations on the tag and data corresponding to the specific instruction when the execution state of the specific instruction is determined to be execution. By using the method of speculative execution of specific instructions to obtain exclusive access to the shared cache in advance, the submission time of the specific instruction can be accelerated in scenarios where the specific instruction has not been canceled, thereby improving CPU performance.

[0137] A computer system is provided in the embodiments of this application, such as Figure 6 The computer system 400 shown includes a processor 401 and a memory 403. The processor 401 and the memory 403 are connected, for example, via a bus 402.

[0138] Processor 401 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 401 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.

[0139] Bus 402 may include a pathway for transmitting information between the aforementioned components. Bus 402 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 402 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 6 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0140] The memory 403 may be ROM (Read Only Memory) or other types of static storage devices capable of storing static information and instructions, RAM (Random Access Memory) or other types of dynamic storage devices capable of storing information and instructions, or EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium capable of carrying or storing computer programs and capable of being read by a computer, without limitation herein.

[0141] The memory 403 is used to store computer programs that execute the embodiments of this application, and the execution is controlled by the processor 401. The processor 401 is used to execute the computer programs stored in the memory 403 to implement the steps shown in the foregoing method embodiments.

[0142] This application provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it can implement the steps and corresponding content of the aforementioned method embodiments.

[0143] Processor-readable storage media can be any available medium or data storage device that the processor can access, including but not limited to magnetic storage (e.g., floppy disks, hard disks, magnetic tapes, magneto-optical disks (MOs), etc.), optical storage (e.g., CDs, DVDs, BDs, HVDs, etc.), and semiconductor storage (e.g., ROMs, EPROMs, EEPROMs, non-volatile memory (NAND flash), solid-state drives (SSDs)).

[0144] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage and optical storage) containing computer-usable program code.

[0145] It should be understood that although arrows indicate various operation steps in the flowcharts of this application's embodiments, the order in which these steps are implemented is not limited to the order indicated by the arrows. Unless explicitly stated herein, in some implementation scenarios of this application's embodiments, the implementation steps in each flowchart can be executed in other orders as required. Furthermore, some or all steps in each flowchart, based on the actual implementation scenario, may include multiple sub-steps or multiple stages. Some or all of these sub-steps or stages can be executed at the same time, and each sub-step or stage can also be executed at different times. In scenarios where execution times differ, the execution order of these sub-steps or stages can be flexibly configured according to requirements, and this application's embodiments do not limit this.

[0146] The above description is only an optional implementation method for some implementation scenarios of this application. It should be noted that for those skilled in the art, other similar implementation methods based on the technical concept of this application without departing from the technical concept of this application also fall within the protection scope of the embodiments of this application.

Claims

1. A shared cache, characterized in that, The shared cache includes: An exclusive monitor is used to respond to specific instructions from a processor core and signals characterizing the execution status of those specific instructions, determine the execution mode of those specific instructions, and return an instruction completion signal to the processor core upon completion of the execution of those specific instructions. The signal includes a first signal characterizing the execution mode of the specific instruction and a second signal characterizing whether the specific instruction has been cancelled; A state machine is used to determine the exclusive access to the shared cache in response to the execution state of the specific instruction being speculative execution, and to execute the write operation for the tag and data corresponding to the specific instruction in response to the execution state of the specific instruction being determined execution. The exclusive monitor determines the execution status of the specific instruction by one of the following methods: Upon receiving a first signal indicating that the execution mode of the specific instruction is speculative execution and a second signal indicating that the specific instruction is not canceled, the execution state of the specific instruction is determined to be speculative execution. Upon receiving a first signal indicating that the execution mode of the specific instruction is determined to be executed and a second signal indicating that the specific instruction is not canceled, the execution status of the specific instruction is determined to be executed.

2. The shared cache according to claim 1, characterized in that, The exclusive monitor is further configured to, before returning an instruction completion signal to the processor core, determine that the specific instruction is in a speculative execution state if it receives a first signal indicating that the execution status of the specific instruction is speculative execution, and return a third signal indicating that the specific instruction has not been completed to the processor core.

3. The shared cache according to claim 1, characterized in that, The exclusive monitor is further configured to determine, upon receiving a first signal indicating that the execution mode of the specific instruction is speculative execution and a second signal indicating that the specific instruction has been cancelled, that the specific instruction will be re-executed by the processor core.

4. The shared cache according to claim 1, characterized in that, The state machine is configured to respond to the execution of the specific instruction in a deterministic manner. During the execution of the write operation for the tag and data corresponding to the specific instruction, the data corresponding to the specific instruction is written to the storage unit of the shared cache in a bypass manner.

5. The shared cache according to claim 1, characterized in that, The state machine is further configured to respond to the execution mode of the specific instruction as deterministic execution, by executing the write operation corresponding to the tag and data of the specific instruction, and writing the data corresponding to the specific instruction into the storage unit of the shared cache by queuing in the data cache area.

6. The shared cache according to any one of claims 1 to 5, characterized in that, The shared cache is a level 2 cache, and the specific instruction is the SC instruction.

7. A method for executing instructions, characterized in that, The method is applied to a shared cache, which includes an exclusive monitor and a state machine. The method includes: The exclusive monitor responds to a specific instruction from the processor core and a signal characterizing the execution status of the specific instruction to determine the execution mode of the specific instruction, wherein the signal includes a first signal characterizing whether the specific instruction is determined to be executed and a second signal characterizing whether the specific instruction is canceled; The state machine responds to the specific instruction by speculative execution, determining to obtain exclusive access to the shared cache, and responds to the specific instruction by deterministic execution, performing the write operation for the tag and data corresponding to the specific instruction. After the exclusive monitor has completed the execution of the specific instruction, it returns an instruction completion signal to the processor core. The exclusive monitor determines the execution status of the specific instruction using one of the following methods: Upon receiving a first signal indicating that the execution mode of the specific instruction is speculative execution and a second signal indicating that the specific instruction is not canceled, the execution state of the specific instruction is determined to be speculative execution. Upon receiving a first signal indicating that the execution mode of the specific instruction is determined to be executed and a second signal indicating that the specific instruction is not canceled, the execution status of the specific instruction is determined to be executed.

8. The method according to claim 7, characterized in that, The method further includes: If the monitor receives a first signal indicating that the execution status of a specific instruction is speculative execution before returning an instruction completion signal to the processor core, it determines that the specific instruction is in a speculative execution state and returns a third signal indicating that the specific instruction has not been completed to the processor core.

9. The method according to claim 7, characterized in that, The state machine responds to the execution state of the specific instruction as "determined execution," and performs the write operation corresponding to the specific instruction for the tag and data, including: The state machine writes the data corresponding to the specific instruction into the storage unit of the shared cache in a bypass manner.

10. The method according to claim 7, characterized in that, The method further includes: When the exclusive monitor receives a first signal indicating that the execution mode of the specific instruction is speculative execution and a second signal indicating that the specific instruction has been canceled, it determines that the specific instruction will be re-executed by the processor core.

11. The method according to claim 7, characterized in that, The method further includes: The state machine responds to the execution of the specific instruction by deterministic execution, performing the write operation of the tag and data corresponding to the specific instruction, and writing the data corresponding to the specific instruction into the storage unit of the shared cache by queuing in the data buffer area.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the instruction execution method according to any one of claims 7-11.

13. A computer system, comprising: processor; A memory coupled to a processor and storing therein computer-executable instructions for performing the instruction execution method as described in any one of claims 7-11 when executed by said processor.

Citation Information

Patent Citations

  • Method and apparatus to write modified cache data to a backing store while retaining write permissions

    CN105408877A

  • Mechanism for mitigating information leak via cache side channels during speculative execution

    US11231931B1