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

login
register
mail settings
Submitter Colin King
Date Dec. 11, 2012, 12:42 p.m.
Message ID <1355229768-19378-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/205198/
State Accepted
Headers show

Comments

Colin King - Dec. 11, 2012, 12:42 p.m.
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(-)
Ivan Hu - Dec. 19, 2012, 10:02 a.m.
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.
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>

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",