Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-21fa
project05b
Commits
45a94661
Commit
45a94661
authored
4 years ago
by
Caleb C. Sander
Browse files
Options
Download
Email Patches
Plain Diff
Make util function arguments consistent
parent
cee04718
master
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/util.h
+16
-7
include/util.h
lib/util.c
+6
-6
lib/util.c
with
22 additions
and
13 deletions
+22
-13
include/util.h
View file @
45a94661
...
...
@@ -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 */
This diff is collapsed.
Click to expand it.
lib/util.c
View file @
45a94661
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help