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

[Minios-devel] [UNIKRAFT/LWIP PATCH] semaphore: Fix locking of semaphores when using timeouts


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Wed, 3 Apr 2019 13:06:10 +0300
  • Cc: felipe.huici@xxxxxxxxx, Florian.Schmidt@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx, sharan.santhanam@xxxxxxxxx
  • Delivery-date: Wed, 03 Apr 2019 10:06:19 +0000
  • Ironport-phdr: 9a23:05FABhNnla4nusm8sIsl6mtUPXoX/o7sNwtQ0KIMzox0K/37pMbcNUDSrc9gkEXOFd2Cra4d0qyO6eu6AyRAuc/H7ClaNsQUFlcssoY/p0QYGsmLCEn2frbBThcRO4B8bmJj5GyxKkNPGczzNBX4q3y26iMOSF2kbVImbuv6FZTPgMupyuu854PcYxlShDq6fLh+MAi6oR/eu8ULnIduMLo9xgXGrndWZehd2GdkKU6Okxrm6cq84YJv/z5Mt/498sJLTLn3cbk/QbFEFjotLno75NfstRnNTAuP4mUTX2ALmRdWAAbL8Q/3UI7pviT1quRy1i+aPdbrTb8vQjSt871rSB7zhygZMTMy7XzahdZxjKJfpxKhugB/zovJa4ybKPZyYqXQds4cSGFcXMheSjZBD5u8YYUREuQPM+VWoY7mqlcSsRezHxWgCfnzxjNUgHL9wK000/4mEQHDxAEtAdUOsG/IrNX0MqcZTOa7zLTQzTXecvhb3ivy6I/TchA9oPGMW6h8cc7MyUk3CgPIlUmfqZf/MzONy+QCqHKX7/BnVe+2jWMstgJ/oiC3y8sxhYTFm5gZx1PE+Clj3oo5O9+1RFR1bNK8DZdduDyWO5F1T84iWW1kpig3x7MctZKmcyUG1pIqzAPFZfOdaYiH+BfjWf6UITd/mX1qZqqyhw238Ui80u38UdS00EpSoipFjNbMsncN2gTN6siCUPR9/0Oh1SyT2ADI8O1EOV00mrHBJ547xb48jpsTsULdES/qgEj6kaCbelg+9uWr6+nreKvqqoGeOoNuhAzyKqEulda+AeQ8PAgORW+b+eGk2bL/+k35W6lKjvwwkqXDtJDaONwbprOiDgBJyYYv8Q6/Dyq939gCh3kHK0pJeAibgIjxJ1HOPPf4AO+6g1StljdrxvfGPqb4DprQMHfDjqnufbJm5k5YyQoz1sxf54lOBrAOPv3zXFX9tNvCDh82Kwa02froCM1h1oMCXmKCGq+XMKfVsV+S5+IgOe+MaJUItjnhK/gl4v/ugmIlmVIGe6mmw4cYaHSiEft9OUmWf2fsiM8bEWgWpgo+UPDqiFqaXD5deXmyW6M85iklB468DYfDW4Gtj6CA3CqgGJ1ZeHxJClSWHnjzbYmLReoMYjqIIsB9ijwESaShS4g52BG1tA/10aBnIfDS+iECrpLszt515/HTlR4o8zx7FcGd3nqLT25qgmwIQyU507tlrUNj11eJybJ4jOBAFdxP+/NJVR83NYXdz+x/DNDyXBjNftSUSFm4RNWnAC8+Tsgqzt8IfUlyB9GigQrY0CawHbAViqSBBIYo/aLEw3jxO8F9xm7G1ak8lVkmQ9FDNXOhhq576wfTB43Jk0KHl6uxc6QTwjLC9GOZwmWVpk1XThNwAu35WiUaZ03Xqs+86k7cQruGDbU8LhAH2cOEbKxQZY7Hl1JDEdzkI8jfZSqVhn+tTUKDwaiQbYysf3gFwQ3WEw4cjgpV53HQZlt2PTuov2+LVG8mLlnoeU65qeQ=
  • Ironport-sdr: lWssaP/XwWSqcMu4A9Bxe01Tx++nsQlSgWOXcBNY/k6dGHW6J157auv8EIPVPxV0pqSUBrRutr BWUn9ziYJ5ng==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Recently, uk_semaphore_down_to call was changed to be inline with its
POSIX counterpart. This means that when timeout value is 0, the call
returns immediately and behaves like a try lock operation. POSIX passed
the timeout parameter as a pointer and if the pointer was NULL the
function blocked "forever", an approach we cannot use because our
timeout parameter is passed by value. Therefore, we had to update all
the semaphores locking calls to use uk_semaphore_down when timeout was
set to 0 by the caller.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 semaphore.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/semaphore.c b/semaphore.c
index 16da316..3e67eb5 100644
--- a/semaphore.c
+++ b/semaphore.c
@@ -83,12 +83,22 @@ void sys_sem_signal(sys_sem_t *sem)
  */
 u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
 {
+       u32_t ret;
        __nsec nsret;
 
-       nsret = uk_semaphore_down_to(&sem->sem,
-                                    ukarch_time_msec_to_nsec((__nsec)
-                                                             timeout));
-       if (unlikely(nsret == __NSEC_MAX))
-               return SYS_ARCH_TIMEOUT;
-       return (u32_t) ukarch_time_nsec_to_msec(nsret);
+       if (timeout) {
+               nsret = uk_semaphore_down_to(&sem->sem,
+                       ukarch_time_msec_to_nsec((__nsec) timeout));
+               if (unlikely(nsret == __NSEC_MAX))
+                       ret = SYS_ARCH_TIMEOUT;
+               else
+                       ret = (u32_t) ukarch_time_nsec_to_msec(nsret);
+
+       } else {
+               /* no timeout, we wait forever */
+               uk_semaphore_down(&sem->sem);
+               ret = 0;
+       }
+
+       return ret;
 }
-- 
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®.