diff mbox

acpi: cstates: cater for different kernel C-state info

Message ID 1355229768-19378-1-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King Dec. 11, 2012, 12:42 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The kernel interface for reporting C states has changed again
for recent kernels.  Make sure the we can parse the different ways
it is formatted. Sigh.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpi/cstates/cstates.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

Comments

Ivan Hu Dec. 19, 2012, 10:02 a.m. UTC | #1
On 12/11/2012 08:42 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The kernel interface for reporting C states has changed again
> for recent kernels.  Make sure the we can parse the different ways
> it is formatted. Sigh.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/cstates/cstates.c | 22 +++++++++++++++-------
>   1 file changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/src/acpi/cstates/cstates.c b/src/acpi/cstates/cstates.c
> index 79170df..046ec8c 100644
> --- a/src/acpi/cstates/cstates.c
> +++ b/src/acpi/cstates/cstates.c
> @@ -67,9 +67,8 @@ static void get_cstates(char *path, fwts_cstates *state)
>
>   	while ((entry = readdir(dir)) != NULL) {
>   		if (entry && strlen(entry->d_name)>3) {
> -			int nr = 0;
> +			int nr;
>   			int count;
> -			size_t len;
>
>   			snprintf(filename, sizeof(filename), "%s/%s/name",
>   				path, entry->d_name);
> @@ -77,12 +76,21 @@ static void get_cstates(char *path, fwts_cstates *state)
>   				break;
>
>   			/*
> -			 * Names can be Cx\n, or ATM-Cx\n, or SNB-Cx\n,
> -			 * where x is the C state number
> +			 * Names can be "Cx\n", or "ATM-Cx\n", or "SNB-Cx\n",
> +			 * or newer kernels can be "Cx\n" or "Cx-SNB\n" etc
> +			 * where x is the C state number.
>   			 */
> -			len = strlen(data);
> -			if ((len > 2) && (data[len-3] == 'C'))
> -				nr = strtoull(data+len-2, NULL, 10);
> +			if ((data[0] == 'C') && isdigit(data[1]))
> +				nr = strtoull(data+1, NULL, 10);
> +			else if (strcmp("POLL", data) == 0)
> +				nr = 0;
> +			else {
> +				char *ptr = strstr(data, "-C");
> +				if (ptr)
> +					nr = strtoull(ptr + 2, NULL, 10);
> +				else
> +					nr = 0;
> +			}
>   			free(data);
>
>   			snprintf(filename, sizeof(filename), "%s/%s/usage",
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>
Alex Hung Dec. 21, 2012, 2:34 a.m. UTC | #2
On 12/11/2012 08:42 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The kernel interface for reporting C states has changed again
> for recent kernels.  Make sure the we can parse the different ways
> it is formatted. Sigh.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/cstates/cstates.c | 22 +++++++++++++++-------
>   1 file changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/src/acpi/cstates/cstates.c b/src/acpi/cstates/cstates.c
> index 79170df..046ec8c 100644
> --- a/src/acpi/cstates/cstates.c
> +++ b/src/acpi/cstates/cstates.c
> @@ -67,9 +67,8 @@ static void get_cstates(char *path, fwts_cstates *state)
>
>   	while ((entry = readdir(dir)) != NULL) {
>   		if (entry && strlen(entry->d_name)>3) {
> -			int nr = 0;
> +			int nr;
>   			int count;
> -			size_t len;
>
>   			snprintf(filename, sizeof(filename), "%s/%s/name",
>   				path, entry->d_name);
> @@ -77,12 +76,21 @@ static void get_cstates(char *path, fwts_cstates *state)
>   				break;
>
>   			/*
> -			 * Names can be Cx\n, or ATM-Cx\n, or SNB-Cx\n,
> -			 * where x is the C state number
> +			 * Names can be "Cx\n", or "ATM-Cx\n", or "SNB-Cx\n",
> +			 * or newer kernels can be "Cx\n" or "Cx-SNB\n" etc
> +			 * where x is the C state number.
>   			 */
> -			len = strlen(data);
> -			if ((len > 2) && (data[len-3] == 'C'))
> -				nr = strtoull(data+len-2, NULL, 10);
> +			if ((data[0] == 'C') && isdigit(data[1]))
> +				nr = strtoull(data+1, NULL, 10);
> +			else if (strcmp("POLL", data) == 0)
> +				nr = 0;
> +			else {
> +				char *ptr = strstr(data, "-C");
> +				if (ptr)
> +					nr = strtoull(ptr + 2, NULL, 10);
> +				else
> +					nr = 0;
> +			}
>   			free(data);
>
>   			snprintf(filename, sizeof(filename), "%s/%s/usage",
>

Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox

Patch

diff --git a/src/acpi/cstates/cstates.c b/src/acpi/cstates/cstates.c
index 79170df..046ec8c 100644
--- a/src/acpi/cstates/cstates.c
+++ b/src/acpi/cstates/cstates.c
@@ -67,9 +67,8 @@  static void get_cstates(char *path, fwts_cstates *state)
 
 	while ((entry = readdir(dir)) != NULL) {
 		if (entry && strlen(entry->d_name)>3) {
-			int nr = 0;
+			int nr;
 			int count;
-			size_t len;
 
 			snprintf(filename, sizeof(filename), "%s/%s/name",
 				path, entry->d_name);
@@ -77,12 +76,21 @@  static void get_cstates(char *path, fwts_cstates *state)
 				break;
 
 			/*
-			 * Names can be Cx\n, or ATM-Cx\n, or SNB-Cx\n,
-			 * where x is the C state number
+			 * Names can be "Cx\n", or "ATM-Cx\n", or "SNB-Cx\n",
+			 * or newer kernels can be "Cx\n" or "Cx-SNB\n" etc
+			 * where x is the C state number.
 			 */
-			len = strlen(data);
-			if ((len > 2) && (data[len-3] == 'C'))
-				nr = strtoull(data+len-2, NULL, 10);
+			if ((data[0] == 'C') && isdigit(data[1]))
+				nr = strtoull(data+1, NULL, 10);
+			else if (strcmp("POLL", data) == 0)
+				nr = 0;
+			else {
+				char *ptr = strstr(data, "-C");
+				if (ptr) 
+					nr = strtoull(ptr + 2, NULL, 10);
+				else
+					nr = 0;
+			}
 			free(data);
 
 			snprintf(filename, sizeof(filename), "%s/%s/usage",