Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Dec 2009 06:52:12 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r200891 - head/sys/sparc64/sparc64
Message-ID:  <200912230652.nBN6qCRa088827@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Wed Dec 23 06:52:12 2009
New Revision: 200891
URL: http://svn.freebsd.org/changeset/base/200891

Log:
  Calculate the average CPU clock frequency and export that through
  the hw.freq.cpu sysctl variable. This can be used by ports that
  need to know "the" CPU frequency.

Modified:
  head/sys/sparc64/sparc64/identcpu.c

Modified: head/sys/sparc64/sparc64/identcpu.c
==============================================================================
--- head/sys/sparc64/sparc64/identcpu.c	Wed Dec 23 05:15:40 2009	(r200890)
+++ head/sys/sparc64/sparc64/identcpu.c	Wed Dec 23 06:52:12 2009	(r200891)
@@ -27,6 +27,13 @@ static char cpu_model[128];
 SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD,
     cpu_model, 0, "Machine model");
 
+SYSCTL_NODE(_hw, OID_AUTO, freq, CTLFLAG_RD, 0, "");
+
+static u_int cpu_count;
+static u_int cpu_freq;
+SYSCTL_UINT(_hw_freq, OID_AUTO, cpu, CTLFLAG_RD, &cpu_freq, 0,
+    "CPU clock frequency");
+
 int cpu_impl;
 
 void
@@ -104,4 +111,11 @@ cpu_identify(u_long vers, u_int freq, u_
 		printf("  mask=0x%lx maxtl=%ld maxwin=%ld\n", VER_MASK(vers),
 		    VER_MAXTL(vers), VER_MAXWIN(vers));
 	}
+
+	/*
+	 * Calculate the average CPU frequency.
+	 */
+	freq = (freq + 500000ul) / 1000000ul;
+	cpu_freq = (cpu_freq * cpu_count + freq) / (cpu_count + 1);
+	cpu_count++;
 }



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