Commit 45a94661 authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

Make util function arguments consistent

parent cee04718
No related merge requests found
Showing with 22 additions and 13 deletions
+22 -13
......@@ -7,14 +7,23 @@
typedef uint8_t page_t[PAGE_SIZE];
// Forces a memory read of the byte at address p. This will result in the byte
// being loaded into cache.
void force_read(const void *p);
/**
* Forces a memory read of the byte at the given address.
* This will load the byte at the address into the cache.
*/
void force_read(const void *address);
// Flushes the cache line containing the provided address
void flush_cache_line(const void *memory);
/**
* Evicts any cache line currently storing the given address.
* This ensures that the byte at the address is no longer in the cache.
*/
void flush_cache_line(const void *address);
// Returns the number of clocks taken to read the provided byte of memory.
uint64_t time_read(const void *memory);
/**
* Counts the number of processor clocks elapsed when reading a byte at the given address.
* Note that the number of clocks can be quite large
* if the process happens to be interrupted in this function.
*/
uint64_t time_read(const void *address);
#endif /* _UTIL_H */
......@@ -2,20 +2,20 @@
#include "util.h"
void force_read(const void *p) {
*(volatile char *) p;
void force_read(const void *address) {
*(volatile uint8_t *) address;
}
void flush_cache_line(const void *memory) {
_mm_clflush(memory);
void flush_cache_line(const void *address) {
_mm_clflush(address);
_mm_mfence();
for (volatile int i = 0; i < 10000; i++) {}
}
uint64_t time_read(const void *memory) {
uint64_t time_read(const void *address) {
uint64_t start = __rdtsc();
_mm_lfence();
force_read(memory);
force_read(address);
_mm_mfence();
_mm_lfence();
uint64_t result = __rdtsc() - start;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment