Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Nov 2021 18:27:36 GMT
From:      Colin Percival <cperciva@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 57a8fa6f0189 - main - kvmclock: Expose implied TSC frequency via sysctl
Message-ID:  <202111161827.1AGIRat4078564@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by cperciva:

URL: https://cgit.FreeBSD.org/src/commit/?id=57a8fa6f0189316ab4d13ffbc6dc5410d56dcbac

commit 57a8fa6f0189316ab4d13ffbc6dc5410d56dcbac
Author:     Colin Percival <cperciva@FreeBSD.org>
AuthorDate: 2021-11-16 18:21:31 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2021-11-16 18:27:27 +0000

    kvmclock: Expose implied TSC frequency via sysctl
    
    An interface was added to derive an implied TSC frequency from pvclock
    in 2015, but this interface was never exposed anywhere user-visible.
    
    Reviewed by:    kib, bryanv
    Differential Revision:  https://reviews.freebsd.org/D32974
---
 sys/dev/kvm_clock/kvm_clock.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/sys/dev/kvm_clock/kvm_clock.c b/sys/dev/kvm_clock/kvm_clock.c
index 1a76432e417d..747b98c4f173 100644
--- a/sys/dev/kvm_clock/kvm_clock.c
+++ b/sys/dev/kvm_clock/kvm_clock.c
@@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/malloc.h>
 #include <sys/module.h>
 #include <sys/smp.h>
+#include <sys/sysctl.h>
 
 #include <vm/vm.h>
 #include <vm/pmap.h>
@@ -77,6 +78,7 @@ static devclass_t	kvm_clock_devclass;
 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_pcpu(void *arg);
+static void	kvm_clock_setup_sysctl(device_t);
 
 static struct pvclock_wall_clock *
 kvm_clock_get_wallclock(void *arg)
@@ -166,6 +168,7 @@ kvm_clock_attach(device_t dev)
 	sc->pvc.timeinfos = sc->timeinfos;
 	sc->pvc.stable_flag_supported = stable_flag_supported;
 	pvclock_init(&sc->pvc, dev, KVM_CLOCK_DEVNAME, KVM_CLOCK_TC_QUALITY, 0);
+	kvm_clock_setup_sysctl(dev);
 	return (0);
 }
 
@@ -217,6 +220,29 @@ kvm_clock_settime(device_t dev, struct timespec *ts)
 	return (0);
 }
 
+static int
+kvm_clock_tsc_freq_sysctl(SYSCTL_HANDLER_ARGS)
+{
+	struct kvm_clock_softc *sc = oidp->oid_arg1;
+        uint64_t freq = pvclock_tsc_freq(sc->timeinfos);
+
+        return (sysctl_handle_64(oidp, &freq, 0, req));
+}
+
+static void
+kvm_clock_setup_sysctl(device_t dev)
+{
+	struct kvm_clock_softc *sc = device_get_softc(dev);
+        struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev);
+        struct sysctl_oid *tree = device_get_sysctl_tree(dev);
+        struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
+
+        SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "tsc_freq",
+            CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0,
+            kvm_clock_tsc_freq_sysctl, "QU",
+            "Time Stamp Counter frequency");
+}
+
 static device_method_t kvm_clock_methods[] = {
 	DEVMETHOD(device_identify,	kvm_clock_identify),
 	DEVMETHOD(device_probe,		kvm_clock_probe),



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202111161827.1AGIRat4078564>