Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3959688pxu; Mon, 12 Oct 2020 06:05:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMajiadyEio2N1T4nceI+1oIx82B/mqWqN6/ZFc2ZzDxYF1o0/6angYp3aZ3BfAI9gnXc/ X-Received: by 2002:aa7:dc50:: with SMTP id g16mr13917278edu.95.1602507805716; Mon, 12 Oct 2020 06:03:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602507805; cv=none; d=google.com; s=arc-20160816; b=qsiEQfs+WKZv0aMI42D3Y+3RCq1dKfl8noEPh5dLSe2lCx29Tmg46ZLPt3DtOyYXzz 3MudGU8muEIzIXLomSBQN/5pTk4MugEMD3D6d1CrwJaFO3QFV1MLIHmvQ7a0vpSmiIVu 4cVZLuW2OyL1JriIhU2zyIVBaNnwyypuF1WZrSpRkzHIP63lsbNho/mcDSRjTeXxLijU u3ORBeFGKjdwLsT/ehRL8mAdiYY4/XOuitW4IHZOWK+T6BcTHeUv2u/63EEIMkhtKGDe D81lni58xI8ZaaSewcC7Mr+6nxlos9qztHc35ftMi3H6eciFKpN4vMDEDRS1EdxDT40+ fH9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:ironport-sdr :ironport-sdr; bh=M1UwvMbpm8mscBDCz10VckxrqS85lXYg7jr12lcYrOc=; b=eEkt0yBOda7JDzfbX9CnGM4Eoy8aRM2zOlZrv6/Sg7TO4Hff9CwTRK6z58U/wtfqOO DAJv+HSf8Zt588km8usPUD9fw55saDH5we0XjpdlZU/taiwcjmPAj7jQKPsAobZX+xjy fRJYTFi4BoC+r+r4Jpd469m0PR1wQQB5FQz2T6qP6pFRRMITHCvBJFlSlym3LKFc4TY5 f0RbFN179g3Kp2s9JVLG/ainKY6iLXagc1ADHPVjObI2UGNMJi+uXjcPf/INmn8QUV1B REvge9iq9rMhcioNcJprBKbtORV1TzKdkDJSYM4fu2MNULGWLRpBjcMMUphllglBPo68 fpvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d12si13966001ejj.595.2020.10.12.06.02.41; Mon, 12 Oct 2020 06:03:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387407AbgJLKAf (ORCPT + 99 others); Mon, 12 Oct 2020 06:00:35 -0400 Received: from mga12.intel.com ([192.55.52.136]:42332 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726104AbgJLKAf (ORCPT ); Mon, 12 Oct 2020 06:00:35 -0400 IronPort-SDR: eqTR4pqskpZdlwvAV3/uqJxQAdVfvaVAYMWMPlzcSXrebrHm4V42FFzS/tzaDKi2eTZJ/0YJyR 73Qc9qHr3QjQ== X-IronPort-AV: E=McAfee;i="6000,8403,9771"; a="145037207" X-IronPort-AV: E=Sophos;i="5.77,366,1596524400"; d="scan'208";a="145037207" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2020 03:00:34 -0700 IronPort-SDR: ZBUJ9FTeS1dbqqTgViZaqMf0Aaln1rKcDCYFdzx6WM4yYjQZUrcO1RB9kYDMZ5uXnJgABF8Ecw gKmnu1Qt/HpQ== X-IronPort-AV: E=Sophos;i="5.77,366,1596524400"; d="scan'208";a="529901172" Received: from chenyu-office.sh.intel.com ([10.239.158.173]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2020 03:00:32 -0700 From: Chen Yu To: Len Brown Cc: "Rafael J. Wysocki" , Zhang Rui , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Chen Yu Subject: [PATCH][RFC] tools/power turbostat: Fix ACPI CState format issue Date: Mon, 12 Oct 2020 18:02:05 +0800 Message-Id: <20201012100205.2750-1-yu.c.chen@intel.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently if the system boots with BIOS _CST Cstate information enabled, the turbostat output would have unaligned problems: C1_ACPI C2_ACPI C3_ACPI POLL% C1_ACPI% C2_ACPI% C3_ACPI% CPU%c1 5 37 138 0.00 0.02 1.30 98.51 0.38 0.00 0.00 99.43 The C1_ACPI% is of 8 bytes, so extend the format accordingly if the field name equals to/longer than 8 bytes. After the patch applied: C1_ACPI C2_ACPI C3_ACPI POLL% C1_ACPI% C2_ACPI% C3_ACPI% CPU%c1 2 42 96 0.00 0.12 2.60 97.09 0.60 Reported-by: Zhang Rui Signed-off-by: Chen Yu --- tools/power/x86/turbostat/turbostat.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 33b370865d16..73aa8738ae36 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -664,14 +664,16 @@ void print_header(char *delim) outp += sprintf(outp, "%sSMI", (printed++ ? delim : "")); for (mp = sys.tp; mp; mp = mp->next) { - + int name_len = strlen(mp->name); if (mp->format == FORMAT_RAW) { if (mp->width == 64) outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), mp->name); else outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), mp->name); } else { - if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) + if (((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) || + /* Deal with corner case: Cx_ACPI% is of 8 bytes. */ + ((mp->type == COUNTER_USEC) && name_len >= 8)) outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), mp->name); else outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), mp->name); @@ -1005,6 +1007,7 @@ int format_counters(struct thread_data *t, struct core_data *c, /* Added counters */ for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { + int name_len = strlen(mp->name); if (mp->format == FORMAT_RAW) { if (mp->width == 32) outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) t->counter[i]); @@ -1016,9 +1019,13 @@ int format_counters(struct thread_data *t, struct core_data *c, else outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->counter[i]); } else if (mp->format == FORMAT_PERCENT) { - if (mp->type == COUNTER_USEC) - outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), t->counter[i]/interval_float/10000); - else + if (mp->type == COUNTER_USEC) { + /* Deal with corner case: Cx_ACPI% is of 8 bytes. */ + if (name_len >= 8) + outp += sprintf(outp, "%s%-8.2f", (printed++ ? delim : ""), t->counter[i]/interval_float/10000); + else + outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), t->counter[i]/interval_float/10000); + } else outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->counter[i]/tsc); } } -- 2.25.1