diff mbox

fail in thermal manager utility.

Message ID BANLkTi=xqGWYra0sFQCx+CUO0FJFoWjgPQ@mail.gmail.com
State New
Headers show

Commit Message

Amit Daniel Kachhap June 10, 2011, 1:43 p.m. UTC
Hi Steve,

The attached patch uses stats/time_in_state to find each frequency.

Regards,
Amit Daniel

On 10 June 2011 14:27, Amit Kachhap <amit.kachhap@linaro.org> wrote:

> Hi Amit,
>
> Just i checked,  scaling_available_frequencies sysfs attribute is not
> present by default.
> It has to be registered from cpufreq driver. Some platforms are creating
> this entry that way.
> I am using 2.6.38 kernel but this entry is not registered from cpufreq
> driver.
> Also I checked powertop, it uses stats/time_in_state to scroll each
> frequency states.
>
> Regards,
> Amit Daniel
>
>
> On 10 June 2011 13:43, Amit Kucheria <amit.kucheria@linaro.org> wrote:
>
>> On 11 Jun 10, Amit Kachhap wrote:
>> > Hi Steve,
>> >
>> > I was just trying to use the thermal manager tool from your git
>> repository
>> > to read temperature from thermal sensor
>> > but while running it got the below error.
>> >
>> > root@localhost:/work/steve_tree/thermal_manager/generic# ./thmand
>> > Running thmand v0.2.2
>> > Could not handle
>> > /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies -
>> check
>> > permissions
>>
>> That will should exist if you have CPU_FREQ enabled in your kernel.
>>
>> > It seems that the file scaling_available_frequencies does not exist from
>> 38
>> > kernel onwards. But similar to it there is
>> > /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state.
>>
>> What kernel is this?
>>
>> /Amit
>>
>>
>

Comments

Steve Jahnke June 10, 2011, 2:17 p.m. UTC | #1
Amit,
 Thanks for looking into this; I will review the patch and apply.

Steve

On Fri, 2011-06-10 at 19:13 +0530, Amit Kachhap wrote:
> Hi Steve,
> 
> The attached patch uses stats/time_in_state to find each frequency.
> 
> Regards,
> Amit Daniel
> 
> On 10 June 2011 14:27, Amit Kachhap <amit.kachhap@linaro.org> wrote:
>         Hi Amit,
>         
>         Just i checked,  scaling_available_frequencies sysfs attribute
>         is not present by default.
>         It has to be registered from cpufreq driver. Some platforms
>         are creating this entry that way.
>         I am using 2.6.38 kernel but this entry is not registered from
>         cpufreq driver.
>         Also I checked powertop, it uses stats/time_in_state to scroll
>         each frequency states.
>         
>         Regards,
>         Amit Daniel
>         
>         
>         
>         On 10 June 2011 13:43, Amit Kucheria
>         <amit.kucheria@linaro.org> wrote:
>                 On 11 Jun 10, Amit Kachhap wrote:
>                 > Hi Steve,
>                 >
>                 > I was just trying to use the thermal manager tool
>                 from your git repository
>                 > to read temperature from thermal sensor
>                 > but while running it got the below error.
>                 >
>                 >
>                 root@localhost:/work/steve_tree/thermal_manager/generic# ./thmand
>                 > Running thmand v0.2.2
>                 > Could not handle
>                 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies - check
>                 > permissions
>                 
>                 
>                 That will should exist if you have CPU_FREQ enabled in
>                 your kernel.
>                 
>                 > It seems that the file scaling_available_frequencies
>                 does not exist from 38
>                 > kernel onwards. But similar to it there is
>                 > /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state.
>                 
>                 
>                 What kernel is this?
>                 
>                 /Amit
>                 
>         
>         
>
diff mbox

Patch

From bc10e59aa18f2ad628a157cc03f79a6740b28d23 Mon Sep 17 00:00:00 2001
From: Amit Daniel Kachhap <amit.kachhap@linaro.org>
Date: Fri, 10 Jun 2011 19:07:52 +0530
Subject: [PATCH] Bug fix: Read the frequency levels from
  /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state. This will be more
 generic for all platforms.

Signed-off-by: Amit Daniel Kachhap <amit.kachhap@linaro.org>
---
 Source/headdefine.h |    2 +
 Source/update.c     |   64 ++++++++++++++++++++++++---------------------------
 2 files changed, 32 insertions(+), 34 deletions(-)

diff --git a/Source/headdefine.h b/Source/headdefine.h
index d9449a7..91438bc 100644
--- a/Source/headdefine.h
+++ b/Source/headdefine.h
@@ -37,10 +37,12 @@ 
 /* CPU information. Everything fixed on cpu0 right now */
 #define MAXCPUFREQ0 "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq"
 #define SET_AVAILFREQ0 "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies"
+#define SET_FREQSTAT0 "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state"
 
 /* type definitions */
 #define MAX_FILECHARSIZE 80
 #define MAX_VALUES 20
+#define MAX_LINECHARSIZE 1024
 
 /* get_state return definitions */
 #define SAFE_STATE 100
diff --git a/Source/update.c b/Source/update.c
index a21f167..ea34cc4 100644
--- a/Source/update.c
+++ b/Source/update.c
@@ -19,49 +19,45 @@ 
 int available_freq (void)
 {
 	FILE *avail_freq_file;
-	char *validfreq; /* A single available freq */
-	int ch;
-	int i,j,k;
+	char *freqend; /* A single available freq */
+	int j, lenfreq;
+	char *line;
+
+	avail_freq_file = fopen(SET_FREQSTAT0, "r");
+	if (avail_freq_file == NULL)
+		err_fileopen(SET_FREQSTAT0);
 	
 	/* Initial memory */
-	if ((validfreq = calloc(MAX_FILECHARSIZE, sizeof(char))) == NULL)
+	line = calloc(MAX_LINECHARSIZE, sizeof(char));
+	if (line == NULL)
 		err_allocatemem();
-  
-	if ((avail_freq_file = fopen (SET_AVAILFREQ0, "r")) == NULL)
-		err_fileopen (SET_AVAILFREQ0);
 		
-	i = 0;
 	j = 0;
-	k = 0;
-	while ((ch = fgetc(avail_freq_file)) != '\n') {
-		if (ch == ' ') {
-			if ((avail_freq[j].s_validfreq = calloc(strlen(validfreq), 
-					sizeof(char))) == NULL) {
-				fclose(avail_freq_file);	
-				err_allocatemem();
-				}
-			strcpy (avail_freq[j].s_validfreq, validfreq); 
-			memset (validfreq, 0x00, MAX_FILECHARSIZE);
-			j++;
-			if (j > MAX_VALUES) {
-				fclose(avail_freq_file);
-				err_maxvalues();
-			}
-			k = 0;
-		}
-		else {
-			validfreq[k] = (char)ch;
-			k++;
+
+	while (!feof(avail_freq_file)) {
+		if (fgets(line, MAX_LINECHARSIZE-1, avail_freq_file) == NULL)
+			break;
+
+		freqend = strchr(line, ' ');
+		if (freqend == NULL) {
+			fclose(avail_freq_file);
+			free(line);
+			err_filedata(SET_FREQSTAT0);
 		}
-		i++;
-		if (i > MAX_FILECHARSIZE) {
+		lenfreq = freqend - line;
+
+		avail_freq[j].s_validfreq = calloc(lenfreq + 1,
+					sizeof(char));
+		if (avail_freq[j].s_validfreq == NULL) {
 			fclose(avail_freq_file);
-			err_filedata (SET_AVAILFREQ0);
+			free(line);
+			err_allocatemem();
 		}
+		strncpy(avail_freq[j].s_validfreq, line, lenfreq);
+		j++;
 	}
-	free (validfreq);
-	 
-	fclose(avail_freq_file);	
+	free(line);
+	fclose(avail_freq_file);
 	return j; /* Number of freq values */
 }
 
-- 
1.7.1