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

[Minios-devel] [UNIKRAFT PATCH] lib/ukmpi: Fix locking of semaphores when using timeouts for mailboxes


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Wed, 3 Apr 2019 13:04:19 +0300
  • Cc: felipe.huici@xxxxxxxxx, Florian.Schmidt@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx, sharan.santhanam@xxxxxxxxx
  • Delivery-date: Wed, 03 Apr 2019 10:04:31 +0000
  • Ironport-phdr: 9a23:nCVxMxwxk74ElI/XCy+O+j09IxM/srCxBDY+r6Qd0usWKfad9pjvdHbS+e9qxAeQG9mCsrQc0aGM6uigATVGvc/Z9ihaMdRlbFwssY0uhQsuAcqIWwXQDcXBSGgEJvlET0Jv5HqhMEJYS47UblzWpWCuv3ZJQk2sfQV6Kf7oFYHMks+5y/69+4HJYwVPmTGxfa5+IA+5oAnMq8Uam5duJrg+xhfXv3dDZuBayX91KV6JkBvw+9u88IR//yhMvv4q6tJNX7j9c6kkV7JTES4oM3oy5M3ltBnDSRWA634BWWgIkRRGHhbI4gjiUpj+riX1uOx92DKHPcLtVrA7RS6i76ZwRxD2jioMKiM0/3vWisx0i6JbvQ6hqhliyIPafI2ZKPxzdb7bcNgHR2ROQ9xRWjRBDI2icoUBAekPM+FDooXhu1cDtweyCBOwCO/zzDJDm3/43bc90+QkCQzLwgsgH8kSsHTVqtX+KaEcUf2tzKnV0D7OaO9Z2TDm6IjUcxAhp+uAXbZtccrJ1EkiDB/Kjk6KpYz9IjOazf4Bs3Kc7+d5U++klm0pqxlprzSyycogl5PFi4EVx1ze6yl13oQ4Kce2RUJjfNKpH4ZcuzuZOoZ2WM8uXW9ltSggxrEbtpO3Yi4Hw4k9yRHFcfyIaY2I7wrmVOaWPDh3mmpoeKm6hxau6UigzfD8VtWs3FZKsCVFlt7Mu2gT1xzW8MeHS/998l291jaUzQzT8vxELlsumarBLJ4t2r8wlpwNvkTfBiL6hUr7gLKMekgn+uWk8frrbqvkq5OGOYJ4kgT+Pb4vmsy7D+Q4KA8OX22D9Oug073j5lH5QLRMjvEslqnZrYjaJdkAq6GlGA9ZyJ4j6wukADu8ytQYmmELLEhZdxKfk4jpJ1bOLej9Dfe+hVSskTBrx+vfMrL8HJrNMGbMkLP6cLZ56k5c0xYzzctF65NbFL4BJuj/WkjrtNzXFhU5KRC7w/77CNVh0YMTQWKBAqueMKPIsF+H/OQvL/ORaoAJuDb9Lvkl6OPyjXIin18SY7Wm3Z8NZ3+jBPhpPViZa2L2gtgdCWcKohY+TOvyhV2MTzFTY3eyX7oi6T0hCIKmEIbDSZysgLGa2ie0AIFZZmRcBV+XC3vnaZiEUe8WaC2OOs9hjiAEVb+5Ro861RGhrhX6xKBhLubO4S0Xr5Tj1MR15+LJkxE97zl0At+b026TU250mnkHSCQs0K9hvEx30k2D3rRgg/xECdxT4OtEUhw7NZ7ZyOx6Dcr+WgHcftiXTlanQ8upASsqQ9I33dABf0J9FM+5gRzZwSWqHqcfl6aXC5ws7qLcw3/xKt59ynbbzqkhjkMqQtVINW2imqF/9wvTB4nXk0iCkaala7gT3CrX+2iY12aBolxYA0ZMVvDAXHYeYVCTodnn60fqS761Fa9hIgZHj8mYJfhkcNrs2H5BX+viPpz6fnqs0zO7Ag2Ux7XKaJfyZk0Wx2PFFUJCiQdFriXODhQ3Gir0+zGWNzdpD1+6O04=
  • Ironport-sdr: LA1cBoifRfjyAP062G0yeKfy6QT69T74lPBtKC+fc6yN3OWKC+URAvBoxD13OCgjLhJbYbMjQx Vn/OSg9vA8Uw==
  • 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>
---
 lib/ukmpi/mbox.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/lib/ukmpi/mbox.c b/lib/ukmpi/mbox.c
index 3a0354dd..31acdc6d 100644
--- a/lib/ukmpi/mbox.c
+++ b/lib/ukmpi/mbox.c
@@ -100,9 +100,17 @@ __nsec uk_mbox_post_to(struct uk_mbox *m, void *msg, 
__nsec timeout)
 
        UK_ASSERT(m);
 
-       ret = uk_semaphore_down_to(&m->writesem, timeout);
-       if (ret != __NSEC_MAX)
+       if (timeout) {
+               ret = uk_semaphore_down_to(&m->writesem, timeout);
+               if (ret != __NSEC_MAX)
+                       _do_mbox_post(m, msg);
+       } else {
+               /* no timeout, we wait forever */
+               uk_semaphore_down(&m->readsem);
                _do_mbox_post(m, msg);
+               ret = 0;
+       }
+
        return ret;
 }
 
@@ -172,9 +180,16 @@ __nsec uk_mbox_recv_to(struct uk_mbox *m, void **msg, 
__nsec timeout)
 
        UK_ASSERT(m);
 
-       ret = uk_semaphore_down_to(&m->readsem, timeout);
-       if (ret != __NSEC_MAX)
+       if (timeout) {
+               ret = uk_semaphore_down_to(&m->readsem, timeout);
+               if (ret != __NSEC_MAX)
+                       rmsg = _do_mbox_recv(m);
+       } else {
+               /* no timeout, we wait forever */
+               uk_semaphore_down(&m->readsem);
                rmsg = _do_mbox_recv(m);
+               ret = 0;
+       }
 
        if (msg)
                *msg = rmsg;
-- 
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®.