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

[Minios-devel] [UNIKRAFT PATCH 13/23] plat: Call scheduler on timer interrupts


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 8 Jul 2019 11:33:42 +0300
  • Cc: felipe.huici@xxxxxxxxx, simon.kuenzer@xxxxxxxxx
  • Delivery-date: Mon, 08 Jul 2019 08:50:22 +0000
  • Ironport-phdr: 9a23:c7DU4BDTJs5kZh15YcpYUyQJP3N1i/DPJgcQr6AfoPdwSPT8osbcNUDSrc9gkEXOFd2Cra4d0ayK6+u4BSQp2tWoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7Ovr6GpLIj8Swyuu+54Dfbx9HiTagf79+Nhq7oRneusUKjoZpN7o8xAbOrnZUYepd2HlmJUiUnxby58ew+IBs/iFNsP8/9MBOTLv3cb0gQbNXEDopPWY15Nb2tRbYVguA+mEcUmQNnRVWBQXO8Qz3UY3wsiv+sep9xTWaMMjrRr06RTiu86FmQwLuhSwaNTA27XvXh9RwgqxFvRyvqR9xzYnWb4GbL/dyYr/RcMkGSWdbQspdSypMCZ68YYsVCOoBOP5Vopf6p1sVsRu+BA+sD/7pxD9Vnn/2wLAx3uM9HgHBxwwgA9MOsHLOoNXxKacSSf21wbLUwjXYdf9WwSr955PSfhA7pvGBRLR9etfSx0k3Dw7Jk1qdpZH/Mz6W1ukBqXaX4/RiWO61hWMrsxx9rzeyyss2iYTEhpgZxk7K+Ch32oo5ONK1RFB9bNW5CpVfrTuaOJFzQs46RmFovzs1xaMetJ6geSgK1IwnxxnCa/yba4SI4gzsVOKWITpgmnJlfaiwhxe28US61uL8TdO40E5XriVeiNXMrHcN2wTS6siBVPR94l+s1SuA2gzO8O1JIkA5mbDFJ5I/wLM8jJQevVzGHiDsmUX2iKGWdl8j+uit8+nofrLmpoSAN491jAHyKKAumtGnAeQlKQUBQ3Ob9f6k1L3+5kL1Wq9KjvounqnDrJ/aPdgbprK+AwJN14Yj6hC/Dzah0NQDhHUIMUxKeAyZgIjtIFzOJPH4Deyjg1S3ijtqyO7JPrv7DpXKNHjDn6/rfaxh5E5E1Aoz0ddf6opaCr4fJPLzW1fxu8LCAh85Lgy0wvroCNRm24MYR22AHquZP7nJvlOS+O0vPvGGZJUJtzblN/gl+/nugGcimV8ceKmp2p0XZGq7HvR7PUqZZ3vtjckbEWoRuAoxUvDliFmYXjFIfXq9Qb88tXkHD9ejDIHCQZvojLGf0SOTGpxNensAGl2KV3DyeNaqQfAJPQmVOdNglHQgSKC8A9sq0gqytQm8z6d/M8Lf4WsAqJilzt8jtL6brg076TEhV5fV6GqKVWwhxm4=
  • Ironport-sdr: g0z8BK6AOL+IUVNgL2o2FNbZqOSqfwL53IgCO+ixks/ZT045yhzeqz81HuEuf4rLTvRXTKmrmq pwTmwVp3obsA==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

In order to notify the scheduler on time interrupts, the scheduler needs to
register its callback to the underlying platform. On each subsequent timer
interrupt, the registered callback will be called.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 include/uk/plat/time.h      |  6 +++
 plat/common/include/_time.h |  5 +++
 plat/common/time.c          | 77 +++++++++++++++++++++++++++++++++++++
 plat/kvm/Makefile.uk        |  1 +
 plat/kvm/x86/time.c         |  6 +++
 plat/xen/Makefile.uk        |  1 +
 plat/xen/x86/arch_time.c    |  3 ++
 7 files changed, 99 insertions(+)
 create mode 100644 plat/common/time.c

diff --git a/include/uk/plat/time.h b/include/uk/plat/time.h
index ad3fd954..9185ca34 100644
--- a/include/uk/plat/time.h
+++ b/include/uk/plat/time.h
@@ -52,6 +52,12 @@ __nsec ukplat_wall_clock(void);
 #define UKPLAT_TIME_TICK_NSEC  (UKARCH_NSEC_PER_SEC / CONFIG_HZ)
 #define UKPLAT_TIME_TICK_MSEC  ukarch_time_nsec_to_msec(UKPLAT_TIME_TICK_NSEC)
 
+/* Scheduler callback type */
+typedef void (*ukplat_scheduler_cb_t)(void *arg);
+
+int ukplat_time_schedule_register(ukplat_scheduler_cb_t cb, void *arg);
+int ukplat_time_schedule_unregister(ukplat_scheduler_cb_t cb);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/plat/common/include/_time.h b/plat/common/include/_time.h
index 06240ff0..a09f12f9 100644
--- a/plat/common/include/_time.h
+++ b/plat/common/include/_time.h
@@ -35,8 +35,13 @@
 #ifndef __PLAT_CMN_TIME_H__
 #define __PLAT_CMN_TIME_H__
 
+#include <uk/config.h>
 #include <uk/plat/time.h>
 
 void time_block_until(__snsec until);
 
+#if CONFIG_HAVE_SCHED_PREEMPT
+void time_do_schedule(void);
+#endif
+
 #endif /* __PLAT_CMN_TIME_H__ */
diff --git a/plat/common/time.c b/plat/common/time.c
new file mode 100644
index 00000000..a9bb2fde
--- /dev/null
+++ b/plat/common/time.c
@@ -0,0 +1,77 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Costin Lupu <costin.lupu@xxxxxxxxx>
+ *
+ * Copyright (c) 2019, University Politehnica of Bucharest. 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.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER 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.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+#include <uk/plat/time.h>
+#include <uk/assert.h>
+#include <_time.h>
+
+/* Scheduler callback */
+static ukplat_scheduler_cb_t sched_cb;
+/* Scheduler callback argument */
+static void *sched_cb_arg;
+
+
+int ukplat_time_schedule_register(ukplat_scheduler_cb_t cb, void *arg)
+{
+       UK_ASSERT(cb != NULL);
+
+       if (sched_cb)
+               return -EBUSY;
+
+       sched_cb = cb;
+       sched_cb_arg = arg;
+
+       return 0;
+}
+
+int ukplat_time_schedule_unregister(ukplat_scheduler_cb_t cb)
+{
+       UK_ASSERT(cb != NULL);
+
+       if (sched_cb != cb)
+               return -EINVAL;
+
+       sched_cb = NULL;
+       sched_cb_arg = NULL;
+
+       return 0;
+}
+
+void time_do_schedule(void)
+{
+       if (sched_cb)
+               sched_cb(sched_cb_arg);
+}
diff --git a/plat/kvm/Makefile.uk b/plat/kvm/Makefile.uk
index 50319a6e..d4f3a04b 100644
--- a/plat/kvm/Makefile.uk
+++ b/plat/kvm/Makefile.uk
@@ -37,6 +37,7 @@ LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += 
$(UK_PLAT_COMMON_BASE)/x86/thread_start
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += 
$(UK_PLAT_COMMON_BASE)/x86/hw_ctx.c|common
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/thread.c|common
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/sw_ctx.c|common
+LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/time.c|common
 endif
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBKVMPLAT_BASE)/x86/entry64.S
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBKVMPLAT_BASE)/x86/traps.c
diff --git a/plat/kvm/x86/time.c b/plat/kvm/x86/time.c
index 333ad9f3..438d0bd0 100644
--- a/plat/kvm/x86/time.c
+++ b/plat/kvm/x86/time.c
@@ -43,6 +43,9 @@
 #include <stdlib.h>
 #include <uk/plat/time.h>
 #include <uk/plat/irq.h>
+#if CONFIG_HAVE_SCHED_PREEMPT
+#include <_time.h>
+#endif
 #include <kvm/tscclock.h>
 #include <uk/assert.h>
 
@@ -64,6 +67,9 @@ __nsec ukplat_wall_clock(void)
  */
 static int timer_handler(void *arg __unused)
 {
+#if CONFIG_HAVE_SCHED_PREEMPT
+       time_do_schedule();
+#endif
        /* Yes, we handled the irq. */
        return 1;
 }
diff --git a/plat/xen/Makefile.uk b/plat/xen/Makefile.uk
index aaf645f5..4ccf47b1 100644
--- a/plat/xen/Makefile.uk
+++ b/plat/xen/Makefile.uk
@@ -42,6 +42,7 @@ LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += 
$(UK_PLAT_COMMON_BASE)/x86/hw_ctx.c|com
 endif
 LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/thread.c|common
 LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/sw_ctx.c|common
+LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/time.c|common
 endif
 LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBXENPLAT_BASE)/x86/setup.c
 LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBXENPLAT_BASE)/x86/traps.c
diff --git a/plat/xen/x86/arch_time.c b/plat/xen/x86/arch_time.c
index c6b8d02d..7979c1ee 100644
--- a/plat/xen/x86/arch_time.c
+++ b/plat/xen/x86/arch_time.c
@@ -226,6 +226,9 @@ static void timer_handler(evtchn_port_t ev __unused,
        __nsec until = ukplat_monotonic_clock() + UKPLAT_TIME_TICK_NSEC;
 
        HYPERVISOR_set_timer_op(until);
+#if CONFIG_HAVE_SCHED_PREEMPT
+       time_do_schedule();
+#endif
 }
 
 
-- 
2.20.1


_______________________________________________
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®.