Skip to content

Commit

Permalink
Use volatile in readfe/readff/writeef/writeff/writexf.
Browse files Browse the repository at this point in the history
The xlc compiler will optimize out the while loop in these functions even with -O0.
Use the volatile keyword to protect these accesses to shared memory instead.
  • Loading branch information
ehein6 committed Nov 21, 2016
1 parent 19fbb3b commit 0eb1f54
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
7 changes: 2 additions & 5 deletions lib/stinger_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(sources
src/stinger_shared.c
src/stinger_vertex.c
src/xmalloc.c
src/x86_full_empty.c
)
set(headers
inc/core_util.h
Expand All @@ -24,9 +25,6 @@ set(headers
inc/x86_full_empty.h
inc/xmalloc.h
)
set(unoptimized_sources
src/x86_full_empty.c
)

set(config
stinger_names.h
Expand All @@ -39,6 +37,5 @@ include_directories("${CMAKE_BINARY_DIR}/include/stinger_core")
include_directories("${CMAKE_BINARY_DIR}/include/stinger_utils")

set_source_files_properties(${config} PROPERTIES GENERATED TRUE)
set_source_files_properties(${unoptimized_sources} PROPERTIES COMPILE_FLAGS -O0)
add_library(stinger_core SHARED ${sources} ${unoptimized_sources} ${headers} ${config})
add_library(stinger_core SHARED ${sources} ${headers} ${config})
target_link_libraries(stinger_core compat)
10 changes: 5 additions & 5 deletions lib/stinger_core/inc/x86_full_empty.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ extern "C" {
#define MARKER UINT64_MAX

uint64_t
readfe(uint64_t * v);
readfe(volatile uint64_t * v);

uint64_t
writeef(uint64_t * v, uint64_t new_val);
writeef(volatile uint64_t * v, uint64_t new_val);

uint64_t
readff(uint64_t * v);
readff(volatile uint64_t * v);

uint64_t
writeff(uint64_t * v, uint64_t new_val);
writeff(volatile uint64_t * v, uint64_t new_val);

uint64_t
writexf(uint64_t * v, uint64_t new_val);
writexf(volatile uint64_t * v, uint64_t new_val);

#ifdef __cplusplus
}
Expand Down
10 changes: 5 additions & 5 deletions lib/stinger_core/src/x86_full_empty.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "x86_full_empty.h"

uint64_t
readfe(uint64_t * v) {
readfe(volatile uint64_t * v) {
uint64_t val;
while(1) {
val = *v;
Expand All @@ -30,7 +30,7 @@ readfe(uint64_t * v) {
}

uint64_t
writeef(uint64_t * v, uint64_t new_val) {
writeef(volatile uint64_t * v, uint64_t new_val) {
uint64_t val;
while(1) {
val = *v;
Expand All @@ -44,7 +44,7 @@ writeef(uint64_t * v, uint64_t new_val) {
}

uint64_t
readff(uint64_t * v) {
readff(volatile uint64_t * v) {
uint64_t val = *v;
while(val == MARKER) {
val = *v;
Expand All @@ -53,7 +53,7 @@ readff(uint64_t * v) {
}

uint64_t
writeff(uint64_t * v, uint64_t new_val) {
writeff(volatile uint64_t * v, uint64_t new_val) {
uint64_t val;
while(1) {
val = *v;
Expand All @@ -67,7 +67,7 @@ writeff(uint64_t * v, uint64_t new_val) {
}

uint64_t
writexf(uint64_t * v, uint64_t new_val) {
writexf(volatile uint64_t * v, uint64_t new_val) {
*v = new_val;
return new_val;
}

0 comments on commit 0eb1f54

Please sign in to comment.