Source-Changes-HG archive

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

[src/bouyer-xenpvh]: src/sys/arch/xen Rename xen/xen/clock.c to xen_clock.c, ...



details:   https://anonhg.NetBSD.org/src/rev/56d00f6c38f6
branches:  bouyer-xenpvh
changeset: 982942:56d00f6c38f6
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Thu Apr 16 19:23:50 2020 +0000

description:
Rename xen/xen/clock.c to xen_clock.c, so that it can be compiled
with x86/isa/clock.c
call events_default_setup() from hypervisor_match to that event
arrays are properly initialised.
Use xen_delay() and xen's timecounter for PVHVM.

diffstat:

 sys/arch/xen/conf/files.xen    |     4 +-
 sys/arch/xen/conf/files.xen.pv |     3 +-
 sys/arch/xen/xen/clock.c       |  1011 ---------------------------------------
 sys/arch/xen/xen/hypervisor.c  |    13 +-
 sys/arch/xen/xen/xen_clock.c   |  1013 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1026 insertions(+), 1018 deletions(-)

diffs (truncated from 2115 to 300 lines):

diff -r af4240a36fd8 -r 56d00f6c38f6 sys/arch/xen/conf/files.xen
--- a/sys/arch/xen/conf/files.xen       Thu Apr 16 17:50:51 2020 +0000
+++ b/sys/arch/xen/conf/files.xen       Thu Apr 16 19:23:50 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.xen,v 1.180.2.3 2020/04/16 08:46:35 bouyer Exp $
+#      $NetBSD: files.xen,v 1.180.2.4 2020/04/16 19:23:50 bouyer Exp $
 
 defflag        opt_xen.h                       XEN XENPVH XENPVHVM
 
@@ -9,7 +9,7 @@
 file   arch/xen/xen/xengnt.c                   xen
 file   arch/xen/x86/xen_ipi.c                  multiprocessor & xen
 file   arch/xen/x86/xen_mainbus.c              xen
-
+file   arch/xen/xen/xen_clock.c                xen
 
 define hypervisorbus {}
 define xendevbus {}
diff -r af4240a36fd8 -r 56d00f6c38f6 sys/arch/xen/conf/files.xen.pv
--- a/sys/arch/xen/conf/files.xen.pv    Thu Apr 16 17:50:51 2020 +0000
+++ b/sys/arch/xen/conf/files.xen.pv    Thu Apr 16 19:23:50 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.xen.pv,v 1.1.2.1 2020/04/16 08:46:35 bouyer Exp $
+#      $NetBSD: files.xen.pv,v 1.1.2.2 2020/04/16 19:23:50 bouyer Exp $
 
 file   arch/xen/x86/autoconf.c         xenpv
 file   arch/xen/x86/x86_xpmap.c        xenpv
@@ -6,7 +6,6 @@
 file   arch/xen/x86/xenfunc.c          xenpv
 file   arch/xen/xen/xen_acpi_machdep.c acpi & xenpv
 
-file   arch/xen/xen/clock.c            xenpv
 file   arch/xen/x86/xen_bus_dma.c      machdep & xenpv
 file   arch/xen/x86/consinit.c         machdep & xenpv
 file   arch/xen/x86/pintr.c            machdep & dom0ops & xenpv
diff -r af4240a36fd8 -r 56d00f6c38f6 sys/arch/xen/xen/clock.c
--- a/sys/arch/xen/xen/clock.c  Thu Apr 16 17:50:51 2020 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,1011 +0,0 @@
-/*     $NetBSD: clock.c,v 1.80.6.2 2020/04/12 17:25:53 bouyer Exp $    */
-
-/*-
- * Copyright (c) 2017, 2018 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Taylor R. Campbell.
- *
- * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "opt_xen.h"
-
-#ifndef XEN_CLOCK_DEBUG
-#define        XEN_CLOCK_DEBUG 0
-#endif
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.80.6.2 2020/04/12 17:25:53 bouyer Exp $");
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/atomic.h>
-#include <sys/callout.h>
-#include <sys/cpu.h>
-#include <sys/device.h>
-#include <sys/evcnt.h>
-#include <sys/intr.h>
-#include <sys/kernel.h>
-#include <sys/lwp.h>
-#include <sys/proc.h>
-#include <sys/sysctl.h>
-#include <sys/systm.h>
-#include <sys/time.h>
-#include <sys/timetc.h>
-
-#include <dev/clock_subr.h>
-
-#include <machine/cpu.h>
-#include <machine/cpu_counter.h>
-#include <machine/lock.h>
-
-#include <xen/evtchn.h>
-#include <xen/hypervisor.h>
-#include <xen/include/public/vcpu.h>
-#include <xen/xen.h>
-
-#include <x86/rtc.h>
-
-#define NS_PER_TICK ((uint64_t)1000000000ULL/hz)
-
-static uint64_t        xen_vcputime_systime_ns(void);
-static uint64_t        xen_vcputime_raw_systime_ns(void);
-static void    xen_wallclock_time(struct timespec *);
-static uint64_t        xen_global_systime_ns(void);
-static unsigned        xen_get_timecount(struct timecounter *);
-static int     xen_rtc_get(struct todr_chip_handle *, struct timeval *);
-static int     xen_rtc_set(struct todr_chip_handle *, struct timeval *);
-static int     xen_timer_handler(void *, struct clockframe *);
-
-/*
- * xen timecounter:
- *
- *     Xen vCPU system time, plus an adjustment with rdtsc.
- */
-static struct timecounter xen_timecounter = {
-       .tc_get_timecount = xen_get_timecount,
-       .tc_poll_pps = NULL,
-       .tc_counter_mask = ~0U,
-       .tc_frequency = 1000000000ULL,  /* 1 GHz, i.e. units of nanoseconds */
-       .tc_name = "xen_system_time",
-       .tc_quality = 10000,
-};
-
-/*
- * xen_global_systime_ns_stamp
- *
- *     The latest Xen vCPU system time that has been observed on any
- *     CPU, for a global monotonic view of the Xen system time clock.
- */
-static volatile uint64_t xen_global_systime_ns_stamp __cacheline_aligned;
-
-/*
- * xen time of day register:
- *
- *     Xen wall clock time, plus a Xen vCPU system time adjustment.
- */
-static struct todr_chip_handle xen_todr_chip = {
-       .todr_gettime = xen_rtc_get,
-       .todr_settime = xen_rtc_set,
-};
-
-#ifdef DOM0OPS
-/*
- * xen timepush state:
- *
- *     Callout to periodically, after a sysctl-configurable number of
- *     NetBSD ticks, set the Xen hypervisor's wall clock time.
- */
-static struct {
-       struct callout  ch;
-       int             ticks;
-} xen_timepush;
-
-static void    xen_timepush_init(void);
-static void    xen_timepush_intr(void *);
-static int     sysctl_xen_timepush(SYSCTLFN_ARGS);
-#endif
-
-/*
- * startrtclock()
- *
- *     Initialize the real-time clock from x86 machdep autoconf.
- */
-void
-startrtclock(void)
-{
-
-       todr_attach(&xen_todr_chip);
-}
-
-/*
- * setstatclockrate(rate)
- *
- *     Set the statclock to run at rate, in units of ticks per second.
- *
- *     Currently Xen does not have a separate statclock, so this is a
- *     noop; instad the statclock runs in hardclock.
- */
-void
-setstatclockrate(int rate)
-{
-}
-
-/*
- * idle_block()
- *
- *     Called from the idle loop when we have nothing to do but wait
- *     for an interrupt.
- */
-void
-idle_block(void)
-{
-
-       HYPERVISOR_block();
-}
-
-/*
- * xen_rdtsc()
- *
- *     Read the local pCPU's tsc.
- */
-static inline uint64_t
-xen_rdtsc(void)
-{
-       uint32_t lo, hi;
-
-       asm volatile("rdtsc" : "=a"(lo), "=d"(hi));
-
-       return ((uint64_t)hi << 32) | lo;
-}
-
-/*
- * struct xen_vcputime_ticket
- *
- *     State for a vCPU read section, during which a caller may read
- *     from fields of a struct vcpu_time_info and call xen_rdtsc.
- *     Caller must enter with xen_vcputime_enter, exit with
- *     xen_vcputime_exit, and be prepared to retry if
- *     xen_vcputime_exit fails.
- */
-struct xen_vcputime_ticket {
-       uint64_t        version;
-};
-
-/*
- * xen_vcputime_enter(tp)
- *
- *     Enter a vCPU time read section and store a ticket in *tp, which
- *     the caller must use with xen_vcputime_exit.  Return a pointer
- *     to the current CPU's vcpu_time_info structure.  Caller must
- *     already be bound to the CPU.
- */
-static inline volatile struct vcpu_time_info *
-xen_vcputime_enter(struct xen_vcputime_ticket *tp)
-{
-       volatile struct vcpu_time_info *vt = &curcpu()->ci_vcpu->time;
-
-       while (__predict_false(1 & (tp->version = vt->version)))
-               SPINLOCK_BACKOFF_HOOK;
-
-       /*
-        * Must read the version before reading the tsc on the local
-        * pCPU.  We are racing only with interruption by the
-        * hypervisor, so no need for a stronger memory barrier.
-        */
-       __insn_barrier();
-
-       return vt;
-}
-
-/*
- * xen_vcputime_exit(vt, tp)
- *
- *     Exit a vCPU time read section with the ticket in *tp from
- *     xen_vcputime_enter.  Return true on success, false if caller
- *     must retry.
- */
-static inline bool
-xen_vcputime_exit(volatile struct vcpu_time_info *vt,
-    struct xen_vcputime_ticket *tp)
-{
-
-       KASSERT(vt == &curcpu()->ci_vcpu->time);
-
-       /*
-        * Must read the tsc before re-reading the version on the local
-        * pCPU.  We are racing only with interruption by the
-        * hypervisor, so no need for a stronger memory barrier.
-        */
-       __insn_barrier();
-
-       return tp->version == vt->version;
-}
-
-/*
- * xen_tsc_to_ns_delta(delta_tsc, mul_frac, shift)
- *
- *     Convert a difference in tsc units to a difference in
- *     nanoseconds given a multiplier and shift for the unit
- *     conversion.
- */
-static inline uint64_t
-xen_tsc_to_ns_delta(uint64_t delta_tsc, uint32_t tsc_to_system_mul,
-    int8_t tsc_shift)
-{
-       uint32_t delta_tsc_hi, delta_tsc_lo;
-
-       if (tsc_shift < 0)
-               delta_tsc >>= -tsc_shift;
-       else



Home | Main Index | Thread Index | Old Index