CPU Cache ON/OFF
CPU Cache ON/OFF
i was wondering is my l1 or l2 cache enabled automaticly after boot, or should i enable it, and how to do it, and how to check it's status.
Just do it
Re: CPU Cache ON/OFF
Hi,
Unless you're messing the the chipset's DRAM controllers or shifting memory mapped I/O devices around you shouldn't need to worry about the L1, L2 or L3 caches.
IIRC there is at least one version of the Bochs BIOS (maybe all versions) that leave the caches disabled in CR0. This is a "mini-bug" in the Bochs BIOS, but it makes no difference because Bochs has no L1, L2 or L3 caches anyway.
For checking the cache's status, it depends what you want to do. To see if it's enabled or not just check the flags in CR0.
To determine the sizes and types of different caches newer CPUs provide information via. CPUID, but older CPUs generally suck.
To test if the L1 and L2 caches are working correctly (for e.g. if they corrupt data or not) you'd need to know what size and type of caches are present in the CPU and you'd need some way of detecting if data was corrupted (e.g. write a pattern to memory with caches disabled, then enable caches, read and modify the pattern, flush the caches, disable caches and see if the modified pattern in RAM is how it should be). For testing instruction caches (e.g. L1 instruction cache and/or trace cache) this doesn't work. In general, a faulty cache will either be detected by the BIOS (the CPU does a built in self test when it first gets turned on, if this is enabled by the chipset), or it'll crash the computer fairly quickly - i.e. if your code hasn't crashed for no reason during boot, then you can probably assume the caches are OK....
Also, the 80486 (and "compatables") have test registers (TR3, TR4, TR5, TR6 and TR7) that can be used for testing caches. See Intel's 80486 Programmer's Manual for details. These test registers are obsolete now though and are barely mentioned in the latest manuals. Newer CPUs have support for "machine check exceptions", but I'm not too sure if that detects cache errors or not (I think it does, but it's CPU specific).
Lastly, if you want to check how well the caches are working (for e.g. comparing the amount of cache hits to the amount of cache misses), then there's performance monitoring counters that can be used on modern CPUs.
My advice is to forget everything I said, and ignore the CPUs caches (except TLB invalidation) for a long time...
Cheers,
Brendan
CPU caches are mostly transparent and should be enabled by the BIOS. This includes the MTRRs, the flags in CR0, etc. The PAT entries are left at their default settings from CPU reset or power-on (which make page-level cache control behave the same as on older CPUs without PAT support).AirFlight wrote:i was wondering is my l1 or l2 cache enabled automaticly after boot, or should i enable it, and how to do it, and how to check it's status.
Unless you're messing the the chipset's DRAM controllers or shifting memory mapped I/O devices around you shouldn't need to worry about the L1, L2 or L3 caches.
IIRC there is at least one version of the Bochs BIOS (maybe all versions) that leave the caches disabled in CR0. This is a "mini-bug" in the Bochs BIOS, but it makes no difference because Bochs has no L1, L2 or L3 caches anyway.
For checking the cache's status, it depends what you want to do. To see if it's enabled or not just check the flags in CR0.
To determine the sizes and types of different caches newer CPUs provide information via. CPUID, but older CPUs generally suck.
To test if the L1 and L2 caches are working correctly (for e.g. if they corrupt data or not) you'd need to know what size and type of caches are present in the CPU and you'd need some way of detecting if data was corrupted (e.g. write a pattern to memory with caches disabled, then enable caches, read and modify the pattern, flush the caches, disable caches and see if the modified pattern in RAM is how it should be). For testing instruction caches (e.g. L1 instruction cache and/or trace cache) this doesn't work. In general, a faulty cache will either be detected by the BIOS (the CPU does a built in self test when it first gets turned on, if this is enabled by the chipset), or it'll crash the computer fairly quickly - i.e. if your code hasn't crashed for no reason during boot, then you can probably assume the caches are OK....
Also, the 80486 (and "compatables") have test registers (TR3, TR4, TR5, TR6 and TR7) that can be used for testing caches. See Intel's 80486 Programmer's Manual for details. These test registers are obsolete now though and are barely mentioned in the latest manuals. Newer CPUs have support for "machine check exceptions", but I'm not too sure if that detects cache errors or not (I think it does, but it's CPU specific).
Lastly, if you want to check how well the caches are working (for e.g. comparing the amount of cache hits to the amount of cache misses), then there's performance monitoring counters that can be used on modern CPUs.
My advice is to forget everything I said, and ignore the CPUs caches (except TLB invalidation) for a long time...
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.