A caching control method, device, program product, processor, and storage medium
By using the eviction history information set to determine the candidate block retention value of the cache replacement algorithm in a multi-core processor, the cache replacement strategy is optimized, the cache hit rate and adaptability are improved, and the problem of high cache miss rate is solved.
Patent Information
- Application Number
- CN202510361489.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-26
- Publication Date
- 2025-06-17
- Estimated Expiration
- 2045-03-26
AI Technical Summary
In multi-core processors, the cache replacement algorithm is insufficiently adaptive, resulting in a high cache miss rate and affecting system performance.
By obtaining the eviction cache information of the current candidate block in the target cache area, combining the cache entries in the eviction historical information set, the reserved value of the current candidate block is determined, and whether to retain the current candidate block is determined based on the reserved value and value threshold, thereby optimizing the cache replacement strategy.
Improves the adaptability and cache hit rate of cache replacement policies, reduces the performance losses caused by cache misses, and reduces hardware overhead.
Smart Images

Figure CN119883951B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of processors, and particularly to a cache control method, apparatus, program product, processor, and storage medium. Background Art
[0002] Currently, the rapid development of computer systems has led to a significant improvement in the performance of processors (such as the central processing unit CPU). However, the relatively lagging development of memory technology has led to an increasing gap between the processor cycle time and the memory access latency, thus forming the "memory wall" problem. To address this challenge, modern processors rely on a memory system composed of a cache hierarchy, and by storing data as close as possible to the cache level closer to the processor, the overall processing efficiency of the system is improved. However, cache misses are inevitable in the cache system, which makes selecting an appropriate cache replacement policy the key to optimizing system performance.
[0003] In related technologies, the LRU (Least Recently Used) algorithm is currently one of the cache replacement algorithms widely used in processors, and its core idea is to replace the data block that has not been used for the longest time in the cache. However, in high-parallel computing scenarios, frequent cache replacements will not only cause cache pollution but also may result in performance bottlenecks, affecting the overall performance of the system; especially in a multi-core processor architecture, the cache coherence problem further exacerbates the complexity of cache management. To address these problems, prediction models are usually adopted to optimize the cache replacement policy, and these models predict the most appropriate cache replacement policy by analyzing characteristics such as data access frequency, memory access patterns, and instruction behavior; however, these models still lack adaptability when dealing with complex and dynamic computing environments.
[0004] Therefore, how to optimize the cache replacement algorithm in a multi-core processor, improve the adaptability of the cache replacement policy and the cache hit rate, and reduce the performance loss caused by cache misses is an urgent problem to be solved today. Summary of the Invention
[0005] The object of the present invention is to provide a cache control method, apparatus, computer program product, processor, and computer-readable storage medium to optimize the cache replacement algorithm in a multi-core processor, improve the adaptability of the cache replacement policy and the cache hit rate, and reduce the performance loss caused by cache misses.
[0006] To solve the above technical problems, the present invention provides a cache control method applied to a cache controller of a processor, including:
[0007] Obtain the eviction cache information of the current candidate block in the target cache area; wherein, the current candidate block is a cache data to be evicted selected by a cache replacement algorithm, and the eviction cache information includes a consistency state and a sharing state information;
[0008] Determine the retention value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set; wherein, the cache entries include the consistency state and the sharing state information of the evicted cache data;
[0009] Judge whether to retain the current candidate block according to the retention value and a value threshold;
[0010] If so, obtain the eviction cache information of the next candidate block in the target cache area, and use the next candidate block as the current candidate block, and execute the step of determining the retention value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set;
[0011] If not, evict the current candidate block from the target cache area, and store the cache entry corresponding to the eviction cache information in the eviction history information set.
[0012] On the other hand, determining the retention value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set includes:
[0013] Determine each consistency state weight, sharing quantity over-threshold weight, and sharing quantity non-over-threshold weight according to the cache entries in the eviction history information set;
[0014] Determine the retention value of the current candidate block according to each of the consistency state weights, the sharing quantity over-threshold weight, the sharing quantity non-over-threshold weight, and the consistency state and sharing state information in the eviction cache information.
[0015] On the other hand, the consistency state is a state in the modified-exclusive-shared-invalidated protocol, and the consistency state weights include a dirty state weight, an exclusive state weight, and a shared state weight; determining the retention value of the current candidate block according to each of the consistency state weights, the sharing quantity over-threshold weight, the sharing quantity non-over-threshold weight, and the consistency state and sharing state information in the eviction cache information includes:
[0016] Through V = w M *M + w E *E + w S *S + w AT *AT + w BT *BT, determine the retention value of the current candidate block; wherein, V is the retention value, w M 、wE and w S are the dirty state weight, the exclusive state weight, and the shared state weight respectively; M, E, and S are the number of sharings corresponding to the shared state information in the eviction cache information when the coherence state in the eviction cache information is in the modified state, exclusive state, and shared state respectively; w AT and w BT are the weight for the sharing quantity exceeding the threshold and the weight for the sharing quantity not exceeding the threshold respectively; AT is 1 when the sharing quantity exceeds the quantity threshold and 0 when the sharing quantity does not exceed the quantity threshold; BT is 1 when the sharing quantity does not exceed the quantity threshold and 0 when the sharing quantity exceeds the quantity threshold.
[0017] On the other hand, determining each coherence state weight, the weight for the sharing quantity exceeding the threshold, and the weight for the sharing quantity not exceeding the threshold according to each cache entry in the eviction history information set includes:
[0018] Determining each coherence state weight according to the number of cache entries in the eviction history information set and the coherence state of each cache entry;
[0019] Determining the weight for the sharing quantity exceeding the threshold and the weight for the sharing quantity not exceeding the threshold according to the number of cache entries, the first quantity, and the second quantity in the eviction history information set; wherein, the first quantity is the number of cache entries whose sharing quantity corresponding to the shared state information exceeds the quantity threshold, and the second quantity is the number of cache entries whose sharing quantity corresponding to the shared state information does not exceed the quantity threshold.
[0020] On the other hand, before determining the retention value of the current candidate block according to the cache entries in the eviction cache information and the eviction history information set, it further includes:
[0021] Judging whether the number of cache entries in the eviction history information set meets the requirements;
[0022] If it meets the requirements, execute the step of determining the retention value of the current candidate block according to the cache entries in the eviction cache information and the eviction history information set;
[0023] If it does not meet the requirements, evict the current candidate block from the target cache area and add the cache entry corresponding to the eviction cache information to the eviction history information set.
[0024] On the other hand, when the eviction history information set is an eviction history table, judging whether the number of cache entries in the eviction history information set meets the requirements includes:
[0025] Judging whether the number of cache entries in the eviction history table reaches a preset evaluation quantity;
[0026] If the preset evaluation quantity is reached, execute the step of determining the retention value of the current candidate block according to the cache entries in the eviction cache information and the eviction history information set;
[0027] If the preset evaluation quantity is not reached, execute the step of evicting the current candidate block from the target cache area and adding the cache entry corresponding to the eviction cache information to the eviction history information set.
[0028] On the other hand, storing the cache entry corresponding to the eviction cache information in the eviction history information set includes:
[0029] If the number of cache entries in the eviction history information set reaches the preset full write quantity, determine a target cache entry according to the storage time, miss time, and / or current retention value of each cache entry in the eviction history information set;
[0030] Replace the target cache entry with the cache entry corresponding to the eviction cache information.
[0031] On the other hand, determining a target cache entry according to the storage time, miss time, and / or current retention value of each cache entry in the eviction history information set includes:
[0032] Determine the cache entry with the longest miss time in the eviction history information set as the target cache entry.
[0033] On the other hand, the cache entry further includes address information, threshold comparison information, and a valid bit; the shared state information in the cache entry is a shared vector bit, and the threshold comparison information is used to indicate whether the shared quantity corresponding to the shared vector bit exceeds a quantity threshold.
[0034] On the other hand, the cache replacement algorithm is the least recently used algorithm.
[0035] On the other hand, the processor adopts a cache architecture with at least two layers, and the target cache area includes the bottom cache of the cache architecture.
[0036] On the other hand, judging whether to retain the current candidate block according to the retention value and the value threshold includes:
[0037] Judge whether the retention value is greater than the value threshold;
[0038] If it is greater than the value threshold, determine to retain the current candidate block;
[0039] If it is not greater than the value threshold, determine not to retain the current candidate block.
[0040] On the other hand, obtaining the eviction cache information of the current candidate block in the target cache area includes:
[0041] Obtaining a cache access request;
[0042] Checking whether the cache access request hits the cache data in the cache of the processor;
[0043] If not hit, using the cache replacement algorithm to determine the current candidate block in the target cache area and obtaining the eviction cache information of the current candidate block.
[0044] On the other hand, the method further includes:
[0045] Checking whether the obtained cache access request hits the cache entry in the eviction history information set;
[0046] If hitting the cache entry in the eviction history information set, deleting the hit cache entry from the eviction history information set.
[0047] On the other hand, before taking the next candidate block as the current candidate block and performing the step of determining the retention value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set, it further includes:
[0048] If the cache access request does not hit the cache entry in the eviction history information set, updating the respective consistency state weights, shared quantity over-threshold weights, and shared quantity non-over-threshold weights corresponding to the eviction history information set according to the eviction cache information.
[0049] On the other hand, updating the respective consistency state weights, shared quantity over-threshold weights, and shared quantity non-over-threshold weights corresponding to the eviction history information set according to the eviction cache information includes:
[0050] Calculating the sum of the target consistency state weight and the first learning rate to obtain the updated target consistency state weight; wherein, the target consistency state weight is the consistency state weight corresponding to the consistency state of the eviction cache information;
[0051] Normalizing the updated target consistency state weight and the other consistency state weights to obtain the updated respective consistency state weights; wherein, the sum of the updated respective consistency state weights is 1;
[0052] Calculating the sum of the target shared state weight and the second learning rate to obtain the updated target shared state weight; wherein, the target shared state weight is the shared quantity over-threshold weight or the shared quantity non-over-threshold weight corresponding to the shared state information of the eviction cache information;
[0053] Normalize the updated target shared state weight and another shared state weight to obtain the updated shared quantity over-threshold weight and the shared quantity non-over-threshold weight; wherein, the sum of the updated shared quantity over-threshold weight and the shared quantity non-over-threshold weight is 1.
[0054] The present invention also provides a cache control device, which is applied to the cache controller of a processor and includes:
[0055] An acquisition module, configured to acquire the eviction cache information of the current candidate block in the target cache area; wherein, the current candidate block is a piece of cache data to be evicted selected by a cache replacement algorithm, and the eviction cache information includes a consistency state and shared state information;
[0056] A determination module, configured to determine the retention value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set; wherein, the cache entries include the consistency state and shared state information of the evicted cache data;
[0057] A judgment module, configured to judge whether to retain the current candidate block according to the retention value and a value threshold;
[0058] A retention module, configured to, if the current candidate block is to be retained, acquire the eviction cache information of the next candidate block in the target cache area, use the next candidate block as the current candidate block, and send a start signal to the determination module;
[0059] An eviction module, configured to, if the current candidate block is not to be retained, evict the current candidate block from the target cache area and store the cache entry corresponding to the eviction cache information in the eviction history information set.
[0060] The present invention also provides a computer program product, including a computer program / instructions, and when the computer program / instructions are executed by a processor, the steps of the cache control method as described above are implemented.
[0061] The present invention also provides a processor, including:
[0062] A memory, configured to store a computer program;
[0063] A cache controller, configured to implement the steps of the cache control method as described above when executing the computer program.
[0064] In addition, the present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the cache control method as described above are implemented.
[0065] A cache control method provided by the present invention is applied to a cache controller of a processor, and includes: obtaining eviction cache information of a current candidate block in a target cache area; wherein, the current candidate block is a piece of cache data to be evicted selected by a cache replacement algorithm, and the eviction cache information includes a coherence state and shared state information; determining the retention value of the current candidate block according to the eviction cache information and cache entries in an eviction history information set; wherein, the cache entries include the coherence state and shared state information of the evicted cache data; judging whether to retain the current candidate block according to the retention value and a value threshold; if so, obtaining the eviction cache information of the next candidate block in the target cache area, and using the next candidate block as the current candidate block, and executing the step of determining the retention value of the current candidate block according to the eviction cache information and cache entries in the eviction history information set; if not, evicting the current candidate block from the target cache area, and storing the cache entry corresponding to the eviction cache information in the eviction history information set.
[0066] It can be seen that the present invention can utilize the coherence state and shared state information of the evicted cache blocks in the eviction history information set to determine the retention value of the current candidate block selected by the cache replacement algorithm, so as to judge whether the current candidate block may be accessed again in the future, thereby optimizing the cache replacement algorithm in a multi-core processor, improving the self-adaptability of the cache replacement strategy and the cache hit rate, and reducing the performance loss caused by cache misses; and since the eviction history information set does not need to store specific cache block data, compared with the method of increasing the cache capacity to improve the cache hit rate, the hardware overhead is smaller. In addition, the present invention also provides a cache control device, a computer program product, a processor and a computer-readable storage medium, which also have the above beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained according to the provided drawings without creative efforts.
[0068] Figure 1 It is a flowchart of a cache control method provided by an embodiment of the present invention;
[0069] Figure 2 It is a schematic structural diagram of a reinforcement learning system provided by an embodiment of the present invention;
[0070] Figure 3 It is a display diagram of an eviction history table provided by an embodiment of the present invention;
[0071] Figure 4Schematic flowchart of a cache replacement algorithm based on reinforcement learning provided by an embodiment of the present invention;
[0072] Figure 5 Schematic diagram of the reward feedback process of a cache control method provided by an embodiment of the present invention;
[0073] Figure 6 Schematic flowchart of another cache control method provided by an embodiment of the present invention;
[0074] Figure 7 Block diagram of the structure of a cache control device provided by an embodiment of the present invention;
[0075] Figure 8 Schematic diagram of the structure of a processor provided by an embodiment of the present invention. Detailed implementation manners
[0076] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0077] Please refer to Figure 1 , Figure 1 Flowchart of a cache control method provided by an embodiment of the present invention. This method is applied to the cache controller of a processor and may include:
[0078] Step 101: Obtain the eviction cache information of the current candidate block in the target cache area; wherein, the current candidate block is a piece of cache data to be evicted selected by the cache replacement algorithm, and the eviction cache information includes the consistency state and the shared state information.
[0079] It can be understood that the target cache area in this embodiment may be the cache area in all caches of the processor that needs to optimize the cache replacement algorithm by the method provided in this embodiment. For example, when the processor adopts a cache architecture with at least two layers, the target cache area may include the bottom cache of the cache architecture; for example, when the processor adopts a three-layer cache architecture, the target cache area may include the third-level cache (i.e., L3 cache). As Figure 2 shown, the cache controller in this embodiment may be an L3 cache controller.
[0080] Correspondingly, the current candidate block in this embodiment can be a piece of cache data (or cache block or cache line) that needs to be evicted currently selected by a cache replacement algorithm. For the specific algorithm type of the cache replacement algorithm adopted in the target cache area in this embodiment, it can be set by designers according to the practical scenario and user requirements. For example, the cache replacement algorithm can adopt the LRU (Least Recently Used) algorithm, or can also adopt the LFU (Least Frequently Used) algorithm or other cache replacement algorithms. This embodiment does not impose any restrictions on this.
[0081] Correspondingly, the eviction cache information of the current candidate block in this embodiment can include the coherence state and shared state information of the current candidate block; among them, the coherence state can be the state of the current candidate block in the adopted cache coherence protocol. For example, when the cache coherence protocol is the MESI (Modified Exclusive Shared Invalidated) protocol, the coherence state can be the modified state (M state), the exclusive state (E state) or the shared state (S state); when the cache coherence protocol is the CHI (Coherent Hub Interface) protocol, the CHI protocol defines five states: the invalid state (I state), the clean shared state (SC state), the dirty shared state (SD state), the clean exclusive state (UC state) and the dirty exclusive state (UD state), and the coherence state can be the SC state, the SD state, the UC state or the UD state.
[0082] It should be noted that for the specific manner in which the cache controller obtains the eviction cache information of the current candidate block in the target cache area in this step, it can be set by designers according to the practical scenario and user requirements. For example, it can be implemented in the same or similar manner as the method in the related art where the cache controller uses a cache replacement algorithm (such as the LRU algorithm) to determine the cache data to be evicted; for example, in this step, the cache controller can obtain a cache access request; check whether the cache access request hits the cache data in the processor's cache; if it does not hit, then use the cache replacement algorithm to determine the current candidate block in the target cache area and obtain the eviction cache information of the current candidate block. That is to say, when the processor core accesses the cache, the cache controller can detect whether the cache hits; if it hits, then use the hit cache data to complete the access; if it does not hit, then it can find the corresponding data in the main memory to complete the access and replace the cache data in the cache; and during the process of replacing the cache data in the cache, the cache replacement algorithm is used to determine the current candidate block in the target cache area and obtain the eviction cache information of the current candidate block, so as to determine whether to evict the current candidate block through the method provided in this embodiment and replace it with the corresponding data.
[0083] Step 102: Determine the retention value of the current candidate block according to the cache entries in the eviction cache information and the eviction history information set; wherein, the cache entries include the consistency state and the sharing state information of the evicted cache data.
[0084] It can be understood that the eviction history information set in this embodiment can be a set of relevant information (i.e., cache entries) of the historically evicted cache data (i.e., cache blocks) in the target cache area recorded. That is to say, as Figure 2 shown, the eviction history information set can be used as the environment of the cache reinforcement learning system, and send the states (such as the consistency state and the sharing state information) of the historically evicted cache blocks recorded to the cache controller (L3 cache controller) serving as the agent, so that the cache controller can evaluate and determine whether to evict the current candidate block.
[0085] Correspondingly, for the specific storage form of the eviction history information set in this embodiment, it can be set by the designer himself. For example, the eviction history information set can be stored in the form of a table, that is, the eviction history information set can be specifically an eviction history table; the eviction history information set can also be stored in the form of an array or other forms, and this embodiment does not make any restrictions on this.
[0086] Similarly, for the specific content of each cache entry in the eviction history information set in this embodiment, it can be set by the designer according to the practical scenario and user requirements. For example, the cache entry can include the consistency state and the sharing state information of the evicted cache data; in order to facilitate reflecting the sharing state of the consistency state of the cache data in each processor core, the sharing state information can be specifically a sharer vector bit, that is, the sharer vector bit can include the sharing state vectors corresponding to each processor core to record which cores specifically share this consistency state; as Figure 4 shown, when the number of processor cores is 4, the sharer vector bit can include 4 sharing state vectors. When the sharing state vector is 1, it can indicate that the cache data is shared by the corresponding core, and when the sharing state vector is 0, it can indicate that the cache data is not shared by the corresponding core. For example, the sharer vector bit is 0010, and the recorded consistency state is the M state, indicating that the consistency state of the cache data in the 4 cores is the M state in the 2nd core. The cache entry can also include the address information (such as the cache line address) of the evicted cache data to facilitate subsequent checking whether the cache entry is hit. The cache entry can also include threshold comparison information, which is used to represent the result of comparing the number of processor cores sharing the cache data (i.e., the sharing number) with the number threshold, such as indicating whether the sharing number exceeds the number threshold; as Figure 4The middle threshold comparison information being 1 can indicate that the sharing quantity of the cached data exceeds the quantity threshold, and the threshold comparison information being 0 can indicate that the sharing quantity of the cached data does not exceed the quantity threshold, which is convenient for calculating the weights for the sharing quantity exceeding the threshold and the weights for the sharing quantity not exceeding the threshold. The cache entry can also have a valid bit to facilitate the replacement and update of the cache entry. For example, the valid bit being 0 can indicate that the cache entry is invalid and will be replaced subsequently. As long as it is ensured that the cache entry does not include the evicted cached data, so that its occupied resources are much smaller than those of the cache, reducing the hardware overhead, this embodiment does not impose any restrictions on this.
[0087] It should be noted that in this embodiment, the specific method for determining the retention value of the current candidate block based on the cache entries in the eviction cache information and the eviction history information set can be set by the designer according to the practical scenario and user requirements. For example, the cache controller can determine the retention value of the current candidate block based on the number of cache entries corresponding to each coherence state in the eviction history information set and the number of cache entries corresponding to the sharing quantity exceeding the quantity threshold and not exceeding the quantity threshold respectively. For example, the retention value of the current candidate block can be the sum of the first entry quantity and the second entry quantity corresponding to the current candidate block. The first entry quantity can be the number of cache entries corresponding to the coherence state in the eviction cache information of the current candidate block, and the second entry quantity can be the number of cache entries corresponding to the sharing quantity when it exceeds the quantity threshold or does not exceed the quantity threshold indicated by the sharing state information in the eviction cache information of the current candidate block.
[0088] In some other embodiments, the cache controller can also determine the weights of each coherence state, the weights for the sharing quantity exceeding the threshold, and the weights for the sharing quantity not exceeding the threshold based on the cache entries in the eviction history information set; and determine the retention value of the current candidate block according to the weights of each coherence state, the weights for the sharing quantity exceeding the threshold, the weights for the sharing quantity not exceeding the threshold, and the coherence state and sharing state information in the eviction cache information.
[0089] For example, the sum of the weights of each consistency state is 1, and the sum of the weights of the shared quantity exceeding the threshold and the weights of the shared quantity not exceeding the threshold is 1. The process of determining the weights of each consistency state, the weights of the shared quantity exceeding the threshold, and the weights of the shared quantity not exceeding the threshold according to each cache entry in the eviction history information may include: determining the weights of each consistency state according to the number of cache entries in the eviction history information and the consistency state of each cache entry; determining the weights of the shared quantity exceeding the threshold and the weights of the shared quantity not exceeding the threshold according to the number of cache entries in the eviction history information, the first quantity, and the second quantity; where the first quantity is the number of cache entries whose shared quantity corresponding to the shared state information exceeds the quantity threshold, and the second quantity is the number of cache entries whose shared quantity corresponding to the shared state information does not exceed the quantity threshold. That is to say, the weights of each consistency state may be the quotient of the number of cache entries corresponding to each consistency state and the number of cache entries in the eviction history information, the weight of the shared quantity exceeding the threshold may be the quotient of the first quantity and the number of cache entries in the history information, and the weight of the shared quantity not exceeding the threshold may be the quotient of the second quantity and the number of cache entries in the history information.
[0090] For example, when the consistency state is the state in the MESI protocol, the weights of the consistency state include the weight of the dirty state, the weight of the exclusive state, and the weight of the shared state. The process of determining the retention value of the current candidate block according to the weights of each consistency state, the weights of the shared quantity exceeding the threshold, the weights of the shared quantity not exceeding the threshold, and the consistency state and shared state information in the eviction cache information may include: by V = w M *M + w E *E + w S *S + w AT *AT + w BT *BT, determine the retention value of the current candidate block; where V is the retention value, w M 、w E and w S are the weights of the dirty state, the weight of the exclusive state, and the weight of the shared state respectively; M, E, and S are the shared quantities corresponding to the shared state information in the eviction cache information when the consistency state in the eviction cache information is in the modified state, the exclusive state, and the shared state respectively; w AT and w BTThey are the weight when the shared quantity exceeds the threshold and the weight when the shared quantity does not exceed the threshold respectively; AT is 1 when the shared quantity exceeds the quantity threshold and 0 when the shared quantity does not exceed the quantity threshold; BT is 1 when the shared quantity does not exceed the quantity threshold and 0 when the shared quantity exceeds the quantity threshold. That is to say, M is the corresponding shared quantity when the coherence state in the eviction cache information is in the modified state, and 0 when the coherence state in the eviction cache information is not in the modified state; E is the corresponding shared quantity when the coherence state in the eviction cache information is in the exclusive state, and 0 when the coherence state in the eviction cache information is not in the exclusive state; S is the corresponding shared quantity when the coherence state in the eviction cache information is in the shared state, and 0 when the coherence state in the eviction cache information is not in the shared state.
[0091] Correspondingly, when the coherence state is the state in the CHI protocol, the coherence state weights can also include the dirty state weight, the exclusive state weight, and the shared state weight; the UD state in the CHI protocol can be used as the above M state, the UC state in the CHI protocol can be used as the above M state, and the SD and SC states in the CHI protocol can be used as the S state. Thus, a formula similar to the formula for determining the reserved value in the above MESI protocol is used for corresponding setting, and this embodiment does not make any restrictions on this.
[0092] Furthermore, in order to ensure the accuracy of the reserved value determination and avoid invalid calculation processes, in this embodiment, before step 102, the cache controller can determine whether the number of cache entries in the eviction history information set meets the requirements; if it meets the requirements, step 102 is entered; if it does not meet the requirements, the current candidate block is evicted from the target cache area, and a cache entry corresponding to the eviction cache information is added to the eviction history information set. That is to say, when the number of cache entries in the eviction history information set is too small, the reserved value of the current candidate block determined using the eviction history information set is not accurate enough. Therefore, a candidate block selected by the cache replacement algorithm can be directly evicted to replace the corresponding data.
[0093] Correspondingly, the process of determining whether the number of cache entries in the eviction history information set meets the requirements can include: determining whether the number of cache entries in the eviction history information set (such as the eviction history table) reaches a preset evaluation quantity; if it reaches the preset evaluation quantity, it is determined that the requirements are met, and the step of determining the reserved value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set can be executed; if it does not reach the preset evaluation quantity, it is determined that the requirements are not met, and the step of evicting the current candidate block from the target cache area and adding a cache entry corresponding to the eviction cache information to the eviction history information set can be executed.
[0094] Among them, the specific value of the preset evaluation quantity is not limited in this embodiment. For example, the preset evaluation quantity can be the preset full-write quantity, that is, the maximum number of cache entries that can be stored in the eviction history information set (such as the eviction history table); such as Figure 4 As shown, when accessing the cache, it can first be determined whether the eviction history table is full; if the eviction history table is not full, the LRU cache replacement algorithm in the related technology is followed for cache replacement; if the eviction history table is full, a candidate block is selected for replacement according to the LRU cache replacement algorithm in the related technology; and before the cache controller decides whether the candidate block is to be replaced, the retention value of the candidate block is calculated according to the cache entry in the eviction history table using a value function (such as the above-mentioned retention value determination formula) to determine whether it should be replaced; if the retention value of the candidate block is relatively high, the candidate block can be retained to give it a second chance, and according to the LRU cache replacement algorithm, the next candidate block is selected; if the value of the subsequently selected candidate block is relatively low, the cache controller can perform a replacement operation, remove the candidate block from the cache, and record the corresponding cache entry in the eviction history table.
[0095] Step 103: Determine whether to retain the current candidate block according to the retention value and the value threshold; if so, proceed to step 104.
[0096] It can be understood that in this step, the cache controller can determine whether to retain the current candidate block according to the retention value and the value threshold of the current candidate block, that is, determine whether the current candidate block should be replaced; thus, when the retention value of the current candidate block is relatively high, by retaining the current candidate block, a second chance is given to the current candidate block to retain the buffer block with a relatively high probability of future re-access, improving the cache hit rate.
[0097] Correspondingly, for the specific manner of determining whether to retain the current candidate block according to the retention value and the value threshold in this step, it can be set by the designer. For example, the cache controller can determine whether the retention value is greater than the value threshold; if it is greater than the value threshold, it is determined to retain the current candidate block and proceed to step 104; if it is not greater than the value threshold, it is determined not to retain the current candidate block and proceed to step 105. In some other embodiments, the cache controller can also determine whether the retention value is less than the value threshold; if it is less than the value threshold, it is determined to retain the current candidate block; if it is not less than the value threshold, it is determined not to retain the current candidate block. This embodiment does not impose any restrictions on this.
[0098] Correspondingly, for the specific value of the value threshold in this embodiment, it can be set by the designer himself. For example, the value threshold can be a fixed value set in advance; the value threshold can also be a value that can be adaptively adjusted. For example, the value threshold can be a value determined according to the retention value of each cache entry in the eviction history information set. For example, the value threshold can be the minimum retention value or the average retention value of the retention values of all cache entries in the eviction history information set.
[0099] Step 104: Obtain the eviction cache information of the next candidate block in the target cache area, and use the next candidate block as the current candidate block, then go to Step 102.
[0100] It can be understood that the next candidate block in this step can be the next cache data to be evicted selected by the cache replacement algorithm. In this step, when the cache controller determines that the current candidate block needs to be retained, it can retain the current candidate block in the target cache area, and use the next candidate block (i.e., the next candidate block) selected by the cache replacement algorithm (such as the LRU algorithm) as the current candidate block, return to Step 102 to calculate the retention value of the new current candidate block, so as to continue to determine whether the new current candidate block needs to be retained until a current candidate block that does not need to be retained is determined.
[0101] Correspondingly, in this step, the cache controller can also count the number of times the candidate block is selected in this cache access. When the number of selections does not reach the number threshold, continue the process of obtaining the eviction cache information of the next candidate block in the target cache area, using the next candidate block as the current candidate block, and going to Step 102; if the number of selections reaches the number threshold, it can directly enter Step 105 to avoid problems such as value evaluation errors and too long cache replacement time.
[0102] Further, as Figure 2 shown, in this embodiment, dynamic adjustment of weights can be achieved based on reinforcement learning, so as to adaptively learn how to take the best actions in different states to obtain the maximum cumulative reward through the interaction of the reward signal between the cache controller (agent) and the eviction history information set (environment). As Figure 5 shown, the reward signal can be feedback according to whether the access cache address in the cache access request hits the address information of the cache entry in the eviction history information set (eviction history table); if there is a hit cache entry in the eviction history information set, a negative reward signal is given, indicating that the current decision is not good and the weight needs to be adjusted; if there is no hit cache entry, a positive reward is given, indicating that the past eviction decision is effective, and the weight can be further optimized and adjusted, so as to dynamically adjust the cache replacement policy to adapt to different computing scenarios.
[0103] For example, in some embodiments, the method provided in this embodiment may further include checking whether the obtained cache access request hits a cache entry in the eviction history information set; if it hits a cache entry in the eviction history information set, the hit cache entry is deleted from the eviction history information set, so as to feedback a negative reward signal by deleting the hit cache entry in the eviction history information set, thereby being able to adjust weights (such as the above-mentioned various consistency state weights, shared quantity exceeding threshold weights, and shared quantity not exceeding threshold weights) or directly evict the current candidate block in the current cache replacement.
[0104] Correspondingly, in some embodiments, before entering step 102 with the next candidate block as the current candidate block in this step, when the cache access request does not hit a cache entry in the eviction history information set, the various consistency state weights, shared quantity exceeding threshold weights, and shared quantity not exceeding threshold weights corresponding to the eviction history information set may be updated according to the eviction cache information of the current candidate block; among them, the updated consistency state weight corresponding to the consistency state in the eviction cache information is greater than the consistency state weight before the update; the updated target shared state weight corresponding to the shared state information in the eviction cache information is greater than the target shared state weight before the update; the target shared state weight is the shared quantity exceeding threshold weight or the shared quantity not exceeding threshold weight corresponding to the shared state information of the eviction cache information.
[0105] For example, the process of updating the various consistency state weights, shared quantity exceeding threshold weights, and shared quantity not exceeding threshold weights corresponding to the eviction history information set according to the eviction cache information of the current candidate block may include: calculating the sum of the target consistency state weight and the first learning rate to obtain the updated target consistency state weight; where the target consistency state weight is the consistency state weight corresponding to the consistency state of the eviction cache information; normalizing the updated target consistency state weight and other consistency state weights to obtain the updated various consistency state weights; where the sum of the updated various consistency state weights is 1; calculating the sum of the target shared state weight and the second learning rate to obtain the updated target shared state weight; where the target shared state weight is the shared quantity exceeding threshold weight or the shared quantity not exceeding threshold weight corresponding to the shared state information of the eviction cache information; normalizing the updated target shared state weight and another shared state weight to obtain the updated shared quantity exceeding threshold weights and shared quantity not exceeding threshold weights; where the sum of the updated shared quantity exceeding threshold weights and shared quantity not exceeding threshold weights is 1.
[0106] Correspondingly, the above-mentioned first learning rate and second learning rate may be preset fixed values; or may be values adaptively adjusted according to the number of update times, such as may decrease correspondingly as the number of weight updates increases, and this embodiment does not make any restrictions on this.
[0107] For example, as Figure 6 shown, when the cache controller obtains a cache access request, it can separately check whether the cache of the processor and the eviction history table are hit; if the cache is hit, the cache access is completed using the hit cache block (i.e., cache data); if the cache is not hit, the cache block in the target cache area will be evicted, a new cache block is replaced and written, and the cache entry of the evicted cache block is written into the eviction history table; if the address of the cache access request hits the cache entry hit in the eviction history table, the corresponding cache entry in the eviction history table is deleted; if the eviction history table is not hit during cache access, the cache entry corresponding to the buffer block evicted this time is written into the eviction history table.
[0108] That is to say, in the case of the above cache miss, if the cache entry in the eviction history table is hit, the current candidate block selected by the cache replacement algorithm can be directly used as the buffer block evicted this time to complete the cache replacement of the current cache access request, as Figure 4 shown, the calculation of the retention value of the current candidate block is only performed when the eviction history table is full; it is also possible to enter step 101 to obtain the eviction cache information of the current candidate block to calculate the retention value of the current candidate block so as to determine the buffer block finally evicted this time and complete the cache replacement of the current cache access request, that is, the above preset evaluation quantity can be less than the preset full write quantity.
[0109] Correspondingly, in the case of a cache miss, if the cache entry in the eviction history table is not hit, step 101 can be entered to obtain the eviction cache information of the current candidate block to calculate the retention value of the current candidate block so as to determine the buffer block finally evicted this time. And when the current candidate block needs to be retained, before selecting the next candidate block as the new current candidate block and calculating the retention value of the new current candidate block, the eviction cache information of the retained current candidate block can be used to further update the weight, so as to calculate the retention value of the new current candidate block using the updated weight and implement an intelligent cache management strategy.
[0110] For example, there are 4 processor cores in the processor, and the quantity threshold is 2, as Figure 3 shown in the eviction history table storing 10 cache entries. If the cache access request does not hit the eviction history table, the initial weights can be: w M = 2∕10 = 0.2, w E = 2∕10 = 0.2, w S = 6∕10 = 0.6, w AT = 4∕10 = 0.4, w BT=6∕10 = 0.6; Assume a cache miss occurs. If the coherence state of the current candidate block selected by the cache replacement algorithm is the S state and the sharer vector bits are 0110, its retention value can be: V(S) = 0.2*0 + 0.2*0 + 0.6*2 + 0.4*0 + 0.6*1 = 1.8; If the value threshold is 1.5, the retention value of the current candidate block is greater than the value threshold, so the current candidate block can be retained. Then use the cache replacement algorithm to select the next candidate block and continue to calculate the retention value.
[0111] Correspondingly, before using the cache replacement algorithm to select the next candidate block and continue to calculate the retention value, the weights can be updated using the current candidate block. For example, if the first learning rate and the second learning rate are both 1, w S_new = 0.6 + 0.1 = 0.7. After normalizing with w E and w M the updated w M = 0.18, w E = 0.18, w S = 0.64; w BT_new = 0.6 + 0.1 = 0.7. After normalizing with w AT the updated w AT = 0.36, w BT = 0.64; Then use the updated weights to calculate the retention value of the next candidate block to implement an intelligent cache management strategy.
[0112] Among them, in this embodiment, the specific order of checking whether the cache access request hits the processor's cache and whether it hits the eviction history table is not limited. It can be as Figure 6 shown. After obtaining the cache access request, check whether it hits the processor's cache and whether it hits the eviction history table in parallel; or first check whether it hits the processor's cache, and if it misses the cache, then check whether it hits the eviction history table.
[0113] Step 105: Evict the current candidate block from the target cache area and store the cache entry corresponding to the eviction cache information in the eviction history information set.
[0114] It can be understood that in this step, when the cache controller determines that the current candidate block does not need to be retained, it can evict the current candidate block from the target cache area to replace the corresponding data; and store the cache entry corresponding to the current candidate block in the eviction history information set. For example, when the number of cache entries in the eviction history information set is less than the preset full write number (i.e., the eviction history information set is full), directly write the cache entry corresponding to the current candidate block into the eviction history information set; when the number of cache entries in the eviction history information set is the preset full write number, determine a target cache entry according to the storage time, miss time, and / or current retention value of each cache entry in the eviction history information set; replace the cache entry corresponding to the eviction cache information with the target cache entry.
[0115] Correspondingly, the specific method for determining a target cache entry according to the storage time, miss time, and / or current retention value of each cache entry in the eviction history information set can be set by the designer. For example, the cache controller can directly determine the cache entry with the longest miss time or the longest storage time as the target cache entry; as Figure 6 shown, when the eviction history table is full, the cache entry with the longest time of non-hit (i.e., the target cache entry) can be evicted from the eviction history table to replace the cache entry corresponding to the current candidate block that does not need to be retained. The cache controller can also determine the cache entry with the lowest current corresponding retention value (i.e., the current retention value) as the target cache entry. This embodiment does not make any restrictions on this.
[0116] In this embodiment, the embodiment of the present invention can utilize the consistency state and shared state information of the evicted cache blocks in the eviction history information set to determine the retention value of the current candidate block selected by the cache replacement algorithm, so as to judge whether the current candidate block may be accessed again in the future, thereby optimizing the cache replacement algorithm in the multi-core processor, improving the self-adaptability of the cache replacement policy and the cache hit rate, and reducing the performance loss caused by cache misses; and since the specific cache block data does not need to be stored in the eviction history information set, compared with the method of increasing the cache capacity to improve the cache hit rate, the hardware overhead is smaller.
[0117] Corresponding to the above method embodiment, the embodiment of the present invention also provides a cache control device. A cache control device described below can be correspondingly referred to the above-described cache control method.
[0118] Please refer to Figure 7 , Figure 7 which is a structural block diagram of a cache control device provided by an embodiment of the present invention. The device is applied to the cache controller of the processor and may include:
[0119] An acquisition module 10 is configured to acquire eviction cache information of a current candidate block in a target cache area; wherein, the current candidate block is a cache data to be evicted selected by a cache replacement algorithm, and the eviction cache information includes a consistency state and shared state information;
[0120] A determination module 20 is configured to determine the retention value of the current candidate block according to the eviction cache information and cache entries in an eviction history information set; wherein, the cache entries include the consistency state and shared state information of the evicted cache data;
[0121] A judgment module 30 is configured to judge whether to retain the current candidate block according to the retention value and a value threshold;
[0122] A retention module 40 is configured to, if the current candidate block is to be retained, acquire eviction cache information of the next candidate block in the target cache area, use the next candidate block as the current candidate block, and send a start signal to the determination module;
[0123] An eviction module 50 is configured to, if the current candidate block is not to be retained, evict the current candidate block from the target cache area and store the cache entry corresponding to the eviction cache information in the eviction history information set.
[0124] In some embodiments, the determination module 20 may include:
[0125] A weight determination sub-module is configured to determine each consistency state weight, shared quantity over-threshold weight, and shared quantity non-over-threshold weight according to each cache entry in the eviction history information set;
[0126] A value determination sub-module is configured to determine the retention value of the current candidate block according to each consistency state weight, shared quantity over-threshold weight, shared quantity non-over-threshold weight, and the consistency state and shared state information in the eviction cache information.
[0127] In some embodiments, the consistency state is a state in a modified-exclusive-shared-invalidated protocol, and the consistency state weights include a dirty state weight, an exclusive state weight, and a shared state weight;
[0128] The value determination sub-module may specifically be configured to determine the retention value of the current candidate block through V = w M *M + w E *E + w S *S + w AT *AT + w BT *BT, where V is the retention value, w M 、w E and w SThey are the dirty state weight, the exclusive state weight, and the shared state weight respectively; M, E, and S are the shared quantities corresponding to the shared state information in the eviction cache information when the coherence states in the eviction cache information are in the modified state, exclusive state, and shared state respectively; w AT and w BT They are the shared quantity exceeding threshold weight and the shared quantity not exceeding threshold weight respectively; AT is 1 when the shared quantity exceeds the quantity threshold, and 0 when the shared quantity does not exceed the quantity threshold; BT is 1 when the shared quantity does not exceed the quantity threshold, and 0 when the shared quantity exceeds the quantity threshold.
[0129] In some embodiments, the weight determination sub-module may include:
[0130] The first determination unit is configured to determine the weight of each coherence state according to the number of cache entries in the eviction history information set and the coherence state of each cache entry;
[0131] The second determination unit is configured to determine the shared quantity exceeding threshold weight and the shared quantity not exceeding threshold weight according to the number of cache entries in the eviction history information set, the first quantity, and the second quantity; wherein, the first quantity is the number of cache entries whose shared quantity corresponding to the shared state information exceeds the quantity threshold, and the second quantity is the number of cache entries whose shared quantity corresponding to the shared state information does not exceed the quantity threshold.
[0132] In some embodiments, the apparatus may further include:
[0133] The entry judgment module is configured to judge whether the number of cache entries in the eviction history information set meets the requirements; if it meets the requirements, a start signal is sent to the determination module 20;
[0134] The direct eviction module is configured to, if it does not meet the requirements, evict the current candidate block from the target cache area and add the cache entry corresponding to the eviction cache information to the eviction history information set.
[0135] In some embodiments, the eviction history information set is an eviction history table, and the entry judgment module is specifically configured to judge whether the number of cache entries in the eviction history table reaches a preset evaluation number; if it reaches the preset evaluation number, a start signal is sent to the determination module 20; if it does not reach the preset evaluation number, a start signal is sent to the direct eviction module.
[0136] In some embodiments, the eviction module 50 may include:
[0137] The replacement determination sub-module is configured to, if the number of cache entries in the eviction history information set is a preset full write number, determine a target cache entry according to the storage time, miss time, and / or current retention value of each cache entry in the eviction history information set;
[0138] An eviction sub-module, configured to replace a target cache entry with a cache entry corresponding to eviction cache information.
[0139] In some embodiments, the replacement determination sub-module may be specifically configured to determine, as the target cache entry, the cache entry with the longest miss time in the eviction history information set.
[0140] In some embodiments, the cache entry further includes address information, threshold comparison information, and a valid bit; the shared status information in the cache entry is a sharer vector bit, and the threshold comparison information is used to indicate whether the number of sharers corresponding to the sharer vector bit exceeds a quantity threshold.
[0141] In some embodiments, the cache replacement algorithm is the Least Recently Used (LRU) algorithm.
[0142] In some embodiments, the processor employs a cache architecture with at least two levels, and the target cache area includes the bottom-level cache of the cache architecture.
[0143] In some embodiments, the determination module 20 may be specifically configured to determine whether the retention value is greater than a value threshold; if it is greater than the value threshold, it is determined to retain the current candidate block and send a start signal to the retention module 40; if it is not greater than the value threshold, it is determined not to retain the current candidate block and send a start signal to the eviction module 50.
[0144] In some embodiments, the acquisition module 10 may include:
[0145] An access acquisition sub-module, configured to acquire a cache access request;
[0146] A cache check sub-module, configured to check whether the cache access request hits the cache data in the processor's cache;
[0147] A replacement selection sub-module, configured to, if there is a miss, use the cache replacement algorithm to determine a current candidate block in the target cache area and acquire the eviction cache information of the current candidate block.
[0148] In some embodiments, the apparatus may further include:
[0149] An entry check module, configured to check whether the acquired cache access request hits a cache entry in the eviction history information set;
[0150] A negative reward module, configured to, if a cache entry in the eviction history information set is hit, delete the hit cache entry from the eviction history information set.
[0151] In some embodiments, the retention module 40 may include:
[0152] The positive reward sub-module is used to update the respective consistency state weights, shared quantity over-threshold weights, and shared quantity non-over-threshold weights corresponding to the eviction history information set according to the eviction cache information before the step of taking the next candidate block as the current candidate block and determining the retention value of the current candidate block based on the cache entries in the eviction cache information and the eviction history information set, if the cache access request misses the cache entries in the eviction history information set.
[0153] In some embodiments, the positive reward sub-module may include:
[0154] A first calculation unit for calculating the sum of the target consistency state weight and the first learning rate to obtain the updated target consistency state weight; wherein, the target consistency state weight is the consistency state weight corresponding to the consistency state of the eviction cache information.
[0155] A first update unit for normalizing the updated target consistency state weight and the other consistency state weights to obtain the updated respective consistency state weights; wherein, the sum of the updated respective consistency state weights is 1.
[0156] A second calculation unit for calculating the sum of the target shared state weight and the second learning rate to obtain the updated target shared state weight; wherein, the target shared state weight is the shared quantity over-threshold weight or the shared quantity non-over-threshold weight corresponding to the shared state information of the eviction cache information.
[0157] A second update unit for normalizing the updated target shared state weight and the other shared state weight to obtain the updated shared quantity over-threshold weight and the shared quantity non-over-threshold weight; wherein, the sum of the updated shared quantity over-threshold weight and the shared quantity non-over-threshold weight is 1.
[0158] In this embodiment, the embodiment of the present invention can determine the retention value of the current candidate block selected by the cache replacement algorithm by using the consistency state and shared state information of the evicted cache blocks in the eviction history information set through the determination module 20, so as to judge whether the current candidate block may be accessed again in the future, thereby optimizing the cache replacement algorithm in the multi-core processor, improving the self-adaptability of the cache replacement policy and the cache hit rate, and reducing the performance loss caused by cache misses; and since the specific cache block data does not need to be stored in the eviction history information set, compared with the way of increasing the cache capacity to improve the cache hit rate, the hardware overhead is smaller.
[0159] Corresponding to the above method embodiment, the embodiment of the present invention also provides a processor, and a processor described below can be correspondingly referred to with a cache control method described above.
[0160] Please refer to Figure 8 ,Figure 8 A schematic structural diagram of a processor provided by an embodiment of the present invention. The processor may include:
[0161] A memory D1 for storing computer programs;
[0162] A cache controller D2 for implementing the steps of the cache control method provided by the above method embodiment when executing the computer program.
[0163] Among them, the processor provided by this embodiment may specifically be a central processing unit (CPU), or may specifically be other types of processors, such as a graphics processing unit (GPU).
[0164] Corresponding to the above method embodiment, an embodiment of the present invention also provides a computer program product. A computer program product described below can be correspondingly referred to with a cache control method described above.
[0165] A computer program product includes computer programs / instructions. When the computer programs / instructions are executed by a processor, the steps of the cache control method provided by the above method embodiment are implemented.
[0166] Corresponding to the above method embodiment, an embodiment of the present invention also provides a computer-readable storage medium. A computer-readable storage medium described below can be correspondingly referred to with a cache control method described above.
[0167] A computer-readable storage medium has a computer program stored thereon. When the computer program is executed by a processor, the steps of the cache control method of the above method embodiment are implemented.
[0168] The computer-readable storage medium may specifically be various readable storage media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc that can store program codes.
[0169] The embodiments in the specification are described in a progressive manner. The key points of each embodiment are the differences from other embodiments. The same or similar parts among the embodiments can be referred to each other. For the devices, processors, computer program products, and computer-readable storage media disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the description of the method part.
[0170] The above has introduced in detail a cache control method, device, program product, processor and storage medium provided by the present invention. Specific examples are used in this article to elaborate on the principle and implementation manner of the present invention. The description of the above embodiments is only used to help understand the method and its core idea of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the protection scope of the present invention.
Claims
1. A cache control method, characterized in that: Cache controller for processors, including: Obtaining eviction cache information of a current candidate block in a target cache area; wherein the current candidate block is a cache data to be evicted selected by a cache replacement algorithm, and the eviction cache information includes consistency state and sharing state information; Determining the retention value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set; wherein the cache entries include the consistency state and sharing state information of the evicted cache data; Determining whether to retain the current candidate block according to the retention value and the value threshold; If yes, obtaining the eviction cache information of the next candidate block in the target cache area, taking the next candidate block as the current candidate block, and executing the step of determining the retention value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set; If not, the current candidate block is evicted from the target cache area, and a cache entry corresponding to the evicted cache information is stored in the evicted history information set.
2. The cache control method according to claim 1, characterized in that: Determining the retention value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set includes: Determine, according to each cache entry in the eviction history information set, each consistency state weight, each sharing quantity exceeding a threshold weight, and each sharing quantity not exceeding a threshold weight; The retention value of the current candidate block is determined according to the consistency state weight, the sharing quantity exceeding the threshold weight, the sharing quantity not exceeding the threshold weight, and the consistency state and sharing state information in the eviction cache information.
3. The cache control method according to claim 2, characterized in that: The consistency state is a state in the modified-exclusive-shared-invalidated protocol, and the consistency state weight includes a dirty state weight, an exclusive state weight, and a shared state weight; according to each of the consistency state weights, the shared quantity exceeding a threshold weight, the shared quantity not exceeding a threshold weight, and the consistency state and shared state information in the eviction cache information, determining the retention value of the current candidate block, including: By V=w M *M+w E *E+w S *S+w AT *AT+w BT *BT, determine the retention value of the current candidate block; where V is the retention value, w M 、w E and w S are the dirty state weight, the exclusive state weight and the shared state weight respectively; M, E and S are the shared quantities corresponding to the shared state information in the eviction cache information when the consistency state in the eviction cache information is in the modified state, the exclusive state and the shared state respectively; w AT and w BT They are respectively the weight of the shared quantity exceeding the threshold value and the weight of the shared quantity not exceeding the threshold value; AT is 1 when the shared quantity exceeds the quantity threshold value, and is 0 when the shared quantity does not exceed the quantity threshold value; BT is 1 when the shared quantity does not exceed the quantity threshold value, and is 0 when the shared quantity exceeds the quantity threshold value.
4. The cache control method according to claim 2, characterized in that: Determining, according to each cache entry in the eviction history information set, each consistency state weight, each sharing quantity exceeding a threshold weight, and each sharing quantity not exceeding a threshold weight, including: Determining a weight of each consistency state according to the number of cache entries in the eviction history information set and the consistency state of each cache entry; Determine the weight of the shared quantity exceeding the threshold value and the weight of the shared quantity not exceeding the threshold value according to the number of cache entries in the eviction history information set, the first number, and the second number; wherein the first number is the number of cache entries whose shared quantity corresponding to the shared status information exceeds the quantity threshold, and the second number is the number of cache entries whose shared quantity corresponding to the shared status information does not exceed the quantity threshold.
5. The cache control method according to claim 1, characterized in that: Before determining the retention value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set, the method further includes: Determining whether the number of cache entries in the eviction history information set meets the requirement; If the requirements are met, the step of determining the retention value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set is performed; If it does not meet the requirements, the current candidate block is evicted from the target cache area, and a cache entry corresponding to the evicted cache information is added to the evicted history information set.
6. The cache control method according to claim 5, characterized in that: The eviction history information set is an eviction history table, and judging whether the number of cache entries in the eviction history information set meets the requirement includes: Determining whether the number of cache entries in the eviction history table reaches a preset evaluation number; If the preset evaluation number is reached, the step of determining the retention value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set is performed; If the preset evaluation quantity is not reached, the step of evicting the current candidate block from the target cache area and adding a cache entry corresponding to the evicted cache information to the evicted history information set is performed.
7. The cache control method according to claim 1, characterized in that: Storing the cache entry corresponding to the eviction cache information in the eviction history information set includes: If the number of cache entries in the eviction history information set is a preset full number, determining a target cache entry according to the storage time, miss time and / or current retention value of each cache entry in the eviction history information set; The target cache entry is replaced by the cache entry corresponding to the eviction cache information.
8. The cache control method according to claim 7, characterized in that: Determining a target cache entry according to the storage time, miss time and / or current retention value of each cache entry in the eviction history information set includes: The cache entry with the longest miss time in the eviction history information set is determined as the target cache entry.
9. The cache control method according to claim 1, characterized in that: The cache entry also includes address information, threshold comparison information and a valid bit; the sharing status information in the cache entry is a sharer vector bit, and the threshold comparison information is used to indicate whether the sharing quantity corresponding to the sharer vector bit exceeds a quantity threshold.
10. The cache control method according to claim 1, characterized in that: The cache replacement algorithm is a least recently used algorithm.
11. The cache control method according to claim 1, characterized in that: The processor adopts a cache architecture of at least two layers, and the target cache area includes a bottom layer cache of the cache architecture.
12. The cache control method according to claim 1, characterized in that: According to the retention value and the value threshold, determining whether to retain the current candidate block includes: determining whether the retention value is greater than the value threshold; If it is greater than the value threshold, it is determined to retain the current candidate block; If it is not greater than the value threshold, it is determined not to retain the current candidate block.
13. The cache control method according to claim 1, characterized in that: Get the eviction cache information of the current candidate block in the target cache, including: Get cache access request; Checking whether the cache access request hits cache data in the cache of the processor; If there is a miss, the cache replacement algorithm is used to determine the current candidate block in the target cache area, and obtain the eviction cache information of the current candidate block.
14. The cache control method according to any one of claims 1 to 13, characterized in that: Also includes: Checking whether the obtained cache access request hits a cache entry in the eviction history information set; If a cache entry in the eviction history information set is hit, the hit cache entry is deleted from the eviction history information set.
15. The cache control method according to claim 14, characterized in that: Before taking the next candidate block as the current candidate block and executing the step of determining the retention value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set, the method further includes: If the cache access request does not hit a cache entry in the eviction history information set, the consistency state weights, the sharing quantity exceeding threshold weights and the sharing quantity not exceeding threshold weights corresponding to the eviction history information set are updated according to the eviction cache information.
16. The cache control method according to claim 15, characterized in that: According to the eviction cache information, the consistency state weights, the weights of the number of shares exceeding the threshold, and the weights of the number of shares not exceeding the threshold corresponding to the eviction history information set are updated, including: Calculate the sum of the target consistency state weight and the first learning rate to obtain an updated target consistency state weight; wherein the target consistency state weight is the consistency state weight corresponding to the consistency state of the eviction cache information; Normalize the updated target consistency state weight and other consistency state weights to obtain updated consistency state weights; wherein the sum of the updated consistency state weights is 1; Calculate the sum of the target shared state weight and the second learning rate to obtain an updated target shared state weight; wherein the target shared state weight is a shared quantity exceeding a threshold weight or a shared quantity not exceeding a threshold weight corresponding to the shared state information of the eviction cache information; The updated target sharing state weight and another sharing state weight are normalized to obtain the updated sharing quantity exceeding threshold weight and the sharing quantity not exceeding threshold weight; wherein the sum of the updated sharing quantity exceeding threshold weight and the sharing quantity not exceeding threshold weight is 1.
17. A cache control device, characterized in that: Cache controller for processors, including: An acquisition module is used to acquire eviction cache information of a current candidate block in a target cache area; wherein the current candidate block is a cache data to be evicted selected by a cache replacement algorithm, and the eviction cache information includes consistency state and sharing state information; A determination module, configured to determine the retention value of the current candidate block according to the eviction cache information and the cache entries in the eviction history information set; wherein the cache entries include the consistency state and sharing state information of the evicted cache data; A judgment module, used for judging whether to retain the current candidate block according to the retention value and the value threshold; A retaining module, configured to obtain eviction cache information of a next candidate block in the target cache area if the current candidate block is retained, and use the next candidate block as the current candidate block, and send a start signal to the determining module; The eviction module is used to evict the current candidate block from the target cache area if the current candidate block is not retained, and store the cache entry corresponding to the eviction cache information in the eviction history information set.
18. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the steps of the cache control method according to any one of claims 1 to 16 are implemented.
19. A processor, characterized in that: include: Memory for storing computer programs; A cache controller, configured to implement the steps of the cache control method according to any one of claims 1 to 16 when executing the computer program.
20. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the cache control method according to any one of claims 1 to 16 are implemented.
Citation Information
Patent Citations
Delay cache replacement method and device, equipment, storage medium and product
CN119276939A
Cache entry replacement
US20170337133A1