[v1,1/1] linux-gen: User /proc/cpuinfo, if sysfs is not available. Fixes https://bugs.linaro.org/show_bug.cgi?id=3249

Message ID 1507017606-31412-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series
  • linux-gen: User /proc/cpuinfo, if sysfs is not available.
Related show

Commit Message

Github ODP bot Oct. 3, 2017, 8 a.m.
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>


Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

---
/** Email created from pull request 204 (apalos:bug_3249)
 ** https://github.com/Linaro/odp/pull/204
 ** Patch: https://github.com/Linaro/odp/pull/204.patch
 ** Base sha: b4d17b1f6807cd980a1b2dd30573f17677ea371b
 ** Merge commit sha: b28ddffce2311826aca898bcc6a6ce16be083619
 **/
 platform/linux-generic/odp_system_info.c | 45 +++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)

Comments

Savolainen, Petri (Nokia - FI/Espoo) Oct. 3, 2017, 9:37 a.m. | #1
> -----Original Message-----

> From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of

> Github ODP bot

> Sent: Tuesday, October 03, 2017 11:00 AM

> To: lng-odp@lists.linaro.org

> Subject: [lng-odp] [PATCH v1 1/1] linux-gen: User /proc/cpuinfo, if sysfs

> is not available. Fixes https://bugs.linaro.org/show_bug.cgi?id=3249

> 

> From: Ilias Apalodimas <ilias.apalodimas@linaro.org>



Git log entry is missing. Re-format commit subject line and body of the text.

For example:
"
linux-gen: system_info: use proc/cpuinfo as backup

When sysfs is not available, use /proc/cpuinfo file as
a backup for current cpu MHz.

This fixes	bug: https://bugs.linaro.org/show_bug.cgi?id=3249

Signed-off-by...
"

-Petri
Maxim Uvarov Oct. 3, 2017, 9:56 a.m. | #2
if you will send v2 please refer to original commit from which you restored
that function (or which reverted it.)

On 3 October 2017 at 12:37, Savolainen, Petri (Nokia - FI/Espoo) <
petri.savolainen@nokia.com> wrote:

>

>

> > -----Original Message-----

> > From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of

> > Github ODP bot

> > Sent: Tuesday, October 03, 2017 11:00 AM

> > To: lng-odp@lists.linaro.org

> > Subject: [lng-odp] [PATCH v1 1/1] linux-gen: User /proc/cpuinfo, if sysfs

> > is not available. Fixes https://bugs.linaro.org/show_bug.cgi?id=3249

> >

> > From: Ilias Apalodimas <ilias.apalodimas@linaro.org>

>

>

> Git log entry is missing. Re-format commit subject line and body of the

> text.

>

> For example:

> "

> linux-gen: system_info: use proc/cpuinfo as backup

>

> When sysfs is not available, use /proc/cpuinfo file as

> a backup for current cpu MHz.

>

> This fixes      bug: https://bugs.linaro.org/show_bug.cgi?id=3249

>

> Signed-off-by...

> "

>

> -Petri

>

Patch

diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index d310d7790..790bf68b0 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -378,6 +378,44 @@  int odp_system_info_term(void)
 	return 0;
 }
 
+static uint64_t get_cpuspeed(int id)
+{
+	char str[1024];
+	char *pos;
+	FILE *file = NULL;
+	double mhz = 0.0;
+	int cur_id = 0;
+	uint64_t cur_hz = 0;
+
+	if (id + 1 > odp_global_data.num_cpus_installed) {
+		ODP_ERR("Invalid number of CPUs requested\n");
+		return cur_hz;
+	}
+
+	file = fopen("/proc/cpuinfo", "rt");
+	if (file == NULL) {
+		ODP_ERR("Failed to open /proc/cpuinfo\n");
+		return cur_hz;
+	}
+
+	while (fgets(str, sizeof(str), file) != NULL && id < MAX_CPU_NUMBER) {
+		pos = strstr(str, "cpu MHz");
+		if (pos) {
+			if (id != cur_id) {
+				cur_id++;
+				continue;
+			}
+			if (sscanf(pos, "cpu MHz : %lf", &mhz) == 1) {
+				cur_hz = (uint64_t)(mhz * 1000000.0);
+				break;
+			}
+		}
+	}
+	fclose(file);
+
+	return cur_hz;
+}
+
 /*
  *************************
  * Public access functions
@@ -385,7 +423,12 @@  int odp_system_info_term(void)
  */
 uint64_t odp_cpu_hz_current(int id)
 {
-	return odp_cpufreq_id("cpuinfo_cur_freq", id);
+	uint64_t cur_hz = odp_cpufreq_id("cpuinfo_cur_freq", id);
+
+	if (!cur_hz)
+		cur_hz = get_cpuspeed(id);
+
+	return cur_hz;
 }
 
 uint64_t odp_cpu_hz(void)