In modern processors, prefetching from memory allows data and instructions that may be needed in the future to be loaded in cache. In this way it may be possible to avoid the additional overhead associated with a later transfer if there otherwise would have been a cache miss if not for the prefetching. However, prefetching cache lines that are not needed tends to waste memory bandwidth and pollute caches.
In the following description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the invention. It will be apparent, however, to one skilled in the art that embodiments of the invention can be practiced without these specific details. In other instances, structures and devices are shown in block diagram form in order to avoid obscuring the invention.
Reference throughout this specification to “one embodiment” or “an embodiment” means that a particular feature, structure or characteristic described in connection with the embodiment is included in at least one embodiment of the present invention. Thus, appearances of the phrases “in one embodiment” or “in an embodiment” in various places throughout this specification are not necessarily all referring to the same embodiment. Furthermore, the particular features, structures or characteristics may be combined in any suitable manner in one or more embodiments.
Referring now to
Cache 112 may include any number of separate caches and may contain any number of entries. While intended as a low latency level one cache, cache 112 may be implemented in any memory technology at any hierarchical level. In one embodiment, cache 112 stores a number of cache lines, for example line 114, either fetched or prefetched from regions of memory 104, for example region 118. However, the present invention may be practiced by prefetching between various other levels of cache or memory.
Fuzzy stride prefetch engine 116 may implement a method for fuzzy stride prefetch, for example as described in reference to
As used herein, stride 124 refers to a distance between memory addresses. In some embodiments, stride 124 refers to a current stride or distance between the addresses of consecutive memory reads requested by processor 102. In other embodiments, stride 124 refers to a predicted stride or guess as to what memory address will next be requested and may be advantageous to prefetch, as described in more detail hereinafter.
Referring now to
Detect services 212 may detect when data access strides in a memory (for example stride 124 in memory 104) fall into range 204. As used herein, fuzzy stride refers to a stream of non-constant address strides 124 (for example, a stream of memory reads by processor 102) that fall mostly into a narrow range 204 (for example, range 204 may be 128 bytes to 192 bytes, i.e. two or three cache lines away from the previous data access). While some applications may have data access patterns that would benefit from fuzzy stride prefetching, others applications may not, and the present invention may be practiced in conjunction with other prefetching techniques. In one embodiment, detect services 212 uses a credit-based system to track whether a series of address strides 124 fall with range 204. In one embodiment, detect services 212 increases count 206 when a data access stride 124 falls into range 204 and decreases count 206 when a data access stride 124 falls outside range 204.
Predict services 214 may compute a predicted stride 210. In one embodiment, predict services 214 averages the fuzzy strides of recent previous accesses (for example PredictedStride=SumofPrevious5Strides/5). In another embodiment, predict services 214 may weight the current fuzzy stride more heavily in computing predicted stride 210 (for example PredictedStride=(PredictedStride+CurrentStride)/2). Other methods for computing predicted stride 210 would occur to those skilled in the art and are considered to be within the scope of the present invention.
Prefetch services 216 may selectively prefetch one or more cache lines using predicted stride 210. In one embodiment, prefetch services 216 will only prefetch a cache line identified by predicted stride 210 (for example, by adding predicted stride 210 to the prior memory address accessed) if count 206 meets or exceeds threshold 208, thereby indicating a greater likelihood that a fuzzy stride prefetch would be beneficial. In one embodiment, prefetch services 214 may also prefetch adjacent memory region 122 in a second cache line if the memory address indicated by predicted stride 210 is sufficiently close to a boundary of memory region 120.
Control services 218 may provide adaptive control by an external module, such as other software or hardware or combinations of hardware and software. In one embodiment, control services 218 initializes range 204, count 206 and threshold 208 upon an activation with values stored in a memory. In one embodiment, the range, the threshold, whether to prefetch a cache line, and whether to prefetch a second cache line may be controlled by an external optimization module (not shown) that monitors the effectiveness of fuzzy stride prefetching. In another embodiment, control services 218 may allow a software application that is self-aware as to its data access patterns to initialize, update, and/or modify variables such as range 204 and threshold 208, for example to encourage or discourage fuzzy stride prefetching as appropriate to improve performance.
Referring now to
Detect services 212 will then compare stride 124 with range 204 to determine (306) if stride 124 would be considered a fuzzy stride. If so, count 206 is increased (308). If not, count 206 is decreased (310).
Prefetch services 216 would then compare count 206 with threshold 210 to determine (312) whether to trigger a prefetch. If count 206 has met threshold 210, then prefetch services 216 would prefetch (314) one or more cache lines based on predicted stride 210.
Referring now to
Embodiments may be implemented in many different system types. Referring now to
Still referring to
Furthermore, chipset 590 includes an interface 592 to couple chipset 590 with a high performance graphics engine 538. In turn, chipset 590 may be coupled to a first bus 516 via an interface 596. As shown in
Embodiments may be implemented in code and may be stored on a storage medium having stored thereon instructions which can be used to program a system to perform the instructions. The storage medium may include, but is not limited to, any type of disk including floppy disks, optical disks, compact disk read-only memories (CD-ROMs), compact disk rewritables (CD-RWs), and magneto-optical disks, semiconductor devices such as read-only memories (ROMs), random access memories (RAMs) such as dynamic random access memories (DRAMs), static random access memories (SRAMs), erasable programmable read-only memories (EPROMs), flash memories, solid state drives (SSDs), electrically erasable programmable read-only memories (EEPROMs), magnetic or optical cards, or any other type of media suitable for storing electronic instructions.
While the present invention has been described with respect to a limited number of embodiments, those skilled in the art will appreciate numerous modifications and variations therefrom. It is intended that the appended claims cover all such modifications and variations as fall within the true spirit and scope of this present invention.