Source-Changes-HG archive

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

[src/trunk]: src/sys Get a Hyper-V virtual processor id in cpu_hatch().



details:   https://anonhg.NetBSD.org/src/rev/7c563f68f2d7
branches:  trunk
changeset: 465914:7c563f68f2d7
user:      nonaka <nonaka%NetBSD.org@localhost>
date:      Sat Dec 07 11:45:45 2019 +0000

description:
Get a Hyper-V virtual processor id in cpu_hatch().

Currently, it is got in config_interrupts context.
However, since it is required when attaching a device,
it is got earlier than now.

diffstat:

 sys/arch/x86/x86/cpu.c         |  14 ++++++++++-
 sys/arch/x86/x86/hyperv.c      |  47 +++++++++++++++++++++++++++++++++--------
 sys/arch/x86/x86/hypervvar.h   |   3 +-
 sys/dev/hyperv/hyperv_common.c |   5 ++-
 sys/dev/hyperv/hypervvar.h     |   3 +-
 sys/dev/hyperv/vmbus.c         |   6 ++--
 sys/dev/hyperv/vmbusvar.h      |   3 +-
 7 files changed, 60 insertions(+), 21 deletions(-)

diffs (234 lines):

diff -r cf2b3a4b2abe -r 7c563f68f2d7 sys/arch/x86/x86/cpu.c
--- a/sys/arch/x86/x86/cpu.c    Sat Dec 07 10:19:35 2019 +0000
+++ b/sys/arch/x86/x86/cpu.c    Sat Dec 07 11:45:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.c,v 1.177 2019/11/27 06:24:33 maxv Exp $   */
+/*     $NetBSD: cpu.c,v 1.178 2019/12/07 11:45:45 nonaka Exp $ */
 
 /*
  * Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.177 2019/11/27 06:24:33 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.178 2019/12/07 11:45:45 nonaka Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"                /* for MPDEBUG */
@@ -118,6 +118,13 @@
 
 #include "tsc.h"
 
+#ifndef XEN
+#include "hyperv.h"
+#if NHYPERV > 0
+#include <x86/x86/hypervvar.h>
+#endif
+#endif
+
 static int     cpu_match(device_t, cfdata_t, void *);
 static void    cpu_attach(device_t, device_t, void *);
 static void    cpu_defer(device_t);
@@ -863,6 +870,9 @@
        cpu_init_msrs(ci, true);
        cpu_probe(ci);
        cpu_speculation_init(ci);
+#if NHYPERV > 0
+       hyperv_init_cpu(ci);
+#endif
 
        ci->ci_data.cpu_cc_freq = cpu_info_primary.ci_data.cpu_cc_freq;
        /* cpu_get_tsc_freq(ci); */
diff -r cf2b3a4b2abe -r 7c563f68f2d7 sys/arch/x86/x86/hyperv.c
--- a/sys/arch/x86/x86/hyperv.c Sat Dec 07 10:19:35 2019 +0000
+++ b/sys/arch/x86/x86/hyperv.c Sat Dec 07 11:45:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hyperv.c,v 1.5 2019/11/30 05:28:28 nonaka Exp $        */
+/*     $NetBSD: hyperv.c,v 1.6 2019/12/07 11:45:45 nonaka Exp $        */
 
 /*-
  * Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
@@ -33,7 +33,7 @@
  */
 #include <sys/cdefs.h>
 #ifdef __KERNEL_RCSID
-__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.5 2019/11/30 05:28:28 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.6 2019/12/07 11:45:45 nonaka Exp $");
 #endif
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/sys/dev/hyperv/vmbus/hyperv.c 331757 2018-03-30 02:25:12Z emaste $");
@@ -113,6 +113,8 @@
 
 static int hyperv_idtvec;
 
+uint32_t hyperv_vcpuid[MAXCPUS];
+
 static struct timecounter hyperv_timecounter = {
        .tc_get_timecount = hyperv_get_timecount,
        .tc_counter_mask = 0xffffffff,
@@ -495,12 +497,45 @@
 {
        u_int features, pm_features, features3;
        u_int maxleaf;
+       int i;
 
        if (!hyperv_probe(&maxleaf, &features, &pm_features, &features3))
                return;
 
        if (features & CPUID_HV_MSR_TIME_REFCNT)
                x86_delay = delay_func = delay_msr;
+
+       if (features & CPUID_HV_MSR_VP_INDEX) {
+               /* Save virtual processor id. */
+               hyperv_vcpuid[0] = rdmsr(MSR_HV_VP_INDEX);
+       } else {
+               /* Set virtual processor id to 0 for compatibility. */
+               hyperv_vcpuid[0] = 0;
+       }
+       for (i = 1; i < MAXCPUS; i++)
+               hyperv_vcpuid[i] = hyperv_vcpuid[0];
+}
+
+void
+hyperv_init_cpu(struct cpu_info *ci)
+{
+       u_int features, pm_features, features3;
+       u_int maxleaf;
+
+       if (!hyperv_probe(&maxleaf, &features, &pm_features, &features3))
+               return;
+
+       if (features & CPUID_HV_MSR_VP_INDEX)
+               hyperv_vcpuid[ci->ci_index] = rdmsr(MSR_HV_VP_INDEX);
+}
+
+uint32_t
+hyperv_get_vcpuid(cpuid_t cpu)
+{
+
+       if (cpu < MAXCPUS)
+               return hyperv_vcpuid[cpu];
+       return 0;
 }
 
 static bool
@@ -798,14 +833,6 @@
 
        pd = &sc->sc_percpu[cpu];
 
-       if (hyperv_features & CPUID_HV_MSR_VP_INDEX) {
-               /* Save virtual processor id. */
-               pd->vcpuid = rdmsr(MSR_HV_VP_INDEX);
-       } else {
-               /* Set virtual processor id to 0 for compatibility. */
-               pd->vcpuid = 0;
-       }
-
        /*
         * Setup the SynIC message.
         */
diff -r cf2b3a4b2abe -r 7c563f68f2d7 sys/arch/x86/x86/hypervvar.h
--- a/sys/arch/x86/x86/hypervvar.h      Sat Dec 07 10:19:35 2019 +0000
+++ b/sys/arch/x86/x86/hypervvar.h      Sat Dec 07 11:45:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hypervvar.h,v 1.1 2019/05/24 14:28:48 nonaka Exp $     */
+/*     $NetBSD: hypervvar.h,v 1.2 2019/12/07 11:45:45 nonaka Exp $     */
 
 /*-
  * Copyright (c) 2009-2012,2016 Microsoft Corp.
@@ -32,6 +32,7 @@
 #define _X86_HYPERVVAR_H_
 
 void           hyperv_early_init(void);
+void           hyperv_init_cpu(struct cpu_info *);
 device_t       device_hyperv_register(device_t, void *);
 
 #endif /* _X86_HYPERVVAR_H_ */
diff -r cf2b3a4b2abe -r 7c563f68f2d7 sys/dev/hyperv/hyperv_common.c
--- a/sys/dev/hyperv/hyperv_common.c    Sat Dec 07 10:19:35 2019 +0000
+++ b/sys/dev/hyperv/hyperv_common.c    Sat Dec 07 11:45:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hyperv_common.c,v 1.3 2019/12/06 12:46:06 nonaka Exp $ */
+/*     $NetBSD: hyperv_common.c,v 1.4 2019/12/07 11:45:45 nonaka Exp $ */
 
 /*-
  * Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hyperv_common.c,v 1.3 2019/12/06 12:46:06 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hyperv_common.c,v 1.4 2019/12/07 11:45:45 nonaka Exp $");
 
 #include "hyperv.h"
 
@@ -56,6 +56,7 @@
 __weak_alias(hyperv_set_message_proc, hyperv_voidop);
 __weak_alias(hyperv_send_eom, hyperv_voidop);
 __weak_alias(hyperv_intr, hyperv_voidop);
+__weak_alias(hyperv_get_vcpuid, hyperv_nullop);
 __weak_alias(vmbus_init_interrupts_md, hyperv_voidop);
 __weak_alias(vmbus_deinit_interrupts_md, hyperv_voidop);
 __weak_alias(vmbus_init_synic_md, hyperv_voidop);
diff -r cf2b3a4b2abe -r 7c563f68f2d7 sys/dev/hyperv/hypervvar.h
--- a/sys/dev/hyperv/hypervvar.h        Sat Dec 07 10:19:35 2019 +0000
+++ b/sys/dev/hyperv/hypervvar.h        Sat Dec 07 11:45:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hypervvar.h,v 1.2 2019/05/24 14:28:48 nonaka Exp $     */
+/*     $NetBSD: hypervvar.h,v 1.3 2019/12/07 11:45:45 nonaka Exp $     */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -65,6 +65,7 @@
 int    hyperv_is_gen1(void);
 void   hyperv_send_eom(void);
 void   hyperv_intr(void);
+uint32_t hyperv_get_vcpuid(cpuid_t);
 
 struct vmbus_softc;
 void   vmbus_init_interrupts_md(struct vmbus_softc *);
diff -r cf2b3a4b2abe -r 7c563f68f2d7 sys/dev/hyperv/vmbus.c
--- a/sys/dev/hyperv/vmbus.c    Sat Dec 07 10:19:35 2019 +0000
+++ b/sys/dev/hyperv/vmbus.c    Sat Dec 07 11:45:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vmbus.c,v 1.6 2019/12/06 12:46:06 nonaka Exp $ */
+/*     $NetBSD: vmbus.c,v 1.7 2019/12/07 11:45:45 nonaka Exp $ */
 /*     $OpenBSD: hyperv.c,v 1.43 2017/06/27 13:56:15 mikeb Exp $       */
 
 /*-
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.6 2019/12/06 12:46:06 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.7 2019/12/07 11:45:45 nonaka Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1093,7 +1093,7 @@
        }
 
        ch->ch_cpuid = cpu;
-       ch->ch_vcpu = sc->sc_percpu[cpu].vcpuid;
+       ch->ch_vcpu = hyperv_get_vcpuid(cpu);
 }
 
 void
diff -r cf2b3a4b2abe -r 7c563f68f2d7 sys/dev/hyperv/vmbusvar.h
--- a/sys/dev/hyperv/vmbusvar.h Sat Dec 07 10:19:35 2019 +0000
+++ b/sys/dev/hyperv/vmbusvar.h Sat Dec 07 11:45:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vmbusvar.h,v 1.2 2019/05/24 14:28:48 nonaka Exp $      */
+/*     $NetBSD: vmbusvar.h,v 1.3 2019/12/07 11:45:45 nonaka Exp $      */
 /*     $OpenBSD: hypervvar.h,v 1.13 2017/06/23 19:05:42 mikeb Exp $    */
 
 /*
@@ -146,7 +146,6 @@
 struct vmbus_percpu_data {
        void                    *simp;  /* Synthetic Interrupt Message Page */
        void                    *siep;  /* Synthetic Interrupt Event Flags Page */
-       uint32_t                vcpuid; /* Virtual cpuid */
 
        /* Rarely used fields */
        struct hyperv_dma       simp_dma;



Home | Main Index | Thread Index | Old Index