Data processing method and device and electronic equipment
By determining the target memory access instruction and target data segment during program running, and using the cache lock interface to lock the data segment in the scenario where the CPU memory access behavior changes, the problem of high cache miss rate is solved, program performance is improved, and errors are avoided. Hardware complexity and cost increase.
Patent Information
- Application Number
- CN202411082916.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2024-10-18
AI Technical Summary
Existing technology is difficult to effectively reduce the cache miss rate during program running, especially when the CPU memory access behavior changes randomly or frequently, and conventional methods rely on the accuracy and timeliness of memory access behavior information, which increases the hardware cost. Complexity and cost.
By determining the target memory access instruction and its corresponding target data segment, the cache lock interface is used to store and lock the target data segment in the preset cache before the target memory access instruction is triggered, thereby reducing the cache miss rate.
It reduces the cache miss rate in scenarios where CPU memory access behavior changes randomly or frequently, improves program performance, and does not rely on the accuracy and timeliness of obtaining memory access behavior information, reducing hardware complexity and cost.
Smart Images

Figure CN118796723A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and more specifically, to a data processing method, device and electronic equipment. Background Art
[0002] Cache is a high-speed cache memory located between the central processing unit (CPU) and the main memory, with the characteristics of small capacity and high speed. Since the CPU is designed to be much faster than the memory, when the CPU directly accesses data from the memory, it has to wait for a certain period of time. The cache usually stores the data that the CPU has just used or frequently used (for example, it may include program code or other types of data). If the CPU needs to use this part of data again, the CPU can directly access it from the cache, which can avoid the CPU waiting time caused by re-reading data directly from the memory, thereby improving the CPU's operating efficiency.
[0003] However, the capacity of the cache is limited. During use, the data stored in the cache will be frequently replaced, which makes it very likely that the data required by the CPU will be replaced out of the cache. If the CPU accesses the cache when the required data is replaced out of the cache, it will not be able to access the required data, resulting in a cache miss. When this cache miss occurs, the CPU also needs to reload the required data from the main memory, which will cause additional delays and affect program performance. Therefore, how to reduce the cache miss rate is one of the keys to optimizing program performance. Summary of the invention
[0004] In view of this, embodiments of the present invention provide a data processing method, device, and electronic device to reduce the cache miss rate during program execution, thereby improving overall program performance.
[0005] In a first aspect, an embodiment of the present invention discloses a data processing method, the method comprising:
[0006] Determine at least one target memory access instruction, where the target memory access instruction is a memory access instruction that has a cache miss during the execution of the target program;
[0007] For each of the target memory access instructions, determining a corresponding target data segment according to a historical cache miss of the target memory access instruction, wherein the target data segment is a data segment covering the miss data, and the miss data is data that the processor fails to access in the cache when the target memory access instruction is triggered;
[0008] The address information of each target data segment is sent to a cache locking interface of a preset cache, so that the cache locking interface stores and locks the corresponding target data segment in the preset cache according to the address information before each target memory access instruction is triggered.
[0009] In a second aspect, an embodiment of the present invention discloses a data processing device, the device comprising:
[0010] A target memory access instruction determination unit, used to determine at least one target memory access instruction, wherein the target memory access instruction is a memory access instruction that has a cache miss during the execution of the target program;
[0011] a target data segment determination unit, configured to determine, for each of the target memory access instructions, a corresponding target data segment according to a historical cache miss of the target memory access instruction, wherein the target data segment is a data segment covering the miss data, and the miss data is data that the processor fails to access in the cache when the target memory access instruction is triggered;
[0012] The address information sending unit is used to send the address information of each target data segment to the cache locking interface of the preset cache, so that the cache locking interface can store and lock the corresponding target data segment in the preset cache according to the address information before each target memory access instruction is triggered.
[0013] In a third aspect, an embodiment of the present invention discloses a computer-readable storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, the method described in the first aspect is implemented.
[0014] In a fourth aspect, an embodiment of the present invention discloses an electronic device, the device comprising:
[0015] a memory for storing one or more computer program instructions;
[0016] A processor, wherein the one or more computer program instructions are executed by the processor to implement the method as described in the first aspect.
[0017] In a fifth aspect, an embodiment of the present invention discloses a computer program product. When the computer program product is run on a computer, the computer is enabled to execute the method as described in the first aspect.
[0018] The embodiment of the present invention determines that there is at least one target memory access instruction in which a cache miss occurs during the execution of the target program, and determines the target data segment corresponding to each target memory access instruction based on the historical cache miss situations of each target memory access instruction, and then sends the address information of each target data segment to the cache locking interface of the preset cache, so that the cache locking interface can store and lock the corresponding target data segment into the preset cache according to the address information before each target memory access instruction is triggered, wherein the target data segment is a data segment covering the miss data, and the miss data is data that the processor fails to access in the cache when the target memory access instruction is triggered. Therefore, the embodiment of the present invention can reduce the cache miss rate during the execution of the program, thereby improving the overall program performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The above and other objects, features and advantages of the present invention will become more apparent through the following description of the embodiments of the present invention with reference to the accompanying drawings, in which:
[0020] Figure 1 is a flow chart of a data processing method according to an embodiment of the present invention;
[0021] Figure 2 A flowchart of a method for determining a target data segment according to an embodiment of the present invention;
[0022] Figure 3 A flowchart of a method for determining a target data segment according to an embodiment of the present invention;
[0023] Figure 4 is a flow chart of a method for determining a densest subarray according to an embodiment of the present invention;
[0024] Figure 5 Schematic diagram of a process for determining a subarray according to an embodiment of the present invention;
[0025] Figure 6 is a schematic diagram of a data processing device according to an embodiment of the present invention;
[0026] Figure 7 is a schematic diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0027] The present application is described below based on embodiments, but the present application is not limited to these embodiments. In the detailed description of the present application below, some specific details are described in detail. It is possible for those skilled in the art to fully understand the present application without the description of these details. In order to avoid confusing the essence of the present application, known methods, processes, flows, components and circuits are not described in detail.
[0028] In addition, persons of ordinary skill in the art will appreciate that the drawings provided herein are for illustration purposes and are not necessarily drawn to scale.
[0029] Unless the context clearly requires otherwise, the words "include", "comprising" and similar words throughout the application should be interpreted as including rather than exclusive or exhaustive; that is, the meaning is "including but not limited to".
[0030] In the description of this application, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of this application, unless otherwise specified, the meaning of "plurality" is two or more.
[0031] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0032] In a related technology, in order to reduce the cache miss rate during program execution and reduce the additional delay caused by cache misses, the related technology detects the memory access behavior of the CPU during program execution, and predicts the data that the CPU needs to access at the next moment based on these access behaviors, and then pre-loads the relevant data into the cache based on the prediction results before the CPU actually needs these data. However, the related technology can only cope with scenarios where the CPU's memory access behavior has a high regularity, and cannot handle scenarios where the CPU's memory access behavior changes randomly or frequently. At the same time, the related technology also has high requirements for the acquisition of the CPU's memory access behavior information. Once the CPU's memory access behavior information is not acquired accurately or in a timely manner, the prediction accuracy will decrease.
[0033] In another related technology, in order to reduce the cache miss rate during program execution and reduce the additional delay caused by cache misses, the related technology optimizes the cache replacement strategy of the cache, thereby extending the retention time of the data that the CPU is most likely to access again in the cache. However, the optimization of the cache replacement strategy is difficult, and the optimized cache replacement strategy can usually only be targeted at specific access modes, which not only has poor versatility, but also easily affects the performance of other programs. At the same time, the implementation of the optimized cache replacement strategy often requires strong support from related hardware (such as bitmaps, counters or state machines, etc.), which increases the complexity and cost of the hardware.
[0034] In this regard, embodiments of the present invention provide a data processing method, device, and electronic device to reduce the cache miss rate during program execution, thereby improving overall program performance.
[0035] Compared with the above-mentioned related technologies, the data processing method in the embodiment of the present invention can be used to process scenarios where the memory access behavior of the CPU changes randomly or frequently, and does not rely on the accuracy and timeliness of obtaining memory access behavior information. At the same time, it has stronger versatility and will not increase the complexity and cost of the hardware too much.
[0036] Figure 1 FIG. 1 is a flow chart of a data processing method according to an embodiment of the present invention. Figure 1 As shown, the data processing method may specifically include the following steps:
[0037] It should be understood that Figure 1 The data processing method shown can be used to reduce the cache miss rate of the target device during the operation of the target program, thereby improving the overall program performance of the target program. Among them, the target device can be a data processing device with data processing function (such as a smart phone, tablet computer, smart wearable device, laptop or server, etc.) or an embedded system (such as a microcontroller), etc. The target program can be an application, a system program, a web page program, a cloud computing service program, a big data processing program, or any other program that has a memory access demand during operation. This application does not limit the device type of the target device and the program type of the target program.
[0038] It should be understood that Figure 1 The data processing method shown can be implemented by hardware (the hardware can be integrated in the target device), or by a corresponding program or software (the program or software can be obtained by programming, and the programmed program or software can be run by the target device). In the following description, the data processing method will be implemented by the target device by executing the programmed program or software as an example.
[0039] Step S100: Determine at least one target memory access instruction.
[0040] Specifically, the target device may determine that there is at least one target memory access instruction with a cache miss during the execution of the target program. The cache miss may refer to a situation where, when the memory access instruction is triggered, the processor (i.e., the CPU) attempts to access in the cache but fails to find the required data or only finds part of the required data.
[0041] Optionally, in step S100, the target memory access instruction may be determined by the target device according to the historical operation of the target program. Specifically, during the historical operation of the target program, the target device may perform instruction stream acquisition to obtain cache hit information of at least one access instruction. Based on the cache hit information, the target device may determine the memory access instruction with a cache miss as the target memory access instruction. The cache hit information may include the cache hit rate of the instruction and data information of related data that the processor failed to access in the cache.
[0042] Further optionally, the instruction stream collection operation can be implemented by the target device by calling the corresponding collection program or collection software. Wherein, the collection program or collection software can specifically be DynamoRIO (Dynamo Runtime Instrumentation Overlays, dynamic runtime plug-in coverage) or SPE (Statistical Profiling Extension, statistical analysis extension) and the like. The DynamoRIO is an open source dynamic binary plug-in framework, which can collect the instruction stream information triggered by the program during operation by adopting dynamic binary plug-in, event monitoring and performance counters. The SPE is an optional function in ARMv8.2 (ARM architecture version 8.2-A), which allows the system to collect statistical information about the behavior of the program during operation, and can provide a statistical view of the performance characteristics of the execution instruction. It should be understood that in the actual application process, the target device can also use other collection programs or collection software to implement the instruction stream collection operation, and this application does not specifically limit the collection program or collection software used by the device to implement the instruction stream collection operation.
[0043] Step S200: For each of the target memory access instructions, determine a corresponding target data segment according to a historical cache miss situation of the target memory access instruction.
[0044] Specifically, after determining at least one target memory access instruction, the target device may determine the target data segment corresponding to each target memory access instruction according to the historical cache miss situation of each target memory access instruction. The target data segment may be a data segment covering the miss data, and the miss data may be data that the processor fails to access in the cache when the target memory access instruction is triggered.
[0045] It should be understood that when storing data in the cache, the cache controller (i.e., the hardware component responsible for managing the cache) usually does not store only the data to be stored in the cache separately, but stores a continuous data segment that can cover the data to be stored in the cache. However, the capacity of the cache is limited. If the data to be stored is too scattered, then when the data segment that can completely cover the data to be stored is stored in the cache as the target data segment, it will cause excessive waste of cache capacity. Therefore, in this embodiment, in order to reduce the waste of cache capacity, the target data segment can be a data segment that can completely cover the missed data, or a data segment that can only partially cover the missed data (the specific coverage rate can be set and adjusted by relevant personnel according to actual conditions during actual application). The specific coverage rate can be determined according to actual conditions.
[0046] Figure 2 FIG. 1 is a flow chart of a method for determining a target data segment according to an embodiment of the present invention. Figure 2 As shown, the target data segment determination method may specifically include the following steps:
[0047] It should be understood that for any target memory access instruction, by executing Figure 2 The target data segment determination method shown in the figure enables the target device to determine a reasonable target data segment for the target memory access instruction (that is, to store the target data segment in the cache, which can both maximize the cache hit rate and minimize the waste of cache capacity).
[0048] Step S210: Determine a miss data address array corresponding to the target memory access instruction.
[0049] The miss data address array is a data address set of miss data. Specifically, the target device can determine the miss data that the processor fails to access in the cache when the target memory access instruction is triggered, and obtain the data addresses of these miss data, thereby obtaining the miss data address array corresponding to the target memory access instruction.
[0050] Optionally, the miss data corresponding to the target memory access instruction may be determined by the target device according to cache hit information of the target memory access instruction collected by executing an instruction stream collection operation during the historical running process of the target program.
[0051] Step S220: Determine the memory access length of the miss data address array.
[0052] The memory access length is the address offset between the maximum data address and the minimum data address in the missed data address array. Specifically, after determining the missed data address array corresponding to the target memory access instruction, the target device can determine the address offset between the maximum data address and the minimum data address in the missed data address array, and use the address offset as the memory access length of the missed data address array.
[0053] Step S220: Determine a target data segment corresponding to the target memory access instruction according to the miss data address array and the memory access length.
[0054] Specifically, after determining the memory access length of the missed data address array, the target device may determine the target data segment corresponding to the target memory access instruction according to the missed data address array and the memory access length.
[0055] Optionally, in step S220, the target device may determine whether the memory access length is less than or equal to a first preset length threshold. If the memory access length is less than or equal to the first preset length threshold, the target device may confirm that the data segment that can completely cover the target data is shorter and is suitable for being directly stored in the cache. At this time, the target device may directly determine the data segment between the maximum data address and the minimum data address in the miss data address array as the target data segment corresponding to the target memory access instruction. If the memory access length is greater than the first preset length threshold, the target device may confirm that the data segment that can completely cover the target data is too long and is not suitable for being directly stored in the cache. At this time, the target device may determine a data segment whose length is less than or equal to the second preset length threshold and whose miss data coverage is greater than or equal to the preset coverage threshold as the target data segment corresponding to the target memory access instruction.
[0056] Among them, the first preset length threshold is less than the second preset length threshold, and the specific values of the first preset length threshold and the second preset length threshold can be set and adjusted by relevant personnel according to the actual capacity of the cache. In some embodiments, the specific value of the first preset length threshold can be 64Kb (i.e., kilobits), and the specific value of the second preset length threshold can be half of the preset cache capacity. Similar to the first preset length threshold and the second preset length threshold, the specific value of the preset coverage threshold can also be set and adjusted by relevant personnel according to actual conditions during actual application.
[0057] It should be understood that when determining the target data segment, the target device can determine any data segment that meets the above conditions (that is, the length is less than or equal to the second preset length threshold and the miss data coverage is greater than or equal to the preset coverage threshold) as the target data segment, and the present application does not impose any restrictions on this.
[0058] Alternatively, in order to minimize the waste of cache capacity, the target device may also determine the shortest data segment or a shorter data segment that can meet the above conditions as the target data segment when determining the target data segment.
[0059] Figure 3 FIG. 1 is a flow chart of a method for determining a target data segment according to an embodiment of the present invention. Figure 3 As shown, the target data segment determination method may specifically include the following steps:
[0060] It should be understood that by executing Figure 3 According to the target data segment determination method shown, the target device can find the shortest data segment or a shorter data segment that can meet the above conditions, and determine the data segment as the target data segment.
[0061] Step S221, initialize the sliding window.
[0062] Specifically, the target device may initialize the sliding window. Initializing the sliding window may refer to assigning an initial value to the length of the sliding window. It should be understood that the initial length of the sliding window determines the shortest length of the data segment that can be found to meet the above conditions. In order to find the shortest data segment or a shorter data segment that can meet the above conditions, the initial value assigned by the target device to the sliding window may be set as small as possible. Optionally, in step S221, the target device may set the length of the sliding window to a first preset length threshold.
[0063] Step S222: using the sliding window to determine the most dense subarray in the miss data address array.
[0064] Specifically, using the current sliding window, the target device can determine a most dense subarray in the missed data address array. The most dense subarray is a subset of the missed data address array that contains the most data addresses, and the address offset between the maximum data address and the minimum data address is less than or equal to the length of the current sliding window. For example, assuming that the missed data address array is (1, 2, 3, 4, 7, 9, 10), and the length of the current sliding window is 5, then the most dense subarray determined by the target device in the missed data address array can be (1, 2, 3, 4).
[0065] It should be understood that in the above examples, each integer in the miss data address array can be used to represent a data address. Two adjacent integers can represent that the data addresses represented by the two integers are adjacent.
[0066] Figure 4 FIG. 4 is a flow chart of a method for determining the densest subarray according to an embodiment of the present invention. Figure 4 As shown, the method for determining the densest subarray may specifically include the following steps:
[0067] It should be understood that by executing Figure 4 In the method for determining the densest subarray shown, the target device can use a sliding window to determine the densest subarray that meets the requirements in the miss data address array, thereby implementing the above step S222.
[0068] Step S2221: Slide the sliding window between the maximum data address and the minimum data address in the miss data address array to determine multiple address intervals.
[0069] Specifically, the target device can slide the current sliding window between the maximum data address and the minimum data address in the missed data address array, thereby determining multiple address intervals. The address intervals may be multiple intervals defined by the current sliding window during the sliding process. It should be understood that in actual application, when multiple address intervals are obtained by sliding the sliding window, the distance that the sliding window slides each time can be specifically set and adjusted by relevant personnel according to actual needs, and this application does not limit this.
[0070] Figure 5 FIG. 4 is a schematic diagram of a process for determining a subarray according to an embodiment of the present invention. Figure 5 As shown, for the miss data address array (1, 2, 3, 4, 7, 9, 10), if the sliding distance is 1, the target device can slide the current sliding window 51 (the length of the sliding window is 5) between the maximum data address and the minimum data address in the miss data address array (that is, between 1 and 10), thereby determining multiple address intervals 52, 53, 54, 55, 56 and 57.
[0071] Step S2222: For each of the address intervals, determine the maximum data address and the minimum data address of the miss data address array within the address interval.
[0072] Specifically, after obtaining multiple address intervals, the target device may determine the maximum data address and the minimum data address of the missed data address array in each address interval.
[0073] like Figure 5 As shown, the target device can determine the maximum data address 4 and the minimum data address 1 of the missed data address array (1, 2, 3, 4, 7, 9, 10) in address interval 52, the maximum data address 4 and the minimum data address 2 in address interval 53, the maximum data address 7 and the minimum data address 3 in address interval 54, the maximum data address 7 and the minimum data address 4 in address interval 55, the maximum data address 9 and the minimum data address 7 in address interval 56, and the maximum data address 10 and the minimum data address 7 in address interval 57.
[0074] Optionally, the miss data address array given above is only for illustration. In actual application, the number of data addresses contained in the miss data address array will be very large, and under normal circumstances, the data addresses contained in the miss data address array are usually disordered. In this regard, in order to improve the efficiency of searching for the maximum data address and the minimum data address, when searching for the maximum data address and the minimum data address, the target device can use an increasing monotonic stack to determine the maximum data address of the miss data address array within the address range, and can use a decreasing monotonic stack to determine the minimum data address of the miss data address array within the address range.
[0075] Among them, the monotonic stack is a special type of stack, whose main feature is that the elements in the stack maintain a monotonically increasing or monotonically decreasing order. In a monotonically increasing stack, the elements in the stack are in increasing order from the bottom of the stack to the top of the stack, while in a monotonically decreasing stack, the elements in the stack are in decreasing order from the bottom of the stack to the top of the stack. Therefore, by using the increasing monotonic stack and the decreasing monotonic stack to traverse each data address in the missed data address array respectively, the target device can determine the maximum data address and the minimum data address of the missed data address array in the address range.
[0076] Step S2223: Determine a plurality of sub-arrays according to the maximum data address and the minimum data address of the miss data address array in each of the address intervals.
[0077] Specifically, after the maximum data address and the minimum data address of the missed data address array in each address interval are determined, the target device may determine a plurality of sub-arrays according to the maximum data address and the minimum data address of the missed data address array in each address interval.
[0078] For any address interval, the subarray determined according to the address interval may include the maximum data address and the minimum data address of the missed data address array in the address interval, and other data addresses between two data addresses in the missed data address array.
[0079] like Figure 5As shown, the target device can determine the sub-array (1, 2, 3, 4) according to the maximum data address 4 and the minimum data address 1 of the miss data address array (1, 2, 3, 4, 7, 9, 10) in the address interval 52, determine the sub-array (2, 3, 4) according to the maximum data address 4 and the minimum data address 2 of the miss data address array in the address interval 53, determine the sub-array (3, 4, 7) according to the maximum data address 7 and the minimum data address 3 of the miss data address array in the address interval 54, determine the sub-array (4, 7) according to the maximum data address 7 and the minimum data address 4 of the miss data address array in the address interval 55, determine the sub-array (7, 9) according to the maximum data address 9 and the minimum data address 7 of the miss data address array in the address interval 56, and determine the sub-array (7, 9, 10) according to the maximum data address 10 and the minimum data address 7 of the miss data address array in the address interval 57.
[0080] Step S2224: determine the sub-array containing the most data addresses as the most dense sub-array.
[0081] Specifically, if the length of the current sliding window is less than or equal to the second preset length threshold, then the address offset between the maximum data address and the minimum data address in each sub-array determined in the above manner must also be less than or equal to the second preset length threshold. Therefore, after obtaining each sub-array, the target device can directly determine the sub-array containing the most data addresses as the densest sub-array.
[0082] For example, assuming that the obtained sub-arrays are (1, 2, 3, 4), (2, 3, 4), (3, 4, 7), (4, 7), (7, 9) and (7, 9, 10), the target device can directly determine (1, 2, 3, 4) containing the most data addresses as the most dense sub-array.
[0083] Step S223: Determine the miss data coverage rate of the most dense sub-array.
[0084] Specifically, after determining the most dense subarray in the miss data address array using the current sliding window, the target device may determine the miss data coverage of the current most dense subarray.
[0085] Optionally, in step S223, since the densest subarray is a subset of the miss data address array, the target device may directly determine the miss data coverage of the densest subarray by the ratio of the number of data addresses included in the densest subarray to the number of data addresses included in the miss data address array. For example, for the miss data address array (1, 2, 3, 4, 7, 9, 10), the miss data coverage of the densest subarray (1, 2, 3, 4) may be approximately 57%.
[0086] Step S224: determine whether the miss data coverage is less than a preset coverage threshold.
[0087] Specifically, after determining the miss data coverage of the current most dense subarray, the target device may determine whether the miss data coverage is less than a preset coverage threshold. If not, the target device may execute step S225 to determine the target data segment according to the current most dense subarray. If yes, the target device may execute step S226 to determine the length of the current sliding window.
[0088] Step S225: determine the data segment between the maximum data address and the minimum data address in the densest sub-array as the target data segment.
[0089] Specifically, if it is determined that the miss data coverage is greater than or equal to a preset coverage threshold, the target device can stop the iteration process and determine the data segment between the maximum data address and the minimum data address in the current most dense sub-array as the target data segment.
[0090] Step S226: Determine whether the length of the sliding window increases to a second preset length threshold.
[0091] Specifically, if it is determined that the missed data coverage is less than the preset coverage threshold, the target device can further detect whether the length of the current sliding window has grown to the second preset length threshold. If so, the target device can confirm that a data segment whose length is less than or equal to the second preset length threshold and whose missed data coverage is greater than or equal to the preset coverage threshold does not exist, thereby terminating the iterative process. If not, the target device can execute step S227 to adjust the length of the sliding window, and continue to search for a new most dense subarray using the sliding window after the adjusted length.
[0092] It should be understood that when it is confirmed that the data segment whose length is less than or equal to the second preset length threshold and whose miss data coverage is greater than or equal to the preset coverage threshold does not exist, the target device may also mark the current target memory access instruction as a memory access instruction that cannot be optimized for cache lock. Among them, being marked as unable to perform cache lock optimization is used to characterize that the memory access instruction needs to be optimized using other optimization methods other than cache lock optimization, and this application does not specifically limit other optimization methods used for memory access instructions.
[0093] Step S227: Increase the length of the sliding window by a preset length.
[0094] Specifically, if the length of the current sliding window has not increased to the second preset length threshold, the target device may increase the length of the current sliding window by the preset length. Then, the target device may return and re-execute step 222 to continue searching for a new most dense subarray that meets the requirements using the adjusted sliding window.
[0095] Optionally, in order to find the shortest data segment or shorter data segment that can meet the above conditions (i.e., the length is less than or equal to the second preset length threshold and the miss data coverage is greater than or equal to the preset coverage threshold), the specific value of the preset length can be set as small as possible. Optionally, the specific value of the preset length can be 64Kb.
[0096] Step S300: Send the address information of each target data segment to the cache locking interface of the preset cache, so that the cache locking interface stores and locks the corresponding target data segment in the preset cache according to the address information before each target memory access instruction is triggered.
[0097] Specifically, after determining the target data segment corresponding to each target memory access instruction, the target device can send the address information of each target data segment to the cache locking interface of the preset cache. After receiving the address information of each target data segment, the cache locking interface will store and lock the corresponding target data segment in the preset cache according to the address information of each target data segment before each target memory access instruction is triggered.
[0098] Wherein, since the target data segment is a continuous data segment, the address information of the target data segment may include the starting data address of the target data segment and the length information of the target data segment. The cache locking interface may be an interface for providing a cache data locking service, which may lock the relevant data in the cache, thereby preventing the relevant data from being replaced or modified.
[0099] It should be understood that this embodiment does not limit how the cache locking interface specifically stores and locks the target data segment in the cache, as long as it can ensure that before each target memory access instruction is triggered, the target data segment corresponding to each target memory access instruction is stored and locked in the preset cache. Optionally, as an implementation, the cache locking interface can pre-store and lock the corresponding target data segment in the preset cache before each target memory access instruction is triggered, based on the triggering order of each target memory access instruction. As another implementation, the cache locking interface can also store and lock the target data segment corresponding to each target memory access instruction in the preset cache at one time before each target memory access instruction is triggered.
[0100] Optionally, the cache can be generally divided into three levels according to location, size, speed and function. Among them, compared with the first-level cache and the second-level cache, the third-level cache has a larger storage capacity. Therefore, in this embodiment, the preset cache can specifically refer to the third-level cache. However, it should be understood that in the previous steps, that is, when the target device determines the target memory access instruction with a cache miss and determines the miss data address array corresponding to the target memory access instruction, the target device does not need to distinguish the level of the cache. That is, when determining the target memory access instruction with a cache miss, as long as there is a cache miss, regardless of whether the processor accesses the first-level cache, the second-level cache, or the third-level cache, the relevant memory access instruction will be determined by the target device as the target memory access instruction. Correspondingly, when determining the miss data address array corresponding to the target memory access instruction, the target device will not distinguish whether the miss data is a miss in the first-level cache, a miss in the second-level cache, or a miss in the third-level cache.
[0101] The embodiment of the present invention determines that there is at least one target memory access instruction in which a cache miss occurs during the execution of the target program, and determines the target data segment corresponding to each target memory access instruction based on the historical cache miss situations of each target memory access instruction, and then sends the address information of each target data segment to the cache locking interface of the preset cache, so that the cache locking interface can store and lock the corresponding target data segment into the preset cache according to the address information before each target memory access instruction is triggered, wherein the target data segment is a data segment covering the miss data, and the miss data is data that the processor fails to access in the cache when the target memory access instruction is triggered. Therefore, the embodiment of the present invention can reduce the cache miss rate during the execution of the program, thereby improving the overall program performance.
[0102] Figure 6 FIG. 1 is a schematic diagram of a data processing device according to an embodiment of the present invention. Figure 6 As shown, the data processing device of the embodiment of the present invention includes a target memory access instruction determination unit 61, a target data segment determination unit 62 and an address information sending unit 63.
[0103] Specifically, the target memory access instruction determination unit 61 is used to determine at least one target memory access instruction, where the target memory access instruction is a memory access instruction that has a cache miss during the execution of the target program;
[0104] The target data segment determination unit 62 is used to determine, for each target memory access instruction, a corresponding target data segment according to a historical cache miss of the target memory access instruction, wherein the target data segment is a data segment covering the miss data, and the miss data is data that the processor fails to access in the cache when the target memory access instruction is triggered;
[0105] The address information sending unit 63 is used to send the address information of each target data segment to the cache locking interface of the preset cache, so that the cache locking interface stores and locks the corresponding target data segment in the preset cache according to the address information before each target memory access instruction is triggered.
[0106] The embodiment of the present invention determines that there is at least one target memory access instruction in which a cache miss occurs during the execution of the target program, and determines the target data segment corresponding to each target memory access instruction based on the historical cache miss situations of each target memory access instruction, and then sends the address information of each target data segment to the cache locking interface of the preset cache, so that the cache locking interface can store and lock the corresponding target data segment into the preset cache according to the address information before each target memory access instruction is triggered, wherein the target data segment is a data segment covering the miss data, and the miss data is data that the processor fails to access in the cache when the target memory access instruction is triggered. Therefore, the embodiment of the present invention can reduce the cache miss rate during the execution of the program, thereby improving the overall program performance.
[0107] Figure 7 is a schematic diagram of an electronic device according to an embodiment of the present invention. The electronic device may specifically be a data processing device according to the above embodiment. Figure 7 As shown, the electronic device includes: at least one processor 71; a memory 72 connected to the at least one processor 71 for communication; and a communication component 73 connected to the scanning device for communication, the communication component 73 receiving and sending data under the control of the processor 71; wherein the memory 72 stores instructions executable by the at least one processor 71, and the instructions are executed by the at least one processor 71 to implement the above-mentioned data processing method.
[0108] Specifically, the electronic device includes: one or more processors 71 and a memory 72, Figure 7 A processor 71 is taken as an example. The processor 71 and the memory 72 may be connected via a bus or other means. Figure 7 In the example, the bus connection is used. The memory 72 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The processor 71 executes various functional applications and data processing of the device by running the non-volatile software programs, instructions and modules stored in the memory 72, that is, realizing the above-mentioned data processing method.
[0109] The memory 72 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and applications required for at least one function; the data storage area may store a list of options, etc. In addition, the memory 72 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 72 may optionally include a memory remotely arranged relative to the processor 71, and these remote memories may be connected to an external device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0110] One or more modules are stored in the memory 72, and when executed by one or more processors 71, the data processing method in any of the above method embodiments is executed.
[0111] The above-mentioned product can execute the method provided in the embodiment of the present application, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not fully described in this embodiment, please refer to the method provided in the embodiment of the present application.
[0112] The embodiment of the present invention determines that there is at least one target memory access instruction in which a cache miss occurs during the execution of the target program, and determines the target data segment corresponding to each target memory access instruction based on the historical cache miss situations of each target memory access instruction, and then sends the address information of each target data segment to the cache locking interface of the preset cache, so that the cache locking interface can store and lock the corresponding target data segment into the preset cache according to the address information before each target memory access instruction is triggered, wherein the target data segment is a data segment covering the miss data, and the miss data is data that the processor fails to access in the cache when the target memory access instruction is triggered. Therefore, the embodiment of the present invention can reduce the cache miss rate during the execution of the program, thereby improving the overall program performance.
[0113] Another embodiment of the present invention relates to a non-volatile storage medium for storing a computer-readable program, wherein the computer-readable program is used for a computer to execute part or all of the above method embodiments.
[0114] That is, those skilled in the art can understand that all or part of the steps in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a program, and the program is stored in a storage medium, including a number of instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0115] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A data processing method, characterized in that: The method comprises: Determine at least one target memory access instruction, where the target memory access instruction is a memory access instruction that has a cache miss during the execution of the target program; For each of the target memory access instructions, determining a corresponding target data segment according to a historical cache miss of the target memory access instruction, wherein the target data segment is a data segment covering the miss data, and the miss data is data that the processor fails to access in the cache when the target memory access instruction is triggered; The address information of each target data segment is sent to a cache locking interface of a preset cache, so that the cache locking interface stores and locks the corresponding target data segment in the preset cache according to the address information before each target memory access instruction is triggered.
2. The method according to claim 1, characterized in that Determining the corresponding target data segment according to the historical cache miss situation of the target memory access instruction includes: Determine a miss data address array corresponding to the target memory access instruction, wherein the miss data address array is a data address set of miss data; Determine a memory access length of the missed data address array, wherein the memory access length is an address offset between a maximum data address and a minimum data address in the missed data address array; A target data segment corresponding to the target memory access instruction is determined according to the miss data address array and the memory access length.
3. The method according to claim 2, characterized in that The step of determining the target data segment corresponding to the target memory access instruction according to the miss data address array and the memory access length comprises: In response to the memory access length being less than or equal to a first preset length threshold, determining a data segment between a maximum data address and a minimum data address in the missed data address array as a target data segment corresponding to the target memory access instruction; In response to the memory access length being greater than the first preset length threshold, a data segment whose length is less than or equal to a second preset length threshold and whose miss data coverage is greater than or equal to a preset coverage threshold is determined as a target data segment corresponding to the target memory access instruction, and the first preset length threshold is less than the second preset length threshold.
4. The method according to claim 3, characterized in that: The step of determining a data segment having a length less than or equal to a second preset length threshold and a miss data coverage greater than or equal to a preset coverage threshold as a target data segment corresponding to the target memory access instruction comprises: Initialize the sliding window, and iteratively perform the following steps until the target data segment is obtained or it is detected that the length of the sliding window grows to the second preset length threshold; Determine the most dense subarray in the miss data address array by using the sliding window, the most dense subarray being a subset of the miss data address array that contains the most data addresses and an address offset between a maximum data address and a minimum data address that is less than or equal to a length of the sliding window; Determine the miss data coverage of the densest subarray, the target data segment being a data segment between a maximum data address and a minimum data address in the densest subarray whose miss data coverage is greater than or equal to a preset coverage threshold; The length of the sliding window is increased by a preset length.
5. The method according to claim 4, characterized in that Determining the most dense subarray in the miss data address array using the sliding window includes: Sliding the sliding window between the maximum data address and the minimum data address in the miss data address array to determine a plurality of address intervals; For each of the address intervals, determining a maximum data address and a minimum data address of the miss data address array within the address interval; Determine a plurality of sub-arrays according to the maximum data address and the minimum data address of the miss data address array in each of the address intervals; The sub-array containing the most data addresses is determined as the most dense sub-array.
6. The method according to claim 5, characterized in that Determining the maximum data address and the minimum data address of the miss data address array within the address interval includes: Determine the maximum data address of the miss data address array within the address range by using an increasing monotonic stack; A decreasing monotonic stack is used to determine the minimum data address of the miss data address array within the address range.
7. The method according to claim 4, characterized in that The initialization sliding window includes: The length of the sliding window is set to the first preset length threshold.
8. The method according to claim 4, characterized in that Determining the miss data coverage rate of the densest subarray includes: The ratio of the number of data addresses included in the most dense sub-array to the number of data addresses included in the miss data address array is determined as the miss data coverage rate of the most dense sub-array.
9. The method according to claim 3, characterized in that: The method further comprises: In response to detecting that the data segment whose length is less than or equal to the second preset length threshold and whose miss data coverage is greater than or equal to the preset coverage threshold does not exist, marking the target memory access instruction as a memory access instruction that cannot be cache locked optimized.
10. The method according to claim 1, characterized in that Determining at least one target memory access instruction comprises: During the historical running process of the target program, instruction stream collection is performed to obtain cache hit information of at least one access instruction; A memory access instruction with a cache miss condition is determined as the target memory access instruction according to the cache hit information.
11. A data processing device, characterized in that: The device comprises: A target memory access instruction determination unit, used to determine at least one target memory access instruction, wherein the target memory access instruction is a memory access instruction that has a cache miss during the execution of the target program; a target data segment determination unit, configured to determine, for each of the target memory access instructions, a corresponding target data segment according to a historical cache miss of the target memory access instruction, wherein the target data segment is a data segment covering the miss data, and the miss data is data that the processor fails to access in the cache when the target memory access instruction is triggered; The address information sending unit is used to send the address information of each target data segment to the cache locking interface of the preset cache, so that the cache locking interface can store and lock the corresponding target data segment in the preset cache according to the address information before each target memory access instruction is triggered.
12. A computer-readable storage medium storing computer program instructions, characterized in that: The computer program instructions implement the method according to any one of claims 1 to 10 when executed by a processor.
13. An electronic device, characterized in that: The device comprises: a memory for storing one or more computer program instructions; A processor, wherein the one or more computer program instructions are executed by the processor to implement the method according to any one of claims 1 to 10.
14. A computer program product, characterized in that When the computer program product is run on a computer, the computer is caused to execute the method according to any one of claims 1 to 10.
