Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Dec 2009 04:29:38 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r201013 - in stable/8/sys/ia64: ia64 include
Message-ID:  <200912260429.nBQ4TcpX081996@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Sat Dec 26 04:29:38 2009
New Revision: 201013
URL: http://svn.freebsd.org/changeset/base/201013

Log:
  MFC rev 200889:
  Export the bus, cpu and itc frequencies under the hw.freq sysctl node.

Modified:
  stable/8/sys/ia64/ia64/clock.c
  stable/8/sys/ia64/ia64/machdep.c
  stable/8/sys/ia64/include/clock.h
  stable/8/sys/ia64/include/md_var.h
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)
  stable/8/sys/dev/xen/xenpci/   (props changed)

Modified: stable/8/sys/ia64/ia64/clock.c
==============================================================================
--- stable/8/sys/ia64/ia64/clock.c	Sat Dec 26 02:56:58 2009	(r201012)
+++ stable/8/sys/ia64/ia64/clock.c	Sat Dec 26 04:29:38 2009	(r201013)
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/clock.h>
 #include <machine/cpu.h>
 #include <machine/efi.h>
+#include <machine/md_var.h>
 
 uint64_t ia64_clock_reload;
 
@@ -78,15 +79,15 @@ pcpu_initclock(void)
 void
 cpu_initclocks()
 {
+	u_long itc_freq;
 
-	if (itc_frequency == 0)
-		panic("Unknown clock frequency");
+	itc_freq = (u_long)ia64_itc_freq() * 1000000ul;
 
 	stathz = hz;
-	ia64_clock_reload = (itc_frequency + hz/2) / hz;
+	ia64_clock_reload = (itc_freq + hz/2) / hz;
 
 #ifndef SMP
-	ia64_timecounter.tc_frequency = itc_frequency;
+	ia64_timecounter.tc_frequency = itc_freq;
 	tc_init(&ia64_timecounter);
 #endif
 

Modified: stable/8/sys/ia64/ia64/machdep.c
==============================================================================
--- stable/8/sys/ia64/ia64/machdep.c	Sat Dec 26 02:56:58 2009	(r201012)
+++ stable/8/sys/ia64/ia64/machdep.c	Sat Dec 26 04:29:38 2009	(r201013)
@@ -101,11 +101,21 @@ __FBSDID("$FreeBSD$");
 
 #include <i386/include/specialreg.h>
 
+SYSCTL_NODE(_hw, OID_AUTO, freq, CTLFLAG_RD, 0, "");
 SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RD, 0, "");
 
-u_int64_t processor_frequency;
-u_int64_t bus_frequency;
-u_int64_t itc_frequency;
+static u_int bus_freq;
+SYSCTL_UINT(_hw_freq, OID_AUTO, bus, CTLFLAG_RD, &bus_freq, 0,
+    "Bus clock frequency");
+
+static u_int cpu_freq;
+SYSCTL_UINT(_hw_freq, OID_AUTO, cpu, CTLFLAG_RD, &cpu_freq, 0,
+    "CPU clock frequency");
+
+static u_int itc_freq;
+SYSCTL_UINT(_hw_freq, OID_AUTO, itc, CTLFLAG_RD, &itc_freq, 0,
+    "ITC frequency");
+
 int cold = 1;
 
 u_int64_t pa_bootinfo;
@@ -203,9 +213,7 @@ identifycpu(void)
 			 * (i.e. the clock frequency) to identify those.
 			 * Allow for roughly 1% error margin.
 			 */
-			tmp = processor_frequency >> 7;
-			if ((processor_frequency - tmp) < 1*Ghz &&
-			    (processor_frequency + tmp) >= 1*Ghz)
+			if (cpu_freq > 990 && cpu_freq < 1010)
 				model_name = "Deerfield";
 			else
 				model_name = "Madison";
@@ -232,11 +240,8 @@ identifycpu(void)
 	features = ia64_get_cpuid(4);
 
 	printf("CPU: %s (", model_name);
-	if (processor_frequency) {
-		printf("%ld.%02ld-Mhz ",
-		    (processor_frequency + 4999) / Mhz,
-		    ((processor_frequency + 4999) / (Mhz/100)) % 100);
-	}
+	if (cpu_freq)
+		printf("%u Mhz ", cpu_freq);
 	printf("%s)\n", family_name);
 	printf("  Origin = \"%s\"  Revision = %d\n", vendor, revision);
 	printf("  Features = 0x%b\n", (u_int32_t) features,
@@ -396,7 +401,7 @@ cpu_est_clockrate(int cpu_id, uint64_t *
 
 	if (pcpu_find(cpu_id) == NULL || rate == NULL)
 		return (EINVAL);
-	*rate = processor_frequency;
+	*rate = (u_long)cpu_freq * 1000000ul;
 	return (0);
 }
 
@@ -600,6 +605,15 @@ map_gateway_page(void)
 	ia64_set_k5(VM_MAX_ADDRESS);
 }
 
+static u_int
+freq_ratio(u_long base, u_long ratio)
+{
+	u_long f;
+
+	f = (base * (ratio >> 32)) / (ratio & 0xfffffffful);
+	return ((f + 500000) / 1000000);
+}
+
 static void
 calculate_frequencies(void)
 {
@@ -622,15 +636,9 @@ calculate_frequencies(void)
 			       pal.pal_result[2] >> 32,
 			       pal.pal_result[2] & ((1L << 32) - 1));
 		}
-		processor_frequency =
-			sal.sal_result[0] * (pal.pal_result[0] >> 32)
-			/ (pal.pal_result[0] & ((1L << 32) - 1));
-		bus_frequency =
-			sal.sal_result[0] * (pal.pal_result[1] >> 32)
-			/ (pal.pal_result[1] & ((1L << 32) - 1));
-		itc_frequency =
-			sal.sal_result[0] * (pal.pal_result[2] >> 32)
-			/ (pal.pal_result[2] & ((1L << 32) - 1));
+		cpu_freq = freq_ratio(sal.sal_result[0], pal.pal_result[0]);
+		bus_freq = freq_ratio(sal.sal_result[0], pal.pal_result[1]);
+		itc_freq = freq_ratio(sal.sal_result[0], pal.pal_result[2]);
 	}
 }
 
@@ -971,6 +979,13 @@ bzero(void *buf, size_t len)
 	}
 }
 
+u_int
+ia64_itc_freq(void)
+{
+
+	return (itc_freq);
+}
+
 void
 DELAY(int n)
 {
@@ -979,7 +994,7 @@ DELAY(int n)
 	sched_pin();
 
 	start = ia64_get_itc();
-	end = start + (itc_frequency * n) / 1000000;
+	end = start + itc_freq * n;
 	/* printf("DELAY from 0x%lx to 0x%lx\n", start, end); */
 	do {
 		now = ia64_get_itc();

Modified: stable/8/sys/ia64/include/clock.h
==============================================================================
--- stable/8/sys/ia64/include/clock.h	Sat Dec 26 02:56:58 2009	(r201012)
+++ stable/8/sys/ia64/include/clock.h	Sat Dec 26 04:29:38 2009	(r201013)
@@ -14,7 +14,6 @@
 #define	CLOCK_VECTOR	254
 
 extern uint64_t	ia64_clock_reload;
-extern uint64_t	itc_frequency;
 
 #endif
 

Modified: stable/8/sys/ia64/include/md_var.h
==============================================================================
--- stable/8/sys/ia64/include/md_var.h	Sat Dec 26 02:56:58 2009	(r201012)
+++ stable/8/sys/ia64/include/md_var.h	Sat Dec 26 04:29:38 2009	(r201013)
@@ -90,6 +90,7 @@ int	ia64_highfp_enable(struct thread *, 
 int	ia64_highfp_save(struct thread *);
 int	ia64_highfp_save_ipi(void);
 struct ia64_init_return ia64_init(void);
+u_int	ia64_itc_freq(void);
 void	ia64_probe_sapics(void);
 void	ia64_sync_icache(vm_offset_t, vm_size_t);
 void	interrupt(struct trapframe *);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200912260429.nBQ4TcpX081996>