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

[Minios-devel] [UNIKRAFT PATCH v4 4/7] plat/xen: Introduce Xenbus watch


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 17 Sep 2018 13:32:28 +0300
  • Cc: yuri.volchkov@xxxxxxxxx
  • Delivery-date: Mon, 17 Sep 2018 10:32:44 +0000
  • Ironport-phdr: 9a23:mFBYphEvtw/ivUZYE2LwQZ1GYnF86YWxBRYc798ds5kLTJ7zp8qwAkXT6L1XgUPTWs2DsrQY07WQ6/iocFdDyK7JiGoFfp1IWk1NouQttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXdrXKo8DEdBAj0OxZrKeTpAI7SiNm82/yv95HJbAhEmDiwbaluIBmqsA7cqtQYjYx+J6gr1xDHuGFIe+NYxWNpIVKcgRPx7dqu8ZBg7ipdpesv+9ZPXqvmcas4S6dYDCk9PGAu+MLrrxjDQhCR6XYaT24bjwBHAwnB7BH9Q5fxri73vfdz1SWGIcH7S60/VDK/5KlpVRDokj8KOT4n/m/KhMJ+j6VVrxCvpxFk34LYfJuYOOZkc6/BYd8XQ3dKUMZLVyxGB4Oxd5UCD+0aPeZEron9oUYFox2jBQm0GePk1zhFiWPx3a0hz+QhEAfG0BYkH9ITqHTUsc74O7sJUeyv1KnI0C7MY+lM2Tf68YXFdA0qr/KUXb9obMbcxlQjGxnGg1iQs4DpIS2Z2+YXv2WV9+ZsSO2ih3M9pwxyojWj3Nkgh4fHi44P11zJ+jt1zYAoLtOiUkF7e8SrEJ5IuiGfMIt5X90tTnlzuCY/1r0GoZm7fDUWyJg/xx7QdfiHc4+Q7xL9UeaeOzZ4hHZ/dL2jnBa+61CgyvDnWcWuylZKqTJJktjKtn8Tyxze8tWLR/Rg8ku72juC1xrf5v9aLU02j6bWJYYtwrsqmZoStUTDEDX2mELzjKKOakok/fOo6/jmYrXgvJOcM5J0ihnjMqk1hsO/Gv40MhATX2eA4+i8zrrj8VXjQLpWlv02jrXZsJfCKMQep665BQ5V0oE46xqmEjipzsoYkmcDLF9efBKHjpPpO03VIPziAvawnVKsnC1sx/DcMb3rGo/NIWTbkLf9YbZ97FZRyQouzdBF5pJYEK8BIPX3WkDttNzYDRg5MxKvzubhFtpyyoceVniUDaODLqzSrAzA2uV6JuiKZYgO/TrwNfUhz/rvlmMi308Qe++ux5RERmq/G6FNJF6FYHykpsoZDC9etQ0lUO3szlmfSSN7bG30R782oCs8XtH1RbzfT5yg1eTSlBywGYdbMzhL
  • 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>
Reviewed-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
 plat/xen/include/xenbus/client.h | 21 +++++++++++++++++++++
 plat/xen/include/xenbus/xenbus.h | 16 ++++++++++++++++
 plat/xen/xenbus/client.c         | 40 ++++++++++++++++++++++++++++++++++++++++
 plat/xen/xenbus/exportsyms.uk    |  2 +-
 4 files changed, 78 insertions(+), 1 deletion(-)

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;
+}
diff --git a/plat/xen/xenbus/exportsyms.uk b/plat/xen/xenbus/exportsyms.uk
index e58bcf8..6fb2e04 100644
--- a/plat/xen/xenbus/exportsyms.uk
+++ b/plat/xen/xenbus/exportsyms.uk
@@ -24,4 +24,4 @@ xs_get_self_id
 xenbus_state_to_str
 xenbus_devtype_to_str
 xenbus_str_to_devtype
-
+xenbus_watch_wait_event
-- 
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®.