Data prefetching method, data prefetching device and processor
1. A data pre-fetching method is applied to a cache, the cache comprises at least one cache replacement group, each cache replacement group comprises a plurality of cache lines,
the method comprises the following steps:
obtaining a current data prefetch request, wherein the current data prefetch request corresponds to a target cache replacement set in the cache;
obtaining the access condition of the target cache replacement group;
and adjusting a prefetching strategy when a target data prefetching request is executed based on the access condition of the target cache replacement group, wherein the target data prefetching request comprises the current data prefetching request or a data prefetching request executed after the current data prefetching request.
2. The data prefetching method according to claim 1, wherein the access condition of the target cache replacement set includes an access condition of each cache line included in the target cache replacement set.
3. The data prefetching method according to claim 2, wherein adjusting the prefetching policy when executing the target data prefetching request based on the access condition of the target cache replacement group comprises:
and determining the number of prefetched data when the target data prefetching request is executed based on the access condition of each cache line.
4. The data prefetching method of claim 3, wherein determining the number of prefetched data when executing the target data prefetching request based on the access condition of the respective cache line comprises:
responding to a first event, adjusting the number of prefetched data when the target data prefetching request is executed to be any value in a first prefetching range, wherein the first event comprises that the access condition of each cache line indicates that each cache line is accessed for multiple times within a preset time;
responding to a second event, adjusting the number of prefetched data when the target data prefetching request is executed to be any value in a second prefetching range, wherein the second event comprises that the access condition of each cache line indicates that any cache line in each cache line is empty or each cache line is not accessed for multiple times in the preset time;
not changing the number of prefetched data when executing the target data prefetch request in response to a third event, wherein the third event is different from the first event and the second event,
wherein an average value of the first prefetch range is less than an average value of the second prefetch range.
5. The data prefetching method according to claim 4, wherein the access condition of each cache line included in the target cache replacement set includes a replacement priority of the each cache line,
the replacement priority of each cache line is inversely related to the number of accesses of said each cache line in said predetermined time,
determining that the respective cache line is accessed a plurality of times within the predetermined time when the number of cache lines of which replacement priority is lower than or equal to a first priority threshold among the respective cache lines is greater than a first replacement threshold,
determining that the respective cache line has not been accessed a plurality of times within the predetermined time when the number of cache lines of which replacement priority is higher than or equal to a second priority threshold among the respective cache lines is larger than a second replacement threshold,
wherein the first priority threshold is lower than or equal to the second priority threshold.
6. The data prefetching method of claim 4, wherein the current data prefetching request comprises a first prefetching confidence, the target data prefetching request comprises a second prefetching confidence,
the second prefetch confidence is positively correlated with the number of prefetched data when the target data prefetch request is executed,
adjusting the number of prefetched data when the target data prefetch request is executed to be any value in a first prefetch range, wherein the method comprises the following steps:
reducing or not changing the first prefetch confidence to arrive at the second prefetch confidence;
and when the target data prefetching request is executed, determining the number of prefetched data when the target data prefetching request is executed according to the second prefetching confidence coefficient, and enabling the number of the prefetched data to be any value in the first prefetching range.
7. The data prefetching method of claim 6, wherein reducing or not altering the first prefetch confidence to arrive at the second prefetch confidence comprises:
when the first prefetching confidence coefficient belongs to a first confidence coefficient range, reducing the first prefetching confidence coefficient to obtain a second prefetching confidence coefficient;
when the first prefetch confidence does not belong to a first confidence range, the first prefetch confidence is taken as the second prefetch confidence,
wherein an average of the first confidence range is greater than a preset confidence threshold.
8. The data prefetching method of claim 4, wherein the current data prefetching request comprises a first prefetching confidence, the target data prefetching request comprises a second prefetching confidence,
the second prefetch confidence is positively correlated with the number of prefetched data when the target data prefetch request is executed,
adjusting the number of prefetched data when the target data prefetch request is executed to be any value in a second prefetch range, including:
increasing or not changing the first prefetch confidence to arrive at the second prefetch confidence;
and when the target data prefetching request is executed, determining the number of prefetched data when the target data prefetching request is executed according to the second prefetching confidence coefficient, and enabling the number of the prefetched data to be any value in the second prefetching range.
9. The data prefetching method of claim 8, wherein increasing or not changing the first prefetching confidence to derive the second prefetching confidence comprises:
when the first prefetching confidence coefficient belongs to a second confidence coefficient range, increasing the first prefetching confidence coefficient to obtain a second prefetching confidence coefficient;
when the first prefetch confidence does not belong to a second confidence range, taking the first prefetch confidence as the second prefetch confidence,
wherein an average of the second confidence range is less than a preset confidence threshold.
10. A data pre-fetching device is applied to a cache, the cache comprises at least one cache replacement group, each cache replacement group comprises a plurality of cache lines,
the data prefetching apparatus includes:
a prefetch request obtaining unit configured to obtain a current data prefetch request, wherein the current data prefetch request corresponds to a target cache replacement group in the cache;
an access condition acquisition unit configured to acquire an access condition of the target cache replacement set,
and the adjusting unit is configured to adjust a prefetching strategy when a target data prefetching request is executed based on the access condition of the target cache replacement group, wherein the target data prefetching request comprises the current data prefetching request or a data prefetching request executed after the current data prefetching request.
11. The data prefetching apparatus according to claim 10, wherein the access condition of the target cache replacement set includes an access condition of each cache line included in the target cache replacement set,
the adjusting unit, when executing the prefetch strategy when adjusting the prefetch request of the target data based on the access condition of the target cache replacement group, comprises the following operations:
and determining the number of prefetched data when the target data prefetching request is executed based on the access condition of each cache line.
12. The data prefetching apparatus of claim 11, wherein the adjustment unit comprises a first adjustment subunit, a second adjustment subunit, and a third adjustment subunit,
the first adjusting subunit is configured to adjust, in response to a first event, the number of prefetched data when the target data prefetch request is executed to an arbitrary number in a first prefetch range, where the first event includes that the access condition of each cache line indicates that each cache line is accessed multiple times within a predetermined time;
the second adjusting subunit is configured to adjust, in response to a second event, the number of prefetched data when the target data prefetch request is executed to be any value in a second prefetch range, where the second event includes that the access condition of each cache line indicates that any cache line in each cache line is empty, or each cache line is not accessed multiple times within the predetermined time;
the third adjustment subunit is configured to respond to a third event, which is different from the first event and the second event, by not changing the number of prefetched data when the target data prefetch request is executed,
wherein an average value of the first prefetch range is less than an average value of the second prefetch range.
13. A processor, comprising:
a data prefetching apparatus as claimed in any one of claims 10 to 12; and
and caching.
Background
The working speed of the processor is much higher than that of the memory, and if the processor directly accesses the memory to read and write data, the processor needs to wait for a certain time period, so a high-speed buffer storage device (Cache) is usually adopted in the process of accessing the memory to improve the system efficiency and the speed of the processor accessing the memory. Generally, a processor looks up data from a Cache preferentially, for example, if data requested by an application or software exists in the Cache, it is called a Cache hit (Cache hit), and vice versa, it is called a miss (Cache miss).
To further reduce the latency of fetching data, prefetching (prefetcch) is often used to load data ahead of time, where a Prefetch request is issued before a Cache miss may occur, so as to fetch data into the Cache ahead of time when the data is actually used, thereby avoiding processor stalls caused by Cache misses.
Disclosure of Invention
At least one embodiment of the present disclosure provides a data prefetching method, applied to a cache, where the cache includes at least one cache replacement group, and each cache replacement group includes a plurality of cache lines, and the method includes: obtaining a current data prefetch request, wherein the current data prefetch request corresponds to a target cache replacement set in the cache; obtaining the access condition of the target cache replacement group; and adjusting a prefetching strategy when a target data prefetching request is executed based on the access condition of the target cache replacement group, wherein the target data prefetching request comprises the current data prefetching request or a data prefetching request executed after the current data prefetching request.
For example, in the data prefetching method provided by at least one embodiment of the present disclosure, the access condition of the target cache replacement set includes an access condition of each cache line included in the target cache replacement set.
For example, in a data prefetching method provided by at least one embodiment of the present disclosure, adjusting a prefetching policy when a target data prefetching request is executed based on an access condition of the target cache replacement group includes: and determining the number of prefetched data when the target data prefetching request is executed based on the access condition of each cache line.
For example, in a data prefetching method provided in at least one embodiment of the present disclosure, determining, based on the access condition of each cache line, the number of prefetched data in executing the target data prefetching request includes: responding to a first event, adjusting the number of prefetched data when the target data prefetching request is executed to be any value in a first prefetching range, wherein the first event comprises that the access condition of each cache line indicates that each cache line is accessed for multiple times within a preset time; responding to a second event, adjusting the number of prefetched data when the target data prefetching request is executed to be any value in a second prefetching range, wherein the second event comprises that the access condition of each cache line indicates that any cache line in each cache line is empty or each cache line is not accessed for multiple times in the preset time; and responding to a third event, not changing the number of the prefetched data when the target data prefetching request is executed, wherein the third event is different from the first event and the second event, and the average value of the first prefetching range is smaller than the average value of the second prefetching range.
For example, in the data prefetching method provided by at least one embodiment of the present disclosure, the access condition of each cache line included in the target cache replacement group includes a replacement priority of the cache line, the replacement priority of each cache line is in a negative correlation with the number of times that each cache line is accessed within the predetermined time, determining that the respective cache line is accessed a plurality of times within the predetermined time when the number of cache lines of which replacement priority is lower than or equal to a first priority threshold among the respective cache lines is greater than a first replacement threshold, when the number of cache lines of which replacement priority is higher than or equal to the second priority threshold among the respective cache lines is larger than the second replacement threshold, determining that the respective cache line has not been accessed multiple times within the predetermined time, wherein the first priority threshold is lower than or equal to the second priority threshold.
For example, in the data prefetching method provided in at least one embodiment of the present disclosure, the current data prefetching request includes a first prefetching confidence level, the target data prefetching request includes a second prefetching confidence level, the second prefetching confidence level has a positive correlation with the number of prefetched data when the target data prefetching request is executed, and the number of prefetched data when the target data prefetching request is executed is adjusted to be any number value in a first prefetching range, including: reducing or not changing the first prefetch confidence to arrive at the second prefetch confidence; and when the target data prefetching request is executed, determining the number of prefetched data when the target data prefetching request is executed according to the second prefetching confidence coefficient, and enabling the number of the prefetched data to be any value in the first prefetching range.
For example, in a data prefetching method provided in at least one embodiment of the present disclosure, reducing or not changing the first prefetching confidence to obtain the second prefetching confidence includes: when the first prefetching confidence coefficient belongs to a first confidence coefficient range, reducing the first prefetching confidence coefficient to obtain a second prefetching confidence coefficient; and when the first prefetching confidence coefficient does not belong to a first confidence coefficient range, taking the first prefetching confidence coefficient as the second prefetching confidence coefficient, wherein the average value of the first confidence coefficient range is larger than a preset confidence threshold value.
For example, in the data prefetching method provided in at least one embodiment of the present disclosure, the current data prefetching request includes a first prefetching confidence level, the target data prefetching request includes a second prefetching confidence level, the second prefetching confidence level has a positive correlation with the number of prefetched data when the target data prefetching request is executed, and the number of prefetched data when the target data prefetching request is executed is adjusted to any number value in a second prefetching range, including: increasing or not changing the first prefetch confidence to arrive at the second prefetch confidence; and when the target data prefetching request is executed, determining the number of prefetched data when the target data prefetching request is executed according to the second prefetching confidence coefficient, and enabling the number of the prefetched data to be any value in the second prefetching range.
For example, in a data prefetching method provided in at least one embodiment of the present disclosure, increasing or not changing the first prefetching confidence to obtain the second prefetching confidence includes: when the first prefetching confidence coefficient belongs to a second confidence coefficient range, increasing the first prefetching confidence coefficient to obtain a second prefetching confidence coefficient; and when the first prefetching confidence coefficient does not belong to a second confidence coefficient range, taking the first prefetching confidence coefficient as the second prefetching confidence coefficient, wherein the average value of the second confidence coefficient range is smaller than a preset confidence threshold.
At least one embodiment of the present disclosure further provides a data prefetching apparatus, which is applied to a cache, where the cache includes at least one cache replacement group, and each cache replacement group includes a plurality of cache lines, and the data prefetching apparatus includes: a prefetch request obtaining unit configured to obtain a current data prefetch request, wherein the current data prefetch request corresponds to a target cache replacement group in the cache; the cache replacement unit is configured to execute a target data prefetch request, wherein the target data prefetch request comprises the current data prefetch request or a data prefetch request executed after the current data prefetch request.
For example, in the data prefetching apparatus provided by at least one embodiment of the present disclosure, the access condition of the target cache replacement group includes an access condition of each cache line included in the target cache replacement group, and the adjusting unit, when performing the adjustment of the prefetching policy when the target data prefetching request is performed based on the access condition of the target cache replacement group, includes performing the following operations: and determining the number of prefetched data when the target data prefetching request is executed based on the access condition of each cache line.
For example, in the data prefetching apparatus provided in at least one embodiment of the present disclosure, the adjusting unit includes a first adjusting subunit, a second adjusting subunit, and a third adjusting subunit, where the first adjusting subunit is configured to adjust the number of prefetched data when the target data prefetching request is executed to an arbitrary number in a first prefetching range in response to a first event, where the first event includes that the access condition of each cache line indicates that each cache line is accessed multiple times within a predetermined time; the second adjusting subunit is configured to adjust, in response to a second event, the number of prefetched data when the target data prefetch request is executed to be any value in a second prefetch range, where the second event includes that the access condition of each cache line indicates that any cache line in each cache line is empty, or each cache line is not accessed multiple times within the predetermined time; the third adjusting subunit is configured to respond to a third event, wherein the third event is different from the first event and the second event, and the average value of the first prefetching range is smaller than the average value of the second prefetching range, and the number of prefetched data when the target data prefetching request is executed is not changed.
At least one embodiment of the present disclosure further provides a processor, including: a data prefetching apparatus as described in any of the embodiments of the present disclosure; and the cache.
Drawings
To more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings of the embodiments will be briefly introduced below, and it is apparent that the drawings in the following description relate only to some embodiments of the present disclosure and are not limiting to the present disclosure.
FIG. 1 is a process diagram of a cache prefetch, replacement mechanism;
FIG. 2 is a schematic flow chart diagram of a data prefetching method according to at least one embodiment of the disclosure;
FIG. 3 is a diagram illustrating a prefetch and replace process according to at least one embodiment of the present disclosure;
FIG. 4 is a flowchart illustrating a data prefetching method according to at least one embodiment of the disclosure;
fig. 5 is a schematic block diagram of a data prefetching apparatus according to at least one embodiment of the disclosure;
FIG. 6 is a schematic block diagram of a processor provided in at least one embodiment of the present disclosure;
fig. 7 is a schematic block diagram of an electronic device provided in at least one embodiment of the present disclosure;
fig. 8 is a schematic block diagram of another electronic device provided in at least one embodiment of the present disclosure.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described below clearly and completely with reference to the accompanying drawings of the embodiments of the present disclosure. It is to be understood that the described embodiments are only a few embodiments of the present disclosure, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the described embodiments of the disclosure without any inventive step, are within the scope of protection of the disclosure.
Unless otherwise defined, technical or scientific terms used herein shall have the ordinary meaning as understood by one of ordinary skill in the art to which this disclosure belongs. The use of "first," "second," and similar terms in this disclosure is not intended to indicate any order, quantity, or importance, but rather is used to distinguish one element from another. The word "comprising" or "comprises", and the like, means that the element or item listed before the word covers the element or item listed after the word and its equivalents, but does not exclude other elements or items. The terms "connected" or "coupled" and the like are not restricted to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "upper", "lower", "left", "right", and the like are used merely to indicate relative positional relationships, and when the absolute position of the object being described is changed, the relative positional relationships may also be changed accordingly.
To maintain the following description of the embodiments of the present disclosure clear and concise, a detailed description of some known functions and components have been omitted from the present disclosure.
In order to increase the hit rate of the cache, a prefetch module is generally added to the cache to generate a prefetch address, which is a predicted address that a subsequent processor may access to load data into the cache in advance. If the processor then accesses the data at that address, it can read directly from the cache without having to fetch the data from a storage device (e.g., memory), causing the processor to stall.
Currently common prefetching approaches include stride prefetching and sequential prefetching. For example, stride prefetch is a stride that identifies a plurality of data read from a cache, and data is prefetched based on the stride, e.g., address 1, address 3, address 6 are read in the order of address, and stride 3 is identified, so that address 9 is prefetched when data is prefetched. For example, the sequential prefetch is to prefetch the address 4 when data is prefetched if data of the address 1, the address 2 and the address 3 are consecutively read.
For example, a Cache memory device (Cache, hereinafter "Cache") includes at least one Cache replacement set, each Cache replacement set including a plurality of Cache lines. For example, when the cache architecture is a set-associative architecture, each cache replacement set has the same index address (index), and different cache lines are distinguished by tags (tags) within the cache replacement set. For example, when the cache architecture is a fully associative architecture, the entire cache is considered a cache replacement set that includes all cache lines in the cache.
For example, when a prefetch operation occurs, a new cache line needs to be loaded, but if the current cache replacement set is full, a cache line needs to be selected from the current cache replacement set, the data of the cache line needs to be replaced by the data of the new cache line, and the policy of selecting the cache line is the replacement policy. In the replacement policy, it is usually necessary to record the recently accessed cache line, and generally the least recently accessed cache line is selected as the replaced cache line.
Currently, the prefetch policy is usually to prefetch a fixed amount of prefetch data, e.g., 2 or 1 data load into the cache at a time, e.g., the address of the prefetch data may be consecutive to each other, or may be separated by a fixed step size.
FIG. 1 is a process diagram of a cache prefetch and replacement mechanism.
As shown in FIG. 1, the cache replacement set includes 4 ways of cache lines, 1 way, 2 ways, 3 ways, and 4 ways as shown in FIG. 1. Each box represents the state of the data in the way cache line, e.g., I represents that the cache line is empty, data a1 through data a5 represent any form of data/address. The block side storing the data is marked with access information, the access information represents the replacement priority of the cache line, for example, at time 6, the access information of 1-way cache line is 2, the access information of 2-way cache line to 4-way cache line is 3, for example, the larger the value of the access information is, the higher the replacement priority of the cache line is, and when cache replacement occurs, the cache line with the higher replacement priority is preferentially replaced.
For example, the change policy of the access information may be set as: when the data reading process is executed, if the data access at the current moment is hit, the access information of the hit cache line is changed into 0, and the access information is not changed by other cache lines; when the cache replacement operation is performed, the access information of the cache line in which the data replacement occurs is changed to 2, the access information of the other cache lines is added by 1, the maximum value of the access information is 3, and the access information is not added when the access information is added to 3.
Of course, the change policy of the access information may be set as needed, and the disclosure does not limit this.
As shown in fig. 1, at time 1, each cache line is empty, and then at time 2 to time 5, the processor sequentially issues requests to read data a1, data a2, data a3, and data a4, and since there is no corresponding data in the cache block, the hit condition of the cache block is a miss, and the processor extracts data a1, data a2, data a3, and data a4 from the memory and stores the data a1, data a2, data a3, and data a4 into the 1-way cache line, the 2-way cache line, the 3-way cache line, and the 4-way cache line, respectively.
For example, when the access information is 0 or 2, it indicates that the cache line has a lower replacement priority and should be replaced last when a cache replacement occurs. For example, when the access information is 3, it indicates that the replacement priority of the cache line is high, and the cache line should be replaced preferentially when cache replacement occurs.
For example, according to the prefetching policy, the processor prefetches data a5 and stores data a5 into the cache, when cache replacement is performed, since the access information of each cache line is 2, it is determined that each cache line is in the most recently frequently accessed state, data a1 in 1-way cache line is selected for replacement, the access information of 1-way cache line is changed into 2, the access information of 2-way cache line to 4-way cache line is increased to 3, and the state of each cache line is shown as time 6.
Thereafter, the processor issues a read data a1 request at time 7, and since data a1 has been replaced by prefetched data a5, the hit is still a miss, and a cache replacement is performed to store data a1 in the cache. For example, since the access information of the 2-way cache line to the 4-way cache line is 3 and the replacement priority is higher than that of the 1-way cache line, the data a2 in the 2-way cache line is selected for replacement, the access information of the 2-way cache line becomes 2, the access information of the 3-way cache line and the 4-way cache line remains at 3, and the state of each cache line is as shown at time 7.
Then, the requests for reading the data a3 and the data a4 are sequentially sent at the time 8 and the time 9, according to the process described above, the hits of the two read requests are both misses, so that the cache access has a continuous miss due to the fact that the data a5 is prefetched into the cache, the processor is halted for multiple times, and the processing efficiency of the processor is affected.
In the above cache replacement and prefetch strategies, when a processor initiates a prefetch request, the access condition in the cache replacement group is not considered, and the prefetch request cannot be dynamically adjusted according to the access condition in the cache replacement group, so that the problems of cache resource waste and reduced processor access efficiency are generated.
At least one embodiment of the disclosure provides a data prefetching method, a data prefetching apparatus and a processor. The data prefetching method comprises the following steps: obtaining a current data prefetch request, wherein the current data prefetch request corresponds to a target cache replacement group in a cache; obtaining the access condition of a target cache replacement group; and adjusting the prefetching strategy when executing the target data prefetching request based on the access condition of the target cache replacement group, wherein the target data prefetching request comprises the current data prefetching request or a data prefetching request executed after the current data prefetching request.
The data prefetching method dynamically adjusts prefetching requests in real time based on the access condition of a target cache replacing group, avoids data which are accessed frequently recently in a cache from being replaced due to prefetching data, improves the processing efficiency of a processor, and reasonably utilizes cache resources.
The invention does not limit the prefetching strategy and the cache replacement strategy, can adopt any feasible prefetching strategy and cache replacement strategy, and realizes the dynamic adjustment of the prefetching request by combining the adjustment of the number of prefetching items according to the cache access condition in the invention on the basis, thereby achieving the aim of the invention.
For example, the present invention may be applied to a cache architecture that is a set associative (set associative) architecture or a fully associative architecture, that is, when cache replacement and cache prefetch exist in a cache, the data prefetching method provided by the present disclosure may be applied, and the present disclosure does not limit the cache architecture.
For example, in the present disclosure, one prefetch data is stored in one cache line, for example, 32 bytes long, and one prefetch data is also 32 bytes long.
Embodiments of the present disclosure will be described in detail below with reference to the accompanying drawings, but the present disclosure is not limited to these specific embodiments.
Fig. 2 is a schematic flow chart of a data prefetching method according to at least one embodiment of the disclosure.
For example, the data prefetching method is applied to a cache, which may be, for example, a level one cache, a level two cache, or the like, that includes one or more cache replacement sets, each cache replacement set including a plurality of cache lines. The concepts of the cache replacement set and the cache line are as described above and will not be described herein.
For example, as shown in fig. 2, the data prefetching method provided by the embodiment of the present disclosure includes steps S10 to S30.
At step S10, a current data prefetch request is obtained.
For example, the current data prefetch request corresponds to a target cache replacement set in the cache. For example, if the processor initiates a prefetch operation for a cache replacement set in the cache to store data in a cache line of the cache replacement set from the memory in advance, the cache replacement set is the target cache replacement set.
In step S20, the access condition of the target cache replacement set is acquired.
For example, the access condition of the target cache replacement set includes the access condition of each cache line included in the target cache replacement set.
For example, access conditions may include rarely accessed recently, accessed frequently recently, and so on.
In step S30, the prefetch policy when executing the target data prefetch request is adjusted based on the access condition of the target cache replacement group.
For example, the target data prefetch request includes a current data prefetch request, or a data prefetch request that is executed after the current data prefetch request. That is, the adjustment of the prefetch policy may be performed when the data prefetch request is initiated, or the adjustment of the prefetch policy may be performed in the next data prefetch request after the current data prefetch request, or the adjustment of the prefetch policy may be performed in the data prefetch request after the current data prefetch request, which satisfies the predetermined condition, and the description of the relevant contents when the data prefetch request includes the prefetch confidence in the data prefetch request in the following text may be referred to, and will not be described herein again.
For example, step S30 may include: and determining the number of the prefetched data when the target data prefetching request is executed based on the access condition of each cache line.
For example, when each cache line in the target cache replacement set is in a state of being accessed frequently recently, the number of prefetched data should be reduced to avoid the valid data being accessed frequently being replaced, and the data reading efficiency is reduced. For example, when there is an empty cache line in the target cache replacement set, or each cache line is in a state of being accessed rarely recently, the number of prefetched data should be increased, and the waste of cache resources is reduced.
For example, determining the number of prefetched data when executing the target data prefetch request based on the access condition of each cache line may include: in response to a first event, adjusting the number of prefetched data when the target data prefetching request is executed to be any value in a first prefetching range, for example, the first event comprises that the access condition of each cache line indicates that each cache line is accessed for multiple times within a preset time; in response to a second event, adjusting the number of prefetched data when the target data prefetching request is executed to be any value in a second prefetching range, for example, the second event includes that the access condition of each cache line indicates that any cache line in each cache line is empty, or each cache line is not accessed for multiple times within a preset time; in response to a third event, the number of prefetched data in the target data prefetch request is not changed, for example, the third event is different from the first event and the second event, and the average value of the first prefetch range is smaller than the average value of the second prefetch range.
For example, the first prefetch range and the second prefetch range may be set according to actual needs. For example, the first prefetch range characterizes prefetching a small amount of data, e.g., no or only 1 or 2 data, where the first prefetch range may be [0,2 ]. For example, the second prefetch range indicates that more data is prefetched, e.g., 2, 3, or 4 data are prefetched, in which case the first prefetch range may be [2,4 ]. It should be noted that the prefetching range is only illustrative and does not limit the disclosure.
For example, when the access condition of each cache line indicates that each cache line is accessed multiple times within a predetermined time, which indicates that most cache lines are in a state of being accessed frequently recently, the number of prefetched data when the target data prefetch request is executed should be reduced, for example, the number of prefetched data is adjusted to be 0 or 1.
For example, when the access condition of each cache line indicates that any one of the cache lines is empty, or each cache line is not accessed for a plurality of times within a predetermined time, which indicates that most cache lines are in a state of being accessed rarely recently, the number of the prefetch data when the target data prefetch request is executed is increased, for example, the number of the prefetch data is adjusted to be 3 or 4.
For example, in the case of other cases than the above two cases, the number of prefetched data when the target data prefetch request is executed is not changed, and the current prefetch policy is maintained.
For example, the access condition of each cache line included in the target cache replacement set includes the replacement priority of each cache line, and the replacement priority of each cache line is in a negative correlation with the access number of each cache line in the predetermined time, that is, when the replacement priority of one cache line is higher, the access number of the cache line in the predetermined time is indicated to be lower, and the cache line should be replaced preferentially when cache replacement occurs, and conversely, when the replacement priority of one cache line is lower, the access number of the cache line in the predetermined time is indicated to be higher, and the cache line should not be replaced preferentially when cache replacement occurs.
For example, taking the access information shown in fig. 1 as an example, the access information being 3 indicates the highest replacement priority, and the access information being 0 indicates the lowest replacement priority.
It should be noted that, according to actual needs, the replacement priority may also be set to have a positive correlation with the access frequency of each cache line in the predetermined time, and the determination condition of the access condition of each cache line is correspondingly adjusted according to the positive correlation, which is not limited in this disclosure.
For example, when the number of cache lines of which replacement priority is lower than or equal to a first priority threshold is greater than a first replacement threshold in each cache line, it is determined that each cache line is accessed a plurality of times within a predetermined time, and when the number of cache lines of which replacement priority is higher than or equal to a second priority threshold in each cache line is greater than a second replacement threshold, it is determined that each cache line is not accessed a plurality of times within a predetermined time, wherein the first priority threshold is lower than or equal to the second priority threshold.
For example, taking the access information shown in fig. 1 as an example, when the access information is 3, the replacement priority is represented by three levels, when the access information is 2, the replacement priority is represented by two levels, and when the access information is 0, the replacement priority is represented by one level.
For example, the first priority threshold may be set as two levels, and when the number of cache lines of which access information is 2 or 0 in each cache line is greater than the first replacement threshold (e.g., 80% of the total number of cache lines), it is determined that each cache line is accessed multiple times within a predetermined time, that is, it is determined that most cache lines are in a state of being accessed most recently frequently.
For example, the second priority threshold may be set to three levels, and when the number of cache lines of which access information is 3 in each cache line is greater than the second replacement threshold (e.g., 80% of the total number of cache lines), it is determined that each cache line is not accessed for multiple times within a predetermined time, that is, it is determined that most cache lines are in a state of being accessed rarely recently.
For example, the first replacement threshold and the second replacement threshold may be the same or different.
Fig. 3 is a schematic diagram of a prefetch and replacement process according to at least one embodiment of the present disclosure.
The meaning of the reference numerals shown in fig. 3 can refer to the description related to fig. 1, and will not be described again here.
For example, as described above, when the access information is 3, the replacement priority is represented by three levels, when the access information is 2, the replacement priority is represented by two levels, when the access information is 0, the replacement priority is represented by one level, and the first priority threshold may be set to two levels.
For example, when a data prefetch request is initiated at time 5, since the access information in each cache line is 2 at this time, that is, the replacement priority of all cache lines is equal to the first priority threshold, it is determined that each cache line is accessed multiple times within a predetermined time, that is, it is determined that most cache lines are in a state of being accessed most recently.
According to the foregoing, since most cache lines are in the most recently frequently accessed state, prefetching may be selected not to be performed, so that accesses to data a1, data a2, data a3, and data a4 initiated from time 6 to time 9 all hit, and a situation of consecutive misses as shown in fig. 1 may not be generated.
According to the data prefetching method provided by the disclosure, the prefetching strategy is dynamically adjusted in combination with the access condition of the cache replacement group, when the access condition of the cache replacement group indicates that most cache lines are in a state of being accessed most recently, a small amount of data is not prefetched or prefetched, and when the access condition of the cache replacement group indicates that most cache lines are in a state of being accessed least recently or empty cache lines exist, more data is prefetched, so that cache resources are utilized to the maximum extent, the cache hit rate is improved, the number of times of processor stalls is reduced, and the processing efficiency is improved.
For example, in some embodiments, the data prefetch request includes a prefetch confidence by which the prefetch policy, i.e., the number of prefetched data, is changed.
For example, prefetch confidence represents the prefetch strength, and is associated with the hit rate of the data resulting from each prefetch. For example, the prefetch confidence is set to a fixed initial value, when a prefetch operation is initiated, data of an address 1 and an address 2 are loaded into a cache according to a prefetch policy, if the address 1 and/or the address 2 in a data request initiated by a subsequent processor is hit (cache hit), that is, the processor initiates a read request for the address 1 and/or the address 2, the prefetch confidence is increased, that is, the number of prefetched data in each time is increased, and if the address 1 and the address 2 are not hit, the prefetch confidence is reduced, that is, the number of prefetched data in each time is reduced.
For example, the prefetch confidence corresponds to an address set that includes at least one address, e.g., the address set may include N consecutive addresses, or the address set may include N addresses of fixed step intervals, as desired by design.
For example, the prefetch confidence may be modified according to the hit rate of the address in the address set, so that when a data prefetch request is initiated next time for the address in the address set, that is, when a target data prefetch request is executed, the prefetch policy is adjusted according to the modified prefetch confidence, for example, the number of prefetched data is selected according to the prefetch confidence.
For example, the higher the prefetch confidence, the more data is prefetched per time, and the lower the prefetch confidence, the less data is prefetched per time. For example, when a processor initiates a data access request to a cache, a prefetch confidence and prefetch addresses are generated based on the access address, e.g., the number of prefetch addresses is determined from the prefetch confidence. For example, the range of the number of prefetched data is set to [0,4], when the prefetching confidence is high, for example, the prefetching confidence belongs to a first confidence range (for example, 80% -100%), 3 or 4 data are extracted in a single prefetching operation and stored into corresponding 3 or 4 cache lines; when the prefetch confidence is low, for example, the prefetch confidence belongs to a second confidence range (e.g., 0-20%), 1 data or no data is fetched in a single prefetch operation; when the prefetch confidence does not fall within either the first confidence range or the second confidence range (e.g., 20% -80%), 2 data are fetched in a single prefetch operation.
In the above embodiment, when the cache in the processor prefetches data, prefetching is performed only in consideration of the miss condition of the cache, and when there is no empty cache line in the cache replacement group and each cache line is in a state of being accessed recently and frequently, the prefetching policy may load new data that is accessed rarely and replace the original frequently-accessed valid data in the cache, thereby reducing the processing performance of the processor.
In addition, if the data included in the cache replacement group is rarely accessed, or an empty cache line exists in the cache replacement group, since the above-mentioned prefetching policy only considers the hit rate without considering the state of the cache replacement group, and possibly because the hit rate is low, the prefetching confidence is also low, so that no prefetching or a small amount of prefetching is selected when the target data prefetching request is executed, which causes a waste of cache resources, thereby reducing the processing efficiency of the processor.
For example, the current data prefetch request includes a first prefetch confidence level, the target data prefetch request includes a second prefetch confidence level, and the second prefetch confidence level has a positive correlation with the number of prefetched data when the target data prefetch request is executed, i.e., the higher the prefetch confidence level, the more the number of prefetched data when the data prefetch request is executed.
For example, the access condition of the cache replacement group and the prefetching confidence level can be combined to comprehensively judge whether to prefetch and the quantity of prefetched data when the target data prefetching request is executed.
For example, adjusting the number of prefetched data when executing the target data prefetch request to be any value in the first prefetch range may include: reducing or not changing the first prefetch confidence to arrive at a second prefetch confidence; and when the target data prefetching request is executed, determining the number of the prefetched data when the target data prefetching request is executed according to the second prefetching confidence coefficient, and enabling the number of the prefetched data to be any value in the first prefetching range.
For example, reducing or not changing the first prefetch confidence to arrive at the second prefetch confidence may include: when the first prefetching confidence coefficient belongs to the first confidence coefficient range, reducing the first prefetching confidence coefficient to obtain a second prefetching confidence coefficient; and when the first prefetching confidence coefficient does not belong to the first confidence coefficient range, taking the first prefetching confidence coefficient as a second prefetching confidence coefficient, wherein the average value of the first confidence coefficient range is larger than a preset confidence threshold value.
For example, when most cache lines are in a state of being accessed frequently recently and the first confidence level is higher, the first prefetching confidence level is reduced, and a second prefetching confidence level with a value smaller than that of the first prefetching confidence level is obtained, so that when the target data prefetching request is executed, a smaller number of prefetching data are selected not to be prefetched or to be prefetched according to the second prefetching confidence level.
For example, adjusting the number of prefetched data when the target data prefetch request is executed to be any value in the second prefetch range may include: increasing or not changing the first prefetch confidence to arrive at a second prefetch confidence; and when the target data prefetching request is executed, determining the number of the prefetched data when the target data prefetching request is executed according to the second prefetching confidence coefficient, and enabling the number of the prefetched data to be any value in a second prefetching range.
For example, increasing or not changing the first prefetch confidence to arrive at the second prefetch confidence may include: when the first prefetching confidence coefficient is in a second confidence coefficient range, increasing the first prefetching confidence coefficient to obtain a second prefetching confidence coefficient; and when the first prefetching confidence coefficient is not in a second confidence coefficient range, taking the first prefetching confidence coefficient as a second prefetching confidence coefficient, wherein the average value of the second confidence coefficient range is smaller than a preset confidence threshold value.
For example, when most cache lines are in a state of being accessed rarely recently or a condition that the cache lines are empty exists, and the first confidence level is lower, the first prefetching confidence level is increased, and a second prefetching confidence level with a value larger than that of the first prefetching confidence level is obtained, so that when the target data prefetching request is executed, a larger number of prefetching data are selected to be prefetched according to the second prefetching confidence level.
For example, the first confidence level range indicates that the prefetching confidence level is high, the second confidence level range indicates that the prefetching confidence level is low, and specific values of the first confidence level range and the second confidence level range may be set according to design requirements, which is not limited by the present disclosure.
Fig. 4 is a flowchart illustrating a data prefetching method according to at least one embodiment of the disclosure.
The following describes the execution process of the data prefetching method provided by the present disclosure in detail with reference to fig. 4.
First, when a processor initiates an access request, a data prefetch request is generated, the data prefetch request including a prefetch confidence.
Meanwhile, the access condition of the cache replacement set is obtained, for example, the access condition of each cache line included in the cache replacement set is obtained.
Then, it is determined whether the access condition of each cache line included in the cache replacement group indicates that most cache lines are in a state of being accessed rarely recently, or whether an empty cache line exists in the cache replacement group, where a specific determination process is as described above and is not described herein again.
If most cache lines are in a state of being accessed rarely recently or empty cache lines exist in the cache replacement group, further judging whether the prefetching confidence degree belongs to a second confidence degree range, namely whether the prefetching confidence degree is low, if the prefetching confidence degree belongs to the second confidence degree range, namely the prefetching confidence degree is low, increasing the prefetching confidence degree, and updating the prefetching confidence degree (namely obtaining the second prefetching confidence degree), so that when a target data prefetching request is executed, for example, when a data prefetching request of an address in an address set corresponding to the prefetching confidence degree is executed, more prefetching data are selected for prefetching; if the prefetching confidence does not belong to the second confidence range, that is, the prefetching confidence is normal or high, the prefetching confidence is maintained, that is, the prefetching confidence is not changed, and the number of the selected prefetched data is not changed when the target data prefetching request is executed.
If most cache lines are not in the state of being accessed rarely recently, whether each cache line is in the state of being accessed frequently recently is further judged, and the specific judgment process is as described above and is not described herein again.
If most cache lines are in a state of being accessed frequently recently, further judging whether the prefetching confidence degree belongs to a first confidence degree range, namely whether the prefetching confidence degree is higher, if the prefetching confidence degree belongs to the first confidence degree range, namely the prefetching confidence degree is higher, reducing the prefetching confidence degree, and updating the prefetching confidence degree, so that no prefetching or less data prefetching is selected according to the updated prefetching confidence degree when a target data prefetching request is executed; if the prefetching confidence does not belong to the second confidence range, that is, the prefetching confidence is normal or low, the prefetching confidence is maintained, that is, the prefetching confidence is not changed, and the number of the selected prefetched data is not changed when the target data prefetching request is executed.
If most cache lines are not in a state of being accessed frequently recently, the prefetching confidence is kept, namely the prefetching confidence is not changed, and the number of the selected prefetching data is not changed when the target data prefetching request is executed.
In the data prefetching method provided by the disclosure, the prefetching confidence of the data prefetching request is updated in combination with the access condition of the cache replacement group, so that the situation that data of a cache line which is not to be replaced is replaced by the prefetched data and the situation that prefetching is not initiated due to the fact that the prefetching confidence is low when an empty cache line exists or most cache lines are not accessed recently is avoided, the utilization rate of cache resources is improved, and the efficiency of a processor is improved.
Corresponding to the above data prefetching method, at least one embodiment of the present disclosure further provides a data prefetching apparatus, and fig. 5 is a schematic block diagram of a data prefetching apparatus provided in at least one embodiment of the present disclosure.
For example, as shown in fig. 5, the data prefetching apparatus 500 includes: a prefetch request acquisition unit 501, an access situation acquisition unit 502, and an adjustment unit 503.
A prefetch request obtaining unit 501 configured to obtain a current data prefetch request, for example, the current data prefetch request corresponds to a target cache replacement group in a cache;
an access condition obtaining unit 502 configured to obtain an access condition of the target cache replacement group.
The adjusting unit 503 is configured to adjust a prefetching policy when the target data prefetching request is executed based on the access condition of the target cache replacement group, for example, the target data prefetching request includes the current data prefetching request or a data prefetching request executed after the current data prefetching request.
For example, the adjusting unit 503 performs the adjustment of the prefetch policy when executing the target data prefetch request based on the access condition of the target cache replacement group, including performing the following operations: and determining the number of the prefetched data when the target data prefetching request is executed based on the access condition of each cache line.
For example, the adjusting unit 503 includes a first adjusting subunit, a second adjusting subunit, and a third adjusting subunit.
For example, the first adjusting subunit is configured to adjust the number of prefetched data when the target data prefetch request is executed to an arbitrary number in a first prefetch range in response to a first event, where the first event includes that the access condition of each cache line indicates that each cache line is accessed multiple times within a predetermined time.
For example, the second adjusting subunit is configured to adjust the number of prefetched data when the target data prefetch request is executed to be any value in a second prefetch range in response to a second event, where the second event includes that the access condition of each cache line indicates that any cache line in each cache line is empty or each cache line is not accessed multiple times within a predetermined time.
For example, the third adjustment subunit is configured to not change the number of prefetched data when the target data prefetch request is executed in response to a third event, wherein the third event is different from the first event and the second event.
For example, the average value of the first prefetch range is less than the average value of the second prefetch range.
For example, when the first adjusting subunit performs the adjustment to adjust the number of prefetched data when the target data prefetch request is executed to be any value in the first prefetch range, the method includes the following steps: reducing or not changing the first prefetch confidence to arrive at a second prefetch confidence; and when the target data prefetching request is executed, determining the number of the prefetched data when the target data prefetching request is executed according to the second prefetching confidence coefficient, and enabling the number of the prefetched data to be any value in the first prefetching range.
For example, when the second adjusting subunit performs the adjustment to adjust the number of the prefetched data when the target data prefetch request is executed to be any value in the second prefetch range, the method includes the following steps: increasing or not changing the first prefetch confidence to arrive at a second prefetch confidence; and when the target data prefetching request is executed, determining the number of the prefetched data when the target data prefetching request is executed according to the second prefetching confidence coefficient, and enabling the number of the prefetched data to be any value in a second prefetching range.
For example, the prefetch request acquisition unit 501, the access situation acquisition unit 502, and the adjustment unit 503 include codes and programs stored in a memory; the processor may execute the code and program to implement some or all of the functions of the prefetch request acquisition unit 501, the access situation acquisition unit 502, and the adjustment unit 503 as described above. For example, the prefetch request acquisition unit 501, the access condition acquisition unit 502, and the adjustment unit 503 may be dedicated hardware devices for implementing some or all of the functions of the prefetch request acquisition unit 501, the access condition acquisition unit 502, and the adjustment unit 503 as described above. For example, the prefetch request acquisition unit 501, the access situation acquisition unit 502, and the adjustment unit 503 may be one circuit board or a combination of a plurality of circuit boards for realizing the functions as described above. In the embodiment of the present application, the one or a combination of a plurality of circuit boards may include: (1) one or more processors; (2) one or more non-transitory memories connected to the processor; and (3) firmware stored in the memory executable by the processor.
It should be noted that the prefetch request obtaining unit 501 is configured to implement step S10 shown in fig. 2, the access situation obtaining unit 502 is configured to implement step S20 shown in fig. 2, and the adjusting unit 503 is configured to implement step S30 shown in fig. 2. Thus, for the specific description of the prefetch request obtaining unit 501, reference may be made to the related description of step S10 shown in fig. 2 in the embodiment of the data prefetching method, for the specific description of the access condition obtaining unit 502, reference may be made to the related description of step S20 shown in fig. 2 in the embodiment of the data prefetching method, and for the specific description of the adjusting unit 503, reference may be made to the related description of step S30 shown in fig. 2 in the embodiment of the data prefetching method. In addition, the data prefetching apparatus can achieve similar technical effects to the aforementioned data prefetching method, and is not described herein again.
Fig. 6 is a schematic block diagram of a processor according to at least one embodiment of the present disclosure.
As shown in fig. 6, the processor 600 includes a data prefetching apparatus 601 and a cache 602 according to any embodiment of the disclosure. The structure, function, and technical effects of the data prefetching apparatus 601 are as described above, and are not described in detail here.
For example, the cache 602 includes a prefetch module, an access case calculation module, and an address matching module.
For example, the cache architecture may be group-connected or fully-connected, and details about the cache architecture are not described herein.
For example, the prefetch module is configured to generate a data prefetch request according to a prefetch policy when a result of a data access request initiated by the processor 600 to the cache 602 is a miss, e.g., the data prefetch request includes a prefetch confidence and one or more prefetch addresses, e.g., the number of prefetch addresses is determined by the prefetch confidence.
For example, the address matching module is configured to analyze the prefetch address to obtain a tag and an index, find the corresponding cache replacement group through the index, compare the tag with the tags of each cache line in the cache replacement group, determine whether a hit occurs, and send the hit result back to the prefetch module.
For example, if a hit occurs, it indicates that the prefetch data corresponding to the prefetch address already exists in the cache 602, and no cache replacement is performed, and if each cache line misses, it indicates that cache replacement is required.
For example, the access condition calculating module is configured to calculate the replacement priority of each cache line according to the prefetch address, and the process of calculating the replacement priority may adopt any feasible calculation method, for example, reference may be made to the related content of the change policy of the aforementioned access information, which is not described herein again.
For example, the address matching module receives the access condition of the cache replacement group obtained by the access condition calculation module, that is, the replacement priority of each cache line, and when cache replacement is required, performs cache replacement according to the replacement priority of each cache line.
For example, the data prefetching apparatus 601 increases, decreases or maintains the prefetching confidence based on the received access condition of the cache replacement group sent by the access condition calculation module and the prefetching confidence sent by the prefetching module, and sends the updated prefetching confidence to the prefetching module, so that the prefetching module adjusts the prefetching policy according to the updated prefetching confidence when executing the target data prefetching request.
As shown in fig. 6, a data prefetching apparatus may be added on the basis of the existing cache, so as to achieve the purpose of dynamically adjusting the prefetching policy according to the access condition of the cache replacement group.
At least one embodiment of the present disclosure further provides an electronic device, and fig. 7 is a schematic block diagram of the electronic device provided in at least one embodiment of the present disclosure.
For example, as shown in fig. 7, the electronic device includes a processor 701, and the processor 701 is configured to implement the data prefetching method described above.
The processor 701 may perform one or more of the steps of the data prefetching methods described above when running. For example, the processor 701 may be a Central Processing Unit (CPU) or other form of processing unit having data processing capabilities and/or program execution capabilities. For example, the Central Processing Unit (CPU) may be an X86 or ARM architecture or the like. The processor 701 may be a general-purpose processor or a special-purpose processor that may control other components in the electronic device 700 to perform desired functions.
It should be noted that, in the embodiment of the present disclosure, reference may be made to the above description on the data prefetching method for specific functions and technical effects of the electronic device 700, and details are not described here.
For example, the processor 701 may include a data prefetching apparatus and a cache as described above, and the connection relationship between the data prefetching apparatus and the cache is described with reference to fig. 6, and is not described herein again.
Fig. 8 is a schematic block diagram of another electronic device provided by some embodiments of the present disclosure. The electronic device 800 is, for example, suitable for implementing the data prefetching method provided by the embodiments of the present disclosure. The electronic device 800 may be a terminal device or the like. It should be noted that the electronic device 800 shown in fig. 8 is only one example, and does not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 8, electronic device 800 may include a processing means (e.g., central processing unit) 810 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)820 or a program loaded from a storage means 880 into a Random Access Memory (RAM) 830.
In the RAM830, various programs and data necessary for the operation of the electronic apparatus 800 are also stored. The processing device 810, the ROM820, and the RAM830 are connected to each other by a bus 840. An input/output (I/O) interface 850 is also connected to bus 840.
Generally, the following devices may be connected to the I/O interface 850: input devices 860, for example, input devices 860 may include a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, or the like; output devices 870, for example, output devices 870 may include a Liquid Crystal Display (LCD), a speaker, a vibrator, etc.; storage 880, e.g., storage 880 may include magnetic tape, hard disk, etc.; and a communication device 890. The communication device 890 may allow the electronic apparatus 800 to communicate wirelessly or by wire with other electronic apparatuses to exchange data. While fig. 8 illustrates an electronic device 800 having various means, it is to be understood that not all illustrated means are required to be implemented or provided, and that the electronic device 800 may alternatively be implemented or provided with more or less means.
For example, according to an embodiment of the present disclosure, the processing device 810 may execute the data prefetching method described above, and may implement the functions defined in the data prefetching method provided by the embodiment of the present disclosure.
For the present disclosure, there are also the following points to be explained:
(1) the drawings of the embodiments of the disclosure only relate to the structures related to the embodiments of the disclosure, and other structures can refer to the common design.
(2) Thicknesses and dimensions of layers or structures may be exaggerated in the drawings used to describe embodiments of the present invention for clarity. It will be understood that when an element such as a layer, film, region, or substrate is referred to as being "on" or "under" another element, it can be "directly on" or "under" the other element or intervening elements may be present.
(3) Without conflict, embodiments of the present disclosure and features of the embodiments may be combined with each other to arrive at new embodiments.
The above description is only for the specific embodiments of the present disclosure, but the scope of the present disclosure is not limited thereto, and the scope of the present disclosure should be subject to the scope of the claims.