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

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


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 10 Sep 2018 12:05:59 +0300
  • Cc: simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Mon, 10 Sep 2018 09:06:22 +0000
  • Ironport-phdr: 9a23:eNL3fh8Czlp9Kv9uRHKM819IXTAuvvDOBiVQ1KB31eIcTK2v8tzYMVDF4r011RmVBdqds6oMotGVmpioYXYH75eFvSJKW713fDhBt/8rmRc9CtWOE0zxIa2iRSU7GMNfSA0tpCnjYgBaF8nkelLdvGC54yIMFRXjLwp1Ifn+FpLPg8it2O2+55/ebx9UiDahfLh/MAi4oQLNu8cMnIBsMLwxyhzHontJf+RZ22ZlLk+Nkhj/+8m94odt/zxftPw9+cFAV776f7kjQrxDEDsmKWE169b1uhTFUACC+2ETUmQSkhpPHgjF8BT3VYr/vyfmquZw3jSRMMvrRr42RDui9b9mRh/2hikaOTA382bZhc5+jK9AvB6tuwZyz5LObY2JKPZzeL7Wc9MARWpGW8ZcTzJMAoSnb4sTDuoBO/tToY/gp1sWsBu1GA6hC//oyj9Tmn/23Ks63/4lEQHbxAwgAskDv2jPrNnvLKcSTPu6wLPSzTXEdv5b3yr25ovQch05vP2BUq98fdDSxEQvDQ/JkEucpI7/Mz6bzugBrmeW4/d6We+si2MrsR99rzahy8s2l4XEiZwZx1bZ/itj2ok1P8e3SEtjbN6hF5tfqj+VOpNtQsMnX2FooCE6yqAauZKjfCgF1pAnxxnHZvyZdoiH+BPjVOKLLThkn3JpYqq/hwup/kS60O38UdG40FdMriVbjtnBrm0B2hPO5sSdSfZw/l2t1SiR2w3R8O1JL1g4la/BJJ4gxr4wmIATsUPGHiLuhEr2i7SWdlkl+uiu8ejnZqjmpoeBN4Jvlg7+Kb4imtSiAesjKAQORW+b9fym1LL/5U35XKlKjvoun6ncsZDaI8UbpqmiAwNMz4ks9Qi/ACmi0NkDmXkHLUlFeA6cj4TzNFDBPvb4Ae24g1S2nzdh3+rGMaH5ApXRMnjDl6/sfa18605Zzwozy8pT55FJCr4fJvLyW1H+tMbDAx8/LQO73+LnB89m2Y8ER22PH7eTMLnOvl+Q+uIvP+6MaZcVuTbgMfgl5uTijWE+mV8ZYaap3ZgXaHemHvl9JUWWf2bjgtMbHmgRpAYxUvHq2xW+VmtWZnCzWLl56jwlBYaOCYbYWpvrkLGHmiChEc54fGdDX3uLCmvpcc2gRu8RIHaZJdR9kzpCUaW5Vqcqzle2qQW80b0xfbmcwTERqZ+2jIs93ObUjxxnrTE=
  • 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 ++++++++++++++++++++++++++++++++++++++++
 plat/xen/xenbus/exportsyms.uk    |  2 ++
 4 files changed, 79 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;
+}
diff --git a/plat/xen/xenbus/exportsyms.uk b/plat/xen/xenbus/exportsyms.uk
index e58bcf8..2352a82 100644
--- a/plat/xen/xenbus/exportsyms.uk
+++ b/plat/xen/xenbus/exportsyms.uk
@@ -24,4 +24,6 @@ xs_get_self_id
 xenbus_state_to_str
 xenbus_devtype_to_str
 xenbus_str_to_devtype
+xenbus_watch_wait_event
+xenbus_watch_notify_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®.