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

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


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 3 Jun 2019 18:16:37 +0300
  • Cc: Florian.Schmidt@xxxxxxxxx
  • Delivery-date: Mon, 03 Jun 2019 15:16:53 +0000
  • Ironport-phdr: 9a23:djw/0xe8nP7Zm0nEaFRCNK8TlGMj4u6mDksu8pMizoh2WeGdxcS4Zh7h7PlgxGXEQZ/co6odzbaP6ua5AjNLsc/JmUtBWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYdFRrlKAV6OPn+FJLMgMSrzeCy/IDYbxlViDanbr5+MQi6oR/MusQYg4ZuJaU8xgbUqXZUZupawn9lK0iOlBjm/Mew+5Bj8yVUu/0/8sNLTLv3caclQ7FGFToqK2866tHluhnFVguP+2ATUn4KnRpSAgjK9w/1U5HsuSbnrOV92S2aPcrrTbAoXDmp8qlmRAP0hCoBKjU09nzchM5tg6JBuB+vpwJxzZPabo+WM/RxfK3dcMgGSWZdRMtdSzZMDp+gY4YJEuEPPfxYr474p1YWsxa+AhKsBP/uyj9Om3T427A60/w8EQrb2wEvA9UOsG/IrNX0MqceS+S1zLTQzTXedP5ZxSz95JLQchA8uv6AR6hwcc3IxEQpCgjLjU2QpJT4Mz6ay+gBqWuW4up6We6xlWIqqRt9rza3yssxhYTFm5gZx1PE+Clj3oo4K9O1RFRmbdOrDpddsTyROZFsTcM4WW5ovT43yrgBuZGmYicH0I8nxxvDa/yfdIiI/w7jWP6RIThmgHJlf6qyhwi38Ue6y+38UtO430pRriZfitnMq2sC2wbJ6siAUvd9/0Gh1iiT1w3L9+1JLl04mbDYJpMh2LI8iIQfvEbZEiL4gEn2ibWZdkQg+uim8eTnZbDmq4eAOI9zkQH+LqUumsqlDeQ8LwgOR3Wb9P+g273450H5WKhKgeYsnqnDt5DWPd4bqbKhAw9JzoYj7A6yDzKn0NQenHkHK0lFdAuagIf3JVHBPvT4AOy7g1Stizdr2+vGMqfuA5rTKHjPirDhfaxy60RE0go80chf545ICrEGOP/9WkvxtNvCDh84KQO0xfzrBshh2YMeXGKPA7KWML/JvF+O+O0gP+2Ma5UOtzrnNfcl+q2msXhsnF4bfK6ymJcadn28NvBnOFmCJ2rhhJEGC2hZkBA5SbnBj0aeUDgbQ2uqQupo7TYgFIOgS4PeXp2Fi6fHxDqxWIdRMDMVQmuQGGvlIt3XE8wHbzifd5ds
  • Ironport-sdr: Z5iI4wG9osHaENMBJnmE61G5/uqaiN4Ah7xzJhd9NXI71AKyS7iRhStlm1KJVTaX9t2O0xPlQ5 lENFSAqrPfEg==
  • 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®.