1. io file
  2. flush+reload
    1. 原理

io file

io_file 里面

flush+reload

原理

int probe(char *adrs) {
    volatile unsigned long time;
    asm __volatile__ (
        "mfence    \n"    // memory fence, load 和 read 不能跨越这个 fence
        "lfence    \n"    // load fence, 不懂为什么要有这一步
        "rdtsc    \n"     // read time stamp counter 读时间戳到 EDX:EAX
        "lfence    \n"
        "movl %%eax, %%esi    \n"
        "movl (%1), %%eax    \n"     // 访问 addr
        "lfence    \n"
        "rdtsc    \n"
        "subl %%esi, %%eax    \n"    //时间差
        "clflush 0(%1)    \n"
        : "=a" (time)
        : "c" (adrs)
        :
        "%esi", "%edx");
    return time < threshold;
}