aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorYoshihiro Takahashi <nyan@FreeBSD.org>2005-02-04 13:34:24 +0000
committerYoshihiro Takahashi <nyan@FreeBSD.org>2005-02-04 13:34:24 +0000
commit0faf0782315c2e52e490d65af6f24e6b53c8c699 (patch)
tree8b361cf082e01cc25a41fbbf5a7d88005487220b /sys
parentb8900c134b0fc14ca37ce2494bc3a1b8950731f7 (diff)
downloadsrc-0faf0782315c2e52e490d65af6f24e6b53c8c699.tar.gz
src-0faf0782315c2e52e490d65af6f24e6b53c8c699.zip
MFi386: revision 1.605.
Notes
Notes: svn path=/head/; revision=141276
Diffstat (limited to 'sys')
-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 1e38c6187991..cb4f75a6f3b6 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 1e38c6187991..cb4f75a6f3b6 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
*/