Page MenuHomeFreeBSD

D37705.id114183.diff
No OneTemporary

D37705.id114183.diff

diff --git a/sys/dev/kvm_clock/kvm_clock.c b/sys/dev/kvm_clock/kvm_clock.c
--- a/sys/dev/kvm_clock/kvm_clock.c
+++ b/sys/dev/kvm_clock/kvm_clock.c
@@ -71,10 +71,12 @@
struct pvclock_vcpu_time_info *timeinfos;
u_int msr_tc;
u_int msr_wc;
+ int firstcpu;
};
static struct pvclock_wall_clock *kvm_clock_get_wallclock(void *arg);
-static void kvm_clock_system_time_enable(struct kvm_clock_softc *sc);
+static void kvm_clock_system_time_enable(struct kvm_clock_softc *sc,
+ const cpuset_t *cpus);
static void kvm_clock_system_time_enable_pcpu(void *arg);
static void kvm_clock_setup_sysctl(device_t);
@@ -88,9 +90,10 @@
}
static void
-kvm_clock_system_time_enable(struct kvm_clock_softc *sc)
+kvm_clock_system_time_enable(struct kvm_clock_softc *sc, const cpuset_t *cpus)
{
- smp_rendezvous(NULL, kvm_clock_system_time_enable_pcpu, NULL, sc);
+ smp_rendezvous_cpus(*cpus, NULL, kvm_clock_system_time_enable_pcpu,
+ NULL, sc);
}
static void
@@ -104,6 +107,38 @@
wrmsr(sc->msr_tc, vtophys(&(sc->timeinfos)[curcpu]) | 1);
}
+#ifndef EARLY_AP_STARTUP
+static void
+kvm_clock_init_smp(void *arg __unused)
+{
+ devclass_t kvm_clock_devclass;
+ cpuset_t cpus;
+ struct kvm_clock_softc *sc;
+ int max;
+
+ kvm_clock_devclass = devclass_find(KVM_CLOCK_DEVNAME);
+ max = devclass_get_maxunit(kvm_clock_devclass);
+ for (int i = 0; i < max; i++) {
+ sc = devclass_get_softc(kvm_clock_devclass, i);
+ if (sc == NULL)
+ continue;
+
+ /*
+ * Register with the hypervisor on all CPUs except the one that
+ * registered in kvm_clock_attach().
+ */
+ cpus = all_cpus;
+ KASSERT(CPU_ISSET(sc->firstcpu, &cpus),
+ ("%s: invalid first CPU %d", __func__, sc->firstcpu));
+ CPU_CLR(sc->firstcpu, &cpus);
+ if (CPU_EMPTY(&cpus))
+ continue;
+ kvm_clock_system_time_enable(sc, &cpus);
+ }
+}
+SYSINIT(kvm_clock, SI_SUB_SMP, SI_ORDER_ANY, kvm_clock_init_smp, NULL);
+#endif
+
static void
kvm_clock_identify(driver_t *driver, device_t parent)
{
@@ -132,6 +167,8 @@
struct kvm_clock_softc *sc = device_get_softc(dev);
bool stable_flag_supported;
+ sc->firstcpu = -1;
+
/* Process KVM "features" CPUID leaf content: */
kvm_cpuid_get_features(regs);
if ((regs[0] & KVM_FEATURE_CLOCKSOURCE2) != 0) {
@@ -150,7 +187,12 @@
/* Set up 'struct pvclock_vcpu_time_info' page(s): */
sc->timeinfos = kmem_malloc(mp_ncpus *
sizeof(struct pvclock_vcpu_time_info), M_WAITOK | M_ZERO);
- kvm_clock_system_time_enable(sc);
+#ifdef EARLY_AP_STARTUP
+ kvm_clock_system_time_enable(sc, &all_cpus);
+#else
+ sc->firstcpu = curcpu;
+ kvm_clock_system_time_enable_pcpu(sc);
+#endif
/*
* Init pvclock; register KVM clock wall clock, register KVM clock
@@ -192,7 +234,7 @@
* conservatively assume that the system time must be re-inited in
* suspend/resume scenarios.
*/
- kvm_clock_system_time_enable(device_get_softc(dev));
+ kvm_clock_system_time_enable(device_get_softc(dev), &all_cpus);
pvclock_resume();
inittodr(time_second);
return (0);

File Metadata

Mime Type
text/plain
Expires
Sat, Jan 17, 10:01 AM (12 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27688452
Default Alt Text
D37705.id114183.diff (2 KB)

Event Timeline