Method, device, equipment and storage medium for reducing redundant cache consistency operations

Manage the cache coherence protocol status of the processor core through cache coherence off and on instructions, reduce redundant cache coherence operations, solve the problem of redundant cache coherence operations in parallel programs, improve performance and reduce the cost of hardware systems Design pressure.

CN118377637BActive Publication Date: 2024-10-11BEIJING KAPULA SCI&TECH CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410831240.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-26
Publication Date
2024-10-11
Estimated Expiration
2044-06-26

AI Technical Summary

Technical Problem

In parallel programs, most cache coherence operations are redundant, causing cache coherence maintenance overhead to reduce parallel program performance and increase hardware system design pressure.

Method used

The cache coherence protocol state of the processor core is changed through the cache coherence off instruction and the cache coherence on instruction. The cache coherence operation is only performed when the protocol state is on, thereby reducing redundant cache coherence operations.

Benefits of technology

It effectively reduces the impact of cache consistency maintenance overhead on program performance, improves the performance of parallel programs, and reduces the pressure on hardware system design.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118377637B_ABST
    Figure CN118377637B_ABST
Patent Text Reader

Abstract

The present disclosure relates to the field of computer technology, and in particular to a method, apparatus, device and storage medium for reducing redundant cache consistency operations, the method comprising: in response to the scheduling and execution of a memory access instruction, obtaining the state of the cache consistency protocol of the current processor core; if the state of the cache consistency protocol of the current processor core is in a closed state, then in the process of executing the memory access instruction, the cache consistency operation between the processor cores is not performed; if the state of the cache consistency protocol of the current processor core is in an open state, the memory access instruction is executed according to the cache consistency protocol requirements between the processor cores. When the state of the cache consistency protocol is in a closed state, the cache consistency operation between the processor cores is not performed, which can reduce the impact of the cache consistency maintenance overhead on the program performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a method, apparatus, device and storage medium for reducing redundant cache consistency operations. Background Art

[0002] Each processor core on a modern multi-core processor has a cache to improve data access speed and ensure the convenience of program writing. When running parallel programs, multiple threads or processes running on multiple processor cores may read and write data in the same shared memory area. In order to ensure the correctness of parallel program operation, cache coherence is required between different processors in the same computing node and between different processor cores of the same processor, so that the same data is consistent between the caches of multiple processor cores.

[0003] With the continuous development of computer technology, almost all applications running on supercomputers have achieved process-level parallelism. However, in most cases, there is no shared memory area or variable between different processes, so cache consistency operations are usually not required between two processes. Some applications may have both process-level and thread-level parallelism capabilities, that is, a process will contain multiple threads running in the same computing node. Since all threads belonging to the same process share the memory space of the process, cache consistency operations are usually required between these threads. Nevertheless, each thread will also have private variables, so there will not be shared use of all variables between threads; even for the same shared variable, it may be shared read and written between multiple threads in a certain program segment, and may be privately used by each thread in another program segment. It can be seen that most cache consistency operations are redundant. Maintaining cache consistency will not only reduce the performance of parallel programs, but also increase the pressure on hardware system design. Therefore, a method to reduce redundant cache consistency operations is urgently needed. Summary of the invention

[0004] The present disclosure provides a method, apparatus, device and storage medium for reducing redundant cache consistency operations, so as to reduce the impact of cache consistency maintenance overhead on program performance.

[0005] In a first aspect, the present disclosure provides a method for reducing redundant cache consistency operations, comprising:

[0006] In response to the scheduling and execution of the memory access instruction, obtaining the state of the cache coherence protocol of the current processor core;

[0007] If the cache coherence protocol of the current processor core is in the off state, no cache coherence operation between the processor cores is performed during the execution of the memory access instruction;

[0008] If the state of the cache coherence protocol of the current processor core is turned on, the memory access instruction is executed according to the cache coherence protocol requirements between the processor cores.

[0009] In some embodiments, the method further comprises:

[0010] In response to a cache coherence shutdown instruction initiated by the current thread, setting the state of the cache coherence protocol of the current processor core to a shutdown state;

[0011] In response to a cache coherence enable instruction initiated by the current thread, the state of the cache coherence protocol of the current processor core is set to an enable state.

[0012] In some embodiments, if the current processor core supports out-of-order execution, the method further includes:

[0013] Cache coherence-enabling instructions cannot be executed out of order with memory access instructions issued after them;

[0014] A cache coherency off instruction cannot be executed out-of-order with memory access instructions that were issued before it.

[0015] In some embodiments, not performing cache coherence operations between processor cores includes at least one of the following:

[0016] The current processor core does not initiate any cache coherence operations to the cache coherence hardware system;

[0017] The current processor core ignores any cache coherence operations initiated by other processor cores.

[0018] In some embodiments, the method further comprises:

[0019] When the cache coherence protocol of the current processor core is in a closed state, the accessed cache block is marked as a private access state;

[0020] When the cache coherence protocol of the current processor core is in the on state, if a memory access instruction hits a cache block marked as a private access state, the cache block marked as a private access state is initialized and the private access state mark is removed according to the attributes of the memory access instruction and the cache coherence protocol.

[0021] In some embodiments, the method further comprises:

[0022] Obtaining the running results of the target program when the cache coherence protocol is in the closed state and the opened state respectively;

[0023] If the operating results in the two states are different, it is determined that it is unsafe to turn off the cache consistency protocol.

[0024] In some embodiments, the method further comprises:

[0025] A test mode is provided through the hardware system, and the test mode is used to test the security of disabling the cache consistency protocol;

[0026] When the cache coherence off instruction is called in the test mode, the current processor core is marked as being in the test mode on state, and the cache coherence operation between the processor cores is performed according to the cache coherence protocol requirements;

[0027] When the test mode is turned on, when the current processor core executes an explicit memory access instruction, the cache block corresponding to the explicit memory access instruction is marked as a private access state;

[0028] If a cache coherence operation invalidates a cache block of a processor core that is marked as a private access state, it is determined that it is unsafe to disable the cache coherence protocol of the processor core;

[0029] If the cache block marked as the private access state in the first processor core invalidates the cache block in the second processor core through a cache coherence operation, it is determined that shutting down the cache coherence protocol of the first processor core is unsafe.

[0030] In some embodiments, if the current processor core runs multiple hyperthreads simultaneously, recording the state of the cache coherence protocol of each hyperthread, obtaining the state of the cache coherence protocol of the current processor core includes:

[0031] The state of the cache coherence protocol of the current processor core is jointly determined according to the states of the cache coherence protocols of all hyperthreads on the current processor core, wherein the jointly determining includes:

[0032] If the states of the cache coherence protocols of all hyperthreads on the current processor core are in a closed state, the state of the cache coherence protocol of the current processor core is a closed state;

[0033] If the state of the cache coherence protocol of any hyperthread on the current processor core is in the on state, the state of the cache coherence protocol of the current processor core is in the on state.

[0034] In some embodiments, the method further comprises:

[0035] When the current processor core runs multiple hyperthreads simultaneously, the state of the cache coherence protocol of each hyperthread is recorded;

[0036] The current processor core does not initiate any cache consistency operation to the cache consistency hardware system during the process of executing the memory access instruction of the hyperthread whose cache consistency protocol is in the disabled state;

[0037] When the state of the cache coherence protocol of any hyperthread of the current processor core is in an on state, the current processor core responds to the cache coherence operation initiated by other processor cores;

[0038] When the states of cache coherence protocols of all hyperthreads of the current processor core are in a closed state, the current processor core ignores any cache coherence operations initiated by other processor cores.

[0039] In some embodiments, the method further comprises:

[0040] If the current processor core is in an idle state, the state of the cache coherence protocol of the current processor core is set to a closed state.

[0041] In a second aspect, the present disclosure provides a device for reducing redundant cache consistency operations, comprising:

[0042] An acquisition module, configured to acquire the state of the cache coherence protocol of the current processor core in response to the scheduling execution of the memory access instruction;

[0043] A redundancy reduction module, for not performing cache consistency operations between processor cores during the execution of memory access instructions if the cache consistency protocol of the current processor core is in a closed state;

[0044] The processing module is used to execute the memory access instruction according to the cache consistency protocol requirements between the processor cores if the state of the cache consistency protocol of the current processor core is turned on.

[0045] In a third aspect, the present disclosure provides a computer device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the method described in the above aspects.

[0046] In a fourth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of the method described in the above aspects when executed by a processor.

[0047] In a fifth aspect, the present disclosure provides a computer program product, including a computer program / instructions, which implements the steps of the method described in the above aspects when the computer program is executed by a processor.

[0048] The present disclosure provides a method, device, equipment and storage medium for reducing redundant cache consistency operations. The method obtains the state of the cache consistency protocol of the current processor core in response to the scheduling and execution of the memory access instruction. If the state of the cache consistency protocol of the current processor core is in the closed state, the cache consistency operation between the processor cores is not performed during the execution of the memory access instruction. If the state of the cache consistency protocol of the current processor core is in the open state, the memory access instruction is executed according to the cache consistency protocol requirements between the processor cores. When the state of the cache consistency protocol is in the closed state, the cache consistency operation between the processor cores is not performed, which can reduce the impact of the cache consistency maintenance overhead on the program performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] The present disclosure will be described in more detail below based on embodiments and with reference to the accompanying drawings:

[0050] Figure 1 A flowchart of a method for reducing redundant cache consistency operations provided by an embodiment of the present disclosure;

[0051] Figure 2 A schematic diagram of the structure of a device for reducing redundant cache consistency operations provided by an embodiment of the present disclosure.

[0052] In the drawings, the same reference numerals are used for the same components, and the drawings are not drawn to scale. DETAILED DESCRIPTION

[0053] In order to enable those skilled in the art to better understand the technical solution of the present disclosure, and to fully understand and implement how the present disclosure applies technical means to solve technical problems and achieve the corresponding technical effects, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only embodiments of a part of the present disclosure, not all of the embodiments. The embodiments of the present disclosure and the various features in the embodiments can be combined with each other without conflict, and the technical solutions formed are all within the scope of protection of the present disclosure. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative work should fall within the scope of protection of the present disclosure.

[0054] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.

[0055] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0056] There are two main cache consistency protocols: the snooping-based consistency protocol (hereinafter referred to as the snooping protocol) and the directory-based consistency protocol (hereinafter referred to as the directory protocol). The implementation of the snooping protocol relies on a bus or bus-like network connection. Using this network connection, all requests issued by the private cache of a single processor core will be broadcast to the private caches of all other processor cores in the system, and the access requests of all processors can also be sequenced on this bus to achieve the requirements for access order in the cache consistency model and the storage identity model. The snooping protocol can also handle multiple conflicting requests for the same data block well through the bus structure, and the private caches of multiple processors can also communicate directly through this bus structure, reducing communication delays. However, since all requests are transmitted through the bus, and the bus bandwidth resources are limited, it will affect the scalability of the entire system. The directory protocol uses a directory structure to manage cache lines. In the directory protocol, the memory access request issued by the private cache of the processor core will first be sent to the directory structure that owns the corresponding cache block. This directory structure records the sharing status of the current cache block. The directory structure controller will choose to respond to this request or forward this request to the private cache of other corresponding processor cores according to the status of the current cache block. This method does not need to rely on a network with a specific topology, and reduces bandwidth consumption in the network through point-to-point direct communication, which is easy to expand. However, in the implementation of the directory protocol, all requests must be processed through the directory structure, which will introduce additional delays.

[0057] For example, in commercial processors from companies such as AMD, the snooping protocol is mainly used to achieve cache consistency. Currently, the number of cores in a CPU has reached nearly 100, and a computing node in a supercomputer usually has two CPUs, which requires the snooping protocol to support the cache consistency of nearly 200 processor cores. This not only brings difficulties to the design and layout of the bus, but also makes the bus bandwidth resources more restrictive on the performance of parallel programs. As the number of processor cores in the same CPU or the same computing node increases, the directory protocol will also encounter bottleneck problems, such as the directory becoming larger and the access delay increasing. It can be seen that the cache consistency maintenance overhead not only affects the performance of parallel programs, but also increases the pressure on hardware system design.

[0058] For process-level parallel applications, in most cases, there is no shared memory area or variable between different processes, so there is usually no need to perform cache consistency operations between two processes. For applications that have both process-level and thread-level parallel capabilities, although cache consistency operations need to be performed between all threads that share the same process memory space, each thread will also have private variables, so there will not be shared use of all variables between threads; even for the same shared variable, it may be shared read and write between multiple threads in a certain program segment and privately used by each thread in another program segment. Therefore, it can be said that most cache consistency operations are redundant, but because the hardware cannot determine whether there is shared data read and write between multiple processes or threads currently running in the same computing node, on the one hand, a hardware system must be provided for cache consistency operations between all processor cores in the same computing node, and on the other hand, cache consistency operations must be triggered when the state of a cache block changes. In order to reduce the impact of cache consistency maintenance overhead on the performance of parallel programs and the pressure on hardware system design, this application changes the state of the cache consistency protocol of the processor core through cache consistency shutdown instructions and cache consistency startup instructions. Only when the state of the cache consistency protocol of the processor core is in the open state, cache consistency operations are performed according to the requirements of the cache consistency protocol, which greatly reduces redundant cache consistency operations and improves program performance. The method provided by this application will be described in detail through specific embodiments.

[0059] Embodiment 1

[0060] Figure 1 A flowchart of a method for reducing redundant cache consistency operations provided by an embodiment of the present disclosure. Figure 1 As shown, a method for reducing redundant cache consistency operations includes:

[0061] S101 . In response to scheduling and executing a memory access instruction, a state of a cache coherence protocol of a current processor core is obtained.

[0062] The memory access instructions in this embodiment include both explicit memory access instructions such as load and store, and implicit memory access instructions such as hardware data prefetch. It can be understood that in order to keep the same data consistent between the caches of multiple processor cores, the state of the cache consistency protocol of each processor core is enabled by default.

[0063] In this embodiment, the state of the cache consistency protocol of the processor core can be changed by means of a cache consistency closing instruction and a cache consistency opening instruction. Among them, the cache consistency closing instruction is used to close the cache consistency protocol, which can make the cache consistency protocol of the processor core in a closed state, including changing from an open state to a closed state and continuing to maintain a closed state; the cache consistency opening instruction is used to open the cache consistency protocol, which can make the cache consistency protocol of the processor core in an open state, including changing from a closed state to an open state and continuing to maintain an open state. Specifically, the cache consistency closing instruction and the cache consistency opening instruction can be inserted into the execution flow of the program code or the program, and the current processor core responds to the cache consistency closing instruction initiated by the current thread, and sets the state of the cache consistency protocol of the current processor core to a closed state; responds to the cache consistency opening instruction initiated by the current thread, and sets the state of the cache consistency protocol of the current processor core to an open state.

[0064] The cache consistency off instruction and the cache consistency on instruction can be inserted into the program code by the programmer or compiler, or inserted into the program execution flow by the operating system when performing process or thread related operations, or written into certain function libraries. For redundant cache consistency operations in parallel programs, the cache consistency off instruction can be used to set the state of the cache consistency protocol of the current processor core to the off state to avoid redundant cache consistency operations, thereby improving the performance of parallel running of applications, reducing the working pressure of the cache consistency bus or directory, and making it possible to reduce their working frequency and thus reduce the power consumption of the CPU.

[0065] When inserting a cache consistency off instruction or a cache consistency on instruction, the characteristics of the parallel program need to be fully considered. For example, for a parallel program that only has process-level parallelism and no shared memory between processes, the cache consistency off instruction can be called as soon as the parallel program starts. In a process-level parallel program, processes often communicate based on a message passing interface (MPI). Each process is often equipped with an auxiliary thread for communication, and there is an interactive process based on shared data between the process and its communication auxiliary thread. This requires the process to ensure that the processor's cache consistency protocol is in the on state during the communication call. After completing the shared data interaction process, the processor's cache consistency protocol can be restored to its original state.

[0066] S102: If the state of the cache coherence protocol of the current processor core is closed, no cache coherence operation between the processor cores is performed during the execution of the memory access instruction.

[0067] The process of executing memory access instructions in this embodiment also includes events such as replacement of cache blocks. During the parallel operation of applications, it may happen that the cache consistency protocol of some processor cores in the same computing node is in a closed state, while the cache consistency protocol of other processor cores is in an open state. Therefore, for the processor cores whose cache consistency protocol is in a closed state, cache consistency operations between processor cores are not performed. Specifically, at least one of the following methods may be included: the current processor core does not initiate any cache consistency operations to the cache consistency hardware system; the current processor core ignores any cache consistency operations initiated by other processor cores (for example, it does not receive cache consistency operations initiated by other processor cores, and other processor cores do not wait for response information from processor cores whose cache consistency protocol is in a closed state). Among them, the cache consistency hardware system can be, for example, a bus or a directory structure.

[0068] S103: If the state of the cache coherence protocol of the current processor core is on, execute the memory access instruction according to the cache coherence protocol requirements between the processor cores.

[0069] When the cache coherence protocol of the current processor core is in the on state, the memory access instruction is executed according to the cache coherence protocol requirements between the processor cores. Specifically, for a processor that uses a snooping protocol to achieve cache coherence, the memory access instruction is executed according to the snooping protocol requirements; for a processor that uses a directory protocol to achieve cache coherence, the memory access instruction is executed according to the directory protocol requirements.

[0070] The method for reducing redundant cache consistency operations provided in this embodiment sets the state of the cache consistency protocol of the current processor core to the closed state through the cache consistency close instruction. When the state of the cache consistency protocol of the processor core is the closed state, cache consistency operations are not performed between the processor cores, thereby avoiding redundant cache consistency operations, and can effectively reduce the impact of cache consistency maintenance overhead on program performance.

[0071] Embodiment 2

[0072] The technical solution provided in this application will not change the existing instruction format of the processor, for example, it will not change the format of memory access instructions such as load and store. At present, processors often use pipeline technology to improve the throughput of executing instructions, reduce average latency, and use functions such as multi-issue and out-of-order execution to improve instruction-level parallelism. An instruction often takes multiple cycles from issuance to completion. Although different instructions are issued and completed in sequence, in the process of out-of-order execution of several instructions, the instructions issued later may be executed first. If a cache consistency enable instruction and a memory access instruction issued after it are executed out of order, or a cache consistency disable instruction and a memory access instruction issued before it are executed out of order, it may cause program execution exceptions. Therefore, in order to avoid the occurrence of the above-mentioned abnormal situation, on the basis of the above-mentioned embodiment, for the processor core that supports out-of-order execution, the method for reducing redundant cache consistency operations provided by this embodiment may also include: the cache consistency enable instruction cannot be executed out of order with the memory access instruction issued thereafter, that is, the memory access instruction issued thereafter can only be executed after the cache consistency protocol is enabled; the cache consistency disable instruction cannot be executed out of order with the memory access instruction issued before it, that is, the cache consistency protocol can only be disabled after all memory access instructions issued before it are completed.

[0073] The implementation of cache coherence usually requires the maintenance of the status of each cache block based on the MESI (Modified, Exclusive, Shared, Invalid) protocol or its extended version. These statuses not only record whether the cache block has been modified, but also record the sharing of the cache block between different processor cores. When the cache coherence protocol is in the off state, the memory access instruction execution process does not perform cache coherence operations between processor cores, so it is impossible to record the sharing of a cache block between multiple processor cores. When the cache coherence protocol of a processor core changes from the stopped state to the enabled state, the status information of the cache block accessed in the stopped state may be inconsistent with the requirements of the cache coherence protocol. For example, it may happen that the cache block that needs to be accessed with cache coherence in the future is fetched in advance when the coherence protocol is turned off. After entering the area where the cache coherence protocol is enabled, if the cache block that has been pre-fetched is accessed without checking whether other cores have changed the value of the cache block, the data may not be updated in time.

[0074] In order to avoid the above situation, based on any of the above embodiments, the method for reducing redundant cache consistency operations provided by this embodiment may also include: when the state of the cache consistency protocol of the current processor core is closed, marking the accessed cache block as a private access state; when the state of the cache consistency protocol of the current processor core is open, if the memory access instruction hits the cache block marked as a private access state, then the cache block marked as a private access state is initialized according to the attribute of the memory access instruction and the cache consistency protocol and the mark of the private access state is removed. By recording whether each cache block has been accessed after the consistency protocol is closed (that is, the cache block accessed after the consistency protocol is closed is marked as a private access state), when the cache consistency protocol is in the open state, if the memory access instruction hits a cache block marked as a private access state, then the consistency state of the cache block is initialized according to the attribute of the current access and the cache consistency protocol, and the mark of the private access state is removed. The above initialization process usually triggers cache consistency operations between processor cores, and may cause the cache block data to be reloaded from other cores or memory, thereby ensuring that the data is updated in a timely manner.

[0075] Embodiment 3

[0076] It should be noted that when multiple processes or threads are reading and writing shared variables, the cache coherence protocol should not be turned off. So how to avoid the cache coherence protocol being turned off by mistake?

[0077] On the basis of any of the above embodiments, the method for reducing redundant cache consistency operations provided in this embodiment further avoids the situation where the cache consistency protocol is mistakenly turned off by testing the safety of turning off the cache consistency protocol of a program. Specifically, the running results of the target program when the cache consistency protocol is in the closed state and the open state are obtained respectively; if the running results in the two states are different, it is determined that it is unsafe to turn off the cache consistency protocol. In other words, by comparing whether the running results of the target program before and after the cache consistency protocol is turned off are exactly the same, it is determined whether it is safe to turn off the cache consistency protocol of the target program. If they are exactly the same, it means it is safe; otherwise, it means it is unsafe.

[0078] The above method can detect the security of turning off the cache consistency protocol to a certain extent, but it may also bring inconveniences. For example, it may take a long time to run before the running results can be output; it may also be insufficiently effective, resulting in misjudgment. For example, the running results output by the program are not sensitive to the program segment where the cache consistency protocol is turned off. In order to avoid these situations, the security of turning off the cache consistency protocol can be conveniently tested by extending the hardware system. Specifically, a test mode can be provided by the hardware system, and the test mode is used to test the security of turning off the cache consistency protocol; at this time, a parameter of the cache consistency closing instruction is used to specify the test mode or the execution mode. When the cache consistency closing instruction is called in the execution mode, the cache consistency protocol of the current processor core will be stopped, that is, before calling the cache consistency opening instruction, the current processor core does not perform cache consistency operations. When the cache consistency shutdown instruction is called in the test mode, the current processor core is marked as being in the test mode on state, and the cache consistency operation between the processor cores is performed according to the cache consistency protocol requirements; when the test mode is in the on state, when the current processor core executes the explicit memory access instruction, the cache block corresponding to the explicit memory access instruction is marked as a private access state; if the cache consistency operation invalidates the cache block marked as the private access state of a processor core, it is determined that it is unsafe to shut down the cache consistency protocol of the processor core; if the cache block marked as the private access state in the first processor core invalidates the cache block in the second processor core through the cache consistency operation, it is determined that it is unsafe to shut down the cache consistency protocol of the first processor core.

[0079] Furthermore, when it is determined that it is unsafe to disable the cache coherence protocol, the processor can directly interrupt the execution of the program, or the unsafe test result can be recorded so that the application program can query it through corresponding instructions.

[0080] Embodiment 4

[0081] For a processor core that can run multiple (two or more) hyperthreads simultaneously (i.e., the CPU has a hyperthreading function), if the processor core runs multiple hyperthreads simultaneously, it is possible that these hyperthreads have inconsistent setting requirements for the cache consistency state: for example, at the same moment, some hyperthreads of the current processor core have not yet executed the cache consistency enable instruction after executing the cache consistency disable instruction, while the remaining hyperthreads of the current processor core have not yet executed the cache consistency disable instruction after executing the cache consistency enable instruction.

[0082] In view of the above situation, the present application provides a specific solution: if the current processor core runs multiple hyperthreads at the same time, the state of the cache consistency protocol of each hyperthread is recorded, and the cache consistency protocol state of the current processor core is determined based on all hyperthreads. In other words, obtaining the state of the cache consistency protocol of the current processor core can specifically include: jointly determining the state of the cache consistency protocol of the current processor core based on the state of the cache consistency protocol of all hyperthreads on the current processor core, and the specific method of "jointly determining" is: if the state of the cache consistency protocol of all hyperthreads on the current processor core is in the off state, then the state of the cache consistency protocol of the current processor core is the off state; if the state of the cache consistency protocol of any hyperthread on the current processor core is in the on state, then the state of the cache consistency protocol of the current processor core is the on state.

[0083] However, the above solution may cause the hyperthread whose cache consistency protocol is in the off state to initiate cache consistency operations to the cache consistency hardware system. In order to avoid this situation, in the method for reducing redundant cache consistency operations provided in this embodiment, when the current processor core runs multiple hyperthreads at the same time, the state of the cache consistency protocol of each hyperthread is recorded; when the current processor core is executing the memory access instruction of the hyperthread whose cache consistency protocol is in the off state, it does not initiate any cache consistency operations to the cache consistency hardware system; when the state of the cache consistency protocol of any hyperthread of the current processor core is in the on state, the current processor core responds to the cache consistency operations initiated by other processor cores; when the state of the cache consistency protocol of all hyperthreads of the current processor core is in the off state, the current processor core can ignore any cache consistency operations initiated by other processor cores.

[0084] On a computing node, some processor cores may be in a running state while some processor cores are in an idle state (no threads are running). The processor core in the idle state will not execute memory access instructions, and therefore will not initiate any cache consistency operations to the cache consistency hardware system. Similarly, there is no need for the processor core in the idle state to respond to cache consistency operations initiated by other processor cores. Therefore, the state of the cache consistency protocol of the processor core in the idle state can be set to an off state. That is to say, in the method for reducing redundant cache consistency operations provided in this embodiment, if the current processor core is in an idle state, the state of the cache consistency protocol of the current processor core is set to an off state.

[0085] Embodiment 5

[0086] Figure 2 A schematic diagram of a structure of a device for reducing redundant cache consistency operations provided by an embodiment of the present disclosure. Figure 2 As shown, the apparatus 20 for reducing redundant cache consistency operations provided in this embodiment may include: an acquisition module 201 , a redundancy reduction module 202 and a processing module 203 .

[0087] An acquisition module 201 is used to acquire the state of the cache coherence protocol of the current processor core in response to the scheduling execution of the memory access instruction;

[0088] The redundancy reduction module 202 is used for not performing cache consistency operations between processor cores during the execution of memory access instructions if the state of the cache consistency protocol of the current processor core is closed;

[0089] The processing module 203 is configured to execute the memory access instruction according to the cache coherence protocol requirements between the processor cores if the cache coherence protocol of the current processor core is in the on state.

[0090] In some embodiments, the device 20 for reducing redundant cache consistency operations may also include a setting module (not shown in the figure) for setting the state of the cache consistency protocol of the current processor core to a closed state in response to a cache consistency shutdown instruction initiated by the current thread; and setting the state of the cache consistency protocol of the current processor core to an open state in response to a cache consistency startup instruction initiated by the current thread.

[0091] In some embodiments, if the current processor core supports out-of-order execution, a cache coherence on instruction cannot be executed out-of-order with a memory access instruction issued thereafter; a cache coherence off instruction cannot be executed out-of-order with a memory access instruction issued therebefore.

[0092] In some embodiments, not performing cache consistency operations between processor cores includes at least one of the following: the current processor core does not initiate any cache consistency operations to the cache consistency hardware system; the current processor core ignores any cache consistency operations initiated by other processor cores.

[0093] In some embodiments, the redundancy reduction module 202 is also used to mark the accessed cache block as a private access state when the state of the cache consistency protocol of the current processor core is in the off state; the processing module 203 is also used to initialize the cache block marked as a private access state and remove the private access state mark according to the attributes of the memory access instruction and the cache consistency protocol when the state of the cache consistency protocol of the current processor core is in the on state if the memory access instruction hits the cache block marked as a private access state.

[0094] In some embodiments, the device 20 for reducing redundant cache consistency operations may also include a first detection module (not shown in the figure), which is used to obtain the running results of the target program when the state of the cache consistency protocol is closed and opened respectively; if the running results in the two states are different, it is determined that turning off the cache consistency protocol is unsafe.

[0095] In some embodiments, the apparatus 20 for reducing redundant cache coherence operations may further include a second detection module (not shown in the figure), which is used to provide a test mode through a hardware system, and the test mode is used to test the security of closing the cache coherence protocol;

[0096] When the cache coherence off instruction is called in the test mode, the current processor core is marked as being in the test mode on state, and the cache coherence operation between the processor cores is performed according to the cache coherence protocol requirements;

[0097] When the test mode is turned on, when the current processor core executes an explicit memory access instruction, the cache block corresponding to the explicit memory access instruction is marked as a private access state;

[0098] If a cache coherence operation invalidates a cache block of a processor core that is marked as a private access state, it is determined that it is unsafe to disable the cache coherence protocol of the processor core;

[0099] If the cache block marked as the private access state in the first processor core invalidates the cache block in the second processor core through a cache coherence operation, it is determined that shutting down the cache coherence protocol of the first processor core is unsafe.

[0100] Embodiment 6

[0101] Based on the above embodiments, this embodiment provides an application example.

[0102] The current processor core responds to the cache coherence shutdown instruction initiated by the current thread by setting the state of the cache coherence protocol of the current processor core to a closed state;

[0103] The current processor core responds to the cache coherence enable instruction initiated by the current thread by setting the state of the cache coherence protocol of the current processor core to an enable state;

[0104] The current processor core obtains the current state of the cache consistency protocol of the current processor core in response to the scheduling execution of a memory access instruction. When the current state is the closed state, no cache consistency operation between processor cores is performed during the execution of the memory access instruction; when the current state is the open state, the memory access instruction is executed in accordance with the cache consistency protocol requirements between processor cores.

[0105] What needs to be explained about the "cache consistency off instruction" and the "cache consistency on instruction" is that the cache consistency off instruction is a control instruction that needs to be added in this application, which enables the cache consistency protocol of the processor core to change from an on state to a off state. The cache consistency on instruction is another control instruction that needs to be added in this application, which enables the cache consistency protocol of the processor core to change from an off state to an on state. The cache consistency off instruction and the cache consistency on instruction can be inserted into the program code by the programmer or the compiler, or can be inserted into the execution flow of the program by the operating system when performing related operations on processes or threads, or can be written into certain function libraries. These two instructions allow application programmers, compilers or operating systems to avoid redundant cache consistency operations as much as possible according to the characteristics of parallel programs, thereby improving the performance of parallel running of applications; on the other hand, they can also reduce the working pressure of the cache consistency bus or directory, so that there is an opportunity to reduce their operating frequency to reduce the power consumption of the CPU. For example, for parallel programs that only have process-level parallelism and no shared memory between processes, application programmers can let the parallel program call the cache consistency off instruction as soon as it starts. In process-level parallel programs, processes often communicate with each other based on a message passing interface (MPI). Each process is often equipped with an auxiliary thread for communication. There is an interactive process based on shared data between the process and its communication auxiliary thread. This requires that when the process calls the communication, there must be a link to ensure that the processor cache consistency protocol is in the enabled state. After completing the interactive process of shared data, the processor's cache consistency protocol can be restored to its original state. Therefore, there is also a need for instructions to obtain the current state of the cache consistency protocol and instructions to restore the cache consistency protocol state. When the operating system switches threads, it needs to record the cache consistency protocol state of the swapped-out thread and restore the cache consistency protocol state of the swapped-in thread.

[0106] Regarding “the current processor core obtains the current state of the cache coherence protocol of the current processor core in response to scheduling execution of a memory access instruction, and when the current state is the closed state, no cache coherence operation between processor cores is performed during execution of the memory access instruction”, it should be noted that:

[0107] The memory access instructions here include explicit memory access instructions such as load and store, and implicit memory access operations such as hardware data prefetching. In addition, the "process of executing the memory access instructions" also includes events such as replacement of cache blocks.

[0108] The present application does not require changes to the existing instruction format of the processor, for example, the format of memory access instructions such as load and store is not changed. Now the processor uses pipeline technology to improve the throughput of executing instructions, reduce the average delay, and uses functions such as multi-issue and out-of-order execution to improve instruction-level parallelism. An instruction often takes multiple cycles from issuance to execution completion. Although different instructions are issued and completed in sequence, in the process of out-of-order execution of several instructions, the instructions issued later may be executed first. Generally speaking, cache consistency operation instructions need to meet the following principles: cache consistency opening instructions cannot be executed out of order with memory access instructions issued after it, and even need to complete its opening of the cache consistency protocol before executing the memory access instructions issued after it; cache consistency closing instructions cannot be executed out of order with memory access instructions issued before it, and even need to complete all memory access instructions issued before it before completing its closing of the cache consistency protocol. Therefore, for processors that support out-of-order execution, the corresponding out-of-order execution control component needs to ensure the above principles. Similarly, during the compilation optimization process, when the compiler schedules instructions, the order of memory access instructions and cache consistency operation instructions in the generated target file must also meet the above principles.

[0109] The implementation of cache consistency usually requires maintaining the status of each cache block based on the Modified, Exclusive, Shared, Invalid (MESI) protocol or its extended version. These statuses not only record whether the cache block has been modified, but also record the sharing of the cache block between different processor cores. When the cache consistency protocol is in the off state, the memory access instruction execution process does not perform cache consistency operations between processor cores, so it is impossible to record the sharing of a cache block between multiple processor cores. When the cache consistency protocol of a processor core changes from the stopped state to the enabled state, the status information of the cache blocks accessed in the stopped state may be inconsistent with the requirements of the cache consistency protocol. An optional solution is to record whether each cache block has been accessed after the consistency protocol is turned off (that is, mark the cache blocks accessed after the consistency protocol is turned off as private access status). When the cache consistency protocol is in the on state, if the memory access instruction hits a cache block marked with private access status, it is necessary to initialize the consistency state of the cache block according to the current access attributes and the cache consistency protocol, and remove the private access status mark. The above initialization process usually triggers cache consistency operations between processor cores, which may cause the cache block data to be reloaded from other cores or memory. The above function is necessary, especially for the common hardware prefetch function on modern processors. For example, it may happen that when the consistency protocol is turned off, the cache block that needs to be accessed with cache consistency in the future is fetched in advance. After entering the area where the cache consistency protocol is enabled, if the cache block that has been prefetched before is accessed without checking whether other cores have changed the value of the cache block, the data may not be updated in time.

[0110] During the parallel operation of applications, it may happen that the cache consistency protocol of some processor cores in the same computing node is in a closed state, while the cache consistency protocol of some processor cores is in an open state. For processor cores with the cache consistency protocol in the closed state, the "not performing cache consistency operations between processor cores" may include one or both of the following two specific methods:

[0111] 1) Do not initiate any cache consistency operations on the cache consistency hardware system (such as the bus or directory structure);

[0112] 2) Ignore any cache coherence operations initiated by other processor cores.

[0113] So how can we further help application developers detect the security of cache consistency shutdown optimization implementations?

[0114] When multiple processes or threads are reading and writing shared variables, the cache consistency protocol should not be turned off. However, it is impossible to completely avoid the situation where the cache consistency protocol is turned off by the application developer by mistake. Application developers often need to test the security of turning off the cache consistency protocol for a section of the program. One test method is to check whether the program running results before and after the shutdown are exactly the same. This test method may cause inconvenience, for example, the program may need to run for a long time before outputting the results; it may also be insufficiently effective, for example, the running results output by the program are not sensitive to the program segment where the cache consistency protocol is turned off.

[0115] The security of turning off the cache consistency protocol can be conveniently tested by extending the hardware system. A typical implementation method is: the hardware system provides a test mode when turning off the cache consistency protocol. Among them, the cache consistency off instruction has a parameter that specifies the test mode or execution mode. When the cache consistency off instruction is called in execution mode, the cache consistency protocol of the current processor core will be stopped, that is, before calling the cache consistency on instruction, the current processor core will not perform cache consistency operations. When the cache consistency off instruction is called in test mode, the current processor core will mark the test mode as on, but will not stop the cache consistency protocol, that is, cache consistency operations between processor cores will still be performed. When the current processor core executes an explicit memory access instruction such as load or store in the on state of the test mode, the following steps need to be performed:

[0116] 1) When an explicit memory access instruction does not hit the cache and the corresponding cache block has a modified copy in other processor cores, it is determined that it is unsafe to turn off the cache consistency protocol, that is, the cache consistency of the corresponding program segment cannot be turned off;

[0117] 2) Mark the cache block corresponding to the explicit memory access instruction as private access state.

[0118] When a cache consistency operation invalidates a cache block in a private access state of a processor core, it is determined that it is unsafe to shut down the cache consistency protocol of the processor core; when a private access state cache block on a processor core A invalidates a cache block of another processor core through a cache consistency operation, it is determined that it is unsafe to shut down the cache consistency protocol of processor core A.

[0119] Regarding the problem of how to report an error to the program after determining that disabling the cache consistency protocol is unsafe, one way is to let the processor directly interrupt the execution of the program; the other is to record the unsafe test results and return them when the application queries the results through the corresponding instructions.

[0120] Embodiment 7

[0121] On the basis of the above embodiments, this embodiment provides a computer device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the method described in the above embodiments.

[0122] In some implementations of this embodiment, a computer-readable storage medium is provided, on which a computer program is stored, characterized in that when the computer program is executed by a processor, the steps of the method described in the above embodiment are implemented.

[0123] In some implementations of this embodiment, a computer program product is provided, including a computer program / instructions, characterized in that when the computer program is executed by a processor, the steps of the method described in the above embodiment are implemented.

[0124] The processor may include, but is not limited to, one or more processors or microprocessors. Each processor may be an application specific integrated circuit (ASIC), a digital signal processor (DSP), a digital signal processing device (DSPD), a programmable logic device (PLD), a field programmable gate array (FPGA), a controller, a microcontroller, a microprocessor or other electronic components to execute the method in the above embodiments.

[0125] The computer-readable storage medium may be implemented by any type of volatile or non-volatile storage device or a combination thereof, and the computer-readable storage medium may include but is not limited to, for example, random access memory (RAM), read-only memory (ROM), flash memory, EPROM memory, EEPROM memory, registers, computer storage media (e.g., hard disk, floppy disk, solid-state drive, removable disk, CD-ROM, DVD-ROM, Blu-ray disc, etc.).

[0126] The computer-readable storage medium may also store at least one computer executable program / instruction, which may be, for example, a computer-readable instruction. The computer-readable storage medium includes, but is not limited to, for example, a volatile memory and / or a non-volatile memory. The volatile memory may include, for example, a random access memory (RAM) and / or a cache memory (cache), etc. The computer-readable storage medium may include, for example, a read-only memory (ROM), a hard disk, a flash memory, etc. For example, a non-transitory computer-readable storage medium may be connected to a computing device such as a computer, and then, when the computing device runs the computer-readable instructions stored on the computer-readable storage medium, the various methods described above may be performed.

[0127] In addition, the computer device may also include (but not limited to) a data bus, an input / output (I / O) bus, a display, and input / output devices (eg, keyboard, mouse, speaker, etc.), etc.

[0128] The processor may communicate with external devices via an I / O bus via a wired or wireless network.

[0129] In one embodiment, the at least one computer executable instruction may also be compiled into or constitute a software product / computer program product, wherein one or more computer executable instructions are executed by a processor to perform the various functions and / or method steps in the embodiments described in the present technology.

[0130] In the embodiments provided in the present disclosure, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0131] It should be noted that in the present disclosure, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element limited by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0132] Although the embodiments disclosed in the present disclosure are as above, the above contents are only embodiments adopted for facilitating the understanding of the present disclosure and are not intended to limit the present disclosure. Any technician in the technical field to which the present disclosure belongs can make any modifications and changes in the form and details of the implementation without departing from the spirit and scope disclosed in the present disclosure, but the scope of patent protection of the present disclosure shall still be subject to the scope defined in the attached claims.

Claims

1. A method for reducing redundant cache consistency operations, characterized in that: include: In response to scheduling and executing a memory access instruction, obtaining a state of a cache coherence protocol of a current processor core; If the state of the cache coherence protocol of the current processor core is closed, no cache coherence operation between the processor cores is performed during the execution of the memory access instruction; If the state of the cache coherence protocol of the current processor core is in the on state, executing the memory access instruction according to the cache coherence protocol requirements between the processor cores; In response to a cache coherence shutdown instruction initiated by the current thread, the state of the cache coherence protocol of the current processor core is set to a closed state, wherein the cache coherence shutdown instruction is a control instruction added to close the cache coherence protocol, which causes the cache coherence protocol of the processor core to change from an open state to a closed state or continue to remain in a closed state; In response to a cache coherence enable instruction initiated by the current thread, the state of the cache coherence protocol of the current processor core is set to an enable state, wherein the cache coherence enable instruction is a control instruction added to enable the cache coherence protocol, which causes the cache coherence protocol of the processor core to change from an off state to an on state or continue to remain in an on state; The cache consistency closing instruction and the cache consistency opening instruction are inserted into the program code by a program programmer or a compiler, or are inserted into the execution flow of the program by the operating system when performing relevant operations of a process or a thread.

2. The method according to claim 1, characterized in that If the current processor core supports out-of-order execution, the method further includes: The cache coherence enabling instruction cannot be executed out of order with the memory access instruction issued thereafter; The cache coherency disable instruction cannot be executed out of order with the memory access instruction issued before it.

3. The method according to claim 1, characterized in that The not performing cache consistency operation between processor cores includes at least one of the following methods: The current processor core does not initiate any cache coherence operations to the cache coherence hardware system; The current processor core ignores any cache coherence operations initiated by other processor cores.

4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: When the state of the cache coherence protocol of the current processor core is in a closed state, marking the accessed cache block as a private access state; When the state of the cache consistency protocol of the current processor core is turned on, if a memory access instruction hits a cache block marked as a private access state, the cache block marked as a private access state is initialized and the private access state mark is removed according to the attributes of the memory access instruction and the cache consistency protocol.

5. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Obtaining the running results of the target program when the cache coherence protocol is in the closed state and the opened state respectively; If the operating results in the two states are different, it is determined that it is unsafe to turn off the cache consistency protocol.

6. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Providing a test mode through a hardware system, wherein the test mode is used to test the security of closing a cache consistency protocol; When the cache coherence off instruction is called in the test mode, the current processor core is marked as being in the test mode on state, and the cache coherence operation between the processor cores is performed according to the cache coherence protocol requirements; When the test mode is in the on state, when the current processor core executes an explicit memory access instruction, the cache block corresponding to the explicit memory access instruction is marked as a private access state; If a cache coherence operation invalidates a cache block of a processor core that is marked as a private access state, it is determined that it is unsafe to disable the cache coherence protocol of the processor core; If the cache block marked as private access state in the first processor core invalidates the cache block in the second processor core through a cache coherence operation, it is determined that shutting down the cache coherence protocol of the first processor core is unsafe.

7. The method according to any one of claims 1 to 3, characterized in that: If the current processor core runs multiple hyperthreads at the same time, the state of the cache coherence protocol of each hyperthread is recorded. The state of obtaining the cache coherence protocol of the current processor core includes: The state of the cache coherence protocol of the current processor core is jointly determined according to the states of the cache coherence protocols of all hyperthreads on the current processor core, wherein the jointly determining includes: If the states of the cache coherence protocols of all hyperthreads on the current processor core are in a closed state, the state of the cache coherence protocol of the current processor core is a closed state; If the state of the cache coherence protocol of any hyperthread on the current processor core is in the on state, the state of the cache coherence protocol of the current processor core is in the on state.

8. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: When the current processor core runs multiple hyperthreads simultaneously, the state of the cache coherence protocol of each hyperthread is recorded; The current processor core does not initiate any cache consistency operation to the cache consistency hardware system during the process of executing the memory access instruction of the hyperthread whose cache consistency protocol is in the disabled state; When the state of the cache coherence protocol of any hyperthread of the current processor core is in an on state, the current processor core responds to the cache coherence operation initiated by other processor cores; When the states of cache coherence protocols of all hyperthreads of the current processor core are in a closed state, the current processor core ignores any cache coherence operations initiated by other processor cores.

9. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: If the current processor core is in an idle state, the state of the cache coherence protocol of the current processor core is set to a closed state.

10. A device for reducing redundant cache consistency operations, characterized in that: include: An acquisition module, configured to acquire the state of the cache coherence protocol of the current processor core in response to the scheduling execution of the memory access instruction; A redundancy reduction module, configured to not perform cache consistency operations between processor cores during the execution of the memory access instruction if the cache consistency protocol of the current processor core is in a closed state; A processing module, configured to execute the memory access instruction according to the cache consistency protocol requirements between the processor cores if the state of the cache consistency protocol of the current processor core is turned on; A setting module is used to set the state of the cache consistency protocol of the current processor core to a closed state in response to a cache consistency closing instruction initiated by the current thread, wherein the cache consistency closing instruction is an added control instruction for closing the cache consistency protocol, which causes the cache consistency protocol of the processor core to change from an open state to a closed state or continue to remain in a closed state; in response to a cache consistency opening instruction initiated by the current thread, set the state of the cache consistency protocol of the current processor core to an open state, wherein the cache consistency opening instruction is an added control instruction for opening the cache consistency protocol, which causes the cache consistency protocol of the processor core to change from an closed state to an open state or continue to remain in an open state; the cache consistency closing instruction and the cache consistency opening instruction are inserted into the program code by a programmer or a compiler, or are inserted into the execution flow of the program by the operating system when performing related operations of a process or thread.

11. A computer device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 9.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.

13. A computer program product comprising a computer program / instructions, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.

Citation Information

Cited By

  • Cache consistency optimization method in automatic thread-level parallelization

    CN118820134B

  • Cache data write-back method and device, equipment, medium and program product

    CN121858470A

  • Method and device for controlling cache consistency operation, computer equipment and medium

    CN122111709A