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

[Minios-devel] [UNIKRAFT PATCH v2 07/10] plat/xen: Introduce Xenbus watch


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Thu, 23 Aug 2018 13:59:35 +0300
  • Cc: simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx, sharan.santhanam@xxxxxxxxx
  • Delivery-date: Thu, 23 Aug 2018 10:59:50 +0000
  • Ironport-phdr: 9a23:r6qkyRbWOfJfFDcMKD44eJL/LSx+4OfEezUN459isYplN5qZrs+8bnLW6fgltlLVR4KTs6sC17KJ9fi4EUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCa/bL9oMBm6sRjau9ULj4dlNqs/0AbCrGFSe+RRy2NoJFaTkAj568yt4pNt8Dletuw4+cJYXqr0Y6o3TbpDDDQ7KG81/9HktQPCTQSU+HQRVHgdnwdSDAjE6BH6WYrxsjf/u+Fg1iSWIdH6QLYpUjmk8qxlSgLniD0fOjA57m/Zl8J+gqFcrh2jqRxy2JLYbJ2POfZiZK7RYc8WSGxcVchRTSxBBYa8YpMRAuoGJuZYs4j9p10TphW4GAmsHP7vwSJPi3Dq2q06yPghEQDA3AA6G9IOrWzUrMjuOagOSuC51rHIzSjYYP9Mwzf975HFfxY8qv+PRbJ9adfdxEYyGw/fjVidqZbpMy2L2ukPqWSW4fJsWf+ghmI6sQ18oTiiyt0yhoTHiI8Z0E3I+CpnzIszONa2UlR0YcS+H5tVryyaMox2Td48TGxwoyY6z6EGuYa8fCgX1JQr3x7fZOKDc4iP+h/jSuORLi15hHJhYr6wmw2y/VK4yu3hTca4ykxKri1dntnNsHACyQDT59CaRvZy40utwzWC2gDJ5u1aP0w5l7DXJpA5zr41jJUTsEDDHiHsmEXxia+bblkr+u+z6+T7Y7XmoIWQN4tpigHmL6QjgdCwAf8iPggWQmiU4v6w1Kfk/UHhWrVFkuU2krXFsJDdPckbo6+5AwlU0oYk8BazFiqp38oGnXYZKFJIYxaHj4nyO1HSO/D0F/i+jEqqkDtxwPDGJLLhCI3XLnffiLfhYap960lExQoozdBQ/YhUBasHIP7pQU/+rtrYDgM5MwOuxeboEtB925gYWW2RHqCZNLndvkSS6u0xPumGfJUVtyrlK/g5+/7uimc0mUQcfams2psXbmq0Hvd7I0qHZ3rtg8kOEX0Rswo4UuPllFmCXiRIaHqoQa08+ykxCJi6AofbWoCtnLuB0T+7H51LfGBGC0qAEWnvd4WAR/gMaCGSIsh/kjEfU7iuVZMu1RW0uwDh0bZoMPfUqWUkssfm1d504PaWmRws+DhcC8WGz3rLX2xy2GQSSGwYxqd69Gd60UuC1+BcnuRFXYhY4OhVUwF8MYPE0sRxEJbqRwiHZNDfGwXuecmvHTxkFoF5+NQJeUsoQ9g=
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Introduce the abstraction for Xenbus watches.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 plat/xen/include/xenbus/client.h | 21 +++++++++++++++++++++
 plat/xen/include/xenbus/xenbus.h | 16 ++++++++++++++++
 plat/xen/xenbus/client.c         | 40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+)

diff --git a/plat/xen/include/xenbus/client.h b/plat/xen/include/xenbus/client.h
index 964592d..f3540b7 100644
--- a/plat/xen/include/xenbus/client.h
+++ b/plat/xen/include/xenbus/client.h
@@ -65,4 +65,25 @@ const char *xenbus_devtype_to_str(enum xenbus_dev_type 
devtype);
  */
 enum xenbus_dev_type xenbus_str_to_devtype(const char *devtypestr);
 
+
+/*
+ * Watches
+ */
+
+/*
+ * Waits for a watch event. Called by a client driver.
+ *
+ * @param watch Xenbus watch
+ * @return 0 on success, a negative errno value on error.
+ */
+int xenbus_watch_wait_event(struct xenbus_watch *watch);
+
+/*
+ * Notifies a client driver waiting for watch events.
+ *
+ * @param watch Xenbus watch
+ * @return 0 on success, a negative errno value on error.
+ */
+int xenbus_watch_notify_event(struct xenbus_watch *watch);
+
 #endif /* __XENBUS_CLIENT_H__ */
diff --git a/plat/xen/include/xenbus/xenbus.h b/plat/xen/include/xenbus/xenbus.h
index 970b96a..230dcd4 100644
--- a/plat/xen/include/xenbus/xenbus.h
+++ b/plat/xen/include/xenbus/xenbus.h
@@ -88,6 +88,22 @@ void _xenbus_register_driver(struct xenbus_driver *drv);
 typedef unsigned long xenbus_transaction_t;
 #define XBT_NIL ((xenbus_transaction_t) 0)
 
+/*
+ * Xenbus watch
+ */
+
+struct xenbus_watch {
+       /**< in use internally */
+       UK_TAILQ_ENTRY(struct xenbus_watch) watch_list;
+       /**< Lock */
+       spinlock_t lock;
+       /**< Number of pending events */
+       int pending_events;
+       /**< Watch waiting queue */
+       struct uk_waitq wq;
+};
+UK_TAILQ_HEAD(xenbus_watch_list, struct xenbus_watch);
+
 
 /*
  * Xenbus device
diff --git a/plat/xen/xenbus/client.c b/plat/xen/xenbus/client.c
index 3ddae5e..3dbca0f 100644
--- a/plat/xen/xenbus/client.c
+++ b/plat/xen/xenbus/client.c
@@ -90,3 +90,43 @@ enum xenbus_dev_type xenbus_str_to_devtype(const char 
*devtypestr)
 
        return xenbus_dev_none;
 }
+
+/*
+ * Watches
+ */
+
+int xenbus_watch_wait_event(struct xenbus_watch *watch)
+{
+       if (watch == NULL)
+               return -EINVAL;
+
+       while (1) {
+               ukarch_spin_lock(&watch->lock);
+
+               if (watch->pending_events > 0)
+                       break;
+
+               ukarch_spin_unlock(&watch->lock);
+
+               uk_waitq_wait_event(&watch->wq,
+                       (watch->pending_events > 0));
+       }
+
+       watch->pending_events--;
+       ukarch_spin_unlock(&watch->lock);
+
+       return 0;
+}
+
+int xenbus_watch_notify_event(struct xenbus_watch *watch)
+{
+       if (watch == NULL)
+               return -EINVAL;
+
+       ukarch_spin_lock(&watch->lock);
+       watch->pending_events++;
+       uk_waitq_wake_up(&watch->wq);
+       ukarch_spin_unlock(&watch->lock);
+
+       return 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®.