Determine whether memory location is in CPU cache

前端 未结 3 657
南方客
南方客 2021-02-15 12:33

It is possible for an operating system to determine whether a page of memory is in DRAM or in swap; for example, simply try to access it and if a page fault occurs, it wasn\'t.<

3条回答
  •  情深已故
    2021-02-15 13:10

    X86 dont know how to tell if address IS in cache BUT here is how to tell if address WAS in cache

    rdtsc
    save timestamp
    mov eax,address
    rdtsc read timestamp counter
    calculate timestamp difference
    if < threshold then was in cache
    

    threshold has to be determined from documentation or empirically

    some machines have cache hit/miss counters which would serve equally well

提交回复
热议问题