public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, rs6000] Allow libitm to use HTM on newer hw and kernels
@ 2018-12-12 19:47 Peter Bergner
  2018-12-12 20:52 ` Segher Boessenkool
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Bergner @ 2018-12-12 19:47 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: GCC Patches

Libitm on POWER hardware looks for the "htm" bit in AT_HWCAP2 to determine
whether it can use HTM when executing code within __transaction_atomic
code blocks.  However, on newer hardware and kernels, the "htm" bit is no
longer set and instead the "htm-no-suspend" bit is set, so we currently
don't use HTM on new hw and kernels.  The following patch adds support
for htm-no-suspend to libitm.  I have also added code to use the
__builtin_cpu_supports() builtin if it is available, since that is
much faster than using the getauxval libc call.

This passed bootstrap and regtesting with no errors and someone within
IBM how had a POWER9 box with a newish kernel how ran into the problem
confirmed it works for his test case.

Ok for mainline?  Should be backport this?

Peter

	* config/powerpc/target.h (PPC_FEATURE2_HTM_NO_SUSPEND): Conditionally
	define.
	(htm_available):  Add support for PPC_FEATURE2_HTM_NO_SUSPEND.
	Use __builtin_cpu_supports if available.

Index: libitm/config/powerpc/target.h
===================================================================
--- libitm/config/powerpc/target.h	(revision 267062)
+++ libitm/config/powerpc/target.h	(working copy)
@@ -26,6 +26,11 @@
 #include <sys/auxv.h>
 #endif
 
+/* This is a fairly new feature bit, so handle it not being defined.  */
+#ifndef PPC_FEATURE2_HTM_NO_SUSPEND
+# define PPC_FEATURE2_HTM_NO_SUSPEND 0
+#endif
+
 namespace GTM HIDDEN {
 
 typedef int v128 __attribute__((vector_size(16), may_alias, aligned(16)));
@@ -81,7 +86,16 @@ cpu_relax (void)
 static inline bool
 htm_available (void)
 {
-  return (getauxval (AT_HWCAP2) & PPC_FEATURE2_HAS_HTM) ? true : false;
+#ifdef __BUILTIN_CPU_SUPPORTS__
+  if (__builtin_cpu_supports ("htm-no-suspend")
+      || __builtin_cpu_supports ("htm"))
+    return true;
+#else
+  if (getauxval (AT_HWCAP2)
+      & (PPC_FEATURE2_HAS_HTM | PPC_FEATURE2_HTM_NO_SUSPEND))
+    return true;
+#endif
+  return false;
 }
 
 static inline uint32_t

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-12-13 18:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-12 19:47 [PATCH, rs6000] Allow libitm to use HTM on newer hw and kernels Peter Bergner
2018-12-12 20:52 ` Segher Boessenkool
2018-12-13  0:55   ` Peter Bergner
2018-12-13 11:12     ` Segher Boessenkool
2018-12-13 16:42       ` Peter Bergner
2018-12-13 18:11         ` Peter Bergner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).