[aarch64] Use IFUNCs to enable LSE instructions in libatomic on aarch64

Message ID 1502138734.3962.96.camel@cavium.com
State New
Headers show

Commit Message

Steve Ellcey Aug. 7, 2017, 8:45 p.m.
It would probably help if I included the patch.

Steve Ellcey
sellcey@cavium.com

2017-08-07  Steve Ellcey  <sellcey@cavium.com>

	* Makefile.am (ARCH_AARCH64_LINUX_LSE): Add IFUNC_OPTIONS and
	libatomic_la_LIBADD.
	* config/linux/aarch64/host-config.h: New file.
	* config/linux/aarch64/init.c: New file.
	* configure.ac (AC_CHECK_HEADERS): Check for sys/auxv.h.
	(AC_CHECK_FUNCS): Check for getauxval.
	(ARCH_AARCH64_LINUX_LSE): New conditional for IFUNC builds.
	* configure.tgt (aarch64): Set AARCH and try_ifunc.
	(aarch64*-*-linux*) Update config_path.
	* Makefile.in: Regenerate.
	* auto-config.h.in: Regenerate.
	* configure: Regenerate.

Comments

Steve Ellcey Aug. 24, 2017, 10:36 p.m. | #1
Ping.

> 2017-08-07  Steve Ellcey  <sellcey@cavium.com>
> 
> 	* Makefile.am (ARCH_AARCH64_LINUX_LSE): Add IFUNC_OPTIONS and
> 	libatomic_la_LIBADD.
> 	* config/linux/aarch64/host-config.h: New file.
> 	* config/linux/aarch64/init.c: New file.
> 	* configure.ac (AC_CHECK_HEADERS): Check for sys/auxv.h.
> 	(AC_CHECK_FUNCS): Check for getauxval.
> 	(ARCH_AARCH64_LINUX_LSE): New conditional for IFUNC builds.
> 	* configure.tgt (aarch64): Set AARCH and try_ifunc.
> 	(aarch64*-*-linux*) Update config_path.
> 	* Makefile.in: Regenerate.
> 	* auto-config.h.in: Regenerate.
> 	* configure: Regenerate.
>

Patch

diff --git a/libatomic/Makefile.am b/libatomic/Makefile.am
index d731406..a35df1e 100644
--- a/libatomic/Makefile.am
+++ b/libatomic/Makefile.am
@@ -122,6 +122,10 @@  libatomic_la_LIBADD = $(foreach s,$(SIZES),$(addsuffix _$(s)_.lo,$(SIZEOBJS)))
 
 ## On a target-specific basis, include alternates to be selected by IFUNC.
 if HAVE_IFUNC
+if ARCH_AARCH64_LINUX_LSE
+IFUNC_OPTIONS	     = -mcpu=thunderx2t99
+libatomic_la_LIBADD += $(foreach s,$(SIZES),$(addsuffix _$(s)_1_.lo,$(SIZEOBJS)))
+endif
 if ARCH_ARM_LINUX
 IFUNC_OPTIONS	     = -march=armv7-a -DHAVE_KERNEL64
 libatomic_la_LIBADD += $(foreach s,$(SIZES),$(addsuffix _$(s)_1_.lo,$(SIZEOBJS)))
diff --git a/libatomic/config/linux/aarch64/host-config.h b/libatomic/config/linux/aarch64/host-config.h
index e69de29..4d0ab96 100644
--- a/libatomic/config/linux/aarch64/host-config.h
+++ b/libatomic/config/linux/aarch64/host-config.h
@@ -0,0 +1,33 @@ 
+/* Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This file is part of the GNU Atomic Library (libatomic).
+
+   Libatomic is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#if HAVE_IFUNC
+
+extern bool libat_have_lse HIDDEN;
+
+# define IFUNC_COND_1	libat_have_lse
+# define IFUNC_NCOND(N)	(1)
+
+#endif /* HAVE_IFUNC */
+
+#include_next <host-config.h>
diff --git a/libatomic/config/linux/aarch64/init.c b/libatomic/config/linux/aarch64/init.c
index e69de29..1b135c2 100644
--- a/libatomic/config/linux/aarch64/init.c
+++ b/libatomic/config/linux/aarch64/init.c
@@ -0,0 +1,51 @@ 
+/* Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This file is part of the GNU Atomic Library (libatomic).
+
+   Libatomic is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "libatomic_i.h"
+
+#if HAVE_IFUNC
+
+#include <stdlib.h>
+#ifdef HAVE_SYS_AUXV_H
+# include <sys/auxv.h>
+#endif
+
+bool libat_have_lse = false;
+
+static void __attribute__((constructor))
+init_cpu_revision (void)
+{
+#if defined (HAVE_GETAUXVAL) && defined (HWCAP_ATOMICS)
+  unsigned long i;
+  char *s;
+
+  i = getauxval (AT_HWCAP);
+  s = getenv ("LD_HWCAP_MASK");
+  if (s)
+    i = i & strtoul (s, NULL, 10);
+  if (i & HWCAP_ATOMICS)
+    libat_have_lse = true;
+#endif
+}
+
+#endif /* HAVE_IFUNC */
diff --git a/libatomic/configure.ac b/libatomic/configure.ac
index 023f172..2bdc234 100644
--- a/libatomic/configure.ac
+++ b/libatomic/configure.ac
@@ -171,7 +171,8 @@  CFLAGS="$save_CFLAGS -fno-sync-libcalls $XCFLAGS"
 AC_STDC_HEADERS
 ACX_HEADER_STRING
 GCC_HEADER_STDINT(gstdint.h)
-AC_CHECK_HEADERS([fenv.h])
+AC_CHECK_HEADERS([fenv.h sys/auxv.h])
+AC_CHECK_FUNCS(getauxval)
 
 # Check for common type sizes
 LIBAT_FORALL_MODES([LIBAT_HAVE_INT_MODE])
@@ -247,6 +248,8 @@  AC_SUBST(LIBS)
 AC_SUBST(SIZES)
 
 AM_CONDITIONAL(HAVE_IFUNC, test x$libat_cv_have_ifunc = xyes)
+AM_CONDITIONAL(ARCH_AARCH64_LINUX_LSE,
+	       [expr "$config_path" : ".* linux/aarch64 .*" > /dev/null])
 AM_CONDITIONAL(ARCH_ARM_LINUX,
 	       [expr "$config_path" : ".* linux/arm .*" > /dev/null])
 AM_CONDITIONAL(ARCH_I386,
diff --git a/libatomic/configure.tgt b/libatomic/configure.tgt
index b8af3ab..f70bad5 100644
--- a/libatomic/configure.tgt
+++ b/libatomic/configure.tgt
@@ -40,6 +40,14 @@  case "${target_cpu}" in
   riscv*)		ARCH=riscv ;;
   sh*)			ARCH=sh ;;
 
+  aarch64*)
+	ARCH=aarch64
+	case "${target}" in
+	    aarch64*-*-linux*)
+		try_ifunc=yes
+		;;
+	esac
+	;;
   arm*)
 	ARCH=arm
 	case "${target}" in
@@ -109,6 +117,11 @@  fi
 
 # Other system configury
 case "${target}" in
+  aarch64*-*-linux*)
+	# OS support for atomic primitives.
+	config_path="${config_path} linux/aarch64 posix"
+	;;
+
   arm*-*-linux*)
 	# OS support for atomic primitives.
 	config_path="${config_path} linux/arm posix"