CPU caches are used by exploiting temporal and spatial locality. My question is who is responsible for managing these caches? Is this Operating system that identifies a particular access pattern and then manages (i.e store the data in) cache, using low level OS function calls?
$\begingroup$ If caches where managed by software, CPUs would not get anything done time-wise; also, wouldn't that be a catch 22? $\endgroup$– Raphael ♦Feb 24, 2013 at 16:09
The CPU cache handles each and every access to memory, that is just too fast to be under software control. It is entirely built into the hardware, either on the CPU chip itself or on the motherboard.
The CPU caches are operational from the very moment on when the CPU is powered up. Neither the BIOS nor an OS are strictly speaking “necessary” to control the caches. The BIOS and the OS can change cache configuration settings in the CPU but they don’t control the normal operation, this is all built into the CPU itself.
$\begingroup$ Some processors default to having caching enabled; some default to having it disabled. Having a cache enabled may make it possible for a processor to behave in somewhat controlled fashion even when there's no RAM (e.g. the processor might beep the speaker some number of times); having it initially disabled will avoid the need to disable it before changing any memory-configuration options. $\endgroup$– supercatJun 27, 2015 at 18:00
It is totally depends on your hardware platform (For example Nios® II provides some instruction for managing caches). You should read the instruction and assembly language. Some processor provide you some instructions to manage cache in some level. for example WBINVD provides Write back and flush Internal caches; initiate writing-back and flushing of external caches (or INVD).