Cache, cache pollution monitoring method and chip
By introducing a cache pollution monitor and processing logic circuit into the cache to monitor and adjust data prefetching in real time, the problem of cache pollution caused by data prefetching is solved and the data access efficiency of the processor is improved.
Patent Information
- Application Number
- CN202410774129.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-14
- Publication Date
- 2024-09-17
AI Technical Summary
Data prefetching may cause cache pollution, causing cache misses when the processor subsequently accesses useful data, affecting the processor's data access efficiency.
Design a cache, including a cache pollution monitor and a cache processing logic circuit, to regulate data prefetching and reduce cache pollution caused by data prefetching by monitoring the address mapping position of the cache line in real time, setting a target value and increasing the cache pollution count. .
It achieves precise control of data prefetching, reduces cache pollution, and improves the data access efficiency of the processor.
Smart Images

Figure CN118656311A
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a cache, a cache pollution monitoring method, and a chip. Background Art
[0002] Cache is a storage device between the processor and the memory. A relatively small number of storage units in the cache can map a relatively large number of storage units in the memory, thereby accelerating the processor's data access efficiency. Data prefetching can predict the data that may be accessed in the future by predicting the processor and loading the data into the cache in advance to improve the processor's fast access to data.
[0003] However, data prefetching may cause cache pollution, that is, there may be useful data in the cache that the processor needs to access, and the data prefetched into the cache may evict the useful data from the cache, causing the processor to miss the cache when accessing the useful data subsequently, causing the processor to need to load the useful data from the memory again, affecting the data access efficiency of the processor.
[0004] Based on the situation of cache pollution, how to provide a technical solution to make it possible to improve the data access efficiency of the processor has become a technical problem that technical personnel in this field urgently need to solve. Summary of the invention
[0005] In view of this, embodiments of the present application provide a cache, a cache pollution monitoring method and a chip to improve the data access efficiency of the processor.
[0006] To solve the above problems, the embodiments of the present application provide the following technical solutions.
[0007] In a first aspect, an embodiment of the present application provides a cache, including: a cache pollution monitor and a cache processing logic circuit;
[0008] The cache pollution monitor includes a plurality of mapping locations, one mapping location being used to map addresses of a plurality of cache lines;
[0009] The cache processing logic circuit is used to set the mapping position of the address of the cache line to a target value when the cache line is evicted from the cache due to data prefetching; and when the memory access address of the memory access request does not hit the cache, if the mapping position mapped to the memory access address is the target value, increase the cache pollution count; wherein the cache pollution count is used to adjust data prefetching.
[0010] Optionally, there are multiple cache pollution monitors, one cache pollution monitor corresponds to one cache block, and one cache block includes multiple cache lines;
[0011] A mapping location of the cache pollution monitor is mapped to address hash values of multiple cache lines of the corresponding cache block.
[0012] Optionally, when a cache line is evicted from the cache due to data prefetching, setting a mapping position of an address-phase mapping of the cache line to a target value includes:
[0013] When data prefetching causes cache backfill, determine whether the replaced cache line comes from historical data prefetching;
[0014] If not, the mapping location mapped to the address of the replaced cache line is set to the target value.
[0015] Optionally, the cache line has a pre-fetch flag;
[0016] If the prefetch flag of the replaced cache line is invalid, it is determined that the replaced cache line does not come from data prefetch.
[0017] Optionally, when data prefetching causes cache backfill, the prefetch flag bit of the replaced cache line is set to valid.
[0018] Optionally, when cache backfill occurs on a cache line, if the replaced cache line is not caused by data prefetch, the prefetch flag of the replaced cache line is set to invalid.
[0019] Optionally, it also includes: a cache pollution counter, a pre-fetch counter and a cache pollution calculation unit;
[0020] The cache pollution counter is used to count the amount of cache pollution;
[0021] The pre-fetch counter is used to count the number of data pre-fetches;
[0022] The cache pollution calculation unit is used to determine the cache pollution situation according to the cache pollution quantity and the data pre-fetching times, and the cache pollution situation is used to adjust the data pre-fetching.
[0023] Optionally, the cache pollution situation includes a cache pollution ratio or a cache pollution level.
[0024] In a second aspect, an embodiment of the present application provides a cache pollution monitoring method, which is applied to the cache described in the first aspect above, and the method includes:
[0025] In response to a cache backfill request corresponding to the data prefetch, when a cache line is evicted from the cache due to the data prefetch, setting a mapping location to which an address of the cache line is mapped to a target value;
[0026] Get a memory access request. When the memory access address of the memory access request does not hit the cache, if the mapping location mapped to the memory access address is the target value, the cache pollution count will be increased.
[0027] The cache pollution count is used to adjust data prefetching, and the mapping position is used to map addresses of multiple cache lines.
[0028] Optionally, the mapping location is mapped to an address hash value of the cache line.
[0029] Optionally, when a cache line is evicted from the cache due to data prefetching, setting a mapping position of an address-phase mapping of the cache line to a target value includes:
[0030] When data prefetching causes cache backfill, determine whether the replaced cache line comes from historical data prefetching;
[0031] If not, the mapping location mapped to the address of the replaced cache line is set to the target value.
[0032] Optionally, the cache line has a pre-fetch flag;
[0033] If the prefetch flag of the replaced cache line is invalid, it is determined that the replaced cache line does not come from data prefetch.
[0034] Optionally, when data prefetching causes cache backfilling, for a cache line replaced into the cache, a prefetch flag bit of the replaced cache line is set to valid.
[0035] Optionally, when cache backfill occurs on a cache line, for the cache line replaced to the cache, if the replaced cache line is not caused by data prefetch, the prefetch flag bit of the replaced cache line is set to invalid.
[0036] Optionally, also include:
[0037] Determining the cache pollution amount according to the cache pollution count;
[0038] Counting requests corresponding to data prefetching to determine the number of data prefetching times;
[0039] A cache pollution situation is determined according to the cache pollution amount and the data pre-fetching times, and the cache pollution situation is used to adjust the data pre-fetching.
[0040] In a third aspect, an embodiment of the present application provides a chip, comprising at least the cache as described in the first aspect above.
[0041] The cache provided by the embodiment of the present application includes a cache pollution monitor and a cache processing logic circuit. When the cache pollution monitor includes multiple mapping positions, one mapping position is used to map the addresses of multiple cache lines, and the cache pollution monitor is used to monitor the cache lines in real time; when the cache line is evicted from the cache due to data prefetching, the cache processing logic circuit can set the mapping position mapped to the address of the cache line to a target value; and when the memory address of the memory access request does not hit the cache, if the mapping position mapped to the memory access address is the target value, the cache pollution count will be increased, wherein the cache pollution count is used to adjust data prefetching, so as to achieve precise control of data prefetching and reduce cache pollution caused by data prefetching, thereby improving the data access efficiency of the processor. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0043] Figure 1 is a schematic diagram of the structure of the chip system 100.
[0044] Figure 2 Schematic diagram of the optional internal structure of the cache provided in an embodiment of the present application.
[0045] Figure 3 It is another optional internal structure diagram of the cache provided in an embodiment of the present application.
[0046] Figure 4 It is an optional flow chart of the cache pollution monitoring method provided in the embodiment of the present application.
[0047] Figure 5 This is another optional flow chart of the cache pollution monitoring method provided in the embodiment of the present application. DETAILED DESCRIPTION
[0048] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions 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 are within the scope of protection of this application.
[0049] Figure 1 The schematic diagram of the structure of the chip system 100 is shown as an example. Figure 1As shown, the chip system 100 may include: a processor 110; a cache 120 and a memory 130 arranged outside the processor 110; wherein the cache 120 can exchange data with the memory 130 through a memory controller (not shown in the figure). It should be noted that although the structure of the chip system 100 only shows a processor, a cache and a memory, in the specific implementation process, the chip system may also include other components necessary for normal operation, which will not be expanded here. The chip system referred to in the embodiments of the present application may be, for example, an integrated circuit chip system such as a SOC (System on Chip).
[0050] The processor 110 is the computing and control core of the chip system, such as CPU (Central Processing Unit), GPU (Graphics Processing Unit), NPU (Embedded Neural Network Processor), TPU (Tensor Processing Unit), AI (Artificial Intelligence), etc.
[0051] Cache is a storage device with extremely fast access speed between the processor and the memory. A relatively small number of storage units in the cache can map a relatively large number of storage units in the memory, so that the processor can obtain data from the cache to realize data processing and accelerate data access efficiency. In addition, in order to further improve the processor's rapid access to data, the predictive processor can predict the data that may be accessed in the future and load the data into the cache in advance. This processing method is called data prefetching. Among them, the predictive processor can predict the data required later by monitoring the instructions or data requested in the executing program.
[0052] However, data prefetching may cause cache pollution. For example, there may be useful data in the cache that the processor needs to access, but due to data prefetching, the useful data in the cache is evicted and replaced with the prefetched data, resulting in a cache miss when the processor subsequently accesses the useful data, so that the processor needs to load the useful data from the memory again, reducing the data access efficiency of the processor.
[0053] Based on this, an embodiment of the present application provides an improved cache design scheme, in which the cache includes a cache pollution monitor and a cache processing logic circuit, and the cache pollution monitor includes multiple mapping positions, one mapping position is used to map the addresses of multiple cache lines, and the cache line is monitored in real time by the cache pollution monitor; when the cache line is evicted from the cache due to data prefetching, the cache processing logic circuit can set the mapping position mapped to the address of the cache line to a target value; and when the memory address of the memory access request does not hit the cache, if the mapping position mapped to the memory access address is the target value, the cache pollution count will be increased, wherein the cache pollution count is used to adjust data prefetching, so as to achieve precise control of data prefetching, reduce cache pollution caused by data prefetching, and thereby improve the data access efficiency of the processor.
[0054] Based on the above ideas, Figure 2 The following is an exemplary diagram of an optional internal structure of a cache provided in an embodiment of the present application. Figure 2 As shown, the cache may include: a cache pollution monitor 20 and a cache processing logic circuit 21 .
[0055] In an optional example, the cache pollution monitor 20 of the present application can be designed based on a Bloom filter. The cache pollution monitor 20 can include multiple mapping locations, one mapping location is used to map the addresses of multiple cache lines. Based on the mapping locations in the cache pollution monitor, the cache lines can be monitored in real time to determine the cache pollution caused by data prefetching.
[0056] It should be noted that, in the embodiment of the present application, the number of mapping positions in the cache pollution monitor is less than the number of cache lines, so that one mapping position can map the addresses of multiple cache lines. However, for the address of a cache line, the mapping position to which it is mapped can be accurately determined according to its characteristics (such as the address hash value of the cache line), so that the corresponding cache line information can be accurately found in the cache pollution monitor.
[0057] The cache processing logic circuit 21 is a mapping position of a cache pollution monitor set in the cache, and a processing logic circuit for performing cache pollution counts based on the mapping position. In an embodiment of the present application, the cache processing logic circuit 21 can set the mapping position mapped to the address of the cache line to a target value when the cache line is evicted from the cache due to data prefetching, and when the memory access address of the memory access request does not hit the cache, if the mapping position mapped to the memory access address is the target value, the cache pollution count will be increased. Among them, the cache pollution count can be used to adjust data prefetching, for example, based on the counted cache pollution amount, the number of data prefetches is adjusted to reduce cache pollution caused by data prefetching. As an optional implementation, at least one logic component can be set in the cache processing logic circuit 21 to process the mapping position of the cache pollution monitor and the cache pollution count.
[0058] As an optional main function of the cache processing logic circuit 21, the cache processing logic circuit 21 can be used to determine the cache lines corresponding to data prefetch and memory access requests, and load the cache lines into the cache, wherein the data prefetch can come from the prediction processor or automatic prediction program in the system, and the memory access request can come from the processor.
[0059] It should be noted that, in the embodiment of the present application, when the cache line is monitored in real time based on the mapping position in the cache pollution monitor, when the cache processing logic circuit sets the mapping position mapped to the address of the cache line to the target value when the cache line is evicted from the cache due to data prefetch, the target value of the mapping position can indicate that the cache line mapped by the mapping position is derived from the data prefetch. In other words, based on the value of the mapping position of the cache pollution monitor, the source of the address of the cache line mapped by the mapping position can be determined. Taking the value of the mapping position as 1 or 0 as an example, where 1 is used as the target value, if the value of the mapping position of the cache pollution monitor is 1, it means that the address of the cache line mapped by the mapping position is derived from the data prefetch; if the value of the mapping position of the cache pollution monitor is 0, it means that the address of the cache line mapped by the mapping position is not derived from the data prefetch, and may be derived from a memory access request, for example.
[0060] It should be further explained that when the access address of the memory access request is not hit in the cache, that is, a cache miss occurs in the cache, the cache processing logic circuit can search for the mapping position of the cache pollution monitor based on the access address. If the mapping position mapped to the access address is found in the cache pollution monitor, and the mapping position mapped to the access address is the target value, it can be determined that the access address is driven out of the cache due to the previous data prefetch (i.e., historical data prefetch), resulting in a cache miss. Based on this, the cache processing logic circuit can increase the cache pollution count accordingly and record the number of cache pollution caused by data prefetch. In addition, by counting the cache pollution, the data prefetch can be adjusted based on the counted cache pollution number. For example, when the counted cache pollution number is large, the data prefetch can be reduced, thereby reducing the situation of cache pollution caused by data prefetch. Moreover, based on reducing the data prefetch, the current bandwidth can be used for processing the memory access request, thereby reducing the bandwidth pressure; when the counted cache pollution number is small, the data prefetch can be increased accordingly, thereby improving the address coverage of the prefetched cache line.
[0061] It can be seen that the cache provided in the embodiment of the present application includes a cache pollution monitor and a cache processing logic circuit. When the cache pollution monitor includes multiple mapping positions, one mapping position is used to map the addresses of multiple cache lines, the cache pollution monitor is used to monitor the cache lines in real time; when the cache processing logic circuit can set the mapping position mapped to the address of the cache line to a target value when the cache line is evicted from the cache due to data prefetch; and when the memory address of the memory access request does not hit the cache, if the mapping position mapped to the memory access address is the target value, the cache pollution count will be increased, wherein the cache pollution count is used to adjust data prefetch, so as to achieve precise control of data prefetch and reduce cache pollution caused by data prefetch, thereby improving the data access efficiency of the processor.
[0062] In an optional example, in order to improve the data access speed, the cache can be divided into multiple cache blocks, so as to process multiple requested data in parallel. Among them, a cache block of the cache may include multiple cache lines. Based on the design that the cache has multiple cache blocks, the number of cache pollution monitors in the present application can be multiple, and one cache pollution monitor can correspond to one cache block. Moreover, in the case where the cache pollution monitor includes multiple mapping positions, a mapping position of the cache pollution monitor in the embodiment of the present application can be mapped to the address hash values of multiple cache lines of the corresponding cache block.
[0063] It should be noted that the cache pollution monitor corresponding to the cache block in the embodiment of the present application has a certain length, and the length can match the size of the cache block so as to accommodate the complete data. Based on the length of the cache pollution monitor, the width (number of bits) of the address hash value of the cache line mapped to the mapping position of the cache pollution monitor can be determined, so that the address hash value of the cache line can be used as an index to accurately locate the mapping position mapped to a specific cache line in the cache pollution monitor corresponding to the cache block. For example: a cache pollution monitor with a width of 32, since 32 is 2 to the sixth power, the corresponding hash function can be selected to perform a hash operation on the address of the cache line to obtain 6 bits of data, and the data is used as an index to find the corresponding mapping position in the cache pollution monitor.
[0064] In some embodiments, since the cache does not store all data, a cache miss may occur in the cache, that is, the data to be accessed does not hit (miss) in the cache. When a cache miss occurs, it is necessary to use the cache line in the memory to replace the cache line in the cache, and evict the cache line of the corresponding address in the cache. This behavior is called cache backfill. Among them, cache backfill can occur based on data prefetching or the execution of memory access request.
[0065] As an optional implementation, the cache line is evicted from the cache due to data prefetching, which may occur when the data prefetching causes the cache backfilling. When data prefetching causes the cache backfilling, it is possible to first determine whether the replaced cache line originates from the historical data prefetching, that is, determine whether the replaced cache line is loaded into the cache in advance due to the previous data prefetching. If the judgment result is no, it can be determined that the replaced cache line does not originate from the historical data prefetching. However, since the cache backfilling occurs due to data prefetching, the cache line is replaced, that is, the replaced cache line is replaced due to data prefetching, so when the address of the replaced cache line is mapped to the mapping position of the cache pollution monitor, the mapping position mapped to the address of the replaced cache line can be set to the target value.
[0066] It should be noted that when a cache line is evicted from the cache due to data prefetching, the address of the evicted cache line can be mapped to the mapping position of the cache pollution monitor, that is, when data prefetching causes cache backfilling, the address of the replaced cache line can be mapped to the cache pollution monitor. In the case where a mapping position of the cache pollution monitor is mapped to the address hash values of multiple cache lines of the corresponding cache block, a hash operation can be performed according to the address of the evicted cache line (i.e., the replaced cache line) to determine a hash value, and then determine its mapping position in the cache pollution monitor according to the hash value. In order to avoid the cache pollution monitor accumulating too many hash values and causing index errors, the cache pollution monitor can be refreshed and cleared periodically, wherein the refresh method of the cache pollution monitor can be set according to actual needs, and the embodiments of the present application do not limit this.
[0067] In some embodiments, in order to clearly indicate the address source of the cache line in the cache, the cache line may have a prefetch flag, and the validity or invalidity of the prefetch flag is used to indicate whether the cache line originates from data prefetch. In an optional example, if the prefetch flag of the replaced cache line is invalid, it is determined that the replaced cache line does not originate from data prefetch. The validity or invalidity of the prefetch flag can be represented by the value corresponding to the prefetch flag, for example, the prefetch flag is 1, indicating that it is valid, that is, the cache line originates from data prefetch; the prefetch flag is 0, indicating that it is invalid, that is, the cache line does not originate from data prefetch.
[0068] In an optional example, based on the prefetch flag of the cache line, when data prefetch causes cache backfill, the prefetch flag of the replaced cache line (ie, the backfilled cache line) may be set to valid to indicate that the replaced cache line originates from data prefetch.
[0069] In another optional example, when cache backfill occurs on a cache line, if the replaced cache line is not caused by data prefetch, such as a memory access request, the prefetch flag of the replaced cache line may be set to invalid.
[0070] In some embodiments, to implement the adjustment of data prefetching based on the cache pollution count, Figure 3 Another optional internal structure diagram of the cache in the embodiment of the present application is shown as an example. Figure 3 As shown, the cache may further include: a cache pollution counter 22 , a pre-fetch counter 23 and a cache pollution calculation unit 24 .
[0071] The cache pollution counter 22 may be controlled by the cache processing logic circuit 21 to count the amount of cache pollution.
[0072] The prefetch counter 23 may be used to count the number of data prefetches. In an optional example, the prefetch counter may be used to count the number of data prefetches by counting the number of data prefetch requests sent by the prediction processor in the current counting cycle. The counting cycle may be set according to a preset number of data prefetch requests, for example: the preset number of data prefetch requests is 10, if the value counted by the prefetch counter is 10, then the current counting cycle is completed and enters the next counting cycle. It should be noted that when the prefetch counter ends the counting executed in the current counting cycle, the cache pollution counter also ends the current counting task.
[0073] The cache pollution calculation unit 24 is used to determine the cache pollution situation according to the cache pollution amount counted by the cache pollution counter 22 and the number of data prefetches counted by the prefetch counter 23. The cache pollution situation is used to adjust data prefetching. It should be noted that after the calculation of the cache pollution calculation unit is completed, the cache pollution counter and the prefetch counter can be reset to perform the counting of the next counting cycle, so that the cache pollution calculation unit can calculate the cache pollution situation of the next cycle.
[0074] In an optional example, the cache pollution situation determined by the cache pollution calculation unit may include a cache pollution ratio or a cache pollution level. For example, the cache pollution calculation unit divides the cache pollution amount and the number of data prefetches to obtain a cache pollution ratio, and adjusts data prefetching based on the ratio. For another example, the cache pollution calculation unit determines the cache pollution level corresponding to the cache pollution ratio by looking up a table or the like based on the calculated cache pollution ratio, and then adjusts data prefetching based on the cache pollution level.
[0075] It should be noted that the adjustment of data prefetching based on the cache pollution situation can be implemented by the prefetch processor. For example, the cache pollution calculation unit sends the determined cache pollution situation to the prefetch processor, so that the prefetch processor can adjust the corresponding trigger strategy and the aggressiveness of training according to the cache pollution situation. For example, according to the Best Offset algorithm, when there are different cache pollution situations, the aggressiveness of training is adjusted by setting the maximum number of training rounds, so that when the cache pollution situation is serious, the number of data prefetching is appropriately reduced, and when the cache pollution situation is light, the number of data prefetching is appropriately increased.
[0076] It should be further explained that the above examples are only optional implementations of the cache contamination situation and the corresponding data prefetching adjustment in the embodiments of the present application. The cache contamination situation and the corresponding data prefetching adjustment in the embodiments of the present application may also have other methods, and the embodiments of the present application are not limited to this.
[0077] It can be seen that the cache of the embodiment of the present application includes a cache pollution monitor and a cache processing logic circuit. When the cache pollution monitor includes multiple mapping positions, one mapping position is used to map the addresses of multiple cache lines, and the cache pollution monitor is used to monitor the cache lines in real time; when the cache processing logic circuit can set the mapping position mapped to the address of the cache line to a target value when the cache line is evicted from the cache due to data prefetch; and when the memory address of the memory access request does not hit the cache, if the mapping position mapped to the memory access address is the target value, the cache pollution count will be increased, wherein the cache pollution count is used to adjust data prefetch, so as to achieve precise control of data prefetch and reduce cache pollution caused by data prefetch, thereby improving the data access efficiency of the processor.
[0078] To facilitate understanding of the cache of the embodiment of the present application, and the implementation of the cache pollution count for adjusting data prefetching in the cache, Figure 4 The optional flow chart of the cache pollution monitoring method provided in the embodiment of the present application is shown as an example, and the content of the cache pollution monitoring method in the embodiment of the present application can be referred to in correspondence with the above content. Figure 4 As shown, the method flow may include the following steps.
[0079] In step S41 , in response to a cache backfill request corresponding to data prefetch, when a cache line is evicted from the cache due to data prefetch, a mapping location to which the address of the cache line is mapped is set to a target value.
[0080] The cache backfill request corresponding to the data prefetch is a request to replace a cache line in the cache with the cache line corresponding to the data prefetch in the memory when a cache miss occurs in the cache based on the address of the cache line of the data prefetch.
[0081] When a cache line is evicted from the cache due to data prefetching, the address of the evicted cache line can be mapped to Figure 2 The mapping position of the cache pollution monitor is shown, and the mapping position is used to map the addresses of multiple cache lines to monitor the cache lines in real time. The target value of the mapping position can indicate that the address of the cache line mapped by the mapping position comes from data prefetch. Taking 1 as the target value as an example, if the value of the mapping position of the cache pollution monitor is 1, it means that the address of the cache line mapped by the mapping position comes from data prefetch.
[0082] In step S42, a memory access request is obtained, and when the memory access address of the memory access request does not hit the cache, if the mapping position mapped to the memory access address is the target value, the cache pollution count is increased.
[0083] Among them, the cache pollution count can be understood as a count of cache pollution caused by data prefetching. If the memory access address of the memory access request does not hit the cache, it means that the data corresponding to the access address of the memory access request is not loaded into the cache, and a cache miss has occurred. If the mapping position mapped to the memory access address is the target value, it means that the memory access address has a cache miss in the cache due to data prefetching, that is, cache pollution is caused by data prefetching, and the cache pollution count can be increased accordingly. In addition, in the case where the cache pollution count counts the cache pollution caused by data prefetching, the cache pollution count can be used to adjust data prefetching.
[0084] In an optional implementation, step S41 and step S42 may be implemented by a cache processing logic circuit, and the mapping position of the address of the cache line in step S41 and step S42 may be implemented by a cache pollution monitor. The mapping position may be mapped to the address hash value of the cache line. In a specific example, a hash operation may be performed on the address of the cache line to determine a hash value, and the hash value may be used as an index to search for the corresponding mapping position in the cache pollution monitor.
[0085] In some embodiments, in order to accurately determine whether the cache line mapped by the mapping position is caused by data prefetching, when the cache line is evicted from the cache due to data prefetching, in the step of setting the mapping position mapped by the address of the cache line to the target value, when the data prefetching causes the cache to be backfilled, it can be determined whether the replaced cache line comes from the historical data prefetching. When the judgment result is no, it means that the replaced cache line does not come from the historical data prefetching, that is, the replaced cache line is replaced due to data prefetching, so when the address of the replaced cache line is mapped to the mapping position, the mapping position mapped by the address of the replaced cache line can be set to the target value.
[0086] In some embodiments, in order to clearly indicate the address source of a cache line in a cache, the cache line may have a prefetch flag, and the validity or invalidity of the prefetch flag is used to indicate whether the cache line is derived from data prefetch. The validity or invalidity of the prefetch flag can be indicated by the value corresponding to the prefetch flag, for example, if the prefetch flag is 1, it indicates that it is valid, that is, the cache line is derived from data prefetch; if the prefetch flag is 0, it indicates that it is invalid, that is, the cache line is not derived from data prefetch.
[0087] When data prefetching causes cache backfilling, as an optional implementation, if the prefetch flag of the replaced cache line is invalid, it can be determined that the replaced cache line does not come from data prefetching.
[0088] Based on the prefetch flag of the cache line, in an optional example, when data prefetch causes cache backfill, for the cache line replaced to the cache (i.e., the backfilled cache line), the prefetch flag of the replaced cache line can be set to valid to indicate that the replaced cache line comes from data prefetch.
[0089] In another optional example, when cache backfill occurs on a cache line, for the cache line replaced to the cache, if the replaced cache line is not caused by data prefetch, the prefetch flag of the replaced cache line is set to invalid to indicate that the replaced cache line does not come from data prefetch.
[0090] In some embodiments, Figure 5 Another optional flow chart of the cache pollution monitoring method in the embodiment of the present application is shown as an example. Figure 5 As shown, the cache pollution monitoring method may also include:
[0091] In step S43, the cache pollution amount is determined according to the cache pollution count.
[0092] In step S44, the requests corresponding to the data pre-fetch are counted to determine the number of data pre-fetches.
[0093] It can be understood that one response to a request corresponding to data prefetching corresponds to one execution of data prefetching, so the number of data prefetching can be determined by counting the requests corresponding to data prefetching. The request corresponding to data prefetching can be called a data prefetching request, which can be sent by a prediction processor or a prefetching prediction program of the system.
[0094] It should be noted that counting the requests corresponding to data prefetching can be performed based on a counting cycle, and the counting cycle can be set according to a preset number of data prefetching requests. For example, if the preset number of data prefetching requests is 10, and the counted number of data prefetching is 10, the current counting cycle is completed and the next counting cycle is entered. It should be noted that when the request corresponding to data prefetching ends in the current counting cycle, the cache pollution count also ends the current count.
[0095] In step S45, the cache pollution status is determined according to the cache pollution amount and the number of data pre-fetches.
[0096] Wherein, in the case where the cache pollution is caused by data prefetching, the determined cache pollution situation can be used to adjust the data prefetching. It should be noted that after determining the cache pollution situation, the counted cache pollution quantity and data prefetching times can be cleared accordingly to count the cache pollution quantity and data prefetching times of the next counting cycle, and calculate the cache pollution situation of the next cycle.
[0097] In an optional example, the cache pollution situation may include a cache pollution ratio or a cache pollution level. For example, the cache pollution ratio is obtained according to the ratio of the cache pollution amount and the number of data prefetches, and the data prefetch is adjusted based on the ratio. Another example is: based on the calculated cache pollution ratio, the cache pollution level corresponding to the cache pollution ratio is determined by table lookup or the like, and then the data prefetch is adjusted based on the cache pollution level.
[0098] It should be noted that the adjustment of data prefetching based on the cache pollution situation can be implemented by the prefetch processor. For example, the prefetch processor obtains the determined cache pollution situation, so that the prefetch processor can adjust the corresponding trigger strategy and the aggressiveness of training according to the cache pollution situation. For example, according to the Best Offset algorithm, when there are different cache pollution situations, the aggressiveness of training is adjusted by setting the maximum number of training rounds, so that when the cache pollution situation is serious, the number of data prefetching is appropriately reduced, and when the cache pollution situation is light, the number of data prefetching is appropriately increased.
[0099] It should be further explained that the above examples are only optional implementations of the cache contamination situation and the corresponding data prefetching adjustment in the embodiments of the present application. The cache contamination situation and the corresponding data prefetching adjustment in the embodiments of the present application may also have other methods, and the embodiments of the present application are not limited to this.
[0100] It can be seen that the embodiment of the present application responds to a cache backfill request corresponding to data prefetch, and when a cache line is evicted from the cache due to data prefetch, sets the mapping position mapped to the address of the cache line to a target value, and the mapping position is used to map the addresses of multiple cache lines, thereby monitoring in real time the cache lines that are polluted by the data prefetch; by obtaining a memory access request, when the memory access address of the memory access request does not hit the cache, if the mapping position mapped to the memory access address is the target value, a cache pollution count is increased, and the cache pollution count is used to adjust the data prefetch, thereby achieving precise control of the data prefetch, reducing the cache pollution caused by the data prefetch, and thus improving the data access efficiency of the processor.
[0101] An embodiment of the present application further provides a chip, which may include at least the cache as described above.
[0102] The above describes multiple implementation schemes provided by the embodiments of the present application. The various optional methods introduced in each implementation scheme can be combined and cross-referenced with each other without conflict, thereby extending a variety of possible implementation schemes, which can all be considered as implementation schemes disclosed and open in the embodiments of the present application.
[0103] Although the embodiments of the present application are disclosed above, the present application is not limited thereto. Any person skilled in the art may make various changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be subject to the scope defined by the claims.
Claims
1. A cache, characterized in that: include: Cache pollution monitor and cache handling logic circuit; The cache pollution monitor includes a plurality of mapping locations, one mapping location being used to map addresses of a plurality of cache lines; The cache processing logic circuit is used to set the mapping position of the address of the cache line to a target value when the cache line is evicted from the cache due to data prefetching; and when the memory access address of the memory access request does not hit the cache, if the mapping position mapped to the memory access address is the target value, increase the cache pollution count; wherein the cache pollution count is used to adjust data prefetching.
2. The cache according to claim 1, characterized in that: There are multiple cache pollution monitors, one cache pollution monitor corresponds to one cache block, and one cache block includes multiple cache lines; A mapping location of the cache pollution monitor is mapped to address hash values of multiple cache lines of the corresponding cache block.
3. The cache according to claim 1 or 2, characterized in that: When a cache line is evicted from the cache due to data prefetching, setting the mapping position of the address phase of the cache line to a target value comprises: When data prefetching causes cache backfill, determine whether the replaced cache line comes from historical data prefetching; If not, the mapping location mapped to the address of the replaced cache line is set to the target value.
4. The cache according to claim 3, characterized in that: The cache line has a pre-fetch flag bit; If the prefetch flag of the replaced cache line is invalid, it is determined that the replaced cache line does not come from data prefetch.
5. The cache according to claim 4, characterized in that: When data prefetching causes cache backfill, the prefetch flag bit of the replaced cache line is set to valid.
6. The cache according to claim 4, characterized in that: When cache backfill occurs on a cache line, if the replaced cache line is not caused by data prefetch, the prefetch flag bit of the replaced cache line is set to invalid.
7. The cache according to claim 1, characterized in that: Also includes: cache pollution counter, prefetch counter and cache pollution calculation unit; The cache pollution counter is used to count the amount of cache pollution; The pre-fetch counter is used to count the number of data pre-fetches; The cache pollution calculation unit is used to determine the cache pollution situation according to the cache pollution quantity and the data pre-fetching times, and the cache pollution situation is used to adjust the data pre-fetching.
8. The cache according to claim 7, characterized in that: The cache pollution situation includes a cache pollution ratio or a cache pollution level.
9. A cache pollution monitoring method, characterized in that: Applied to the cache according to any one of claims 1 to 8, the method comprises: In response to a cache backfill request corresponding to the data prefetch, when a cache line is evicted from the cache due to the data prefetch, setting a mapping location to which an address of the cache line is mapped to a target value; Get a memory access request. When the memory access address of the memory access request does not hit the cache, if the mapping position mapped to the memory access address is the target value, increase the cache pollution count. The cache pollution count is used to adjust data prefetching, and the mapping position is used to map addresses of multiple cache lines.
10. The cache pollution monitoring method according to claim 9, characterized in that: The mapping location is mapped to an address hash value of the cache line.
11. The cache pollution monitoring method according to claim 9 or 10, characterized in that: When a cache line is evicted from the cache due to data prefetching, setting the mapping position of the address phase of the cache line to a target value comprises: When data prefetching causes cache backfill, determine whether the replaced cache line comes from historical data prefetching; If not, the mapping location mapped to the address of the replaced cache line is set to the target value.
12. The cache pollution monitoring method according to claim 11, characterized in that: The cache line has a pre-fetch flag bit; If the prefetch flag of the replaced cache line is invalid, it is determined that the replaced cache line does not come from data prefetch.
13. The cache pollution monitoring method according to claim 12, characterized in that: When data prefetching causes cache backfilling, for a cache line replaced into the cache, a prefetch flag bit of the replaced cache line is set to be valid.
14. The cache pollution monitoring method according to claim 12, characterized in that: When cache backfill occurs on a cache line, for the cache line replaced to the cache, if the replaced cache line is not caused by data prefetch, the prefetch flag bit of the replaced cache line is set to invalid.
15. The cache pollution monitoring method according to claim 9, characterized in that: Also includes: Determining the cache pollution amount according to the cache pollution count; Counting requests corresponding to data prefetching to determine the number of data prefetching times; A cache pollution situation is determined according to the cache pollution amount and the data pre-fetching times, and the cache pollution situation is used to adjust the data pre-fetching.
16. A chip, characterized in that: At least comprising the cache as described in any one of claims 1-8.
