Skip to content

Instantly share code, notes, and snippets.

@richinseattle
Created January 7, 2018 02:52
Show Gist options
  • Select an option

  • Save richinseattle/39a6e2bc92e4869260f761f42d69db8c to your computer and use it in GitHub Desktop.

Select an option

Save richinseattle/39a6e2bc92e4869260f761f42d69db8c to your computer and use it in GitHub Desktop.
ulong time_page_fetch (ulong addr)
{
volatile ulong v=0;
asm volatile (
" movq %0, %%rsi \n"
:: "m"(addr)
);
asm volatile (
" xor %eax, %eax \n"
" rdtsc \n"
" shl $32, %rdx \n"
" orq %rax, %rdx \n"
" movl $1000000, %edi \n"
"pf: prefetcht0 (%rsi) \n"
" decl %edi \n"
" jne pf \n"
" movq %rdx, %rdi \n"
" xor %eax, %eax \n"
" rdtsc \n"
" shl $32, %rdx \n"
" orq %rax, %rdx \n"
" subq %rdi, %rdx \n"
);
asm volatile (
" movq %%rdx, %0 \n"
:: "m"(v)
);
return v;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment