summaryrefslogtreecommitdiffstats
path: root/sys/amd64/include/cpu.h
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2000-11-21 19:55:21 +0000
committermarkm <markm@FreeBSD.org>2000-11-21 19:55:21 +0000
commit92be31d0b583b42dee21f006ea62f231ad132326 (patch)
treed6b561d8a67702e3c67ef7b6a1873d03c8cc57cc /sys/amd64/include/cpu.h
parentdfa19cb0cec51bbb1fba802ceae5f4b58cad3892 (diff)
downloadFreeBSD-src-92be31d0b583b42dee21f006ea62f231ad132326.zip
FreeBSD-src-92be31d0b583b42dee21f006ea62f231ad132326.tar.gz
Add a consistent API to a feature that most modern CPUs have; a fast
counter register in-CPU. This is to be used as a fast "timer", where linearity is more important than time, and multiple lines in the linearity caused by multiple CPUs in an SMP machine is not a problem. This adds no code whatsoever to the FreeBSD kernel until it is actually used, and then as a single-instruction inline routine (except for the 80386 and 80486 where it is some more inline code around nanotime(9). Reviewed by: bde, kris, jhb
Diffstat (limited to 'sys/amd64/include/cpu.h')
-rw-r--r--sys/amd64/include/cpu.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/sys/amd64/include/cpu.h b/sys/amd64/include/cpu.h
index 7b090b6..669af64 100644
--- a/sys/amd64/include/cpu.h
+++ b/sys/amd64/include/cpu.h
@@ -47,6 +47,8 @@
#include <machine/frame.h>
#include <machine/segments.h>
#include <machine/globals.h>
+#include <machine/md_var.h>
+#include <machine/specialreg.h>
/*
* definitions of cpu-dependent requirements
@@ -133,6 +135,25 @@ extern char etext[];
void fork_trampoline __P((void));
void fork_return __P((struct proc *, struct trapframe));
+
+/*
+ * Return contents of in-cpu fast counter as a sort of "bogo-time"
+ * for non-critical timing.
+ */
+static __inline u_int64_t
+get_cyclecount(void)
+{
+#if defined(I386_CPU) || defined(I486_CPU)
+ struct timespec tv;
+
+ if ((cpu_feature & CPUID_TSC) == 0) {
+ nanotime(&tv);
+ return (tv.tv_sec * (u_int64_t)1000000000 + tv.tv_nsec);
+ }
+#endif
+ return (rdtsc());
+}
+
#endif
#endif /* !_MACHINE_CPU_H_ */
OpenPOWER on IntegriCloud