[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT/PTHREAD-EMBEDDED PATCH 5/8] patches: Fix atomic operations


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 15 Apr 2019 15:43:17 +0300
  • Cc: felipe.huici@xxxxxxxxx, Florian.Schmidt@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx, sharan.santhanam@xxxxxxxxx
  • Delivery-date: Mon, 15 Apr 2019 12:44:39 +0000
  • Ironport-phdr: 9a23:q7o5mxen5A/RIUCR2XFpNWt7lGMj4u6mDksu8pMizoh2WeGdxc27ZBON2/xhgRfzUJnB7Loc0qyK6vmmAz1LvMzJ8ChbNsAVD1ld0YRetjdjKfbNMVf8Iv/uYn5yN+V5f3ghwUuGN1NIEt31fVzYry76xzcTHhLiKVg9fbytScbdgMutyu+95YDYbRlWizqhe7NyKwi9oRnMusUMjoZuN7s9xgHXrnZMdOhbxX1kLk+Xkxrg+8u85pFu/zlMt/4768JMTaD2dLkkQLJFCzgrL3o779DxuxnZSguP6HocUmEInRdNHgPI8hL0UIrvvyXjruZy1zWUMsPwTbAvRDSt9LxrRwPyiCcGLDE27mfagdFtga1BoRKhoxt/w5PIYIyQKfFzcL/Rcc8cSGFcWMtaSi5PDZ6mb4YXD+QPI/tWoYf+qVUJrxS+CxKhCP/zxjJSmnP7x7E23/gnHArb3AIgBdUOsHHModjrM6cSSvy1zKjOzT7eaf1WxC/96JXVeR0mvf6MWqlwcdbQyUkpDQ/FikiQqZT4Pz6OyusNqHKX7/J9Ve20kWInsQZxryGpy8wxiYfJnpoYxk3L+Clk2oo4Jt21RFRlbdK6EpZcrS+XO5NrTs4tXm1koiU3x70ctZKlciUHxo4rywPQZvCZdYWD/wjtW/yLIThigXJoYLe/hxGv/ke+0uD8Tcy00EpSripCj9nMqmgB1xzN5ciDTftw5lmh2TOV2ADS7uFIO1w7lbHBJ545374/jYAfsV7EHiPumUX2irGZdlk89+S15Onrf6/qq5ycOoNulA3yLKYjltaxDOggNwgBRWmb+eCy1L35+k35Ra1HgeExkqnCrJDaJMIbqrS9Aw9IyoYj9g2yACu90NgChXkHMUlKdAidj4juI13OOuz3De+jg1Swlzdm3/XGPrznApXMKXjDi67tcqtj5E5C1gUzyctS55ZVCrEaPPLzQVX9tdPGAR8/KQC0xPznCNpl3IMERW2PGrOZML/VsVKQ5uwvJ+6MZJUUuDnnLfgp/ePggmM5mV8YfKmmwIcXZWu+Hvt4P0qZZWDjjcwbHWgUowo0VPbqh0GaUT5Pe3ayWLox5j8lB4KiDIfDXp6ijKaB3CemH51ZemFGB0uKEXj2a4qEX+0DZzmILsB/jzwOTaKhRJM51RGyqA/6zKJqLvHU+iICr5Lszt516/fIlR4o8zx0E8Sd3HuLT25um2MFXDk2075jrkx50FiMyrJ0jOJFFdZL/fNGTh86NYLAz+x9E93yQQPBftKOSFagWNmmAiwxQcw3w94PfUl9Ac6vjhbd0CW2B78ajaeECIYq/aLBx3LxPdpyy27a1Kk9iFkrWstONXC8hq5+7QTTGYnJk0GFmKaqdqQc2zDN+XyFzWWQoE5YVBR/Xr7fUX8Be0uF5ej+s0bDSb6pEvErPxVMzeaGK7BWcZv5gFMAQ+3sa/rEZGfksGCrGReOjpeRdJeiL24axzncDg4AjhgO1X2dcxAjDGG7pDSNX3RVCVvzbha0oqFFo3ShQxpswg==
  • Ironport-sdr: 3HC/wKadGrU1q6lo2SHbbSrQJBNvEMUV4g7GdoLzAwiZZ7jh0NdcHzzekZAqf9r+LuUCUObcoM wUVYbk9wmr8Q==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

We use atomic operations as macros because pte uses them for both int
and long types.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 patches/0007-Use-atomic-operations-as-macros.patch | 62 +++++++++++++++++++++
 ...bugfix-Fix-atomic-operations-on-semaphore.patch | 63 ++++++++++++++++++++++
 2 files changed, 125 insertions(+)
 create mode 100644 patches/0007-Use-atomic-operations-as-macros.patch
 create mode 100644 patches/0008-bugfix-Fix-atomic-operations-on-semaphore.patch

diff --git a/patches/0007-Use-atomic-operations-as-macros.patch 
b/patches/0007-Use-atomic-operations-as-macros.patch
new file mode 100644
index 0000000..63313b2
--- /dev/null
+++ b/patches/0007-Use-atomic-operations-as-macros.patch
@@ -0,0 +1,62 @@
+From e0cf6be2cec87542be01bb127413f31a05ec161b Mon Sep 17 00:00:00 2001
+From: Costin Lupu <costin.lup@xxxxxxxxx>
+Date: Wed, 3 Apr 2019 18:54:21 +0300
+Subject: [PATCH 1/2] Use atomic operations as macros
+
+We use atomic operations as macros because pte uses them for both int
+and long types (see next patch).
+
+Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
+---
+ pte_generic_osal.h | 28 ++++++++++++++++++++++++++++
+ 1 file changed, 28 insertions(+)
+
+diff --git a/pte_generic_osal.h b/pte_generic_osal.h
+index de1ea5f..6b1f439 100644
+--- a/pte_generic_osal.h
++++ b/pte_generic_osal.h
+@@ -378,6 +378,7 @@ pte_osResult pte_osTlsFree(unsigned int key);
+ //@}
+ 
+ /** @name Atomic operations */
++#if 0
+ //@{
+ 
+ /**
+@@ -455,6 +456,33 @@ int pte_osAtomicDecrement(int *pdest);
+  * return origVal;
+  */
+ int pte_osAtomicIncrement(int *pdest);
++#else
++
++#include <uk/arch/atomic.h>
++
++#define pte_osAtomicExchange(ptarg, val) \
++      ukarch_exchange_n(ptarg, val)
++
++#define pte_osAtomicCompareExchange(pdest, exchange, comp) \
++({ \
++      __typeof__(*pdest) __orig = *pdest; \
++      ukarch_compare_exchange_sync(pdest, comp, exchange); \
++      __orig; \
++})
++
++#define pte_osAtomicExchangeAdd(paddend, value) \
++      ukarch_fetch_add(paddend, value)
++
++#define atomic_add(ptarg, val) \
++      __atomic_add_fetch(ptarg, val, __ATOMIC_SEQ_CST)
++
++#define pte_osAtomicDecrement(pdest) \
++      atomic_add(pdest, -1)
++
++#define pte_osAtomicIncrement(pdest) \
++      atomic_add(pdest, 1)
++
++#endif
+ //@}
+ 
+ struct timeb;
+-- 
+2.11.0
+
diff --git a/patches/0008-bugfix-Fix-atomic-operations-on-semaphore.patch 
b/patches/0008-bugfix-Fix-atomic-operations-on-semaphore.patch
new file mode 100644
index 0000000..6ca339d
--- /dev/null
+++ b/patches/0008-bugfix-Fix-atomic-operations-on-semaphore.patch
@@ -0,0 +1,63 @@
+From 09a21187f7e426147d4d5fb91451ea55cf7ac274 Mon Sep 17 00:00:00 2001
+From: Costin Lupu <costin.lup@xxxxxxxxx>
+Date: Wed, 3 Apr 2019 18:56:31 +0300
+Subject: [PATCH 2/2] bugfix Fix atomic operations on semaphore
+
+Field 'semaphore' of struct pthread_once_t_ is of type 'void *'.
+Therefore atomic operations should use long type instead of int.
+
+Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
+---
+ pthread_once.c | 12 ++++++------
+ 1 file changed, 6 insertions(+), 6 deletions(-)
+
+diff --git a/pthread_once.c b/pthread_once.c
+index a8166f5..2b6050f 100644
+--- a/pthread_once.c
++++ b/pthread_once.c
+@@ -55,7 +55,7 @@ pte_once_init_routine_cleanup(void * arg)
+ 
+   (void) PTE_ATOMIC_EXCHANGE(&once_control->state,PTE_ONCE_INIT);
+ 
+-  if (PTE_ATOMIC_EXCHANGE_ADD((int*)&once_control->semaphore, 0L)) /* MBR 
fence */
++  if (PTE_ATOMIC_EXCHANGE_ADD((long*)&once_control->semaphore, 0L)) /* MBR 
fence */
+     {
+       pte_osSemaphorePost((pte_osSemaphoreHandle) once_control->semaphore, 1);
+     }
+@@ -134,7 +134,7 @@ pthread_once (pthread_once_t * once_control, void 
(*init_routine) (void))
+            * we didn't create the semaphore.
+            * it is only there if there is someone waiting.
+            */
+-          if (PTE_ATOMIC_EXCHANGE_ADD((int*)&once_control->semaphore, 0L)) /* 
MBR fence */
++          if (PTE_ATOMIC_EXCHANGE_ADD((long*)&once_control->semaphore, 0L)) 
/* MBR fence */
+             {
+               pte_osSemaphorePost((pte_osSemaphoreHandle) 
once_control->semaphore,once_control->numSemaphoreUsers);
+             }
+@@ -143,12 +143,12 @@ pthread_once (pthread_once_t * once_control, void 
(*init_routine) (void))
+         {
+           PTE_ATOMIC_INCREMENT(&once_control->numSemaphoreUsers);
+ 
+-          if (!PTE_ATOMIC_EXCHANGE_ADD((int*)&once_control->semaphore, 0L)) 
/* MBR fence */
++          if (!PTE_ATOMIC_EXCHANGE_ADD((long*)&once_control->semaphore, 0L)) 
/* MBR fence */
+             {
+               pte_osSemaphoreCreate(0, (pte_osSemaphoreHandle*) &sema);
+ 
+-              if (PTE_ATOMIC_COMPARE_EXCHANGE((int *) 
&once_control->semaphore,
+-                                              (int) sema,
++              if (PTE_ATOMIC_COMPARE_EXCHANGE((long *) 
&once_control->semaphore,
++                                              (long) sema,
+                                               0))
+                 {
+                   pte_osSemaphoreDelete((pte_osSemaphoreHandle)sema);
+@@ -168,7 +168,7 @@ pthread_once (pthread_once_t * once_control, void 
(*init_routine) (void))
+             {
+               /* we were last */
+               if ((sema =
+-                     (pte_osSemaphoreHandle) PTE_ATOMIC_EXCHANGE((int *) 
&once_control->semaphore,0)))
++                     (pte_osSemaphoreHandle) PTE_ATOMIC_EXCHANGE((long *) 
&once_control->semaphore,0)))
+                 {
+                   pte_osSemaphoreDelete(sema);
+                 }
+-- 
+2.11.0
+
-- 
2.11.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.