Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/xen/xenbus Convert remaining splfoo/splx and tsleep...
details: https://anonhg.NetBSD.org/src/rev/3ed1803b9f44
branches: trunk
changeset: 932394:3ed1803b9f44
user: bouyer <bouyer%NetBSD.org@localhost>
date: Wed May 06 16:50:13 2020 +0000
description:
Convert remaining splfoo/splx and tsleep/wakeup to mutex and condvar.
Mark kernel threads and interrupt handlers MPSAFE.
diffstat:
sys/arch/xen/xenbus/xenbus_comms.c | 42 ++++++++++++++++++++-----------------
sys/arch/xen/xenbus/xenbus_comms.h | 6 ++++-
sys/arch/xen/xenbus/xenbus_probe.c | 31 ++++++++++++++++++++-------
sys/arch/xen/xenbus/xenbus_xs.c | 18 +++++----------
4 files changed, 57 insertions(+), 40 deletions(-)
diffs (truncated from 354 to 300 lines):
diff -r a85643634793 -r 3ed1803b9f44 sys/arch/xen/xenbus/xenbus_comms.c
--- a/sys/arch/xen/xenbus/xenbus_comms.c Wed May 06 16:17:36 2020 +0000
+++ b/sys/arch/xen/xenbus/xenbus_comms.c Wed May 06 16:50:13 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_comms.c,v 1.22 2020/04/25 15:26:18 bouyer Exp $ */
+/* $NetBSD: xenbus_comms.c,v 1.23 2020/05/06 16:50:13 bouyer Exp $ */
/******************************************************************************
* xenbus_comms.c
*
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.22 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.23 2020/05/06 16:50:13 bouyer Exp $");
#include <sys/types.h>
#include <sys/null.h>
@@ -37,6 +37,7 @@
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/systm.h>
+#include <sys/mutex.h>
#include <xen/xen.h> /* for xendomain_is_dom0() */
#include <xen/intr.h> /* for xendomain_is_dom0() */
@@ -54,6 +55,8 @@
static struct intrhand *ih;
struct xenstore_domain_interface *xenstore_interface;
+static kmutex_t xenstore_lock;
+static kcondvar_t xenstore_cv;
extern int xenstored_ready;
// static DECLARE_WORK(probe_work, xenbus_probe, NULL);
@@ -76,11 +79,12 @@
wake_waiting(void *arg)
{
if (__predict_false(xenstored_ready == 0 && xendomain_is_dom0())) {
- xenstored_ready = 1;
- wakeup(&xenstored_ready);
+ xb_xenstored_make_ready();
}
- wakeup(&xenstore_interface);
+ mutex_enter(&xenstore_lock);
+ cv_broadcast(&xenstore_cv);
+ mutex_exit(&xenstore_lock);
return 1;
}
@@ -118,16 +122,15 @@
struct xenstore_domain_interface *intf = xenstore_domain_interface();
XENSTORE_RING_IDX cons, prod;
- int s = spltty();
-
+ mutex_enter(&xenstore_lock);
while (len != 0) {
void *dst;
unsigned int avail;
while ((intf->req_prod - intf->req_cons) == XENSTORE_RING_SIZE) {
- XENPRINTF(("xb_write tsleep\n"));
- tsleep(&xenstore_interface, PRIBIO, "wrst", 0);
- XENPRINTF(("xb_write tsleep done\n"));
+ XENPRINTF(("xb_write cv_wait\n"));
+ cv_wait(&xenstore_cv, &xenstore_lock);
+ XENPRINTF(("xb_write cv_wait done\n"));
}
/* Read indexes, then verify. */
@@ -135,7 +138,7 @@
prod = intf->req_prod;
xen_rmb();
if (!check_indexes(cons, prod)) {
- splx(s);
+ mutex_exit(&xenstore_lock);
return EIO;
}
@@ -156,8 +159,7 @@
hypervisor_notify_via_evtchn(xen_start_info.store_evtchn);
}
-
- splx(s);
+ mutex_exit(&xenstore_lock);
return 0;
}
@@ -167,14 +169,14 @@
struct xenstore_domain_interface *intf = xenstore_domain_interface();
XENSTORE_RING_IDX cons, prod;
- int s = spltty();
+ mutex_enter(&xenstore_lock);
while (len != 0) {
unsigned int avail;
const char *src;
while (intf->rsp_cons == intf->rsp_prod)
- tsleep(&xenstore_interface, PRIBIO, "rdst", 0);
+ cv_wait(&xenstore_cv, &xenstore_lock);
/* Read indexes, then verify. */
cons = intf->rsp_cons;
@@ -182,7 +184,7 @@
xen_rmb();
if (!check_indexes(cons, prod)) {
XENPRINTF(("xb_read EIO\n"));
- splx(s);
+ mutex_exit(&xenstore_lock);
return EIO;
}
@@ -209,8 +211,7 @@
hypervisor_notify_via_evtchn(xen_start_info.store_evtchn);
}
-
- splx(s);
+ mutex_exit(&xenstore_lock);
return 0;
}
@@ -220,10 +221,13 @@
{
int evtchn;
+ mutex_init(&xenstore_lock, MUTEX_DEFAULT, IPL_TTY);
+ cv_init(&xenstore_cv, "xsio");
+
evtchn = xen_start_info.store_evtchn;
ih = xen_intr_establish_xname(-1, &xen_pic, evtchn, IST_LEVEL, IPL_TTY,
- wake_waiting, NULL, false, device_xname(dev));
+ wake_waiting, NULL, true, device_xname(dev));
hypervisor_unmask_event(evtchn);
aprint_verbose_dev(dev, "using event channel %d\n", evtchn);
diff -r a85643634793 -r 3ed1803b9f44 sys/arch/xen/xenbus/xenbus_comms.h
--- a/sys/arch/xen/xenbus/xenbus_comms.h Wed May 06 16:17:36 2020 +0000
+++ b/sys/arch/xen/xenbus/xenbus_comms.h Wed May 06 16:50:13 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_comms.h,v 1.6 2011/09/20 00:12:25 jym Exp $ */
+/* $NetBSD: xenbus_comms.h,v 1.7 2020/05/06 16:50:13 bouyer Exp $ */
/*
* Private include for xenbus communications.
*
@@ -35,6 +35,8 @@
void xb_suspend_comms(device_t dev);
void xb_resume_comms(device_t dev);
+void xb_xenstored_make_ready(void);
+
/* Low level routines. */
int xb_write(const void *data, unsigned len);
int xb_read(void *data, unsigned len);
@@ -42,6 +44,8 @@
extern struct xenstore_domain_interface *xenstore_interface;
+extern int xenstored_ready;
+
#endif /* _XENBUS_COMMS_H */
/*
diff -r a85643634793 -r 3ed1803b9f44 sys/arch/xen/xenbus/xenbus_probe.c
--- a/sys/arch/xen/xenbus/xenbus_probe.c Wed May 06 16:17:36 2020 +0000
+++ b/sys/arch/xen/xenbus/xenbus_probe.c Wed May 06 16:50:13 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_probe.c,v 1.51 2020/04/28 13:21:01 bouyer Exp $ */
+/* $NetBSD: xenbus_probe.c,v 1.52 2020/05/06 16:50:13 bouyer Exp $ */
/******************************************************************************
* Talks to Xen Store to figure out what devices we have.
*
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.51 2020/04/28 13:21:01 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.52 2020/05/06 16:50:13 bouyer Exp $");
#if 0
#define DPRINTK(fmt, args...) \
@@ -45,6 +45,7 @@
#include <sys/systm.h>
#include <sys/param.h>
#include <sys/kthread.h>
+#include <sys/mutex.h>
#include <uvm/uvm.h>
#include <xen/xen.h> /* for xendomain_is_dom0() */
@@ -108,8 +109,8 @@
xenbus_dmat = xa->xa_dmat;
config_pending_incr(self);
- err = kthread_create(PRI_NONE, 0, NULL, xenbus_probe_init, NULL,
- NULL, "xenbus_probe");
+ err = kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL,
+ xenbus_probe_init, NULL, NULL, "xenbus_probe");
if (err)
aprint_error_dev(xenbus_dev,
"kthread_create(xenbus_probe): %d\n", err);
@@ -618,6 +619,8 @@
/* A flag to determine if xenstored is 'ready' (i.e. has started) */
int xenstored_ready = 0;
+static kmutex_t xenstored_lock;
+static kcondvar_t xenstored_cv;
void
xenbus_probe(void *unused)
@@ -655,6 +658,15 @@
//notifier_call_chain(&xenstore_chain, 0, NULL);
}
+void
+xb_xenstored_make_ready(void)
+{
+ mutex_enter(&xenstored_lock);
+ xenstored_ready = 1;
+ cv_broadcast(&xenstored_cv);
+ mutex_exit(&xenstored_lock);
+}
+
static void
xenbus_probe_init(void *unused)
{
@@ -665,6 +677,8 @@
DPRINTK("");
SLIST_INIT(&xenbus_device_list);
+ mutex_init(&xenstored_lock, MUTEX_DEFAULT, IPL_TTY);
+ cv_init(&xenstored_cv, "xsready");
/*
** Domain0 doesn't have a store_evtchn or store_mfn yet.
@@ -728,13 +742,14 @@
config_pending_decr(xenbus_dev);
#ifdef DOM0OPS
if (dom0) {
- int s;
- s = spltty();
+ mutex_enter(&xenstored_lock);
while (xenstored_ready == 0) {
- tsleep(&xenstored_ready, PRIBIO, "xsready", 0);
+ cv_wait(&xenstored_cv, &xenstored_lock);
+ mutex_exit(&xenstored_lock);
xenbus_probe(NULL);
+ mutex_enter(&xenstored_lock);
}
- splx(s);
+ mutex_exit(&xenstored_lock);
}
#endif
kthread_exit(0);
diff -r a85643634793 -r 3ed1803b9f44 sys/arch/xen/xenbus/xenbus_xs.c
--- a/sys/arch/xen/xenbus/xenbus_xs.c Wed May 06 16:17:36 2020 +0000
+++ b/sys/arch/xen/xenbus/xenbus_xs.c Wed May 06 16:50:13 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_xs.c,v 1.26 2020/04/07 16:10:48 jdolecek Exp $ */
+/* $NetBSD: xenbus_xs.c,v 1.27 2020/05/06 16:50:13 bouyer Exp $ */
/******************************************************************************
* xenbus_xs.c
*
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xenbus_xs.c,v 1.26 2020/04/07 16:10:48 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_xs.c,v 1.27 2020/05/06 16:50:13 bouyer Exp $");
#if 0
#define DPRINTK(fmt, args...) \
@@ -158,9 +158,8 @@
int
xenbus_dev_request_and_reply(struct xsd_sockmsg *msg, void**reply)
{
- int err = 0, s;
+ int err = 0;
- s = spltty();
mutex_enter(&xs_state.xs_lock);
err = xb_write(msg, sizeof(*msg) + msg->len);
if (err) {
@@ -170,7 +169,6 @@
*reply = read_reply(&msg->type, &msg->len);
}
mutex_exit(&xs_state.xs_lock);
- splx(s);
return err;
}
@@ -192,7 +190,7 @@
{
struct xsd_sockmsg msg;
unsigned int i;
Home |
Main Index |
Thread Index |
Old Index