我試圖用來clflush手動逐出緩存行,以確定緩存和行大小。我沒有找到有關如何使用該指令的任何指南。我所看到的是一些為此目的使用更高級別功能的代碼。有一個內核函數void clflush_cache_range(void *vaddr, unsigned int size),但是我仍然不知道代碼中包括什么以及如何使用它。我不知道size該功能是什么。不僅如此,我如何確保將行逐出以驗證代碼的正確性?更新:這是我要嘗試執(zhí)行的初始代碼。#include <immintrin.h>#include <stdint.h>#include <x86intrin.h>#include <stdio.h>int main(){ int array[ 100 ]; /* will bring array in the cache */ for ( int i = 0; i < 100; i++ ) array[ i ] = i; /* FLUSH A LINE */ /* each element is 4 bytes */ /* assuming that cache line size is 64 bytes */ /* array[0] till array[15] is flushed */ /* even if line size is less than 64 bytes */ /* we are sure that array[0] has been flushed */ _mm_clflush( &array[ 0 ] ); int tm = 0; register uint64_t time1, time2, time3; time1 = __rdtscp( &tm ); /* set timer */ time2 = __rdtscp( &array[ 0 ] ) - time1; /* array[0] is a cache miss */ printf( "miss latency = %lu \n", time2 ); time3 = __rdtscp( &array[ 0 ] ) - time2; /* array[0] is a cache hit */ printf( "hit latency = %lu \n", time3 ); return 0;}在運行代碼之前,我想手動驗證它是否正確。我走的路正確嗎?我使用_mm_clflush正確嗎?
- 2 回答
- 0 關注
- 1075 瀏覽
添加回答
舉報
0/150
提交
取消