The following patch implements a trivial timecounter driver for Xen. With
this patch, the test code from the "Timekeeping and scheduling" thread now
works as expected and - MySQL now attempts to start up :-)

Comments? It seemed almost too easy, so there must be something I've left
out.

In the long run, as Antti suggested on IRC we probably want a generic
driver using a hypercall to "get fast time" from the platform.

-mato

diff --git a/platform/xen/Makefile b/platform/xen/Makefile
index e9c8f11..13e6c1b 100644
--- a/platform/xen/Makefile
+++ b/platform/xen/Makefile
@@ -34,7 +34,7 @@ RUMP_LIBS_NET = -lrumpnet_config -lrumpdev_bpf 
-lrumpnet_xenif -lrumpnet_netinet
 RUMP_LIBS_NET+= -lrumpnet_net -lrumpxen_xendev -lrumpnet
 
 # Define some default flags for linking.
-RUMP_LDLIBS = --whole-archive ${RUMP_LIBS_FS} ${RUMP_LIBS_NET} 
${RUMP_LIBS_PCI} ${RUMP_LIBS_SYSPROXY} -lrump --no-whole-archive
+RUMP_LDLIBS = --whole-archive ${RUMP_LIBS_FS} ${RUMP_LIBS_NET} 
${RUMP_LIBS_PCI} ${RUMP_LIBS_SYSPROXY} -lrumpxen_tc -lrump --no-whole-archive
 RUMP_LDLIBS := ${RUMP_LDLIBS} -lpthread -lc
 
 LDFLAGS := -L$(abspath rump/lib)
diff --git a/platform/xen/rumpxentc/Makefile b/platform/xen/rumpxentc/Makefile
new file mode 100644
index 0000000..bc5062e
--- /dev/null
+++ b/platform/xen/rumpxentc/Makefile
@@ -0,0 +1,15 @@
+LIB=   rumpxen_tc
+
+SRCS+= rumpxen_tc.c
+
+RUMPTOP= ${TOPRUMP}
+
+CPPFLAGS+=     -I${RUMPTOP}/librump/rumpkern -I${RUMPTOP}/librump
+CPPFLAGS+=     -I${.CURDIR} -I${.CURDIR}/../rump/include
+CPPFLAGS+=     -I${.CURDIR}/../xen/include -D__RUMP_KERNEL__ -I${.CURDIR}/..
+
+RUMP_SYM_NORENAME=xenbus_|HYPERVISOR_|minios_
+
+.include "${RUMPTOP}/Makefile.rump"
+.include <bsd.lib.mk>
+.include <bsd.klinks.mk>
diff --git a/platform/xen/rumpxentc/rumpxen_tc.c 
b/platform/xen/rumpxentc/rumpxen_tc.c
new file mode 100644
index 0000000..c36cae6
--- /dev/null
+++ b/platform/xen/rumpxentc/rumpxen_tc.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2015 Martin Lucina.  All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/cpu.h>
+#include <sys/kernel.h>
+#include <sys/timetc.h>
+
+#include <mini-os/time.h>
+
+#include "rump_private.h"
+
+static u_int
+rumpxen_tc_get(struct timecounter *tc)
+{
+       return (u_int)(minios_clock_monotonic() / 1000);
+}
+
+static struct timecounter rumpxen_tc = {
+       .tc_get_timecount       = rumpxen_tc_get,
+       .tc_poll_pps            = NULL,
+       .tc_counter_mask        = ~0,
+       .tc_frequency           = 1000000,
+       .tc_name                = "rumpxen",
+       .tc_quality             = 100,
+};
+
+RUMP_COMPONENT(RUMP_COMPONENT_KERN)
+{
+       tc_init(&rumpxen_tc);
+}
-- 
2.1.4


Reply via email to