Skip to content

Commit

Permalink
configure: Check for membarrier support
Browse files Browse the repository at this point in the history
Runtime dynamic patching requires cache synchronization. This is best
achieved by using the 'MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE'
memory barrier. However it was introduced in Linux 4.16. We set a flag
indicating whether this membarrier can be used or if libmcount has to
rely on other mechanisms (e.g. signals).

Signed-off-by: Clément Guidi <cguidi@ciena.com>
  • Loading branch information
clementguidi committed Jul 6, 2023
1 parent 6721fec commit 4a0abd6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions check-deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CHECK_LIST += have_libdw
CHECK_LIST += have_libunwind
CHECK_LIST += have_libcapstone
CHECK_LIST += cc_has_minline_all_stringops
CHECK_LIST += have_membarrier

#
# This is needed for checking build dependency
Expand Down
4 changes: 4 additions & 0 deletions check-deps/Makefile.check
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ endif
ifneq ($(wildcard $(objdir)/check-deps/cc_has_minline_all_stringops),)
LIB_CFLAGS += -minline-all-stringops
endif

ifneq ($(wildcard $(objdir)/check-deps/have_membarrier),)
LIB_CFLAGS += -DHAVE_MEMBARRIER
endif
10 changes: 10 additions & 0 deletions check-deps/__have_membarrier.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <linux/membarrier.h>
#include <sys/syscall.h>
#include <unistd.h>

int main()
{
syscall(__NR_membarrier, MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE, 0, 0);
syscall(__NR_membarrier, MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE, 0, 0);
return 0;
}
3 changes: 3 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ usage() {
--without-capstone build without libcapstone (even if found on the system)
--without-perf build without perf event (even if available)
--without-schedule build without scheduler event (even if available)
--without-membarrier build without membarriers (even if available)
--arch=<ARCH> set target architecture (default: system default arch)
e.g. x86_64, aarch64, i386, or arm
Expand Down Expand Up @@ -198,6 +199,7 @@ for dep in $IGNORE; do
capstone) TARGET=have_libcapstone ;;
perf*) TARGET=perf_clockid ;;
sched*) TARGET=perf_context_switch;;
membarrier) TARGET=have_membarrier ;;
*) ;;
esac
if [ ! -z "$TARGET" ]; then
Expand Down Expand Up @@ -265,6 +267,7 @@ print_feature "perf_event" "perf_clockid" "perf (PMU) event support"
print_feature "schedule" "perf_context_switch" "scheduler event support"
print_feature "capstone" "have_libcapstone" "full dynamic tracing support"
print_feature "libunwind" "have_libunwind" "stacktrace support (optional for debugging)"
print_feature "membarrier" "have_membarrier" "membarrier support (requires Linux 4.16)"

cat >$output <<EOF
# this file is generated automatically
Expand Down

0 comments on commit 4a0abd6

Please sign in to comment.