summaryrefslogtreecommitdiff
path: root/sysutils/mcelog/files/patch-tsc.c
diff options
context:
space:
mode:
authorRyan Steinmetz <zi@FreeBSD.org>2011-10-15 02:53:31 +0000
committerRyan Steinmetz <zi@FreeBSD.org>2011-10-15 02:53:31 +0000
commit6e9151ca055629e8cb7a9bb13be28967ebcf2c61 (patch)
tree63c7b2a3e84449a8af4085b00a4c91e88ef541ac /sysutils/mcelog/files/patch-tsc.c
parentNew port: security/sssd (diff)
New port: sysutils/mcelog
mcelog processes machine checks (in particular memory and CPU hardware errors) on modern x86-based unix systems and produces human-readable output. FreeBSD conversion patches were originally written by John Baldwin <jhb@freebsd.org> and later incorporated into this port. WWW: http://mcelog.org/ PR: ports/161395 Submitted by: Jeremy Chadwick <freebsd@jdc.parodius.com>
Notes
Notes: svn path=/head/; revision=283554
Diffstat (limited to 'sysutils/mcelog/files/patch-tsc.c')
-rw-r--r--sysutils/mcelog/files/patch-tsc.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/sysutils/mcelog/files/patch-tsc.c b/sysutils/mcelog/files/patch-tsc.c
new file mode 100644
index 000000000000..c035eb9850db
--- /dev/null
+++ b/sysutils/mcelog/files/patch-tsc.c
@@ -0,0 +1,95 @@
+--- ./tsc.c.orig 2009-12-15 07:18:40.000000000 -0500
++++ ./tsc.c 2011-10-14 22:36:47.000000000 -0400
+@@ -15,6 +15,12 @@
+ on your Linux system; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+ #define _GNU_SOURCE 1
++#ifdef __FreeBSD__
++#include <sys/types.h>
++#include <sys/sysctl.h>
++#include <machine/cpufunc.h>
++#include <machine/specialreg.h>
++#endif
+ #include <string.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+@@ -46,6 +52,7 @@
+ return 0;
+ }
+
++#ifdef __Linux__
+ static double cpufreq_mhz(int cpu, double infomhz)
+ {
+ double mhz;
+@@ -68,12 +75,29 @@
+ fclose(f);
+ return mhz;
+ }
++#endif
++
++#ifdef __FreeBSD__
++static double cpufreq_mhz(int cpu, double infomhz)
++{
++ double mhz;
++ uint64_t freq;
++ size_t len;
++
++ len = sizeof(freq);
++ if (sysctlbyname("machdep.tsc_freq", &freq, &len, NULL, 0) < 0)
++ return infomhz;
++ mhz = freq / 1000000.0;
++ return mhz;
++}
++#endif
+
+ int decode_tsc_forced(char **buf, double mhz, u64 tsc)
+ {
+ return fmt_tsc(buf, tsc, mhz);
+ }
+
++#ifdef __Linux__
+ static int deep_sleep_states(int cpu)
+ {
+ int ret;
+@@ -132,6 +156,41 @@
+ return 0;
+ return 1;
+ }
++#endif
++
++#ifdef __FreeBSD__
++/* Try to figure out if this CPU has a somewhat reliable TSC clock */
++static int tsc_reliable(int cputype, int cpunum)
++{
++ u_int regs[4];
++ u_int cpu_id, amd_pminfo;
++
++ if (cputype != CPU_K8 && !is_intel_cpu(cputype))
++ return 0;
++
++ do_cpuid(0, regs);
++ cpu_id = regs[1];
++ do_cpuid(0x80000000, regs);
++ if (regs[0] >= 0x80000007) {
++ do_cpuid(0x80000007, regs);
++ amd_pminfo = regs[3];
++ } else
++ amd_pminfo = 0;
++
++ if (amd_pminfo & AMDPM_TSC_INVARIANT)
++ return 1;
++ if (is_intel_cpu(cputype)) {
++ if (CPUID_TO_FAMILY(cpu_id) >= 0x10 ||
++ cpu_id == 0x60fb2)
++ return 1;
++ } else if ((CPUID_TO_FAMILY(cpu_id) == 0x6 &&
++ CPUID_TO_MODEL(cpu_id) >= 0xe) ||
++ (CPUID_TO_FAMILY(cpu_id) == 0xf && CPUID_TO_MODEL(cpu_id) >= 0x3))
++ return 1;
++
++ return 0;
++}
++#endif
+
+ int decode_tsc_current(char **buf, int cpunum, enum cputype cputype, double mhz,
+ unsigned long long tsc)