summaryrefslogtreecommitdiffstats
path: root/sys/pc98
diff options
context:
space:
mode:
authornyan <nyan@FreeBSD.org>2005-02-04 13:34:24 +0000
committernyan <nyan@FreeBSD.org>2005-02-04 13:34:24 +0000
commit8ebefadd24ec57a1210d01d3883ea0e2de2303fe (patch)
tree8b361cf082e01cc25a41fbbf5a7d88005487220b /sys/pc98
parent6861248dfcd7d5c6641f437335516c106f83df33 (diff)
downloadFreeBSD-src-8ebefadd24ec57a1210d01d3883ea0e2de2303fe.zip
FreeBSD-src-8ebefadd24ec57a1210d01d3883ea0e2de2303fe.tar.gz
MFi386: revision 1.605.
Diffstat (limited to 'sys/pc98')
-rw-r--r--sys/pc98/i386/machdep.c60
-rw-r--r--sys/pc98/pc98/machdep.c60
2 files changed, 102 insertions, 18 deletions
diff --git a/sys/pc98/i386/machdep.c b/sys/pc98/i386/machdep.c
index 1e38c61..cb4f75a 100644
--- a/sys/pc98/i386/machdep.c
+++ b/sys/pc98/i386/machdep.c
@@ -53,8 +53,12 @@
#include <sys/param.h>
#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/signalvar.h>
+#include <sys/bio.h>
+#include <sys/buf.h>
+#include <sys/bus.h>
+#include <sys/callout.h>
+#include <sys/cpu.h>
+#include <sys/eventhandler.h>
#include <sys/imgact.h>
#include <sys/kdb.h>
#include <sys/kernel.h>
@@ -63,21 +67,18 @@
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/memrange.h>
+#include <sys/msgbuf.h>
#include <sys/mutex.h>
#include <sys/pcpu.h>
#include <sys/proc.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
#include <sys/reboot.h>
-#include <sys/callout.h>
-#include <sys/msgbuf.h>
#include <sys/sched.h>
-#include <sys/sysent.h>
+#include <sys/signalvar.h>
#include <sys/sysctl.h>
+#include <sys/sysent.h>
+#include <sys/sysproto.h>
#include <sys/ucontext.h>
#include <sys/vmmeter.h>
-#include <sys/bus.h>
-#include <sys/eventhandler.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
@@ -101,6 +102,7 @@
#include <net/netisr.h>
+#include <machine/clock.h>
#include <machine/cpu.h>
#include <machine/cputypes.h>
#include <machine/reg.h>
@@ -1039,6 +1041,46 @@ cpu_boot(int howto)
{
}
+/* Get current clock frequency for the given cpu id. */
+int
+cpu_est_clockrate(int cpu_id, uint64_t *rate)
+{
+ uint64_t tsc1, tsc2;
+
+ if (pcpu_find(cpu_id) == NULL || rate == NULL)
+ return (EINVAL);
+ if (!tsc_present)
+ return (EOPNOTSUPP);
+
+ /* If we're booting, trust the rate calibrated moments ago. */
+ if (cold) {
+ *rate = tsc_freq;
+ return (0);
+ }
+
+#ifdef SMP
+ /* Schedule ourselves on the indicated cpu. */
+ mtx_lock_spin(&sched_lock);
+ sched_bind(curthread, cpu_id);
+ mtx_unlock_spin(&sched_lock);
+#endif
+
+ /* Calibrate by measuring a short delay. */
+ tsc1 = rdtsc();
+ DELAY(1000);
+ tsc2 = rdtsc();
+
+#ifdef SMP
+ mtx_lock_spin(&sched_lock);
+ sched_unbind(curthread);
+ mtx_unlock_spin(&sched_lock);
+#endif
+
+ tsc_freq = (tsc2 - tsc1) * 1000;
+ *rate = tsc_freq;
+ return (0);
+}
+
/*
* Shutdown the CPU as much as possible
*/
diff --git a/sys/pc98/pc98/machdep.c b/sys/pc98/pc98/machdep.c
index 1e38c61..cb4f75a 100644
--- a/sys/pc98/pc98/machdep.c
+++ b/sys/pc98/pc98/machdep.c
@@ -53,8 +53,12 @@
#include <sys/param.h>
#include <sys/systm.h>
-#include <sys/sysproto.h>
-#include <sys/signalvar.h>
+#include <sys/bio.h>
+#include <sys/buf.h>
+#include <sys/bus.h>
+#include <sys/callout.h>
+#include <sys/cpu.h>
+#include <sys/eventhandler.h>
#include <sys/imgact.h>
#include <sys/kdb.h>
#include <sys/kernel.h>
@@ -63,21 +67,18 @@
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/memrange.h>
+#include <sys/msgbuf.h>
#include <sys/mutex.h>
#include <sys/pcpu.h>
#include <sys/proc.h>
-#include <sys/bio.h>
-#include <sys/buf.h>
#include <sys/reboot.h>
-#include <sys/callout.h>
-#include <sys/msgbuf.h>
#include <sys/sched.h>
-#include <sys/sysent.h>
+#include <sys/signalvar.h>
#include <sys/sysctl.h>
+#include <sys/sysent.h>
+#include <sys/sysproto.h>
#include <sys/ucontext.h>
#include <sys/vmmeter.h>
-#include <sys/bus.h>
-#include <sys/eventhandler.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
@@ -101,6 +102,7 @@
#include <net/netisr.h>
+#include <machine/clock.h>
#include <machine/cpu.h>
#include <machine/cputypes.h>
#include <machine/reg.h>
@@ -1039,6 +1041,46 @@ cpu_boot(int howto)
{
}
+/* Get current clock frequency for the given cpu id. */
+int
+cpu_est_clockrate(int cpu_id, uint64_t *rate)
+{
+ uint64_t tsc1, tsc2;
+
+ if (pcpu_find(cpu_id) == NULL || rate == NULL)
+ return (EINVAL);
+ if (!tsc_present)
+ return (EOPNOTSUPP);
+
+ /* If we're booting, trust the rate calibrated moments ago. */
+ if (cold) {
+ *rate = tsc_freq;
+ return (0);
+ }
+
+#ifdef SMP
+ /* Schedule ourselves on the indicated cpu. */
+ mtx_lock_spin(&sched_lock);
+ sched_bind(curthread, cpu_id);
+ mtx_unlock_spin(&sched_lock);
+#endif
+
+ /* Calibrate by measuring a short delay. */
+ tsc1 = rdtsc();
+ DELAY(1000);
+ tsc2 = rdtsc();
+
+#ifdef SMP
+ mtx_lock_spin(&sched_lock);
+ sched_unbind(curthread);
+ mtx_unlock_spin(&sched_lock);
+#endif
+
+ tsc_freq = (tsc2 - tsc1) * 1000;
+ *rate = tsc_freq;
+ return (0);
+}
+
/*
* Shutdown the CPU as much as possible
*/
OpenPOWER on IntegriCloud