linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jon Mason <jon.mason@broadcom.com>
To: Russell King <linux@armlinux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [RFC 1/1] ARM: print MHz in /proc/cpuinfo
Date: Tue,  7 Jun 2016 17:08:33 -0400	[thread overview]
Message-ID: <1465333713-14339-2-git-send-email-jon.mason@broadcom.com> (raw)
In-Reply-To: <1465333713-14339-1-git-send-email-jon.mason@broadcom.com>

Query the CPU core clock in the device tree to determine the core clock
speed.  Output this clock rate in /proc/cpuinfo to match the output
from other architectures.  The output is intentionally patterned after
the x86 output, to match existing (and possibly expected) convention.

If any errors are encountered in querying the clock (or the speed is
erroneously zero), nothing will be printed out.  Thus any existing
devices that do not have CPU clocks defined in the device tree will
work as before.

Signed-off-by: Jon Mason <jon.mason@broadcom.com>
---
 arch/arm/kernel/setup.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index 7b53500..0c3e25a 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -33,6 +33,7 @@
 #include <linux/compiler.h>
 #include <linux/sort.h>
 #include <linux/psci.h>
+#include <linux/clk.h>
 
 #include <asm/unified.h>
 #include <asm/cp15.h>
@@ -1178,10 +1179,32 @@ static const char *hwcap2_str[] = {
 	NULL
 };
 
+static unsigned long cpu_freq(unsigned int core)
+{
+	struct device_node *np;
+	struct clk *c;
+	unsigned long rate = 0;
+
+	np = of_get_cpu_node(core, NULL);
+	if (!np)
+		goto err;
+
+	c = of_clk_get_by_name(np, NULL);
+	if (IS_ERR(c))
+		goto err;
+
+	rate = clk_get_rate(c);
+
+	clk_put(c);
+err:
+	return rate;
+}
+
 static int c_show(struct seq_file *m, void *v)
 {
 	int i, j;
 	u32 cpuid;
+	unsigned long rate;
 
 	for_each_online_cpu(i) {
 		/*
@@ -1194,6 +1217,12 @@ static int c_show(struct seq_file *m, void *v)
 		seq_printf(m, "model name\t: %s rev %d (%s)\n",
 			   cpu_name, cpuid & 15, elf_platform);
 
+		rate = cpu_freq(i);
+		if (rate)
+			/* Change from Hz into MHz */
+			seq_printf(m, "cpu MHz\t\t: %lu.%03lu\n",
+				   rate / 1000000, rate / 1000 % 1000);
+
 #if defined(CONFIG_SMP)
 		seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
 			   per_cpu(cpu_data, i).loops_per_jiffy / (500000UL/HZ),
-- 
1.9.1

  reply	other threads:[~2016-06-07 21:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-07 21:08 [RFC 0/1] " Jon Mason
2016-06-07 21:08 ` Jon Mason [this message]
2016-06-08  8:34   ` [RFC 1/1] " Sudeep Holla
2016-06-08 19:31     ` Jon Mason
2016-06-09  9:09       ` Sudeep Holla
2016-06-09 17:36         ` Jon Mason
2016-06-07 22:18 ` [RFC 0/1] " Russell King - ARM Linux
2016-06-07 22:58   ` Jon Mason
2016-07-02 23:58   ` Jon Masters
2016-07-03 16:54     ` Russell King - ARM Linux
2016-07-03 18:49       ` Andrew Lunn
2016-07-03 19:10         ` Russell King - ARM Linux
2016-07-18 10:02       ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1465333713-14339-2-git-send-email-jon.mason@broadcom.com \
    --to=jon.mason@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --subject='Re: [RFC 1/1] ARM: print MHz in /proc/cpuinfo' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).