This chapter describes the memory cache in Intel 64 and IA-32 processors, as well as the Cache control mechanism, TLB, and storage cache. It also describes the memory type range registers introduced in the P6 family processor and how they are used to control the location of the physical memory, indicates fast storage, cache ing ).
11.1 internal cache, TLB, and Cache
11.2 cache terminology
IA-32 processor (starting with Pentium processor) and Intel 64 processor using MESI (modified, exclusive, shared, invalid) the cache protocol is used to maintain the consistency between the internal cache and the cache of other processors (see section 11.4 ).
When the processor identifies that an operand being read from the memory can be cached, the processor reads the entire cache row to the appropriate cache (L1, L2, L3, or all ). This operation is called onceCache row Filling. If the memory location containing the operand is still cached when the processor tries to access the operand next time, the processor can read the operand directly from the cache instead of returning to the memory. This operation is called onceCache hit.
When the processor tries to write an operand to a cache-able storage area, it first checks whether the cache row corresponding to the memory location exists in the cache. If a valid cache row exists, the processor (depending on the current write policy) can write the operand to the cache instead of writing it to the system memory. This operation is called onceWrite hit. If a write misses the cache (that is, a valid cache row is not in the storage area being written), the processor executes a cache row filling and write allocation. Then it writes the operand to the cache row, and (depending on the current write policy) can also write it to the external memory. If the operand is written to the memory, it is first written to the storage cache, and then written to the memory from the storage cache, when the system bus is available. (Note: For Pentium processors, writing failure does not cause a cache row to be filled; they always cause a write to the memory. For this processor, only a read failure will cause the cache row to fill ).
IA-32 processor (beginning with intelease processor) when operating in an MP System) intel 64 processor has the ability to snoop other processors to access system memory and to access their own internal cache. These processors use this Snoop capability to maintain consistency between their internal cache and system memory and those in other processors on the bus. For example, in Pentium and P6 family processors, if one processor detects that another processor intends to write data to one memory location, and this location, the Snoop processor hasSharing statusIf the cache is cleared, the Snoop processor will not be able to effectively use its own cache row. The next time you access the same location, it will force you to perform a cache row filling.
Starting from the P6 family processor, if one processor detects (via snoop) that another processor is attempting to access a memory location, this location of Snoop processor has been modified in its cache, but it has not been written back to the system memory, so the Snoop processor will send a signal (using the hitm # signal) to the other processor, and the cache row will be keptModifiedStatus, and write the modified data back implicitly once. Implicit write-back is passed directly to the initial request processor and is prying on by the memory controller to ensure that the system memory has been updated. Here, a processor with valid data can pass the data to the processor without actually writing the data to the system memory. However, the memory controller is responsible for spying on this operation and updating the memory.
11.3 available cache Methods
11.4 Cache Control Protocol
The following section describes the Cache control protocols currently defined for Intel 64 and IA-32 architectures. In L1 data cache and L2/L3 unified cache, The MESI (modified, exclusive, shared, and invalid) protocol maintains cache consistency with other processors. L1 data cache and L2/L3 unified cache each cache row has two MESI status signs. Each row can be marked as in one of the states defined in Table 11-4, and MESI operations are transparent to the program.
Table 11-4 MESI cache row statuses
Cache row statusM (modified)E (exclusive)S (shared)I (invalid)
Is this cache row valid? yes or no
Valid when the memory copy is expired --
Does the cache of Other Processors contain copies? Impossible
A write into this row does not lead to the system bus or to the system bus, so that the processor obtains exclusive ownership of this row and directly leads to the system bus.
The L1 instruction cache in the P6 family processor only implements the "Si" section in the MESI protocol, because the Instruction Cache cannot be written. The command cache monitor changes in the data cache to maintain consistency between caches. When the command is modified. See section 11.6.
11.5 Cache Control
11.6 self-modified code
Writing to a memory location in a code segment of the current cache in the processor causes the associated cache rows (or multiple rows) to be invalid. This check is based on the instruction physical address. In addition, the P6 family and the Pentium processor check whether a write to a code segment modifies a prefetch command. If this write affects a prefetch instruction, the prefetch queue is invalid. This is followed by a command-based linear address. The Pentium 4 and Intel Xeon processors write or snoop commands in a code segment. In this code segment, the target commands are decoded and reside in the trace cache, this will invalidate the entire trace cache. The subsequent behavior means that programming self-modified code will cause serious performance degradation when running on Pentium 4 and Intel Xeon processors.
In practice, linear address check should not create compatibility issues between IA-32 processors. Applications that contain self-modified code use the same linear address to modify and retrieve commands. System software, such as a debugger that may use different linear addresses to modify an instruction, instead of a command, will execute a serial operation, such as a cpuid instruction, before the modified command is executed, the command cache and prefetch queue are automatically re-synchronized (see section 8.1.3 ).
For the intelease processor, writing a command in the cache will modify it both in the cache and in the memory. However, if the instruction is prefetch before writing, the old version of the command will be executed. To prevent the execution of old commands, write a jump command immediately after any one of the commands is modified to flush the command prefetch unit.
11.7 implicit cache (Pentium 4, Intel Xeon, and P6 family processor)
When a memory element is implicitly available for cache, the implicit cache occurs, although this element may never have been accessed in the order of von noiman. Implicit cache occurs on P6 or updated processor families because of active prefetch (Note: hardware prefetch, including command and data), branch prediction, and TLB missing processing. Implicit cache is an extension of the existing intel386, intel386, and Pentium processor system behavior, because the software running on these processor families has not been able to predict the behavior of command prefetch with certainty.
To avoid problems related to implicit cache, the operating system must explicitly invalidate the cache. When the data that can be cached is changed, the cache consistency mechanism cannot automatically process the data that can be cached. This includes writing to dual-port or physically overlapping Memory Boards that are not tested by the processor's Snoop mechanism and changes to page table entries in the memory.
The code in example 11-1 shows the effect of implicit cache on Implicit page table entries. The linear address f000h points to the physical location b000h (the f000h page table entry contains the value b000h), while the linear address f000h page table entry is pte_f000.
# Example 11-1 <br/> mov eax, MCM 3; invalid TLB <br/> mov 3303, eax; by copying the product from the product to the product, <br/> mov pte_f000, a000h; change f000h to a000h <br/> mov EBX, [f000h];
Because of speculative execution in P6 or the update Processor family, the final mov command will place the value at the physical address b000h in EBX, instead of the value at the new physical address a000h. This situation can be remedied by putting a TLB between the load and storage.
11.8 explicit Cache
The Pentium III processor introduces four new commands, prefetchHCommand to provide the software with explicit control over the data cache. These commands provide "implied" to the processor by a prefetchHThe data requested by the command should be read to the cache level now, or be used in advance as soon as possible. These commands provide different implied variants that allow you to select which cache level the data will be read.
PrefetchHInstructions can help reduce the long latency associated with reading data from the memory, thus helping prevent the processor from being "delayed ". However, these commands should be used wisely and cautiously. Excessive use may cause resource conflicts and thus reduce application performance. At the same time, these commands should only be used to prefetch data from memory; they should not be used to prefetch commands. For more information about prefetch commands, see Chapter 7 of the Intel optimization documentation.
11.9 invalid translation backup cache (TLB)
The processor transparently updates the address translation cache (TLB) of the software ). Then there are several mechanisms that can be used to allow software and hardware to be invalidated, either explicitly, or as a side effect of another operation. For more details, see section 4.10.4. In addition, the following operations will invalidate all TLB entries, regardless of the G flag settings:
1. assertion or assertion flush # pin.
2. (only the Pentium 4, Intel Xeon, and later processors) Write A mtrr (using a wrmsr command)
3. Write the control register Cr0 to modify the PG or PE flag.
4. (only the Pentium 4, Intel Xeon, and later processors) write the control register Cr4 to modify the PSE, PGE, or PAE flag.
5. Write the control register Cr5 from 1 to 0.
See section 4.10 for additional information about TLB.
11.10 storage cache
Intel 64 and IA-32 processors temporarily store each write to memory in a memory cache. The storage cache improves the processor performance by allowing the processor to continue executing commands without waiting until a write to the memory or cache is completed. It also allows the write to be delayed and more effectively uses the memory access bus cycle.
Generally, the storage cache is transparent to the software, even in a multi-processor system. The processor ensures that write operations are always performed in program order. It also ensures that the content stored in the cache is always discharged to the memory in the following situations:
1. When an exception or interruption occurs
2. (Only for P6 or the updated Processor family) when a serial command is executed
3. When an I/O command is executed
4. When a lock operation is executed
5. (Only for P6 and updated processor families) when a binit operation is executed
6. (For Pentium III and the updated Processor family only) when using an sfence command to arrange storage
7. (For Pentium 4 and the updated Processor family only) when a mfence command is used to arrange storage
The write order is discussed in section 8.2.
11.11 memory type range register