我试图用来clflush手动逐出缓存行,以确定缓存和行大小。我没有找到有关如何使用该指令的任何指南。我所看到的是一些为此目的使用更高级别功能的代码。有一个内核函数void clflush_cache_range(void *vaddr, unsigned int size),但是我仍然不知道代码中包括什么以及如何使用它。我不知道size该功能是什么。不仅如此,我如何确保将行逐出以验证代码的正确性?更新:这是我要尝试执行的初始代码。#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 回答
- 2 回答
- 0 关注
- 1040 浏览
添加回答
举报
0/150
提交
取消