[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH] plat/*: Configure timer interrupt frequency
Add new configuration options for choosing a timer interrupt frequency. This patch adds only 100 Hz and 1000 Hz as currently supported values. The configured frequency is converted to the timer tick length which can be of use for other modules (e.g. preemptive schedulers). Since the frequency configuration is common to all platforms, we introduce the plat/common/time.c for keeping time related functionality which is common to all platforms. Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx> --- include/uk/plat/time.h | 4 ++++ plat/Config.uk | 17 +++++++++++++++ plat/common/time.c | 45 +++++++++++++++++++++++++++++++++++++++ plat/kvm/Makefile.uk | 1 + plat/kvm/time.c | 2 ++ plat/kvm/tscclock.c | 8 +++---- plat/linuxu/Makefile.uk | 1 + plat/linuxu/include/linuxu/time.h | 3 ++- plat/linuxu/time.c | 1 + plat/xen/Makefile.uk | 1 + plat/xen/x86/arch_time.c | 3 ++- 11 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 plat/common/time.c diff --git a/include/uk/plat/time.h b/include/uk/plat/time.h index 202e0f9..0fde1c6 100644 --- a/include/uk/plat/time.h +++ b/include/uk/plat/time.h @@ -44,9 +44,13 @@ extern "C" { void ukplat_time_init(void); void ukplat_time_fini(void); +void ukplat_time_frequency_init(void); __nsec ukplat_monotonic_clock(void); +/* Time tick length */ +extern __nsec ukplat_time_tick_nsec; + #ifdef __cplusplus } #endif diff --git a/plat/Config.uk b/plat/Config.uk index 7c07921..c675597 100644 --- a/plat/Config.uk +++ b/plat/Config.uk @@ -10,3 +10,20 @@ config UKPLAT_MEMRNAME Enable name field in memory region descriptors endmenu + +choice + prompt "Timer frequency" + default HZ_100 + help + Configure the timer interrupt frequency. + + config HZ_100 + bool "100 HZ" + config HZ_1000 + bool "1000 HZ" +endchoice + +config HZ + int + default 100 if HZ_100 + default 1000 if HZ_1000 diff --git a/plat/common/time.c b/plat/common/time.c new file mode 100644 index 0000000..0c492a0 --- /dev/null +++ b/plat/common/time.c @@ -0,0 +1,45 @@ +/* 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/config.h> +#include <uk/print.h> +#include <uk/plat/time.h> + +__nsec ukplat_time_tick_nsec; + +void ukplat_time_frequency_init(void) +{ + uk_printd(DLVL_INFO, "Timer interrupt frequency is %u Hz\n", CONFIG_HZ); + ukplat_time_tick_nsec = ukarch_time_msec_to_nsec(1000 / CONFIG_HZ); +} diff --git a/plat/kvm/Makefile.uk b/plat/kvm/Makefile.uk index 7e5a865..1988f6c 100644 --- a/plat/kvm/Makefile.uk +++ b/plat/kvm/Makefile.uk @@ -47,6 +47,7 @@ LIBKVMPLAT_SRCS-y += $(LIBKVMPLAT_BASE)/tscclock.c LIBKVMPLAT_SRCS-y += $(LIBKVMPLAT_BASE)/io.c LIBKVMPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/lcpu.c|common LIBKVMPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/memory.c|common +LIBKVMPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/time.c|common ## ## PCI library definitions diff --git a/plat/kvm/time.c b/plat/kvm/time.c index 1fb48bf..e02bb74 100644 --- a/plat/kvm/time.c +++ b/plat/kvm/time.c @@ -55,6 +55,8 @@ void ukplat_time_init(void) { int rc; + ukplat_time_frequency_init(); + rc = ukplat_irq_register(0, timer_handler, NULL); if (rc < 0) UK_CRASH("Failed to register timer interrupt handler\n"); diff --git a/plat/kvm/tscclock.c b/plat/kvm/tscclock.c index 8961659..32de9d6 100644 --- a/plat/kvm/tscclock.c +++ b/plat/kvm/tscclock.c @@ -131,7 +131,7 @@ static void i8254_delay(unsigned int n) { unsigned int cur_tick, initial_tick; int remaining; - const unsigned long timer_rval = TIMER_HZ / 100; + const unsigned long timer_rval = TIMER_HZ / CONFIG_HZ; initial_tick = i8254_gettick(); @@ -211,10 +211,10 @@ int tscclock_init(void) { __u64 tsc_freq, rtc_boot; - /* Initialise i8254 timer channel 0 to mode 2 at 100 Hz */ + /* Initialise i8254 timer channel 0 to mode 2 at CONFIG_HZ frequency */ outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT); - outb(TIMER_CNTR, (TIMER_HZ / 100) & 0xff); - outb(TIMER_CNTR, (TIMER_HZ / 100) >> 8); + outb(TIMER_CNTR, (TIMER_HZ / CONFIG_HZ) & 0xff); + outb(TIMER_CNTR, (TIMER_HZ / CONFIG_HZ) >> 8); /* * Read RTC "time at boot". This must be done just before tsc_base is diff --git a/plat/linuxu/Makefile.uk b/plat/linuxu/Makefile.uk index b00540c..d37a960 100644 --- a/plat/linuxu/Makefile.uk +++ b/plat/linuxu/Makefile.uk @@ -34,3 +34,4 @@ LIBLINUXUPLAT_SRCS-y += $(LIBLINUXUPLAT_BASE)/irq.c LIBLINUXUPLAT_SRCS-y += $(LIBLINUXUPLAT_BASE)/time.c LIBLINUXUPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/lcpu.c|common LIBLINUXUPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/memory.c|common +LIBLINUXUPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/time.c|common diff --git a/plat/linuxu/include/linuxu/time.h b/plat/linuxu/include/linuxu/time.h index 2df881e..c5e804e 100644 --- a/plat/linuxu/include/linuxu/time.h +++ b/plat/linuxu/include/linuxu/time.h @@ -35,9 +35,10 @@ #ifndef __LINUXU_TIME_H__ #define __LINUXU_TIME_H__ +#include <uk/config.h> #include <linuxu/signal.h> -#define TIMER_INTVAL_MSEC 10 +#define TIMER_INTVAL_MSEC (1000 / CONFIG_HZ) #define TIMER_SIGNUM SIGALRM diff --git a/plat/linuxu/time.c b/plat/linuxu/time.c index ead07f5..b5b1295 100644 --- a/plat/linuxu/time.c +++ b/plat/linuxu/time.c @@ -76,6 +76,7 @@ void ukplat_time_init(void) struct k_itimerspec its; int rc; + ukplat_time_frequency_init(); ukplat_irq_register(TIMER_SIGNUM, timer_handler, NULL); memset(&sigev, 0, sizeof(sigev)); diff --git a/plat/xen/Makefile.uk b/plat/xen/Makefile.uk index 45096cb..b685455 100644 --- a/plat/xen/Makefile.uk +++ b/plat/xen/Makefile.uk @@ -29,6 +29,7 @@ LIBXENPLAT_SRCS-y += $(LIBXENPLAT_BASE)/hypervisor.c LIBXENPLAT_SRCS-y += $(LIBXENPLAT_BASE)/memory.c LIBXENPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/lcpu.c|common LIBXENPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/memory.c|common +LIBXENPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/time.c|common ifneq (,$(filter x86_32 x86_64,$(CONFIG_UK_ARCH))) LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/x86/trace.c|common diff --git a/plat/xen/x86/arch_time.c b/plat/xen/x86/arch_time.c index f96426f..89b5045 100644 --- a/plat/xen/x86/arch_time.c +++ b/plat/xen/x86/arch_time.c @@ -233,7 +233,7 @@ void time_block_until(__snsec until) static void timer_handler(evtchn_port_t ev __unused, struct __regs *regs __unused, void *ign __unused) { - __nsec until = ukplat_monotonic_clock() + ukarch_time_msec_to_nsec(1); + __nsec until = ukplat_monotonic_clock() + ukplat_time_tick_nsec; HYPERVISOR_set_timer_op(until); } @@ -244,6 +244,7 @@ static evtchn_port_t port; void ukplat_time_init(void) { uk_printd(DLVL_EXTRA, "Initializing timer interface\n"); + ukplat_time_frequency_init(); port = bind_virq(VIRQ_TIMER, &timer_handler, NULL); unmask_evtchn(port); } -- 2.11.0 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |