Können Sie mir bitte sagen, wie Sie die clflush() Anweisungen verwenden? Ich habe den folgenden einfachen Code geschrieben, um den Unterschied zwischen einer Ausführungszeit beim Lesen einer Variablen aus dem Cache und nach der Entfernung aus dem Cache zu messen. Ich habe jedoch keine schlüssigen Ergebnisse gefunden. Was ist der richtige Weg, um einen Cache mit clflush() zu vertreiben?Probleme mit CLFLUSH()?
#include <stdio.h>
#include <stdint.h>
#include"cpucycles.c"
#define REPEAT 1900000
inline void clflush(volatile void *p)
{
asm volatile ("clflush (%0)" :: "r"(p));
}
inline uint64_t rdtsc()
{
unsigned long a, d;
asm volatile ("cpuid; rdtsc" : "=a" (a), "=d" (d) : : "ebx", "ecx");
return a | ((uint64_t)d << 32);
}
volatile int i;
inline void test()
{
uint64_t start, end,clock;
volatile int j;
long int rep;
int k;
clock=0;
for(rep=0;rep<REPEAT;rep++){
start = rdtsc();
j = i+1;
end = rdtsc();
clock=clock+(end-start);
k=j;
}
printf("took %lu ticks\n", clock);
}
inline void testflush()
{
uint64_t start, end,clock;
volatile int j;
int k;
long int rep;
clock=0;
for(rep=0;rep<REPEAT;rep++){
start = rdtsc();
j = i+1;
end = rdtsc();
clflush(&i);
clock=clock+(end-start);
k=j;
}
printf("took %lu ticks\n", clock);
}
int main(int ac, char **av)
{
i=5;
printf("------------------------------------------\n");
test();
printf("------------------------------------------\n");
testflush();
printf("------------------------------------------\n");
test();
return 0;
}
Mögliches Duplikat von [Wie verwendet man clflush?] (Http://stackoverflow.com/questions/39448276/how-to-use-clflush) – Olaf