Adaptive cache prefetch system and method
The adaptive cache prefetch system enhances cache performance by using prefetch flags and history tables to optimize prefetch operations, addressing inefficiencies in existing methods and improving memory access efficiency.
Patent Information
- Application Number
- US19/262014
- Authority / Receiving Office
- US · United States
- Patent Type
- Patents(United States)
- Current Assignee / Owner
- Filing Date
- 2025-07-07
- Publication Date
- 2026-12-01
- Estimated Expiration
- 2045-07-07
AI Technical Summary
Existing cache prefetching methods face challenges in accuracy, timeliness, overhead, adaptability, and redundancy, leading to inefficient memory access and performance degradation due to cache misses and redundant prefetch operations.
A cache memory system with prefetch flags and history tables that adaptively manage prefetch operations, using prefetch flags to track which addresses have already been prefetched and dynamically adjust prefetch directions based on memory access patterns, avoiding redundancy and optimizing prefetch timing.
Improves cache hit rates and overall system performance by intelligently managing prefetch operations, reducing redundant memory accesses and conserving bandwidth, particularly in applications with diverse memory access patterns.
Smart Images

Figure US12817787-D00000_ABST
Abstract
Description
BACKGROUND
[0001] In modern computing systems, there exists a substantial speed disparity between processors and main memory. Processors operate at frequencies measured in gigahertz, while main memory access times are significantly slower. This speed gap, often referred to as the memory wall, creates a bottleneck in system performance. When a processor needs to access data not currently in its cache (a cache miss), it must wait for the relatively slow main memory to respond, resulting in processor stalls that significantly degrade system performance.
[0002] To bridge this performance gap, computer engineers have implemented hierarchical memory systems. At the top of this hierarchy are cache memories—small, high-speed storage areas positioned between the processor and main memory. Caches store copies of frequently accessed data from main memory, allowing processors to access this data with reduced latency. Modern processors typically incorporate multiple levels of cache (L1, L2, and sometimes L3), with each level providing different trade-offs between size, speed, and proximity to the processor core.
[0003] Despite the benefits of cache memories, cache misses still occur when the processor requests data not currently stored in the cache. These misses are particularly costly in terms of performance, as the processor must stall while waiting for the requested data to be fetched from main memory, which can take hundreds of processor cycles.
[0004] Cache prefetching is a technique developed to mitigate the impact of cache misses by predicting which data the processor will need in the near future and proactively loading that data into the cache before it is actually requested. Effective prefetching can significantly reduce cache misses and improve overall system performance.
[0005] While existing prefetching methods have proven beneficial, they still face significant challenges in terms of accuracy, timeliness, overhead, adaptability, and redundancy. Inaccurate prefetching wastes memory bandwidth and can pollute the cache. Prefetched data must arrive in the cache at the right time—not too late, but also not so early that it can be evicted before use. Some techniques require substantial hardware resources or introduce additional memory traffic. Memory access patterns vary widely across different applications and even within different phases of the same application, making static prefetching strategies less effective. Additionally, redundant prefetches can lead to wasted memory bandwidth and cache pollution.
[0006] Conventional cache prefetching methods typically trigger prefetch operations only when a cache miss occurs. While this approach avoids unnecessary prefetching when the processor is successfully accessing data from the cache, it also means that prefetching only begins after the processor has already experienced the latency penalty of a cache miss. Additionally, these methods often lack sophisticated mechanisms to track which addresses have already been prefetched, potentially leading to redundant prefetch operations that waste memory bandwidth and energy. Furthermore, most existing prefetching techniques use fixed prefetching directions or patterns, which may not adapt well to the varying memory access patterns exhibited by modern applications. Some programs access memory in ascending address order, others in descending order, and many switch between patterns during execution.
[0007] There remains a need for more intelligent and adaptive prefetching mechanisms that can accurately predict which data to prefetch, avoid redundant prefetching operations, adapt to changing memory access patterns, and initiate prefetching at optimal times to maximize performance benefits while minimizing resource consumption.SUMMARY
[0008] In accordance with the present disclosure, systems and methods for adaptive cache prefetching are provided. An embodiment provides a prefetch method for a cache memory that manages prefetch operations to optimize memory access efficiency and enhance processor performance.
[0009] In some aspects, a cache memory system is provided that comprises a plurality of cache lines, wherein each cache line includes a prefetch flag that indicates whether an automatic prefetch function has been triggered for the address corresponding to the respective cache line. The prefetch flag may have a first value indicating that the automatic prefetch function has been triggered for the corresponding address, or a second value indicating that the automatic prefetch function has not been triggered for the corresponding address.
[0010] An embodiment provides a method that includes receiving a first address and performing a cache hit check to determine whether data corresponding to the first address is stored in the cache memory. If the cache hit check results in a hit and the prefetch flag of the target cache line has the second value, the method triggers the automatic prefetch function for the first address and updates the prefetch flag to the first value. The method then executes a prefetch operation based on the first address to prefetch external data located outside the cache memory.
[0011] In some aspects, when the cache hit check results in a miss, the method may trigger the automatic prefetch function for the first address, fetch one piece of external data corresponding to the first address into the target cache line, and execute a prefetch operation based on the first address to prefetch additional external data into the cache memory.
[0012] In some aspects, executing the prefetch operation may include determining a starting address based on the first address and a cache line size, determining a combination of N addresses based on the starting address, the cache line size, and a predetermined prefetch mode, and prefetching N pieces of external data into N cache lines of the cache memory, where N is a positive integer.
[0013] In some aspects, the predetermined prefetch mode may include a forward prefetch mode that prefetches in an increasing address manner and / or a backward prefetch mode that prefetches in a decreasing address manner. The method may maintain and update a history table that records addresses corresponding to previous prefetch operations to avoid redundant prefetching.
[0014] In some aspects an adaptive direction mechanism is provided wherein the prefetch method may switch between the forward and backward prefetch modes based on detected memory access patterns. The method may change from forward to backward prefetching if it detects M consecutive addresses that are decreasing in value, or vice versa if M consecutive increasing addresses are detected, where M is a positive integer.
[0015] In some aspects, the method may determine, based on the history table, whether at least one address in the combination of N addresses has already undergone a prefetch operation, and if so, skip the corresponding prefetch operation for that address to avoid redundancy.
[0016] In some aspects, a plurality of instruction sequences may correspond to different history tables, with each instruction sequence having its own corresponding history table to track prefetch operations for different execution contexts.
[0017] In some aspects, a cache memory system is provided comprising a cache memory with prefetch flags and a prefetch circuit configured to implement the disclosed prefetch method. The prefetch circuit may be configured to perform cache hit checks, trigger the automatic prefetch function based on hit status and prefetch flag values, and execute prefetch operations with adaptive directional control.
[0018] To the accomplishment of the foregoing and related ends, certain embodiments comprise the features hereinafter fully described and particularly pointed out in the claims. The following description and accompanying drawings set forth in detail certain illustrative aspects of the embodiments. These aspects are indicative, however, of but a few of the various ways in which the principles of the embodiments may be employed, and the present disclosure is intended to include all such aspects and their equivalents. These and other objectives of the present disclosure will no doubt become obvious to those of ordinary skill in the art after reading the following detailed description of the preferred embodiment that is illustrated in the various figures and drawings.BRIEF DESCRIPTION OF THE DRAWINGS
[0019] FIG. 1 illustrates a diagram of a cache memory system according to an embodiment of the present disclosure.
[0020] FIG. 2 illustrates a diagram of a cache memory system according to another embodiment of the present disclosure.
[0021] FIG. 3 illustrates a diagram showing the operation of the cache prefetch method according to an embodiment of the present disclosure.
[0022] FIG. 4 illustrates a flow diagram of a method for cache prefetching according to an embodiment of the present disclosure.DETAILED DESCRIPTION
[0023] The present disclosure provides a detailed description of various embodiments. While specific implementation details are presented herein to facilitate a comprehensive understanding of the disclosure, it will be apparent to those skilled in the art that the present disclosure may be realized without necessarily adhering to all such particularities. In certain instances, well-established methods, procedures, components, and circuits have been omitted from exhaustive description to avoid obscuring the present disclosure. It should be understood that technical features individually described in relation to a single drawing may be implemented either discretely or in combination with other features, as set forth in the present specification.
[0024] FIG. 1 illustrates a block diagram of a cache memory system 100 incorporating the prefetch method according to an embodiment of the present disclosure. The system 100 includes various components that work together to implement intelligent prefetching based on memory access patterns and prefetch history. The cache memory system 100 includes a prefetch engine 102, an arbiter 104, a multiplexer (Mux) 106 followed by an address handling component, a decoder 108, a cache memory 110, a multiplexer (Mux) 112, and comparison logic (comprising comparators 114 and 116) for hit / miss determination.
[0025] The prefetch engine 102 is responsible for executing the automatic prefetch function. The prefetch engine utilizes configuration parameters 121 and a history table 122, which are data structures used by the prefetch engine 102. The configuration parameters 121 include configurable values that control the prefetch behavior, such as the number of cache lines to prefetch (i.e., N addresses / cache lines to prefetch) and the prefetch direction (increasing or decreasing address). The history table 122 stores records of the addresses that have been previously prefetched, which is used to avoid redundant prefetch operations. For example, the history table records the address corresponding to the last prefetch operation, used to mark addresses that have already undergone prefetch operations.
[0026] The arbiter 104 can manage access to the cache memory system, arbitrating between normal memory access requests and prefetch operations. It can determine which operations have priority and control the multiplexer 106 accordingly.
[0027] The address input to the cache memory can be processed through a multiplexer 106 that selects between addresses from normal memory access requests and addresses generated by the prefetch engine 102. The selected address can then be parsed into its constituent components: tag, index, and offset, which are standard divisions of memory addresses in cache memory systems.
[0028] The decoder 108 can use the index portion of the address to select the appropriate row in the cache memory 110. The cache memory 110 includes multiple cache lines, with each cache line storing: a validity flag (V-flag) indicating whether the data in the cache line is valid, a prefetch flag (P-flag) indicating whether the address corresponding to this cache line has already triggered an automatic prefetch (auto-prefetch) function, a tag (used to determine if the cache line contains the data for a requested address) for storing the upper bits the address associated with the cached data and cache line data including the actual cached data.
[0029] The comparison logic consists of two comparators. A first comparator 116 can check if the tag of the requested address matches the tag stored in the selected cache line and check the validity flag, which are part of the standard cache hit / miss determination. A second comparator 114 can then be involved in the prefetch decision logic, comparing prefetch-related information. The result of the tag comparison, along with the validity flag status, can determine whether the access results in a cache hit or miss. This hit / miss signal can then be used by other components (e.g., the comparator 114) to determine subsequent actions.
[0030] A multiplexer 112 selects the appropriate data to be output based on the results of the corresponding cache access operation. If there is a cache hit, the data from the cache line is selected; otherwise, different handling may be required.
[0031] When an address is received, the cache memory system 100 can perform a series of operations to manage prefetching efficiently. The cache memory system 100 first performs a standard hit / miss check by comparing the incoming tag with the stored tag and check the validity flag. If there is a cache hit and the P-flag has the second value (indicating prefetching has not been triggered for this address), the automatic prefetch function is triggered. The prefetch engine 102 then uses the first address to determine a range of addresses to prefetch, optionally, consulting the history table to avoid redundant prefetching operations. Finally, the P-flag for the accessed cache line is updated to the first value to indicate that the automatic prefetch function has been triggered for this address.
[0032] This architecture enables the cache memory system to intelligently decide when to trigger prefetching based on both hit / miss status and P-flag values, maintain a history of prefetch operations to avoid redundancy, configure the prefetch behavior through the configuration parameters, and adapt the prefetch direction based on observed memory access patterns. The innovation centers on using the P-flags to distinguish between addresses that have and have not triggered prefetching, and in using the history table to optimize the prefetch operations by avoiding redundant work. This approach improves cache hit rates and overall system performance by more intelligently managing when, where, and how prefetching occurs.
[0033] FIG. 2 illustrates a block diagram of an enhanced cache memory system 200 incorporating multiple prefetch engines according to another embodiment of the present disclosure. This embodiment expands upon the single prefetch engine architecture shown in FIG. 1 by implementing multiple prefetch engines that can work in parallel, further improving the system's prefetching capabilities and performance.
[0034] The cache memory system 200 includes multiple prefetch engines 202-1 through 202-K, an arbiter 204, a multiplexer (Mux) 206 followed by an address handling component, a decoder 208, a cache memory 210, a multiplexer (Mux) 212, and comparison logic (comprising comparators 214 and 216) for hit / miss determination.
[0035] The system implements K prefetch engines, shown as prefetch engine 202-1 through prefetch engine 202-K, where K is a positive integer representing the number of prefetch engines in the system. Each prefetch engine is responsible for executing the automatic prefetch function for different types of memory access patterns or different program contexts. Each prefetch engine utilizes its own set of configuration parameters 221-1 through 221-K and its own history table 222-1 through 222-K. This arrangement allows the cache memory system 200 to maintain separate prefetch configurations and history tracking for different types of memory accesses or different execution contexts.
[0036] For example, prefetch engine 202-1 can be configured to handle instruction fetches with its specific configuration parameters 221-1 and history table 222-1, and prefetch engine 202-2 can handle data accesses with its own configuration and history. This separation enables more specialized and efficient prefetching strategies for different types of memory accesses.
[0037] The arbiter 204 has an enhanced role in this multi-engine architecture, as it now arbitrates not only between normal memory access requests and prefetch operations but also between prefetch requests from multiple prefetch engines. The arbiter 204 determines which operations have priority and controls the multiplexer 206 accordingly.
[0038] The multiplexer 206 selects from a greater number of potential address sources compared to the single-engine architecture. It may select between addresses from normal memory access requests and addresses generated by any of the K prefetch engines 202-1 through 202-K.
[0039] The decoder 208, cache memory 210, and other components may function similarly to their counterparts in the single-engine architecture in FIG. 1. The cache memory 210 still includes multiple cache lines with validity flags (V-flag), prefetch flags (P-flag), tag fields, and cache line data.
[0040] The comparison logic, comprising comparators 214 and 216, can operate in the same manner as in the single-engine architecture in FIG. 1. The hit / miss determination process may remain unchanged, though the cache memory system 200 may now need to track which prefetch engine 202-1 through 202-K was responsible for prefetching particular cache lines.
[0041] When an address is received, the cache memory system 200 performs a similar series of operations as in the single-engine architecture, but with the added complexity of determining which prefetch engine 202-1 through 202-K should handle a particular prefetch operation. The selection of the appropriate prefetch engine may be based on factors such as the type of memory access (instruction fetch versus data access), the memory region being accessed, or the current execution context.
[0042] This multi-engine architecture enables the cache memory system 200 to apply different prefetching strategies to different types of memory accesses or different program contexts, maintain separate history tables for different access patterns, implement different prefetch directions or ranges for different types of accesses, and process multiple prefetch operations in parallel, potentially improving prefetch timeliness. The ability to employ multiple prefetch engines with separate configurations and history tracking represents a significant enhancement over the single-engine architecture. By tailoring prefetch strategies to specific access patterns and executing multiple prefetch operations in parallel, this architecture can achieve higher cache hit rates and better overall system performance, particularly for applications with diverse memory access patterns or multiple execution contexts.
[0043] FIG. 3 illustrates a diagram showing the operation of the cache prefetch method over time for sequential commands according to an embodiment. This diagram demonstrates how the V-flags and P-flags change during execution.
[0044] A timeline flowing from left to right, with three columns representing three sequential commands: cmd_1, cmd_2, and cmd_3. Each column depicts the state of the cache memory at that point in time, showing multiple cache lines with their respective V-flags and P-flags. The values of these flags are represented as binary values (0 or 1).
[0045] In the first column, i.e., cmd_1 (miss), the cache memory system (e.g., cache memory system 100 or 200) encounters a cache miss when executing the first command. All V-flags and P-flags are initially set to 0, indicating that no data is valid in any cache line and no prefetching has been triggered for any cache line. Upon experiencing this cache miss, the cache memory system automatically triggers the auto-prefetch function (wherein the prefetch flag of the target cache line corresponding to the first address is set to a first value, such as 1, otherwise, the prefetch flag is set to a second value, such as 0), fetches one piece of external data corresponding to the address into the target cache line of the cache memory and then performs auto-prefetch operation. This auto-prefetch operation loads data into multiple consecutive cache lines, preparing for future accesses. It can be understood that the V-flag of the cache line loaded (fetched / prefetched) with data is set to a third value (such as 1), otherwise, the V-flag is set to a fourth value (such as 0). In the present disclosure, if the automatic prefetch function is triggered for a first address, it may indicate that N pieces of external data will be pre-fetched into the corresponding cache line in advance, wherein N is a positive integer. FIG. 3 takes N=5 as an example. Therefore, in one case where the cache hit check of cmd_1 (associated with a first address) is a miss, upon completion of the automatic prefetch operation, the cache memory may contain a total of (N+1) cache lines of data (a target cache line originally needed to be accessed plus the N prefetched cache lines), that is, N+1 pieces of external data will be stored in the corresponding cache line. Since the external data corresponding to the first address is not stored in the cache line, it is also necessary to fetch a piece of external data corresponding to the first address into the target cache line before performing the prefetch operation.
[0046] The second column, i.e., cmd_2 (hit), shows the state after the first command is executed and the second command cmd_2 is received. This command results in a cache hit. The upper portion of the cache now contains valid data, with V-flags set to 1. Most of these cache lines have their P-flags set to 0, indicating they have not yet triggered the auto-prefetch function. When the cache memory system processes cmd_2, it encounters a cache line with V=1 and P=0, which would trigger another automatic prefetch (auto-prefetch) function. This second auto-prefetch function loads additional external data into the cache lines below the hit location. Notably, this auto prefetch operation can be more limited in scope than the first one, as some cache lines already contain valid data from the previous prefetch. For example, there are already three cache lines prefetching external data, so only two additional external data need to be prefetched into the following cache lines.
[0047] The third column, i.e., cmd_3 (hit), represents the state after the second command is executed and the third command cmd_3 is received. This command also results in a cache hit. In this case, the cache line accessed by cmd_3 has both its V-flag and P-flag set to 1, indicating that this cache line contains valid data and has already triggered an auto-prefetch function. As a result, the cache memory system does not initiate auto-prefetch operation. The remaining cache lines maintain their previous state, with no additional changes to their flags.
[0048] This sequence demonstrates key aspects of the prefetch method. The cache memory system triggers the auto-prefetch function on a cache miss (cmd_1), prefetching / loading multiple cache lines in anticipation of future needs. The cache memory system can also trigger the auto-prefetch function on a cache hit when the P-flag is 0 (cmd_2), but it optimizes the prefetch operation by not reloading cache lines that were already prefetched. The cache memory system avoids redundant prefetching when accessing a cache line that has already triggered prefetching, as indicated by its P-flag being set to 1 (cmd_3).
[0049] Hence, the prefetch operation can be sum up as follows. When the cache receives a load / store instruction, it may use the P-Flag to determine whether the instruction address (a first address) has previously triggered an auto-prefetch operation. If at least one condition is met (for example, the P-Flag is 0 and the cache hit check is a hit, for another example, the cache hit check is miss), indicating no auto-prefetch function has been triggered for this address, the cache memory system can activate the automatic prefetch function to prefetch a configurable range of memory space. The system may then set the P-Flag of the corresponding cache line to 1, marking that this address has triggered the auto-prefetch function.
[0050] Conversely, when the cache memory system receives a load / store instruction for which the corresponding P-Flag is 1 and the cache hit check is a hit, this may indicate that the corresponding cache line has previously triggered an auto-prefetch function, and the memory range N surrounding this address should already be in the cache memory. In this case, the system may not perform any additional prefetch processing, avoiding redundant memory operations.
[0051] After the automatic prefetch function is triggered, it may prefetch external data within a configurable memory range N. In another example, if the function is triggered again during operation, and the triggering instruction address falls within the previously prefetched range, the endpoint of the prefetch range can be updated to the new instruction address plus N. However, if the triggering instruction address falls outside the previously prefetched range, the system may initiate a new prefetch operation starting from the new instruction address and covering a range of N.
[0052] The automatic prefetch function can prefetch external data in two possible directions each time it is triggered: forward (e.g., from address i to address i+N) or backward (e.g., from address i to address i-N). The default direction may be set to forward. The cache memory system can dynamically adjust the prefetch direction based on observed memory access patterns. The direction switching mechanism may be implemented using various algorithms, for example, if M (taking three as an example) consecutive triggering addresses are all less than their respective previous addresses, subsequent prefetch operations may switch to fetching in the backward direction, covering a range of N before the current address. On the contrary, if three consecutive triggering addresses are all greater than their respective previous addresses, subsequent prefetch operations may switch to fetching in the forward direction, covering a range of N after the current address.
[0053] To avoid unnecessary cache accesses caused by overlapping prefetch ranges, each triggering of the automatic prefetch function may record the last address prefetched. If a previously recorded address falls within the current prefetch trigger range, the starting point of the current automatic prefetch operation can be adjusted to begin from the previously recorded address, proceeding either forward or backward as appropriate. This mechanism helps prevent redundant prefetching of memory locations that have already been loaded into the cache, optimizing cache memory system performance and reducing memory bandwidth usage. For example, two cache lines are prefetched for cmd_2 case, because 3 cache lines have been prefetched in the previous auto-prefetch operation.
[0054] The embodiments effectively illustrate how the P-flags help the cache memory system manage prefetch operations efficiently by tracking which cache lines have already triggered auto-prefetching, thereby avoiding unnecessary redundant operations and improving overall cache memory system performance. The embodiment also shows how the prefetch operation adapts based on the current state of the cache memory, optimizing the use of memory bandwidth and cache resources.
[0055] The following implementation examples illustrate specific applications of the cache prefetch method in various scenarios, demonstrating how the cache memory system may adapt to different memory access patterns and optimize prefetching operations.
[0056] In the first implementation example, the automatic prefetch function may be configured to prefetch 7 cache lines (i.e., taking N=7 for an example), with a cache line size of 128 bytes. For example, when the cache memory system receives a load / store instruction, if the corresponding cache line has its P-flag set to 0 and the cache hit check is hit, the cache memory system can trigger the automatic prefetch function to prefetch 7 cache lines, for example, in the forward direction.
[0057] If the cache memory system subsequently receives two load / store instructions with addresses smaller than the previous instruction, for example, three addresses in the sequence 0x5000, 0x4000, and 0x3000, the cache memory system may change the prefetch direction. When the cache memory system receives a new load / store instruction with an address of 0x2000, the prefetch sequence can be in the backward direction: 0x1F80, 0x1F00, 0x1E80, 0x1E00, 0x1D80, 0x1D00, and 0x1C80.
[0058] This example demonstrates how the cache memory system can detect a pattern of decreasing addresses across multiple instructions and may adapt its prefetch direction accordingly. By changing from forward to backward prefetching based on the observed access pattern, the cache memory system can more effectively anticipate future memory needs, particularly in algorithms that traverse data structures in reverse order or move backward through arrays.
[0059] In the second implementation example, the automatic prefetch function may again be configured to prefetch 7 cache lines with a cache line size of 128 bytes. For example, when the automatic prefetch function is executing, it may plan to prefetch addresses in the sequence: 0x6000, 0x6080, 0x6100, 0x6180, 0x6200, 0x6280, and 0x6300.
[0060] If the cache memory system receives a load / store instruction for address 0x6200, which is part of the current prefetch sequence, the cache memory system may modify the endpoint of the prefetch range. The cache memory system can continue prefetching additional addresses beyond the original endpoint, specifically 0x6380, 0x6400, 0x6480, 0x6500 and 0x6580. The last prefetched address (0x6580) may be recorded in the history table.
[0061] Subsequently, if the cache memory system receives an instruction for address 0x6400, the cache memory system can refer to the history table and may determine that address 0x6580 was the last prefetched address. Since the previous prefetch already covered addresses up to 0x6580, the cache memory system can begin prefetching from 0x6600, continuing with 0x6680, 0x6700, and 0x6780.
[0062] This example illustrates how the cache memory system may maintain and use prefetch history to avoid redundant prefetching operations. By recording the last prefetched address and checking this history before initiating new prefetch operations, the cache memory system can ensure it only prefetches data that hasn't already been loaded into the cache, potentially conserving memory bandwidth and improving efficiency.
[0063] In the third implementation example, the automatic prefetch function may be configured to prefetch 7 cache lines with a cache line size of 128 bytes. During the execution of a prefetch operation for addresses 0x6000, 0x6080, 0x6100, 0x6180, 0x6200, 0x6280, and 0x6300, the cache memory system may receive a load / store instruction for address 0x9000.
[0064] When this occurs, the cache memory system can complete the current prefetch operation up to the point it has reached (for example, if it had fetched up to 0x6200), may record this address in the history table, and then can initiate a new prefetch sequence starting at 0x9080 for the new address region. In one embodiment, multiple history tables may be maintained.
[0065] Later, if the cache memory system receives a load / store instruction for address 0x6100, it can check the history table and may find that address 0x6200 was previously prefetched. Since 0x6200 falls within the range of a potential new prefetch operation for 0x6100 (which would normally cover 0x6180 through 0x6480), the cache memory system can optimize by starting the new prefetch operation at 0x6280 instead of repeating already prefetched addresses. The prefetch operation can then continue until 0x6480.
[0066] This example demonstrates how the cache memory system may handle discontinuous memory access patterns by maintaining separate prefetch history records for different address regions. When a program's execution jumps to a different memory region and then returns to a previously accessed region, the cache memory system can efficiently resume prefetching where it left off, potentially avoiding redundant operations while ensuring all necessary data is available in the cache.
[0067] These implementation examples show the adaptability and efficiency that may be achieved by the prefetch method in various scenarios. By using P-flags to track which addresses have triggered auto-prefetch function, maintaining history tables of prefetched addresses, and dynamically adjusting prefetch directions and ranges based on observed access patterns, the cache memory system may significantly improve cache hit rates and overall performance across a wide range of applications and memory access patterns.
[0068] FIG. 4 illustrates a flow diagram of a method 400 for cache prefetching according to an embodiment of the present disclosure. The method 400 provides a systematic approach to implementing the intelligent prefetch mechanism described above.
[0069] S402: Receive a first address;
[0070] S404: Perform a cache hit check on the first address;
[0071] S406: Is the cache hit check result a hit and the prefetch flag has the second value? If so, proceed to S408; if not and the cache hit check is a miss, proceed to S407;
[0072] S407: Fetch the external data corresponding to the first address into the target cache line;
[0073] S408: Trigger the automatic prefetch function for the first address; and
[0074] S410: Executing a prefetch operation based on the first address.
[0075] The method begins at step S402, where the cache memory system (e.g., cache memory system 100 or 200) receives a first address. This address may correspond to a load or store instruction issued by a processor, indicating a memory location that needs to be accessed. Upon receiving this address, the system proceeds to the next step in the process.
[0076] At step S404, the system performs a cache hit check on the first address to determine whether the requested data associated with the first address is already present in the cache memory. This check involves comparing the tag of the incoming address with the tags stored in the corresponding cache lines and verifying that the corresponding validity flag indicates valid data.
[0077] Following the cache hit check, the cache memory system reaches a decision point at step S406, where it evaluates whether two conditions are simultaneously met: first, whether the cache hit check resulted in a hit (meaning the requested data is present in the cache), and second, whether the prefetch flag of the corresponding cache line has the second value (indicating that this address has not yet triggered a prefetch operation). Note that the first value indicates that this address has already triggered an auto-prefetch function. If both conditions are satisfied, the cache memory system proceeds to step S408; if both condition is not met and specifically the cache hit check is a miss, the cache memory system instead follows an alternative path to step S407.
[0078] At step S407, which is executed when the cache hit check resulted in a miss, the cache memory system prefetches the external data corresponding to the first address into the target cache line. This step involves retrieving the requested data from main memory or lower-level caches and storing it in the appropriate cache line.
[0079] The method continues at step S408, where the cache memory system triggers the automatic prefetch function for the first address. This step may be reached either directly from step S406 (in case of a cache hit with the prefetch flag having the second value) or following step S407 (in case of a cache miss). The automatic prefetch function is a key component of the invention that initiates the prefetching process based on the current memory access pattern. As part of this step, the cache memory system may update the prefetch flag of the target cache line to the first value, indicating that this address has now triggered an auto-prefetch function.
[0080] Finally, at step S410, the cache memory system executes a prefetch operation based on the first address. This operation may involve determining a prefetch range, consulting the history table to avoid redundant prefetching, and prefetching a configurable number of cache lines from external memory (such as main memory) into the cache memory. The specific details of the prefetch operation may vary depending on factors such as the prefetch direction (forward or backward), the detected memory access pattern, and the contents of the prefetch history table.
[0081] The disclosed system and method provides an improved cache prefetch method and system that intelligently optimizes memory access operations to enhance processor performance. The invention uses a prefetch flag mechanism to track which memory addresses have triggered prefetch operations, enabling more efficient utilization of cache resources and memory bandwidth.
[0082] When the cache receives a memory access request, it checks whether the corresponding cache line contains valid data (cache hit) and whether its prefetch flag indicates that an automic prefetch function has already been triggered for this address. Based on these conditions, the system may selectively trigger the automatic prefetch function. Unlike conventional approaches that only prefetch on cache miss, this invention can prefetch on cache hits when appropriate, maintaining an optimal prefetch distance ahead of the processor's requests.
[0083] The disclosed system and method incorporates several key innovations: a prefetch flag mechanism for each cache line to avoid redundant prefetch operations; an address history table that records previously prefetched addresses to optimize subsequent prefetch operations; adaptive directional prefetching that can dynamically adjust between forward and backward prefetching based on observed memory access patterns; and on-the-fly adjustment of prefetch ranges when they overlap with previously prefetched regions. Together, these features work in concert to minimize unnecessary memory accesses while ensuring timely data availability.
[0084] The disclosed system and method may be implemented with multiple prefetch engines, each handling different types of memory accesses or program contexts, with separate configuration parameters and history tables.
[0085] Thus, this invention significantly improves cache hit rates and processor efficiency across diverse workloads and memory access patterns. The prefetch method effectively bridges the performance gap between fast processors and relatively slow main memory, resulting in enhanced overall system performance.
[0086] The terminology employed in the description of the various embodiments herein is intended for the purpose of describing particular embodiments and should not be construed as limiting. In the context of this description and the appended claims, the singular forms “a”, “an” and “the” are intended to encompass plural forms as well, unless the context clearly indicates otherwise.
[0087] It should be understood that the term “and / or” as used herein is intended to encompass any and all possible combinations of one or more of the associated listed items. Furthermore, it should be noted that the terms “includes,”“including,”“comprises,” and / or “comprising,” when used in this specification, indicate the presence of stated features, integers, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0088] Unless specifically stated otherwise, the term “some” refers to one or more. Various combinations using “at least one of” or “one or more of” followed by a list (e.g., A, B, or C) should be interpreted to include any combination of the listed items, including individual items and multiple items.
[0089] In the context of this disclosure, the terms “coupled,”“connected,”“connecting,”“electrically connected,” and similar expressions are used interchangeably to broadly denote the state of being electrically or electronically connected. Furthermore, an entity is deemed to be in “communication” with another entity (or entities) when it electrically transmits and / or receives information signals to / from the other entity, irrespective of whether these signals contain image / voice information or data / control information, and regardless of the signal type (analog or digital). It is important to note that this communication can occur through either wired or wireless means. The use of these terms is intended to encompass all forms of electrical or electronic connectivity relevant to the described embodiments.
[0090] The use of ordinal designators like “first,”“second,” and so forth in the specification and claims serves to differentiate between multiple instances of similarly named elements. These designators do not imply any inherent sequence, priority, or chronological order in the manufacturing process or functional relationship between elements. Rather, they are employed solely as a means of uniquely identifying and distinguishing between separate instances of elements that share a common name or description.
[0091] The various illustrative components, logic, logical blocks, modules, circuits, operations and algorithm processes described in connection with the embodiments disclosed herein may be implemented as electronic hardware, firmware, software, or combinations of hardware, firmware or software, including the structures disclosed in this specification and the structural equivalents thereof. The interchangeability of hardware, firmware and software has been described generally, in terms of functionality, and illustrated in the various illustrative components, blocks, modules, circuits and processes described above. Whether such functionality is implemented in hardware, firmware or software depends upon the particular application and design constraints imposed on the overall system.
[0092] The hardware and data processing apparatus utilized to implement the various illustrative components, logics, logical blocks, modules, and circuits described herein may comprise, without limitation, one or more of the following: a general-purpose single-chip or multi-chip processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), other programmable logic devices (PLDs), discrete gate or transistor logic, discrete hardware components, or any suitable combination thereof. Such hardware and apparatus shall be configured to perform the functions described herein.
[0093] A general-purpose processor may include, but is not limited to, a microprocessor, or alternatively, any conventional processor, controller, microcontroller, or state machine. In certain implementations, a processor may be realized as a combination of computing devices. Such combinations may include, for example, a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors in conjunction with a DSP core, or any other such configuration as may be suitable for the intended application.
[0094] Various modifications to the embodiments described in this disclosure may be readily apparent to persons having ordinary skill in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of this disclosure. Thus, the claims are not intended to be limited to the embodiments shown herein, but are to be accorded the widest scope consistent with this disclosure, the principles and the novel features disclosed herein.
[0095] In certain implementations, the embodiments may comprise the disclosed features and may optionally include additional features not explicitly described herein. Conversely, alternative implementations may be characterized by the substantial or complete absence of non-disclosed elements. For the avoidance of doubt, it should be understood that in some embodiments, non-disclosed elements may be intentionally omitted, either partially or entirely, without departing from the scope of the invention. Such omissions of non-disclosed elements shall not be construed as limiting the breadth of the claimed subject matter, provided that the explicitly disclosed features are present in the embodiment.
[0096] Additionally, various features that are described in this specification in the context of separate embodiments also can be implemented in combination in a single implementation. Conversely, various features that are described in the context of a single implementation also can be implemented in multiple embodiments separately or in any suitable combination. As such, although features may be described above as acting in particular combinations, and even initially claimed as such, one or more features from a claimed combination can in some cases be excised from the combination, and the claimed combination may be directed to a combination or variation of a combination.
[0097] The depiction of operations in a particular sequence in the drawings should not be construed as a requirement for strict adherence to that order in practice, nor should it imply that all illustrated operations must be performed to achieve the desired results. The schematic flow diagrams may represent example processes, but it should be understood that additional, unillustrated operations may be incorporated at various points within the depicted sequence. Such additional operations may occur before, after, simultaneously with, or between any of the illustrated operations.
[0098] Additionally, it should be understood that the various figures and component diagrams presented and discussed within this document are provided for illustrative purposes only and are not drawn to scale. These visual representations are intended to facilitate understanding of the described embodiments and should not be construed as precise technical drawings or limiting the scope of the invention to the specific arrangements depicted.
[0099] While the invention has been described in connection with certain embodiments, it will be understood by those skilled in the art that various modifications and adaptations can be made without departing from the scope of the invention. The specific embodiments presented are intended to illustrate the invention and not to limit its application or construction. Those skilled in the art will readily observe that numerous modifications and alterations of the device and method may be made while retaining the teachings of the invention. Accordingly, the above disclosure should be construed as limited only by the metes and bounds of the appended claims.
Claims
1. A prefetch method for a cache memory, comprising:receiving a first address;performing a cache hit check on the first address to determine whether data corresponding to the first address is stored in the cache memory, wherein the cache memory comprises multiple cache lines, each cache line comprises a corresponding prefetch flag used to indicate whether an automatic prefetch function has been triggered for the address corresponding to the respective cache line, wherein the corresponding prefetch flag having a first value indicates that the automatic prefetch function for the address corresponding to the respective cache line has been triggered, and the prefetch flag having a second value, different from the first value, indicates that the automatic prefetch function for the address corresponding to the respective cache line has not been triggered;if the cache hit check is a hit and the prefetch flag of a target cache line corresponding to the first address has the second value, triggering the automatic prefetch function for the first address, wherein the prefetch flag of the target cache line corresponding to the first address is updated to the first value; andexecuting a prefetch operation based on the first address to prefetch external data located outside the cache memory into the cache memory.
2. The method of claim 1, further comprising:if the cache hit check is a miss, triggering the automatic prefetch function for the first address, wherein the prefetch flag of the target cache line corresponding to the first address is set to the first value;fetching one piece of external data corresponding to the first address into the target cache line of the cache memory; andexecuting a prefetch operation based on the first address to prefetch external data located outside the cache memory into the cache memory.
3. The method of claim 1, wherein executing a prefetch operation based on the first address to prefetch external data located outside the cache memory into the cache memory comprises:determining a starting address based on the first address and a cache line size;determining a combination of N addresses based on the starting address, the cache line size, and a predetermined prefetch mode; andbased on the combination of N addresses, prefetching N pieces of external data with a data length of cache line size into N cache lines of the cache memory, wherein N is a positive integer.
4. The method of claim 3, wherein the predetermined prefetch mode comprises a forward prefetch mode that prefetches in an increasing address manner and / or a backward prefetch mode that prefetches in a decreasing address manner.
5. The method of claim 4, further comprising:updating a history table for the prefetch operation executed by the automatic prefetch function, wherein the history table records the address corresponding to the last prefetch operation, used to mark addresses that have already undergone prefetch operations.
6. The method of claim 5, further comprising:determining, based on the history table, whether there exists at least one address in the combination of N addresses for which a prefetch operation has been executed;if at least one address exists, skipping the corresponding prefetch operation for that address.
7. The method of claim 5, wherein a plurality of instruction sequences correspond to different history tables, each instruction sequence having a corresponding history table.
8. The method of claim 4, further comprising:if the predetermined prefetch mode is the forward prefetch mode, but it is detected that first addresses received for M consecutive times are decreasing in value, adjusting the predetermined prefetch mode from the forward prefetch mode to the backward prefetch mode; and / orif the predetermined prefetch mode is the backward prefetch mode, but it is detected that first addresses received for M consecutive times are increasing in value, adjusting the predetermined prefetch mode from the backward prefetch mode to the forward prefetch mode;wherein M is a positive integer.
9. The method of claim 3, wherein the predetermined prefetch mode is adjustable.
10. The method of claim 1, wherein:the first address comprises a first tag, an index, and an offset, each cache line further comprises a validity flag, a second tag, and data;the validity flag is used to indicate whether the data in the respective cache line is valid, wherein the validity flag having a third value indicates that the data is valid, and the validity flag having a fourth value different from the third value indicates that the data is invalid;performing the cache hit check on the first address comprises:if the validity flag of the target cache line corresponding to the index of the first address has the fourth value, then the cache hit check is determined to be a miss;and / or if the validity flag of the target cache line corresponding to the index of the first address has the third value but the first tag of the first address is different from the second tag of the target cache line, then the cache hit check is determined to be a miss; and / orif the validity flag of the target cache line corresponding to the index of the first address has the third value and the first tag of the first address is the same as the second tag of the target cache line, then the cache hit check is determined to be a hit.
11. A cache memory system, comprising:a cache memory comprising a plurality of cache lines, wherein each cache line comprises a corresponding prefetch flag used to indicate whether an automatic prefetch function has been triggered for an address corresponding to the respective cache line, wherein the corresponding prefetch flag having a first value indicates that the automatic prefetch function for the address corresponding to the respective cache line has been triggered, and the prefetch flag having a second value different from the first value indicates that the automatic prefetch function for the address corresponding to the respective cache line has not been triggered; anda prefetch circuit configured to:receive a first address;perform a cache hit check on the first address to determine whether data corresponding to the first address is stored in the cache memory;if the cache hit check is a hit and the prefetch flag of a target cache line corresponding to the first address has the second value, trigger the automatic prefetch function for the first address, wherein the prefetch flag of the target cache line corresponding to the first address is updated to the first value; andexecute a prefetch operation based on the first address to prefetch external data located outside the cache memory into the cache memory.
12. The cache memory system of claim 11, wherein the prefetch circuit is further configured to:if the cache hit check is a miss, trigger the automatic prefetch function for the first address, wherein the prefetch flag of the target cache line corresponding to the first address is set to the first value;fetch one piece of external data corresponding to the first address into the target cache line of the cache memory; andexecute a prefetch operation based on the first address to prefetch external data located outside the cache memory into the cache memory.
13. The cache memory system of claim 11, wherein the prefetch circuit, when executing a prefetch operation based on the first address to prefetch external data located outside the cache memory into the cache memory, is configured to:determine a starting address based on the first address and a cache line size;determine a combination of N addresses based on the starting address, the cache line size, and a predetermined prefetch mode; andbased on the combination of N addresses, prefetch N pieces of external data with a data length of cache line size into N cache lines of the cache memory, wherein N is a positive integer.
14. The cache memory system of claim 13, wherein the predetermined prefetch mode comprises a forward prefetch mode that prefetches in an increasing address manner and / or a backward prefetch mode that prefetches in a decreasing address manner.
15. The cache memory system of claim 14, wherein the prefetch circuit is further configured to:maintain a history table to record an address corresponding to a last prefetch operation executed by the automatic prefetch function, used to mark addresses that have already undergone prefetch operations; andupdate the history table for each prefetch operation executed by the automatic prefetch function.
16. The cache memory system of claim 15, wherein the prefetch circuit is further configured to:determine, based on the history table, whether there exists at least one address in the combination of N addresses for which a prefetch operation has been executed;if at least one address exists, skip the corresponding prefetch operation for that address.
17. The cache memory system of claim 15, wherein the prefetch circuit is further configured to maintain a plurality of history tables, wherein each history table corresponds to a different instruction sequence.
18. The cache memory system of claim 14, wherein the prefetch circuit is further configured to:if the predetermined prefetch mode is the forward prefetch mode, but it is detected that first addresses received for M consecutive times are decreasing in value, adjust the predetermined prefetch mode from the forward prefetch mode to the backward prefetch mode; and / orif the predetermined prefetch mode is the backward prefetch mode, but it is detected that first addresses received for M consecutive times are increasing in value, adjust the predetermined prefetch mode from the backward prefetch mode to the forward prefetch mode;wherein M is a positive integer.
19. The cache memory system of claim 13, wherein the predetermined prefetch mode is adjustable by the prefetch circuit.
20. The cache memory system of claim 11, wherein:each cache line further comprises a validity flag, a first tag, and data;the first address comprises a second tag, an index, and an offset;the validity flag is used to indicate whether the data in the respective cache line is valid, wherein the validity flag having a third value indicates that the data is valid, and the validity flag having a fourth value different from the third value indicates that the data is invalid; andthe prefetch circuit, when performing the cache hit check on the first address, is configured to:if the validity flag of the target cache line corresponding to the index of the first address has the fourth value, then determine the cache hit check to be a miss; and / orif the validity flag of the target cache line corresponding to the index of the first address has the third value but the first tag of the first address is different from the second tag of the target cache line, then determine the cache hit check to be a miss; and / orif the validity flag of the target cache line corresponding to the index of the first address has the third value and the first tag of the first address is the same as the second tag of the target cache line, then determine the cache hit check to be a hit.
Citation Information
Patent Citations
Method and apparatus providing non level one information caching using prefetch to increase a hit ratio
US20030221069A1
Multi-trained scalable prefetcher, and related methods
US20240232090A1
