[PATCH] acpi: cstates: cater for different kernel C-state info
IvanHu
ivan.hu at canonical.com
Wed Dec 19 10:02:07 UTC 2012
On 12/11/2012 08:42 PM, Colin King wrote:
> From: Colin Ian King <colin.king at 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 at 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 at canonical.com>
More information about the fwts-devel
mailing list