Cache management method, chip and electronic equipment
By managing data in the cache module through cache management identifiers, data is written to different types of cache lines or retrieved from system memory according to the reuse probability level, which solves the problem of low cache space utilization and achieves more efficient cache space utilization and data reading.
Patent Information
- Application Number
- CN202511433738.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-30
- Publication Date
- 2025-12-19
AI Technical Summary
How to improve the utilization rate of cache space in the cache module to meet the chip's high-speed data reading requirements, while considering the problem of limited cache space.
By obtaining the access request from the requester, the data in the cache module is managed using the reuse probability in the cache management identifier. This includes writing data to sticky or non-sticky cache lines in response to hit conditions and reuse probability levels, or retrieving data from the system memory module and writing it to the cache module to replace cached data and optimize cache space utilization.
It increases the probability of data reuse in the caching module, improves the utilization rate of cache space, and meets the requester's timeliness requirements for data.
Smart Images

Figure CN121166567A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of cache, in particular to a cache management method, a chip and an electronic device. BACKGROUND
[0002] The chip of the electronic device, such as the central processing unit (CPU) and the graphic processing unit (GPU), is generally configured with a cache module. The data read and written by the chip from the system memory module can be cached in the cache module of the chip, so as to directly use the data in the cache module when it is needed to be reused, thereby meeting the high-speed operation requirement of the chip.
[0003] The cache space of the cache module is small, and the amount of data that can be cached is limited. Therefore, how to improve the utilization rate of the cache space in the cache module and better meet the data reading requirement of the chip based on the limited cache space has become a problem to be solved. SUMMARY
[0004] To this end, the present application discloses the following technical solutions:
[0005] The first aspect of the present application provides a cache management method, comprising:
[0006] obtaining an access request of a request party, the access request corresponding to a cache management identifier of target data to be accessed, the cache management identifier being related to a reuse probability of the target data, and the reuse probability representing a probability that the target data is repeatedly read;
[0007] managing the data cached in the cache module according to a hit condition of the target data in the cache and the cache management identifier corresponding to the target data, the hit condition representing whether the target data has been cached in the cache module.
[0008] Optionally, the management of the data cached in the cache module according to the hit condition of the data request and the reuse probability level comprises:
[0009] in response to that the target data has been cached in the cache module, reading the target data from the cache module and feeding back the target data to the request party;
[0010] in response to that the target data has not been cached in the cache module, obtaining the target data from the system memory module to transmit to the request party, and writing the target data into the cache module according to the cache management identifier.
[0011] Optionally, the cache management identifier comprises an identifier of a reuse probability level, and the reuse probability level corresponds to a reuse probability size.
[0012] writing the target data into the cache module according to the cache management identifier, comprising:
[0013] in response to the reuse probability level corresponding to the target data being a first level, writing the target data into a sticky cache line of the cache module;
[0014] in response to the reuse probability level being a second level, writing the target data into a non-sticky cache line of the cache module;
[0015] in response to the reuse probability level being a third level or a fourth level, not writing the target data into the cache module;
[0016] wherein the first level to the fourth level represent decreasing probabilities of repeated reading, the data cached in the sticky cache line being prohibited from being overwritten by other data or only being overwritten by data of the same type, and the data cached in the non-sticky cache line being able to be overwritten by data of any type.
[0017] Optionally, in response to the target data having been cached in the cache module, after feeding back the target data read from the cache module to the requestor, the method further comprises:
[0018] in response to the reuse probability level being the third level, setting a to-be-cleared flag for the cache line in which the target data is located;
[0019] in response to the reuse probability level being the third level and the cache line in which the target data is located having been set with the to-be-cleared flag, deleting the target data from the cache module.
[0020] Optionally, the writing of the target data into the sticky cache line of the cache module comprises:
[0021] in response to the amount of data cached in the cache module not satisfying a target condition, writing the target data into any idle sticky cache line in the cache module;
[0022] in response to the amount of data cached in the cache module satisfying the target condition, replacing the data cached in any cache line in the cache module with the target data.
[0023] Optionally, the amount of data cached in the cache module satisfying the target condition comprises:
[0024] the total amount of data cached in the cache module being greater than or equal to a threshold of available cache space;
[0025] and / or, the amount of data of the target data type cached in the cache module being greater than or equal to a target-type cache threshold corresponding to the target data type.
[0026] Optionally, the replacing the target data with the data cached in any cache line of the cache module comprises:
[0027] replacing the target data with the data cached in a target non-sticky cache line of the cache module in response to the cached data amount of the target data type being greater than or equal to a target type cache threshold corresponding to the target data type;
[0028] or, replacing the target data with the data cached in a target sticky cache line of the cache module;
[0029] replacing the target data with the data cached in any non-sticky cache line of the cache module in response to the cached data amount of the target data type being less than the target type cache threshold corresponding to the target data type;
[0030] wherein the data cached in the target non-sticky cache line before replacement and the target data both belong to the target data type, and the data cached in the target sticky cache line before replacement and the target data both belong to the target data type.
[0031] Optionally, the writing the target data into the non-sticky cache line of the cache module comprises:
[0032] writing the target data into any idle non-sticky cache line of the cache module in response to the cached data amount of the cache module not satisfying a target condition;
[0033] replacing the target data with the data cached in a target non-sticky cache line of the cache module in response to the cached data amount of the cache module satisfying the target condition;
[0034] wherein the data cached in the target non-sticky cache line before replacement and the target data both belong to the target data type.
[0035] The second aspect of the present application provides a chip comprising a cache module and at least one requestor capable of accessing the cache module;
[0036] The cache module is configured to:
[0037] obtain an access request of a requestor, the access request corresponding to a cache management identifier of target data to be accessed, the cache management identifier being related to a reuse probability of the target data, the reuse probability representing a probability of the target data being repeatedly read;
[0038] According to a hit of the target data in the cache according to the access request and a cache management identifier corresponding to the target data, the data cached in the cache module is managed, and the hit indicates whether the target data has been cached in the cache module.
[0039] The third aspect of the present application provides an electronic device, comprising a processing module and a system memory module, the processing module comprising a cache module and at least one requestor capable of accessing the cache module;
[0040] The cache module is used for:
[0041] obtaining an access request of a requestor, the access request corresponding to a cache management identifier of target data to be accessed, the cache management identifier being related to a reuse probability of the target data, and the reuse probability indicating a probability of repeated reading of the target data;
[0042] According to a hit of the target data in the cache according to the access request and a cache management identifier corresponding to the target data, the data cached in the cache module is managed, and the hit indicates whether the target data has been cached in the cache module.
[0043] The system memory module is used for providing the target data to the requestor in a case where the cache module does not cache the target data. BRIEF DESCRIPTION OF DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description only constitute the embodiments of the present application, and for those skilled in the art, other drawings can be obtained without creative labor on the basis of the provided drawings.
[0045] Figure 1 is a flowchart of a cache management method provided by an embodiment of the present application;
[0046] Figure 2 is a structural schematic diagram of a chip provided by an embodiment of the present application;
[0047] Figure 3 is a flowchart of replacing target data with data already cached in a cache line provided by an embodiment of the present application;
[0048] Figure 4 is a schematic diagram of an electronic device provided by an embodiment of the present application;
[0049] Figure 5 is a data transmission schematic diagram provided by an embodiment of the present application;
[0050] Figure 6 is a schematic diagram of a cache management method for different reuse probability levels provided by an embodiment of the present application. DETAILED DESCRIPTION
[0051] The technical solutions in the embodiments of the present application will be clearly and completely described with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative work fall within the scope of protection of the present application.
[0052] The present embodiment provides a cache management method, please refer to Figure 1 , which is a flowchart of the method. The method can include the following steps.
[0053] S101, obtaining an access request of a requestor, the access request corresponding to a cache management identifier of target data to be accessed, the cache management identifier being related to a reuse probability of the target data, the reuse probability representing a probability of the target data being repeatedly read.
[0054] The cache management method of the present embodiment can be applied to any chip configured on any electronic device. As some examples, the cache management method can be applied to a graphics processing unit (GPU) chip, a central processing unit (CPU) chip, an embedded neural processing unit (NPU) chip, or other chips of an electronic device.
[0055] For ease of illustration, first, the structure of a chip applying the method of the present embodiment is described. As shown in Figure 2 , the chip can include at least one operation core 201 and a cache (Cache) module 202.
[0056] When the chip is working, the operation core 201 can read computer instructions to be executed from a system memory module of the electronic device, execute the read computer instructions, and in the process of executing the computer instructions, the operation core 201 can read data to be processed from the system memory module, process these data by executing the computer instructions, obtain a processing result, and the processing result can be written back to the system memory module.
[0057] Since the processing efficiency of the operation core 201 is higher than the read-write efficiency of the system memory module, the cache module 202 is provided on the chip, the read-write efficiency of the cache module 202 is basically consistent with the read-write efficiency of the operation core 201, and the read-write demand of the operation core 201 can be met in real time. On this basis, the computer instructions, the data to be processed, and the processing result can be temporarily cached in the cache module 202, so that the operation core 201 can read these data from the cache module 202 at any time.
[0058] The system memory module can be a double data rate synchronous dynamic random access memory (DDR) or other types of memory devices, without limitation.
[0059] The access request of S101 can be any request for reading target data from the cache module. The target data can be computer instructions, data to be processed, processing results, intermediate data in the processing process, or any other data. The type of the target data is not limited in the embodiment.
[0060] The requestor that sends the access request can be any operation core of the chip to which the cache module belongs. For example, when the chip to which the cache module belongs is a CPU, the requestor can be an operation core of the CPU. When the chip to which the cache module belongs is a GPU, the requestor can be an operation core of the GPU. When the chip to which the cache module belongs is a system on chip (SoC), the requestor can be an operation core of the CPU and / or an operation core of the GPU. The cache module can be a system level cache, for example.
[0061] The execution subject of the cache management method of the embodiment can be Figure 2 The cache module 201 of the chip structure shown in FIG. 1 can be integrated with a control unit for processing access requests and managing data cached by the cache module 201. The cache management method of the embodiment can be executed by the control unit.
[0062] After receiving the access request, the cache module can obtain the cache management identifier of the target data to be accessed corresponding to the access request,
[0063] The cache management identifier can be obtained by the cache module reading the target data type carried by the access request, and querying the cache management identifier corresponding to the target data type in the preset configuration information as the cache management identifier corresponding to the target data.
[0064] The target data type refers to the data type to which the target data belongs in multiple data types.
[0065] The configuration information can be pre-configured and stored in the cache module and / or the system memory module. The configuration information can include at least multiple data types that can be accessed by the requestor and the cache management identifier corresponding to each data type.
[0066] As an example, refer to Figure 5In a case where the requestor is a GPU operation core and the GPU operation core is used to process a task of an image rendering pipeline, the configuration information can include any one or more of vertex data VTX, texture data Texture, depth buffer data (Z-Buffer / Depth Buffer, Z), a streaming texture cache (STC), color data (Color, CLR), and a render target (Render Target, RT), each data type corresponding to a cache management identifier, different cache management identifiers representing different reuse probabilities, and the cache management identifiers corresponding to different data types can be the same or different. For example Figure 5 In a case where the cache management identifiers corresponding to Texture, CLR, and RT indicate that these three types of data have the highest reuse probability compared to other types of data and are frequently reused during processing of the image rendering pipeline task of the GPU, the cache management identifiers corresponding to VTX, Z, and STC indicate that these three types of data have a lower reuse probability and are occasionally or rarely reused during processing of the image rendering pipeline task of the GPU.
[0067] The cache management identifier can be obtained in the following manner: when the requestor sends an access request, the cache management identifier is determined in advance and configured in the access request, and the cache module directly reads the cache management identifier carried in the access request as the cache management identifier corresponding to the target data. The manner in which the requestor determines the cache management identifier is consistent with the manner in which the cache module determines the cache management identifier based on the configuration information, and thus is not described in detail.
[0068] In order to obtain the above-described cache management identifier, the working processes of multiple chips can be analyzed in advance, and the frequency with which the requestor repeatedly requests data of a certain data type from the cache module during chip operation can be counted. The higher the frequency, the greater the probability that data of the data type is repeatedly read by the requestor, and the lower the frequency, the smaller the probability that data of the data type is repeatedly read by the requestor, thereby obtaining the cache management identifier corresponding to each data type.
[0069] For example, the requestor frequently reads data of the same A data type repeatedly multiple times, and this is true for each piece of data of the A data type. Therefore, it can be determined that the probability that data of the A data type is repeatedly read is relatively high, and a cache management identifier representing a relatively high reuse probability can be configured. For each piece of data of a B data type cached in the cache module, the requestor generally reads it only once and does not repeatedly read the same piece of data of the B data type. Therefore, it can be determined that the probability that data of the B data type is repeatedly read is relatively low, and a cache management identifier representing a relatively low reuse probability can be configured.
[0070] S102, according to the hit of the target data in the cache according to the access request, and the cache management identifier corresponding to the target data, managing the data cached in the cache module, the hit representing whether the target data has been cached in the cache module.
[0071] On the one hand, the cache module can query whether the target data required by the access request is in the currently cached data, to determine the hit of the target data. The hit can be a hit or a miss. The hit means that the target data has been cached in the cache module, and the miss means that the target data has not been cached in the cache module.
[0072] On the other hand, the cache module can manage the data currently cached in the cache module based on the hit and the cache management identifier of the target data. The management manner includes but is not limited to: reading the target data currently cached in the cache module, keeping the currently cached data unchanged, deleting part of the cached data from the cache module, writing the target data into the cache module, etc. When the target data is written into the cache module, which cache lines the target data is written into can be determined based on the cache management identifier of the target data.
[0073] Among them, the higher the reuse probability represented by the cache management identifier, the greater the possibility of the target data being written into the cache module, and the lower the reuse probability represented by the cache management identifier, the smaller the possibility of the target data being written into the cache module.
[0074] The beneficial effects of the embodiment are that the data cached in the cache module is managed according to the cache management identifier representing the repeated reading probability, which is beneficial to improve the overall reuse probability of the data cached in the cache module, so that the cache module caches more data that the request party needs to read repeatedly, and the utilization rate of the cache space of the cache module is improved.
[0075] Optionally, the data cached in the cache module is managed according to the hit of the data request and the reuse probability level, including:
[0076] In response to the target data being cached in the cache module, the target data is read from the cache module and fed back to the request party;
[0077] In response to the target data not being cached in the cache module, the target data is obtained from the system memory module to transmit to the request party, and the target data is written into the cache module according to the cache management identifier.
[0078] In this embodiment, if the cache module query finds that the target data is in the currently cached data, it is determined that the cache module has cached the target data, and then the cached target data is directly read from the cache module, and the target data is fed back to the requester. In this case, the management of the data cached in the cache module can be to read the target data currently cached in the cache module, and keep the data currently cached in the cache module unchanged.
[0079] If the cache module query finds that the target data is not in the currently cached data, it is determined that the cache module has not cached the target data. In this case, the cache module queries the system memory module based on the access request, and reads the target data from the system memory module and feeds it back to the requester after querying the target data in the system memory module. At the same time, based on the cache management identifier corresponding to the target data, the target data is written into the cache module. Thus, if a subsequent requester requests the same target data again, the cached target data can be directly read from the cache module and fed back to the requester.
[0080] Through the method of this embodiment, on the one hand, in the case that the cache module has cached the target data, the target data can be read from the cache module and fed back to the requester, meeting the timeliness requirement of the requester to read the target data; on the other hand, in the case that the cache module has not cached the target data, the target data can be queried from the system memory module and fed back to the requester, meeting the current requirement of the requester to read the target data. At the same time, by writing the target data into the cache module, the target data can be quickly fed back to the cache module from the cache module when the same target data is read next time, meeting the timeliness requirement.
[0081] Optionally, the cache management identifier includes an identifier of a reuse probability level Reused Probability, and the reuse probability level corresponds to a reuse probability size. Correspondingly, when the cache module writes the target data according to the cache management identifier, it can determine which cache lines to write the target data into or whether to write the target data into the cache module according to the cache management identifier. The cache management identifier can also include: an entry type, a replacement policy, a capacity for type, an evict policy, etc.
[0082] The entry type indicates which type of data the cache management identifier is applicable to, the replacement policy indicates what strategy to determine the data to be replaced when the corresponding type of data is replaced, the capacity for type is used to limit how much cache space the data of this type occupies in the cache module, and the evict policy can indicate that the data of the corresponding type can be deleted from the cache module when a certain condition is met.
[0083] The way of writing the target data into the cache module according to the cache management identifier can be:
[0084] In response to the reuse probability level corresponding to the target data being the first level, writing the target data into a sticky cache line of the cache module;
[0085] In response to the reuse probability level being the second level, writing the target data into a non-sticky cache line of the cache module;
[0086] In response to the reuse probability level being the third level or the fourth level, not writing the target data into the cache module;
[0087] The first level to the fourth level represent that the probability of repeated reading decreases in turn, the data cached in the sticky cache line is prohibited to be replaced by other data or can be replaced by data of the same type only, and the data cached in the non-sticky cache line can be replaced by data of any type.
[0088] The cache module includes a plurality of cache lines, which can be divided into sticky cache lines and non-sticky cache lines. When data has been cached in a sticky cache line, the cached data is generally prohibited to be replaced by other data or is allowed to be replaced by data of the same type only. For example, when the cached data is a piece of RT data type data, only another piece of RT data type data is allowed to replace the cached data. In contrast, when data has been cached in a non-sticky cache line, the cached data can be replaced by data of any type according to actual conditions. That is, the data written into the sticky cache line is more likely to be permanently retained in the cache module, and the data written into the non-sticky cache line is more likely to be replaced and removed from the cache module.
[0089] The cache module can configure sticky marks for the cache lines. The cache lines configured with the sticky marks are sticky cache lines, and the cache lines not configured with the sticky marks are non-sticky cache lines. The number of the sticky cache lines and the non-sticky cache lines can be dynamically adjusted by the cache module according to actual conditions.
[0090] The first level to the fourth level can be represented by different characters, as an example, the first level to the fourth level can be represented by 0, 1, 2, 3 in turn, and the identification 0 corresponds to the first level, the identification 1 corresponds to the second level, the identification 2 corresponds to the third level, and the identification 3 corresponds to the fourth level, wherein the first level is mostly reused, and the corresponding reuse probability is the highest, indicating that the corresponding data will be read repeatedly by the requester with high frequency, the second level is normal reused, and the corresponding reuse probability is lower, indicating that the corresponding data will be read repeatedly by the requester occasionally, the third level is least reused, and the corresponding reuse probability is lower, indicating that the corresponding data will be read repeatedly by the requester at most once, and the fourth level is not reused, and the corresponding reuse probability is the lowest, indicating that the corresponding data will not be read repeatedly by the requester, that is, the requester will not read the data again after reading the data of the fourth level once.
[0091] In combination with the foregoing example, the identification corresponding to the CLR and the identification corresponding to the RT can be 0, the identification corresponding to the Texture can be 1, the identification corresponding to the VTX can be 2, and the identification corresponding to the Z and the identification corresponding to the STC can be 3.
[0092] The above embodiments can refer to Figure 6 After obtaining the access request, the reuse probability level corresponding to the target data is determined based on the corresponding cache management identification.
[0093] In the case of the first level, the management is based on the mode of allocating sticky cache lines, that is, if it is hit, the target data is directly read and fed back, and the current state is maintained unchanged, and if it is not hit, a sticky cache line is allocated to write the target data.
[0094] In the case of the second level, the management is based on the mode of allocating regular cache lines, that is, if it is hit, the target data is directly read and fed back, and the current state is maintained unchanged, and if it is not hit, a non-sticky cache line is allocated to write the target data.
[0095] In the case of the fourth level, the management is based on the mode of not allocating cache lines, that is, if it is hit, the target data is directly read and fed back, and the current state is maintained unchanged, and if it is not hit, the allocation of cache lines is refused, that is, the target data is not written to the cache module.
[0096] The beneficial effect of the embodiment is that, for target data corresponding to the first level with a higher reuse probability, the target data is preferentially written into the sticky cache line of the cache module, so that the target data is as persistently retained in the cache module as possible to meet the demand of the requester repeatedly reading the target data, and for target data corresponding to the third level or the fourth level with a too low reuse probability, the target data is not written into the cache module, so that the cache space of the cache module can be preferentially used for data of the first level and the second level with a higher reuse probability, and the utilization rate of the cache space is improved.
[0097] Optionally, in response to the target data being cached in the cache module, after the target data is fed back to the requester by being read from the cache module, the method further comprises:
[0098] In response to the reuse probability level being the third level (Least reused), a to-be-cleared mark is set for the cache line where the target data is located.
[0099] In response to the reuse probability level being the third level and the cache line where the target data is located having been set with the to-be-cleared mark, the target data is deleted from the cache module.
[0100] If the target data corresponds to the third level, it means that the target data is at most read twice by the requester when the target data is cached in the cache module, in other words, the target data is at most used twice by the requester when the program is run.
[0101] The above embodiment can refer to the branch corresponding to the third level in Figure 6 It can be seen that, after it is determined that the target data corresponds to the third level, the cache space can be managed based on de-allocation. Specifically, if the target data is not hit in the cache module, the cache line can be refused to be allocated, that is, the target data is not written into the cache module; if the target data is hit in the cache module, when the target data is provided to the requester for the first time, a to-be-cleared mark can be set for the cache line where the target data is located, to indicate that the target data has been read once by the requester and the target data does not need to be evicted from the cache module when the cache module is full.
[0102] Further, in the case where it is determined that the target data belongs to the third level and the target data is cached in the cache module, if the cache line where the target data is located is configured with the to-be-cleared mark, it can be determined that the target data is read by the requester for the second time, and it can be further determined that the target data will not be read by the requester after the current reading, so that the target data which will not be read by the requester can be deleted from the cache module after the target data is fed back to the requester, thereby saving the cache space of the cache module to cache other data with a higher reuse probability.
[0103] If the target data is deleted from the cache module in the above manner, the target data can not be written back to the system memory module, i.e., the target data is deleted from both the cache module and the system memory module, so as to save the storage space of the system memory module, since the requester will not read the target data any more.
[0104] Optionally, the target data is written into the sticky cache line of the cache module, including:
[0105] In response to the cached data amount of the cache module not satisfying the target condition, the target data is written into any idle cache line of the cache module.
[0106] In response to the cached data amount of the cache module satisfying the target condition, the target data is used to replace the data cached in any cache line of the cache module.
[0107] The cached data amount not satisfying the target condition indicates that the current cached data amount of the cache module is small, in which case there is generally at least one idle cache line in the cache module, so the idle sticky cache line of the cache module can be queried, and the target data is directly written into the idle sticky cache line.
[0108] If the cached data amount of the cache module does not satisfy the target condition, and it is determined after the query that there is only an idle non-sticky cache line, the target data can also be directly written into the idle non-sticky cache line, or the idle non-sticky cache line can be changed to an idle sticky cache line by configuring the sticky flag, and the target data is written into the idle sticky cache line.
[0109] The cache line being in an idle state means that the cache line is not currently used to cache data.
[0110] In the case that the cached data amount of the cache module satisfies the target condition, there can be no idle cache line in the cache module, at this time, in order to meet the reading demand of the target data with a higher reuse probability, the target data can be used to replace the cached data in the cache module, i.e., for any cache line in an occupied state, the target data is written into the cache line, and the data originally cached in the cache line is overwritten by the target data, in which case the data originally cached in the replaced cache line is equivalent to being deleted from the cache module.
[0111] In the case that there is an idle cache line in the cache module, the target data is preferentially written into the idle cache line, so as to avoid using the target data to replace the cached data in the cache module, and prevent the cached data from being replaced, so that the requester cannot read the replaced data from the cache module subsequently, thereby facilitating the efficiency of reading data by the requester.
[0112] In the case that the target data replaces the data cached in any cache line of the cache module, according to the reuse probability level of the replaced data, the replaced data can be written back to the system memory module or not written back to the system memory module (i.e. directly discarded) before replacement.
[0113] In combination with the foregoing examples, if the replaced data corresponds to the first level or the second level, the replaced data can be written to the system memory module, so that when the next request party needs to access the replaced data, the replaced data is read from the system memory module and provided to the request party, and if the replaced data corresponds to the third level or the fourth level, the replaced data can not be written back to the system memory module and is directly discarded.
[0114] Further, if the replaced data corresponds to the third level and the replaced data has been repeatedly read once, the replaced data can not be written back to the system memory module during replacement; if the replaced data corresponds to the third level and the replaced data has not been repeatedly read once, the replaced data can be written back to the system memory module during replacement.
[0115] Optionally, the cached data amount of the cache module satisfies the target condition, including:
[0116] The total amount of the cached data of the cache module is greater than or equal to the available cache space threshold;
[0117] And / or, the cached data amount of the target data type in the cache module is greater than or equal to the target type cache threshold corresponding to the target data type.
[0118] Each data type can correspond to a type cache threshold, which can also be referred to as a type capacity (capacity for type). As described above, the threshold can be configured in the cache management identifier corresponding to the data type.
[0119] In some embodiments, the cache space occupied by each data type in the cache module can not be limited, i.e. each data type can occupy any size of cache space in the cache module. In this case, if the total amount of the cached data of the cache module is less than the available cache space threshold, it can be determined that the cached data amount does not satisfy the target condition, and if the total amount of the cached data of the cache module is greater than or equal to the available cache space threshold, it can be determined that the cached data amount satisfies the target condition.
[0120] The available cache space threshold can be equal to the upper limit of the cache space of the cache module, or can be slightly less than the upper limit of the cache space, for example, equal to the upper limit of the cache space multiplied by 0.9.
[0121] In some embodiments, in order to meet the cache requirements of different data types and avoid data of a certain data type from occupying too much cache space, the cache space occupied by each data type in the cache module can be limited.
[0122] The limiting manner can be that, in the foregoing cache management identifier, a corresponding type cache threshold is configured for the cache management identifier of each data type to limit how much data of each data type can be cached in the cache module. As an example, the type cache threshold corresponding to a certain data type can be 50 megabytes (MB), indicating that the cache module allows a maximum of 50 MB of data of this data type to be cached.
[0123] The type cache thresholds corresponding to different data types can be the same or different, for example, the type cache threshold corresponding to one data type is 60 MB, and the type cache threshold corresponding to another data type is 100 MB.
[0124] If the cache space occupied by each data type in the cache module is limited, the target condition of the cached data amount can be determined in combination with the target type cache threshold corresponding to the target data type.
[0125] Specifically, if any one of the following conditions is met, or both conditions are met, it is determined that the cached data amount meets the target condition: the total amount of cached data is greater than or equal to the available cache space threshold, and the amount of cached data of the target data type is greater than or equal to the target type cache threshold.
[0126] Optionally, the sum of the type cache thresholds corresponding to the plurality of data types can be less than or equal to the available cache space threshold of the cache module. Alternatively, the sum of the type cache thresholds corresponding to the plurality of data types can be greater than the available cache space threshold of the cache module. Configuring the sum to be greater than the available cache space threshold is beneficial to improve the utilization rate of the cache module.
[0127] Optionally, if the cache space occupied by each data type in the cache module is limited, the manner of replacing the data cached in any cache line of the cache module by the target data can be:
[0128] In response to the amount of cached data of the target data type being greater than or equal to the target type cache threshold corresponding to the target data type, the data cached in the target non-sticky cache line of the cache module is replaced by the target data.
[0129] Alternatively, the data cached in the target sticky cache line of the cache module is replaced by the target data.
[0130] If the cached data amount of the target data type is less than the target type cache threshold corresponding to the target data type, replace the data cached by any non-sticky cache line in the target data replacement cache module with the target data;
[0131] In the embodiment, if the cached data amount of the target data type is greater than or equal to the target type cache threshold corresponding to the target data type, it indicates that the data amount of the target data type in the cache module has reached the limit. In this case, only the target data can replace the cached data of the same type in the cache module, and therefore the replacement manner is: replace the data cached by the target non-sticky cache line in the cache module with the target data; or replace the data cached by the target sticky cache line in the cache module with the target data.
[0132] In the embodiment, if the cached data amount of the target data type is greater than or equal to the target type cache threshold corresponding to the target data type, it indicates that the data amount of the target data type in the cache module has reached the limit. In this case, only the target data can replace the cached data of the same type in the cache module, and therefore the replacement manner is: replace the data cached by the target non-sticky cache line in the cache module with the target data; or replace the data cached by the target sticky cache line in the cache module with the target data.
[0133] During the replacement, it can be determined whether the corresponding cache line is in a replaceable state, and only the cache line in the replaceable state is replaced, and the cache line not in the replaceable state is not replaced.
[0134] If a cache line can normally read and write data, and is not read and written by other requesters during the replacement, it can be determined that the cache line is in the replaceable state. If a cache line has an exception and cannot normally read and write data, and / or is read and written by other requesters during the replacement, it can be determined that the cache line is not in the replaceable state.
[0135] During the replacement, the target non-sticky cache line can be preferentially replaced. If there is no target non-sticky cache line in the replaceable state, and the reuse probability level of the target data is the first level, the target sticky cache line in the replaceable state can be queried for replacement.
[0136] Further, the cache module can be pre-configured whether the data of the sticky cache line is allowed to be replaced by the data of the same type. If the data of the sticky cache line is allowed to be replaced, the data of the target sticky cache line can be replaced by the target data. If the data of the sticky cache line is not allowed to be replaced, and it is determined that there is no target non-sticky cache line in the replaceable state after the query, the target data can be discarded, that is, the target data is not written into the cache module.
[0137] The above replacement manner can be implemented based on the replacement process shown in FIG. 8. Figure 3
[0138] S301, query whether there is a target non-sticky cache line in the replaceable state.
[0139] If there is a target non-sticky cache line in replaceable state, step S302 is executed, and if there is no target non-sticky cache line in replaceable state, step S303 is executed.
[0140] S302, the target data is replaced with the data of the cache line found.
[0141] S303, it is determined whether the reuse probability level of the target data is the first level.
[0142] If the reuse probability level of the target data is the first level, step S304 is executed, and if the reuse probability level of the target data is not the first level, step S306 is executed.
[0143] S304, it is determined whether the data of the sticky cache line is allowed to be replaced.
[0144] If the data of the sticky cache line is allowed to be replaced, step S305 is executed, and if the data of the sticky cache line is not allowed to be replaced, step S306 is executed.
[0145] Whether the data of the sticky cache line is allowed to be replaced can be configured by the requester and / or the cache module in advance according to actual conditions. For example, if the data cached in the sticky cache line is relatively large, it can be configured that the data of the sticky cache line is not allowed to be replaced, so as to ensure that the requester can read the data of the sticky cache line from the cache module in time, and if the data cached in the sticky cache line is relatively small, it can be configured that the data of the sticky cache line is allowed to be replaced, so as to flexibly utilize the cache space of the cache module.
[0146] S305, it is inquired whether there is a target sticky cache line in replaceable state.
[0147] If there is a target sticky cache line in replaceable state, step S302 is executed, and if there is no target sticky cache line in replaceable state, step S306 is executed.
[0148] S306, no cache line is allocated for the target data, and the target data is discarded.
[0149] When the above replacement is performed, if there are multiple target non-sticky cache lines in replaceable state, or there are multiple target sticky cache lines in replaceable state, a specific cache line data can be determined based on multiple replacement strategies, for example, the data of the cache line with the least access frequency in a recent period of time can be replaced, the data of the cache line with the farthest time from the current time when last accessed can be replaced, or other strategies are used to determine, without limitation.
[0150] If the cached data amount of the target data type is less than the target type cache threshold corresponding to the target data type, any non-sticky cache line in replaceable state can be inquired in the cache module, and the target data is replaced with the data cached in the cache line.
[0151] When replacing the data of any non-sticky cache line in the cache module, the data of which non-sticky cache line is replaced can be determined based on various replacement strategies, for example, the data that has been accessed least in a certain period of time can be replaced, the data that has not been accessed for the longest time can be replaced, or other strategies can be used, without limitation.
[0152] Based on the above scheme, the target data can replace the same type of data cached in the cache module, thereby meeting the cache requirement of the target data while limiting the cache space occupied by each data type.
[0153] Optionally, writing the target data into the non-sticky cache line of the cache module includes:
[0154] In response to the amount of cached data in the cache module not meeting the target condition, the target data is written into any non-sticky cache line in an idle state in the cache module;
[0155] In response to the amount of cached data in the cache module meeting the target condition, the target data replaces the data cached in the target non-sticky cache line in the cache module;
[0156] The data cached in the target non-sticky cache line before replacement and the target data both belong to the target data type.
[0157] If the amount of cached data in the cache module does not meet the target condition, and it is determined through the query that there is only a sticky cache line in an idle state and there is no non-sticky cache line in an idle state, the target data can be discarded and not written into the cache module, or the target data can replace the data cached in the non-sticky cache line in the cache module.
[0158] Optionally, if the amount of cached data of the target data type is less than the target type cache threshold corresponding to the target data type, the target data can replace the data cached in the target non-sticky cache line in the cache module, or the target data can replace the data cached in other non-sticky cache lines except the target non-sticky cache line in the cache module, when the amount of cached data meets the target condition. If the amount of cached data of the target data type is greater than or equal to the target type cache threshold corresponding to the target data type, only the target data can replace the data cached in the target non-sticky cache line in the cache module.
[0159] When there are multiple target non-sticky cache lines that can be replaced, or there are multiple other non-sticky cache lines that can be replaced, the data of which non-sticky cache line is replaced can be determined based on various replacement strategies, which can be referred to in the foregoing embodiments and will not be described here.
[0160] As described above, the cache management identifier corresponding to the data type further comprises a replacement policy applicable to the data type, and the replacement policy corresponding to different data types can be different. For example, the replacement policy corresponding to the target data type can be any one of a least recently used (LRU) policy and a reference prediction value (RRPV) based policy, or other replacement policies applicable to the cache module in related technologies, without limitation.
[0161] When it is necessary to replace the target data with the same type of data already cached in the cache module, the target replacement policy corresponding to the target data type can be queried from the cache management identifier corresponding to the target data type, and the target data is determined to replace the data of which cache line based on the target replacement policy.
[0162] Taking the LRU as an example of the target replacement policy, each cache line in which the data of the same type is cached in the cache module can be queried to find the cache line that has been accessed least frequently in a recent period of time, and the data cached in the cache line that has been accessed least frequently is replaced with the target data.
[0163] As described above, the cache management identifier corresponding to the data type further comprises an eviction policy applicable to the data type, and the eviction policy can indicate that the data of the data type can be deleted from the cache module when a condition is met. The cache module can periodically query the data cached in each cache line, determine whether the data cached in each cache line meets the eviction policy corresponding to the data type, and delete the data meeting the corresponding eviction policy from the cache module to avoid long-term occupation of the cache space by unnecessary data.
[0164] The embodiment also provides a chip comprising a cache module and at least one requestor capable of accessing the cache module.
[0165] The cache module is configured to:
[0166] obtain an access request of the requestor, the access request corresponding to a cache management identifier of target data to be accessed, the cache management identifier being related to a reuse probability of the target data, and the reuse probability representing a probability of repeated reading of the target data;
[0167] manage the data cached in the cache module according to a hit condition of the target data in the cache and the cache management identifier corresponding to the target data, the hit condition representing whether the target data has been cached in the cache module.
[0168] The structure of the chip can be referred to Figure 2 , and the at least one requestor corresponds to at least one operation core 201 of Figure 2 .
[0169] The embodiment also provides an electronic device, which can be referred toFigure 4 , the processing module 401 comprises a cache module and at least one requestor capable of accessing the cache module;
[0170] The cache module is configured to:
[0171] obtain an access request of the requestor, the access request corresponding to a cache management identifier of target data to be accessed, the cache management identifier being related to a reuse probability of the target data, the reuse probability representing a probability of the target data being repeatedly read;
[0172] manage data cached in the cache module according to a hit of the target data in the cache module and the cache management identifier corresponding to the target data, the hit representing whether the target data has been cached in the cache module;
[0173] The system memory module 402 is configured to: provide the target data to the requestor in a case where the cache module does not cache the target data.
[0174] The working principle of the chip and the electronic device of the embodiment can refer to the related steps of the cache management method of the foregoing embodiments, and details are not repeated.
[0175] It should be noted that each embodiment in the present specification adopts a progressive manner for description, and each embodiment focuses on the difference from other embodiments. The same and similar parts between each embodiment can be referred to.
[0176] For the convenience of description, the above system or device is described in various modules or units in terms of functions. Of course, the functions of each unit can be implemented in the same or multiple software and / or hardware in the implementation of the present application.
[0177] From the above description of the embodiments, those skilled in the art can clearly understand that the present application can be implemented by means of software and necessary general hardware platforms. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product, which can be stored in a storage medium, such as a ROM / RAM, a magnetic disk, an optical disk, etc., and includes a plurality of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute the methods described in various embodiments or some parts of the embodiments.
[0178] Finally, it needs to be pointed out that, in this document, relational terms such as first, second, third and fourth and the like can only be used to distinguish one entity or action from another entity or action, without necessarily requiring or implying any actual relationship or order between or among such entities or actions. Moreover, the terms "comprises", "comprising", or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can include other elements not expressly listed or inherent to such process, method, article, or apparatus. An element proceeded by "comprises... a" does not, without more constraints, exclude the existence of additional identical elements in the process, method, article, or apparatus that comprises the element.
[0179] The above description is only the preferred embodiment of the present application, and it should be pointed out that, for those skilled in the art, some improvements and refinements can be made without departing from the principles of the present application, and these improvements and refinements should also be considered as the protection scope of the present application.
Claims
1. A cache management method, comprising: Obtain the access request from the requester. The access request corresponds to the cache management identifier of the target data to be accessed. The cache management identifier is related to the reuse probability of the target data. The reuse probability represents the probability that the target data is read repeatedly. Based on the hit status of the target data in the cache according to the access request and the cache management identifier corresponding to the target data, the cache module manages the cached data, and the hit status indicates whether the target data has been cached in the cache module.
2. The method according to claim 1, wherein managing the cached data in the caching module based on the hit status of the data request and the reuse probability level includes: In response to the fact that the target data has been cached in the caching module, the target data is read from the caching module and fed back to the requester; In response to the fact that the target data is not cached in the cache module, the target data is obtained from the system memory module and transmitted to the requester, and the target data is written into the cache module according to the cache management identifier.
3. The method according to claim 2, wherein the cache management identifier includes an identifier for the reuse probability level, and the reuse probability level corresponds to the reuse probability magnitude; Writing the target data to the cache module according to the cache management identifier includes: In response to the target data having a reuse probability level of Level 1, the target data is written into the sticky cache line of the cache module; In response to the reuse probability level being the second level, the target data is written into the non-sticky cache line of the cache module; In response to the reuse probability level being level three or four, the target data is not written to the cache module; Among them, the probability of repeated reading represented by the first level to the fourth level decreases sequentially. The data cached by the sticky cache line is prohibited from being overwritten by other data or can only be overwritten by data of the same type. The data cached by the non-sticky cache line can be overwritten by data of any type.
4. The method according to claim 3, after reading the target data from the cache module and feeding it back to the requester in response to the target data already being cached in the cache module, further comprising: In response to the reuse probability level being the third level, a clearing flag is set for the cache line containing the target data; In response to the reuse probability level being the third level and the cache line containing the target data being marked as pending clearing, the target data is deleted from the cache module.
5. The method according to claim 3, wherein writing the target data into the sticky cache line of the cache module comprises: In response to the fact that the amount of cached data in the cache module does not meet the target condition, the target data is written into any sticky cache line in the cache module that is in an idle state; In response to the cached data amount in the cache module meeting the target condition, the target data replaces the data cached in any cache line of the cache module.
6. The method according to claim 5, wherein the amount of cached data in the caching module satisfies the target condition, including: The total amount of cached data in the cache module is greater than or equal to the available cache space threshold. And / or, in the caching module, the amount of cached data of the target data type is greater than or equal to the target type caching threshold corresponding to the target data type.
7. The method according to claim 6, wherein replacing the data cached in any cache line of the cache module with the target data comprises: In response to the fact that the amount of cached data of the target data type is greater than or equal to the target type cache threshold corresponding to the target data type, the target data replaces the data cached in the target non-sticky cache line in the cache module; Alternatively, the target data can be used to replace the data cached in the target sticky cache line of the cache module; If the amount of cached data of the target data type is less than the target type cache threshold corresponding to the target data type, the target data replaces the data cached in any non-sticky cache line in the cache module; Wherein, the data cached in the target non-sticky cache line before replacement and the target data both belong to the target data type, and the data cached in the target sticky cache line before replacement and the target data both belong to the target data type.
8. The method according to claim 3, wherein writing the target data into the non-sticky cache line of the cache module comprises: In response to the fact that the amount of cached data in the cache module does not meet the target condition, the target data is written into any non-sticky cache line in the cache module that is in an idle state; In response to the cached data amount of the cache module meeting the target condition, the target data replaces the data cached in the target non-sticky cache line of the cache module; Wherein, the data cached in the target non-sticky cache row before replacement and the target data both belong to the target data type.
9. A chip, comprising a cache module and at least one requester capable of accessing the cache module; The caching module is used for: Obtain the access request from the requester. The access request corresponds to the cache management identifier of the target data to be accessed. The cache management identifier is related to the reuse probability of the target data. The reuse probability represents the probability that the target data is read repeatedly. Based on the hit status of the target data in the cache according to the access request and the cache management identifier corresponding to the target data, the cache module manages the cached data, and the hit status indicates whether the target data has been cached in the cache module.
10. An electronic device, comprising a processing module and a system memory module, the processing module including a cache module and at least one requester capable of accessing the cache module; The caching module is used for: Obtain the access request from the requester. The access request corresponds to the cache management identifier of the target data to be accessed. The cache management identifier is related to the reuse probability of the target data. The reuse probability represents the probability that the target data is read repeatedly. Based on the hit status of the target data in the cache according to the access request and the cache management identifier corresponding to the target data, the cache module manages the cached data, and the hit status indicates whether the target data has been cached in the cache module; The system memory module is used to provide the target data to the requester when the cache module does not cache the target data.