diff options
author | njl <njl@FreeBSD.org> | 2005-02-04 05:32:56 +0000 |
---|---|---|
committer | njl <njl@FreeBSD.org> | 2005-02-04 05:32:56 +0000 |
commit | 54a88fdbee07d09c2baebe29116e17810f21fb52 (patch) | |
tree | baabe320c2a3cbdc6b455cf3dab23527c56878b7 /sys | |
parent | 9d006c413d7a4ffdf476cee1eb17d4ac55bf34e5 (diff) | |
download | FreeBSD-src-54a88fdbee07d09c2baebe29116e17810f21fb52.zip FreeBSD-src-54a88fdbee07d09c2baebe29116e17810f21fb52.tar.gz |
Add an implementation of cpu_est_clockrate(9). This function estimates the
current clock frequency for the given CPU id in units of Hz.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/alpha/alpha/machdep.c | 9 | ||||
-rw-r--r-- | sys/amd64/amd64/machdep.c | 54 | ||||
-rw-r--r-- | sys/arm/arm/machdep.c | 9 | ||||
-rw-r--r-- | sys/i386/i386/machdep.c | 60 | ||||
-rw-r--r-- | sys/ia64/ia64/machdep.c | 12 | ||||
-rw-r--r-- | sys/powerpc/aim/machdep.c | 9 | ||||
-rw-r--r-- | sys/powerpc/powerpc/machdep.c | 9 | ||||
-rw-r--r-- | sys/sparc64/sparc64/machdep.c | 9 |
8 files changed, 155 insertions, 16 deletions
diff --git a/sys/alpha/alpha/machdep.c b/sys/alpha/alpha/machdep.c index d93a86d..ebf971f 100644 --- a/sys/alpha/alpha/machdep.c +++ b/sys/alpha/alpha/machdep.c @@ -98,6 +98,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/systm.h> +#include <sys/cpu.h> #include <sys/eventhandler.h> #include <sys/imgact.h> #include <sys/kdb.h> @@ -1718,6 +1719,14 @@ cpu_boot(int howto) { } +/* Get current clock frequency for the given cpu id. */ +int +cpu_est_clockrate(int cpu_id, uint64_t *rate) +{ + + return (ENXIO); +} + /* * Shutdown the CPU as much as possible */ diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 16157c1..527c61b 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -56,8 +56,12 @@ __FBSDID("$FreeBSD$"); #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> @@ -69,19 +73,17 @@ __FBSDID("$FreeBSD$"); #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/signalvar.h> #include <sys/sysent.h> #include <sys/sysctl.h> +#include <sys/sysproto.h> #include <sys/ucontext.h> #include <sys/vmmeter.h> -#include <sys/bus.h> -#include <sys/eventhandler.h> +#include <machine/clock.h> #include <machine/pcb.h> #include <vm/vm.h> @@ -450,6 +452,44 @@ 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 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/arm/arm/machdep.c b/sys/arm/arm/machdep.c index 9a9f615..06d33c3 100644 --- a/sys/arm/arm/machdep.c +++ b/sys/arm/arm/machdep.c @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/systm.h> +#include <sys/cpu.h> #include <sys/sysproto.h> #include <sys/signalvar.h> #include <sys/imgact.h> @@ -236,6 +237,14 @@ cpu_startup(void *dummy) SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL) +/* Get current clock frequency for the given cpu id. */ +int +cpu_est_clockrate(int cpu_id, uint64_t *rate) +{ + + return (ENXIO); +} + void cpu_idle(void) { diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index 9c3b98a..ef82b80 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -56,8 +56,12 @@ __FBSDID("$FreeBSD$"); #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> @@ -66,21 +70,18 @@ __FBSDID("$FreeBSD$"); #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> @@ -104,6 +105,7 @@ __FBSDID("$FreeBSD$"); #include <net/netisr.h> +#include <machine/clock.h> #include <machine/cpu.h> #include <machine/cputypes.h> #include <machine/reg.h> @@ -1022,6 +1024,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/ia64/ia64/machdep.c b/sys/ia64/ia64/machdep.c index 608943d..289c3e1 100644 --- a/sys/ia64/ia64/machdep.c +++ b/sys/ia64/ia64/machdep.c @@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/systm.h> +#include <sys/cpu.h> #include <sys/eventhandler.h> #include <sys/kdb.h> #include <sys/sysproto.h> @@ -287,6 +288,17 @@ cpu_boot(int howto) efi_reset_system(); } +/* Get current clock frequency for the given cpu id. */ +int +cpu_est_clockrate(int cpu_id, uint64_t *rate) +{ + + if (pcpu_find(cpu_id) == NULL || rate == NULL) + return (EINVAL); + *rate = processor_frequency; + return (0); +} + void cpu_halt() { diff --git a/sys/powerpc/aim/machdep.c b/sys/powerpc/aim/machdep.c index 1748c02..c54f336 100644 --- a/sys/powerpc/aim/machdep.c +++ b/sys/powerpc/aim/machdep.c @@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/systm.h> +#include <sys/cpu.h> #include <sys/kdb.h> #include <sys/eventhandler.h> #include <sys/imgact.h> @@ -700,6 +701,14 @@ cpu_boot(int howto) { } +/* Get current clock frequency for the given cpu id. */ +int +cpu_est_clockrate(int cpu_id, uint64_t *rate) +{ + + return (ENXIO); +} + /* * Shutdown the CPU as much as possible. */ diff --git a/sys/powerpc/powerpc/machdep.c b/sys/powerpc/powerpc/machdep.c index 1748c02..c54f336 100644 --- a/sys/powerpc/powerpc/machdep.c +++ b/sys/powerpc/powerpc/machdep.c @@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/systm.h> +#include <sys/cpu.h> #include <sys/kdb.h> #include <sys/eventhandler.h> #include <sys/imgact.h> @@ -700,6 +701,14 @@ cpu_boot(int howto) { } +/* Get current clock frequency for the given cpu id. */ +int +cpu_est_clockrate(int cpu_id, uint64_t *rate) +{ + + return (ENXIO); +} + /* * Shutdown the CPU as much as possible. */ diff --git a/sys/sparc64/sparc64/machdep.c b/sys/sparc64/sparc64/machdep.c index b70ac9a..7fe6acd 100644 --- a/sys/sparc64/sparc64/machdep.c +++ b/sys/sparc64/sparc64/machdep.c @@ -44,6 +44,7 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/cons.h> +#include <sys/cpu.h> #include <sys/imgact.h> #include <sys/kdb.h> #include <sys/kernel.h> @@ -669,6 +670,14 @@ cpu_shutdown(void *args) openfirmware_exit(args); } +/* Get current clock frequency for the given cpu id. */ +int +cpu_est_clockrate(int cpu_id, uint64_t *rate) +{ + + return (ENXIO); +} + /* * Duplicate OF_exit() with a different firmware call function that restores * the trap table, otherwise a RED state exception is triggered in at least |