From patchwork Fri Jun 10 13:43:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 1813 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.45.109) by localhost6.localdomain6 with IMAP4-SSL; 10 Jun 2011 20:11:59 -0000 Delivered-To: patches@linaro.org Received: by 10.52.181.10 with SMTP id ds10cs312334vdc; Fri, 10 Jun 2011 06:43:03 -0700 (PDT) Received: by 10.229.67.16 with SMTP id p16mr1573220qci.99.1307713383103; Fri, 10 Jun 2011 06:43:03 -0700 (PDT) Received: from mail-qw0-f50.google.com (mail-qw0-f50.google.com [209.85.216.50]) by mx.google.com with ESMTPS id m36si5519911qck.62.2011.06.10.06.43.02 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 10 Jun 2011 06:43:03 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.216.50 is neither permitted nor denied by best guess record for domain of amit.kachhap@linaro.org) client-ip=209.85.216.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.216.50 is neither permitted nor denied by best guess record for domain of amit.kachhap@linaro.org) smtp.mail=amit.kachhap@linaro.org Received: by qwe5 with SMTP id 5so1509878qwe.37 for ; Fri, 10 Jun 2011 06:43:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.105.211 with SMTP id u19mr1590667qao.370.1307713382215; Fri, 10 Jun 2011 06:43:02 -0700 (PDT) Received: by 10.224.29.9 with HTTP; Fri, 10 Jun 2011 06:43:02 -0700 (PDT) In-Reply-To: References: <20110610081326.GB2951@matterhorn1> Date: Fri, 10 Jun 2011 19:13:02 +0530 Message-ID: Subject: Re: fail in thermal manager utility. From: Amit Kachhap To: Steve Jahnke Cc: Private-PMWG , Patch Tracking 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 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 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 >> >> > >From bc10e59aa18f2ad628a157cc03f79a6740b28d23 Mon Sep 17 00:00:00 2001 From: Amit Daniel Kachhap 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 --- 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