From 372777a64df4957803df998cada3fff1d5a8f176 Mon Sep 17 00:00:00 2001 From: Guillume DIDIER Date: Thu, 14 Oct 2021 14:32:48 +0200 Subject: [PATCH] Now features templates for timed clflush and maccess. --- prefetcher_reverse/src/ip_tool.rs | 44 +++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/prefetcher_reverse/src/ip_tool.rs b/prefetcher_reverse/src/ip_tool.rs index 8bb2492..9fb5d8d 100644 --- a/prefetcher_reverse/src/ip_tool.rs +++ b/prefetcher_reverse/src/ip_tool.rs @@ -1,20 +1,60 @@ global_asm!( ".global timed_maccess_template", "timed_maccess_template:", - "nop", + "mfence", + "rdtsc", + "shl rdx, 32", + "mov rsi, rdx", + "add rsi, rax", + "mfence", + "mov rdi, [rdi]", + "mfence", + "rdtsc", + "shl rdx, 32", + "add rax, rdx", + "mfence", + "sub rax, rsi", "ret", ".global timed_maccess_template_end", "timed_maccess_template_end:", "nop", + ".global timed_clflush_template", + "timed_clflush_template:", + "mfence", + "rdtsc", + "shl rdx, 32", + "mov rsi, rdx", + "add rsi, rax", + "mfence", + "clflush [rdi]", + "mfence", + "rdtsc", + "shl rdx, 32", + "add rax, rdx", + "mfence", + "sub rax, rsi", + "ret", + ".global timed_clflush_template_end", + "timed_clflush_template_end:", + "nop", ); extern "C" { fn timed_maccess_template(pointer: *const u8) -> u64; fn timed_maccess_template_end(); + fn timed_clflush_template(pointer: *const u8) -> u64; + fn timed_clflush_template_end(); } pub fn tmp_test() { let size = timed_maccess_template_end as *const u8 as usize - timed_maccess_template as *const u8 as usize; - println!("function size : {}", size); + println!("maccess function size : {}", size); + let size = timed_clflush_template_end as *const u8 as usize + - timed_clflush_template as *const u8 as usize; + println!("clflush function size : {}", size); + let mem: u8 = 42; + let p = &mem as *const u8; + println!("maccess {:p} : {}", p, unsafe { timed_maccess_template(p) }); + println!("clflush {:p} : {}", p, unsafe { timed_clflush_template(p) }); }