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

Re: [Minios-devel] [UNIKRAFT PATCH 09/17] plat/common: Halting functions



On 27.03.2018 14:29, Costin Lupu wrote:
Revisiting ukplat_lcpu_halt* functions.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
  include/uk/plat/lcpu.h      | 15 +++++++++---
  plat/common/include/_time.h | 42 +++++++++++++++++++++++++++++++
  plat/common/include/cpu.h   | 46 ++++++++++++++++++++++++++++++++++
  plat/common/lcpu.c          | 60 +++++++++++++++++++++++++++++++++++++++++++++
  plat/kvm/Makefile.uk        |  1 +
  plat/kvm/x86/lcpu.c         |  6 -----
  plat/xen/Makefile.uk        |  1 +
  plat/xen/lcpu.c             | 17 -------------
  plat/xen/x86/arch_time.c    | 13 +++-------
  9 files changed, 165 insertions(+), 36 deletions(-)
  create mode 100644 plat/common/include/_time.h
  create mode 100644 plat/common/include/cpu.h
  create mode 100644 plat/common/lcpu.c

diff --git a/include/uk/plat/lcpu.h b/include/uk/plat/lcpu.h
index de37e8b..af1c7dc 100644
--- a/include/uk/plat/lcpu.h
+++ b/include/uk/plat/lcpu.h
@@ -36,6 +36,8 @@
  #ifndef __UKPLAT_LCPU_H__
  #define __UKPLAT_LCPU_H__
+#include <uk/arch/time.h>
+
  #ifdef __cplusplus
  extern "C" {
  #endif
@@ -80,17 +82,22 @@ void ukplat_lcpu_irqs_handle_pending(void);
/**
   * Halts the current logical CPU execution
- * Execution is returned when an interrupt/signal arrived
   */
  void ukplat_lcpu_halt(void);
/**
   * Halts the current logical CPU execution
   * Execution is returned when an interrupt/signal arrived or
- * the specified timeout expired
- * @param millis number of milliseconds to halt at longest
+ * the specified deadline expired
+ * @param until deadline in nanoseconds
+ */
+void ukplat_lcpu_halt_to(__snsec until);
+
+/**
+ * Halts the current logical CPU execution
+ * Execution is returned when an interrupt/signal arrived
   */
-void ukplat_lcpu_halt_to(unsigned long millis);
+void ukplat_lcpu_halt_to_interrupt(void);

Can we call this function differently?
"to" stands for "timeout" in this header. Since it is not waiting for an timeout but only an interrupt request, I would call it:

ukplat_lcpu_halt_irq

#ifdef __cplusplus
  }
diff --git a/plat/common/include/_time.h b/plat/common/include/_time.h
new file mode 100644
index 0000000..06240ff
--- /dev/null
+++ b/plat/common/include/_time.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Costin Lupu <costin.lupu@xxxxxxxxx>
+ *
+ * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. 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.
+ */
+
+#ifndef __PLAT_CMN_TIME_H__
+#define __PLAT_CMN_TIME_H__
+
+#include <uk/plat/time.h>
+
+void time_block_until(__snsec until);
+
+#endif /* __PLAT_CMN_TIME_H__ */
diff --git a/plat/common/include/cpu.h b/plat/common/include/cpu.h
new file mode 100644
index 0000000..153ebf9
--- /dev/null
+++ b/plat/common/include/cpu.h
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Costin Lupu <costin.lupu@xxxxxxxxx>
+ *
+ * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. 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.
+ */
+
+#ifndef __PLAT_CMN_CPU_H__
+#define __PLAT_CMN_CPU_H__
+
+#include <uk/arch/lcpu.h>
+#ifdef __X86_64__
+#include <x86/cpu.h>
+#else
+#error "Add cpu.h for current architecture."
+#endif
+
+
+#endif /* __PLAT_CMN_CPU_H__ */
diff --git a/plat/common/lcpu.c b/plat/common/lcpu.c
new file mode 100644
index 0000000..49b5f7a
--- /dev/null
+++ b/plat/common/lcpu.c
@@ -0,0 +1,60 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Costin Lupu <costin.lupu@xxxxxxxxx>
+ *
+ * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. 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 <uk/plat/lcpu.h>
+#include <cpu.h>
+#include <_time.h>
+
+
+void ukplat_lcpu_halt(void)
+{
+       ukplat_lcpu_disable_irq();
+       halt();
+}
+
+void ukplat_lcpu_halt_to_interrupt(void)
+{
+       ukplat_lcpu_enable_irq();
+       halt();
+       ukplat_lcpu_disable_irq();
+}
+
+void ukplat_lcpu_halt_to(__snsec until)
+{
+       unsigned long flags;
+
+       flags = ukplat_lcpu_save_irqf();
+       time_block_until(until);
+       ukplat_lcpu_restore_irqf(flags);
+}
diff --git a/plat/kvm/Makefile.uk b/plat/kvm/Makefile.uk
index e7a55fd..433d298 100644
--- a/plat/kvm/Makefile.uk
+++ b/plat/kvm/Makefile.uk
@@ -24,3 +24,4 @@ LIBKVMPLAT_SRCS-$(ARCH_X86_64) += 
$(LIBKVMPLAT_BASE)/x86/lcpu.c
  LIBKVMPLAT_SRCS-$(ARCH_X86_64) += $(LIBKVMPLAT_BASE)/x86/time.c
  LIBKVMPLAT_SRCS-y              += $(LIBKVMPLAT_BASE)/shutdown.c
  LIBKVMPLAT_SRCS-y              += $(LIBKVMPLAT_BASE)/memory.c
+LIBKVMPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/lcpu.c|common
diff --git a/plat/kvm/x86/lcpu.c b/plat/kvm/x86/lcpu.c
index 6e7ba04..985c670 100644
--- a/plat/kvm/x86/lcpu.c
+++ b/plat/kvm/x86/lcpu.c
@@ -34,9 +34,3 @@
#include <stdint.h>
  #include <uk/plat/lcpu.h>
-#include <uk/essentials.h>
-
-void ukplat_lcpu_halt_to(unsigned long millis __unused)
-{
-       //TODO
-}
diff --git a/plat/xen/Makefile.uk b/plat/xen/Makefile.uk
index 55ba50c..7cb55dc 100644
--- a/plat/xen/Makefile.uk
+++ b/plat/xen/Makefile.uk
@@ -27,6 +27,7 @@ LIBXENPLAT_CINCLUDES-y         += -I$(LIBXENPLAT_BASE)/include
  LIBXENPLAT_CINCLUDES-y         += -I$(UK_PLAT_COMMON_BASE)/include
  LIBXENPLAT_SRCS-y              += $(LIBXENPLAT_BASE)/hypervisor.c
  LIBXENPLAT_SRCS-y              += $(LIBXENPLAT_BASE)/memory.c
+LIBXENPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/lcpu.c|common
ifneq (,$(filter x86_32 x86_64,$(UK_ARCH)))
  LIBXENPLAT_SRCS-$(ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/x86/trace.c|common
diff --git a/plat/xen/lcpu.c b/plat/xen/lcpu.c
index eed89fb..f0650da 100644
--- a/plat/xen/lcpu.c
+++ b/plat/xen/lcpu.c
@@ -72,20 +72,3 @@ int ukplat_lcpu_irqs_disabled(void)
  {
        return irqs_disabled();
  }
-
-void ukplat_lcpu_halt_to(unsigned long millis)
-{
-       __snsec until;
-       unsigned long flags;
-
-       until = ukplat_monotonic_clock() + ukarch_time_msec_to_nsec(millis);
-
-       flags = ukplat_lcpu_save_irqf();
-       block_domain(until);
-       ukplat_lcpu_restore_irqf(flags);
-}
-
-void ukplat_lcpu_halt(void)
-{
-       //TODO
-}
diff --git a/plat/xen/x86/arch_time.c b/plat/xen/x86/arch_time.c
index 0621d90..08a8d09 100644
--- a/plat/xen/x86/arch_time.c
+++ b/plat/xen/x86/arch_time.c
@@ -35,8 +35,9 @@
#include <stdint.h>
  #include <sys/time.h>
-#include <x86/cpu.h>
  #include <uk/plat/time.h>
+#include <x86/cpu.h>
+#include <_time.h>
  #include <common/hypervisor.h>
  #include <common/events.h>
  #include <xen-x86/irq.h>
@@ -217,19 +218,13 @@ int gettimeofday(struct timeval *tv, void *tz)
  #endif
-void block_domain(__snsec until)
+void time_block_until(__snsec until)
  {
        UK_ASSERT(irqs_disabled());
if ((__snsec) ukplat_monotonic_clock() < until) {
                HYPERVISOR_set_timer_op(until);
-#ifdef CONFIG_PARAVIRT
-               HYPERVISOR_sched_op(SCHEDOP_block, 0);
-#else
-               local_irq_enable();
-               asm volatile("hlt" : : : "memory");
-#endif
-               local_irq_disable();
+               ukplat_lcpu_halt_to_interrupt();
                HYPERVISOR_set_timer_op(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®.