From patchwork Tue Dec 11 12:42:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 205198 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 6D1C52C0080 for ; Tue, 11 Dec 2012 23:42:51 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TiPAg-00081F-9X; Tue, 11 Dec 2012 12:42:50 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TiPAe-000814-PL for fwts-devel@lists.ubuntu.com; Tue, 11 Dec 2012 12:42:48 +0000 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginmedia.com ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1TiPAe-0007u4-Mz for fwts-devel@lists.ubuntu.com; Tue, 11 Dec 2012 12:42:48 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] acpi: cstates: cater for different kernel C-state info Date: Tue, 11 Dec 2012 12:42:48 +0000 Message-Id: <1355229768-19378-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.8.0 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King 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 Acked-by: Ivan Hu Acked-by: Alex Hung --- 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",