1*4882a593SmuzhiyunFrom 439fa2eae78a8900bda120072335be19d626498c Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: "Yann E. MORIN" <yann.morin.1998@free.fr>
3*4882a593SmuzhiyunDate: Sun, 28 Dec 2014 23:39:40 +0100
4*4882a593SmuzhiyunSubject: [PATCH] erts/ethread: instruct libatomic_ops we do require CAS
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunWe do require compare-and-swap (CAS), so we must instruct libatomic_ops
7*4882a593Smuzhiyunto provide it, even if the architecture does not have instructions for
8*4882a593Smuzhiyunit.
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunFor example, on ARM, LDREX is required for fast CAS. But LDREX is only
11*4882a593Smuzhiyunavailable on ARMv6, so by default libatomic_ops will not have CAS for
12*4882a593Smuzhiyunanything below, like ARMv5. But ARMv5 is always UP, so using an
13*4882a593Smuzhiyunemulated CAS (that is signal-asyn-safe) is still possible (albeit much
14*4882a593Smuzhiyunslower).
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunTell libatomic_ops to provide CAS, even if the hardware is not capable
17*4882a593Smuzhiyunof it, by using emulated CAS, as per libatomic_ops dosc:
18*4882a593Smuzhiyun    https://github.com/ivmai/libatomic_ops/blob/master/doc/README.txt#L28
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun    If this is included after defining AO_REQUIRE_CAS, then the package
21*4882a593Smuzhiyun    will make an attempt to emulate compare-and-swap in a way that (at
22*4882a593Smuzhiyun    least on Linux) should still be async-signal-safe.
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunThanks go to Thomas for all this insight! :-)
25*4882a593SmuzhiyunThanks go to Frank for reporting the issue! :-)
26*4882a593Smuzhiyun
27*4882a593SmuzhiyunSigned-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
28*4882a593SmuzhiyunCc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
29*4882a593SmuzhiyunCc: Frank Hunleth <fhunleth@troodon-software.com>
30*4882a593Smuzhiyun---
31*4882a593Smuzhiyun erts/include/internal/libatomic_ops/ethread.h | 1 +
32*4882a593Smuzhiyun 1 file changed, 1 insertion(+)
33*4882a593Smuzhiyun
34*4882a593Smuzhiyundiff --git a/erts/include/internal/libatomic_ops/ethread.h b/erts/include/internal/libatomic_ops/ethread.h
35*4882a593Smuzhiyunindex d65ee19..71d3598 100644
36*4882a593Smuzhiyun--- a/erts/include/internal/libatomic_ops/ethread.h
37*4882a593Smuzhiyun+++ b/erts/include/internal/libatomic_ops/ethread.h
38*4882a593Smuzhiyun@@ -35,6 +35,7 @@
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun #define ETHR_NATIVE_IMPL__ "libatomic_ops"
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun+#define AO_REQUIRE_CAS
43*4882a593Smuzhiyun #include "atomic_ops.h"
44*4882a593Smuzhiyun #include "ethr_membar.h"
45*4882a593Smuzhiyun #include "ethr_atomic.h"
46*4882a593Smuzhiyundiff --git a/erts/aclocal.m4 b/erts/aclocal.m4
47*4882a593Smuzhiyunindex d65ee19..71d3598 100644
48*4882a593Smuzhiyun--- a/erts/aclocal.m4
49*4882a593Smuzhiyun+++ b/erts/aclocal.m4
50*4882a593Smuzhiyun@@ -1414,7 +1414,8 @@
51*4882a593Smuzhiyun 	    	    fi;;
52*4882a593Smuzhiyun 	    esac
53*4882a593Smuzhiyun 	    ethr_have_libatomic_ops=no
54*4882a593Smuzhiyun-	    AC_TRY_LINK([#include "atomic_ops.h"],
55*4882a593Smuzhiyun+	    AC_TRY_LINK([#define AO_REQUIRE_CAS
56*4882a593Smuzhiyun+                    #include "atomic_ops.h"],
57*4882a593Smuzhiyun 	    	        [
58*4882a593Smuzhiyun 	    	    	    volatile AO_t x;
59*4882a593Smuzhiyun 	    	    	    AO_t y;
60*4882a593Smuzhiyun@@ -1455,6 +1455,7 @@
61*4882a593Smuzhiyun 	        AC_CHECK_SIZEOF(AO_t, ,
62*4882a593Smuzhiyun 	    	    	        [
63*4882a593Smuzhiyun 	    	    	    	    #include <stdio.h>
64*4882a593Smuzhiyun+	    	    	    	    #define AO_REQUIRE_CAS
65*4882a593Smuzhiyun 	    	    	    	    #include "atomic_ops.h"
66*4882a593Smuzhiyun 	    	    	        ])
67*4882a593Smuzhiyun 	        AC_DEFINE_UNQUOTED(ETHR_SIZEOF_AO_T, $ac_cv_sizeof_AO_t, [Define to the size of AO_t if libatomic_ops is used])
68*4882a593Smuzhiyun--
69*4882a593Smuzhiyun1.9.1
70*4882a593Smuzhiyun
71