A method for replacing a high-speed cache memory, a high-speed cache memory and a computer system
Using sliding window technology to replace and map small-capacity Cache data solves the deficiencies in data replacement and mapping methods for small-capacity Cache in microcontroller chips, improves hit rate and power consumption efficiency, and adapts to changes in the program execution process.
Patent Information
- Application Number
- CN201910560597.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-06-26
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2039-06-26
AI Technical Summary
The existing technology is difficult to effectively use small-capacity cache memory in cost- and power-sensitive microcontroller chips. In particular, there are deficiencies in data replacement and mapping methods, and it cannot adapt to dynamic changes during program execution.
The sliding window method is used to replace and map the data in the small-capacity Cache. By defining the priority flag for the main memory address range and constructing a sliding window consistent with the Cache capacity, the window position is dynamically adjusted to replace the data block and avoid high-priority programs. The block locks the Cache to ensure that low-priority program blocks can be loaded.
It improves the hit rate of small-capacity Cache, reduces chip power consumption, avoids frequent replacement of Cache blocks through priority configuration, and adapts to various program structures.
Smart Images

Figure CN112148640B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of high-speed cache memory, and in particular to a high-speed cache memory replacement method, a high-speed cache memory and a computer system. Background Art
[0002] Cache is a special memory subsystem in which frequently used data is copied for fast access. The cache of the memory stores the contents of frequently accessed RAM locations and the storage addresses of these data items. Cache consists of two basic parts: tag memory and data memory. Tag memory is used to store the control bits and block address tags of the cache. The control bits are used to manage the read and write operations of the cache, while the block address tags record the addresses of each block in the cache. This address contains the block address mapped to the main memory, and all correspond to a piece of "data" in the cache. And this piece of "data" is stored in the data memory of the cache. When the CPU reads data, it first sends the physical address to the cache through the address bus and compares it with the block address tag in the cache. If it matches, it means that the data already exists in the cache (this situation is jokingly called a "hit"), and then the corresponding data in the cache only needs to be sent directly to the CPU via the data bus. However, if the physical address sent by the CPU does not match the block address tag in the cache, it means that the data is not in the cache (called a "miss"). At this time, the main memory needs to copy the data address required by the CPU to the cache, and then the cache sends the data to the CPU. At this time, the mapping method needs to be discussed. The mapping method refers to how the data in the cache corresponds to the data in the main memory. There are usually three mapping methods:
[0003] Direct mapping: If the blocks on the main memory can only be mapped to specific blocks in the cache, we call this mapping method direct mapping. Direct mapping has the fastest access speed, but also the highest error rate.
[0004] Full mapping: In this mapping mode, blocks on the main memory can be mapped to any block in the cache. When the CPU wants to read a block, the cache will compare the address sent by the CPU with all the address tags in the cache. Because it is a full comparison, the access time is the longest, but the error rate is also the lowest.
[0005] Set-associative mapping: This mapping method divides the cache into several pages, and each page has the same number of blocks. The data block in the main memory can be mapped to any block in the specified page in the cache. This mapping method can be regarded as a compromise between direct mapping and full mapping, and is the most efficient mapping method.
[0006] Adding instruction cache inside a microcontroller chip can significantly improve the efficiency of instruction execution. However, adding a large-capacity cache will significantly increase the cost and power consumption of the chip. Therefore, only small-capacity caches can be used in microcontroller chips that are sensitive to cost and power consumption. When using small-capacity caches, direct mapping, full mapping, or set associative mapping, which are large-capacity cache methods, cannot be used to map and replace the cache, and the existing mapping methods have not yet addressed this technical issue. Summary of the invention
[0007] Purpose of the invention: To provide a suitable data replacement and mapping method for a small-capacity cache, the present invention proposes a high-speed cache replacement method, a high-speed cache and a computer system. The present invention regards the entire small-capacity cache as a block and uses a sliding window method to map and replace the small-capacity cache, that is, the mapping position of the cache and the program memory changes continuously as the program is executed.
[0008] Technical solution: To achieve the above technical effects, the present invention proposes the following technical solution:
[0009] A method for replacing data in a cache memory comprises the steps of:
[0010] (1) Define different priority flags for different address intervals of the main memory, that is, define the priority of each program block in the main memory; define the priority of the interrupt vector table address interval as the lowest;
[0011] (2) Construct a sliding window that is consistent with the capacity k of the cache memory. Initially, the lower end of the window corresponds to address 0 of the program memory, and the higher end corresponds to address k of the program memory. The sliding window corresponds to the data block in the main memory, and the data block in the main memory corresponding to the sliding window and the priority of the data block are stored in the cache memory.
[0012] (3) If an access miss occurs in the cache memory Cache, the cache memory Cache reads a new program block from the main memory, and the cache memory Cache determines whether the priority of the originally stored program block is lower than the priority of the newly accessed program block. If so, the bottom of the sliding window is moved to the address of the miss, and the stored content is replaced with the data block of the main memory corresponding to the sliding window, and its own priority is updated to the priority corresponding to the new data block; if not, the window position of the current cache block remains unchanged, and the cache content remains unchanged.
[0013] Furthermore, the data and priority levels stored in the cache memory Cache can be cleared to prevent a high-priority program block from locking the Cache block, causing a low-priority program block to never be loaded into the Cache.
[0014] Furthermore, when the CPU reads the interrupt vector table, the cache window position and the cache content are forced not to be updated.
[0015] The present invention also provides a high-speed cache memory, which adopts the data replacement method to perform data replacement.
[0016] The present invention also provides a computer system, wherein the computer system comprises the high-speed cache memory.
[0017] Furthermore, the cache memory is implemented using an independent static memory chip, or is integrated inside a CPU chip.
[0018] Beneficial effects: Compared with the prior art, the present invention has the following advantages:
[0019] 1. When using small-capacity high-speed cache storage, it can adapt to programs of various structures and improve the hit rate.
[0020] 2. The priority is configurable to avoid frequent replacement of cache blocks and reduce chip power consumption. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 A flow chart of the data replacement method of the cache memory of the present invention;
[0022] Figure 2 Schematic diagram of sliding window position update. DETAILED DESCRIPTION
[0023] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0024] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0025] The data replacement method of the cache memory includes the following steps (1) to (3):
[0026] 1) Define different priority flags for different address intervals of the main memory in advance, that is, define the priority of each program block in the main memory; define the priority of the interrupt vector table address interval as the lowest;
[0027] (2) Construct a sliding window that is consistent with the capacity k of the cache memory. Initially, the lower end of the window corresponds to address 0 of the program memory, and the higher end corresponds to address k of the program memory. The sliding window corresponds to the data block in the main memory, and the data block in the main memory corresponding to the sliding window and the priority of the data block are stored in the cache memory.
[0028] (3) If an access miss occurs in the cache memory Cache, the cache memory Cache reads a new program block from the main memory, and the cache memory Cache determines whether the priority of the originally stored program block is lower than the priority of the newly accessed program block. If so, the bottom of the sliding window is moved to the address of the miss, and the stored content is replaced with the data block of the main memory corresponding to the sliding window, and its own priority is updated to the priority corresponding to the new data block; if not, the window position of the current cache block remains unchanged, and the cache content remains unchanged.
[0029] like Figure 2 As shown in FIG. 1 , it is a schematic diagram of the sliding window, and the window size is the capacity of the Cache. In the following description, it is assumed that the capacity of the Cache is k. The sliding window workflow is as follows:
[0030] Initially, the lower position of the window corresponds to address 0 of the program memory, and the upper position corresponds to address k of the program memory;
[0031] When the CPU accesses program address y, if address y is not in the current cache window, the window position is updated: the low position corresponds to program memory address y, and the high position corresponds to program memory address y+k-1;
[0032] If the program address accessed by the CPU is within the cache window range, the window position remains unchanged;
[0033] When the CPU reads the interrupt vector table, the cache window position and cache contents are forced not to be updated.
[0034] 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.
[0035] According to an embodiment of the present invention, a high-speed cache memory is further provided, wherein the high-speed cache memory adopts the data replacement method to perform data replacement.
[0036] The present invention also provides a computer system, wherein the computer system includes the high-speed cache memory, which is implemented by an independent static memory chip or integrated inside a CPU chip.
[0037] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.
[0038] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0039] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method for replacing data in a cache memory, characterized in that: Includes steps: (1) Different priority flags are defined for different address intervals of the main memory in advance, that is, the priority of each program block in the main memory is defined; the priority of the interrupt vector table address interval is defined as the lowest; (2) Construct a sliding window that is consistent with the capacity k of the cache memory. Initially, the lower end of the window corresponds to address 0 of the program memory, and the higher end corresponds to address k of the program memory. The sliding window corresponds to the data block in the main memory, and the data block in the main memory corresponding to the sliding window and the priority of the data block are stored in the cache memory. (3) If an access miss occurs in the cache memory Cache, the cache memory Cache reads a new program block from the main memory, and the cache memory Cache determines whether the priority of the originally stored program block is lower than the priority of the newly accessed program block. If so, the bottom of the sliding window is moved to the address of the miss, and the stored content is replaced with the data block of the main memory corresponding to the sliding window, and its own priority is updated to the priority corresponding to the new data block; if not, the window position of the current cache block remains unchanged, and the cache content remains unchanged, wherein the data and priority stored in the cache memory Cache can be cleared to prevent the high-priority program block from locking the cache block, resulting in the low-priority program block never being loaded into the cache.
2. The method for replacing data in a cache memory according to claim 1, characterized in that: When the CPU reads the interrupt vector table, the cache window position and cache contents are forced not to be updated.
3. A cache memory, characterized in that: The cache memory uses the data replacement method as described in any one of claims 1 to 2 to perform data replacement.
4. A computer system, characterized in that: The computer system includes the cache memory according to claim 3.
5. A computer system according to claim 4, characterized in that: The high-speed cache memory is implemented by an independent static memory chip, or is integrated inside a CPU chip.
