Skip to content

Commit

Permalink
perf tools: Add feature test for __sync_val_compare_and_swap
Browse files Browse the repository at this point in the history
Add a feature test for __sync_val_compare_and_swap() and
__sync_bool_compare_and_swap()

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1405332185-4050-30-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Adrian Hunter authored and Arnaldo Carvalho de Melo committed Jul 16, 2014
1 parent a8a8f3e commit f6d3136
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tools/perf/config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ CORE_FEATURE_TESTS = \
backtrace \
dwarf \
fortify-source \
sync-compare-and-swap \
glibc \
gtk2 \
gtk2-infobar \
Expand Down Expand Up @@ -199,6 +200,7 @@ LIB_FEATURE_TESTS = \
VF_FEATURE_TESTS = \
backtrace \
fortify-source \
sync-compare-and-swap \
gtk2-infobar \
libelf-getphdrnum \
libelf-mmap \
Expand Down Expand Up @@ -272,6 +274,10 @@ CFLAGS += -I$(LIB_INCLUDE)

CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE

ifeq ($(feature-sync-compare-and-swap), 1)
CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
endif

ifndef NO_BIONIC
$(call feature_check,bionic)
ifeq ($(feature-bionic), 1)
Expand Down
4 changes: 4 additions & 0 deletions tools/perf/config/feature-checks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ FILES= \
test-bionic.bin \
test-dwarf.bin \
test-fortify-source.bin \
test-sync-compare-and-swap.bin \
test-glibc.bin \
test-gtk2.bin \
test-gtk2-infobar.bin \
Expand Down Expand Up @@ -141,6 +142,9 @@ test-timerfd.bin:
test-libdw-dwarf-unwind.bin:
$(BUILD)

test-sync-compare-and-swap.bin:
$(BUILD) -Werror

-include *.d

###############################
Expand Down
5 changes: 5 additions & 0 deletions tools/perf/config/feature-checks/test-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
# include "test-libdw-dwarf-unwind.c"
#undef main

#define main main_test_sync_compare_and_swap
# include "test-sync-compare-and-swap.c"
#undef main

int main(int argc, char *argv[])
{
main_test_libpython();
Expand All @@ -111,6 +115,7 @@ int main(int argc, char *argv[])
main_test_timerfd();
main_test_stackprotector_all();
main_test_libdw_dwarf_unwind();
main_test_sync_compare_and_swap(argc, argv);

return 0;
}
14 changes: 14 additions & 0 deletions tools/perf/config/feature-checks/test-sync-compare-and-swap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdint.h>

volatile uint64_t x;

int main(int argc, char *argv[])
{
uint64_t old, new = argc;

argv = argv;
do {
old = __sync_val_compare_and_swap(&x, 0, 0);
} while (!__sync_bool_compare_and_swap(&x, old, new));
return old == new;
}

0 comments on commit f6d3136

Please sign in to comment.