How would you generically detect cache line associativity from user mode code?

前端 未结 3 907
暗喜
暗喜 2021-02-05 10:17

I\'m putting together a small patch for the cachegrind/callgrind tool in valgrind which will auto-detect, using completely generic code, CPU instruction and cache configuration

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-05 10:57

    For x86 platform you can use cpuid:

    See http://www.intel.com/content/www/us/en/processors/processor-identification-cpuid-instruction-note.html for details.

    You need something like:

    long _eax,_ebx,_ecx,_edx;
    long op = func;
    
    asm ("cpuid"
        : "=a" (_eax),
        "=b" (_ebx),
        "=c" (_ecx),
        "=d" (_edx)
        : "a" (op)
    );
    

    Then use the info according to the doc in the link mentioned above.

提交回复
热议问题