From patchwork Sat Aug 11 01:58:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Len Brown X-Patchwork-Id: 10563251 X-Patchwork-Delegate: lenb@kernel.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB72D14E2 for ; Sat, 11 Aug 2018 02:01:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 923522B189 for ; Sat, 11 Aug 2018 02:01:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 852022B1A4; Sat, 11 Aug 2018 02:01:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED6FA2B173 for ; Sat, 11 Aug 2018 02:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725882AbeHKEdY (ORCPT ); Sat, 11 Aug 2018 00:33:24 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:40450 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbeHKEdY (ORCPT ); Sat, 11 Aug 2018 00:33:24 -0400 Received: by mail-qt0-f193.google.com with SMTP id h4-v6so12268015qtj.7 for ; Fri, 10 Aug 2018 19:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:reply-to:organization; bh=fOgiT5ba4nJpjes5LxxoWyUmuLeElhdi2+JNEI2t6IE=; b=mP5/149sxTCdX9HH2V4yIy55e+dMnz8rMMH9eNaUMH57wwwabbXgLqXEdoltM/6Ney IZr4BofwFQ6Lp0VuRZDRjuiCv1Y6Tv3l8FKsKB3pwVlXiLzWGlFJPtSewzpAnPoJFCvB TCd+pr6OUjbffGjKcCDowfNHXMCteePdp2SEbInflVUVsKAmzVPnI+zJK90RXd6dlD4J DnQ9kkS9fn7lJV+lVTWS/5DUWDYqxj8j4pe0kf1tRtdDiIiVTp+hikzkqLFuYaqdWY7p hXP61dLrBSyDWW6Stmh3prSFi2juwp0XphX4JbUkOhH/kDhIbAspUjON/NYnTxBJo+bs 2SUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :reply-to:organization; bh=fOgiT5ba4nJpjes5LxxoWyUmuLeElhdi2+JNEI2t6IE=; b=BIC0FjZWxSEWhep1tzXvTTbZ9ifStZi1wNMu7K3NCwAkwDCYmBX0N9YDlFp2W8V03C obkhOX8oJm9Sk4dPsAh7/SS13ipoQ1lwtJ3YQLeMlkLwh0CDD9Zu2MnKR2eFysbHGHVu nWnSjnqLSU0NZ+S7ivJ8MaGjyJKUZ/w7D0YBBXRg5kzckhCgjwWOh0QZpCoDLqqR7D4H Jo3qpbEJUMzoLw5Y47bZFFmNxosWTrdVh2xRv5c1T13fcvrgukqg/nGihNcV6gcnSA9d 2MBESZtScLnbCKkbXR47KTQrf9krncuADx1sF5elG2jQWjZt/K4d7a2iUY+0UXDCMmEO +mNA== X-Gm-Message-State: AOUpUlFW8ahufvGPebWgdY9txTLdfncJHAIvO0H3XWqTMnznpYqFySqt TM4z9WipfdsrpAbdDd/MdWyuFCka X-Google-Smtp-Source: AA+uWPxJ/fKM536Y4jCh8Sa/Ati9n6lIXtow/ilK84l+2QdC8c2bz/F2582GX+b1zNsj/KCzycSiYg== X-Received: by 2002:ac8:193a:: with SMTP id t55-v6mr8350486qtj.251.1533952858677; Fri, 10 Aug 2018 19:00:58 -0700 (PDT) Received: from localhost.localdomain (h66-222-27-236.cntcnh.dsl.dynamic.tds.net. [66.222.27.236]) by smtp.gmail.com with ESMTPSA id u21-v6sm6057965qka.88.2018.08.10.19.00.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 10 Aug 2018 19:00:57 -0700 (PDT) From: Len Brown To: rjw@rjwysocki.net Cc: linux-pm@vger.kernel.org, Len Brown Subject: [PATCH] tools/power turbosat: fix AMD APIC-id output Date: Fri, 10 Aug 2018 21:58:45 -0400 Message-Id: <9e66f9d800deae7a30b51b43c36e0e6ee9b82df0.1533952708.git.len.brown@intel.com> X-Mailer: git-send-email 2.18.0-rc0 Reply-To: Len Brown Organization: Intel Open Source Technology Center Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Len Brown turbostat recently gained a feature adding APIC and X2APIC columns. While they are disabled by-default, they are enabled with --debug or when explicitly requested, eg. $ sudo turbostat --quiet --show Package,Node,Core,CPU,APIC,X2APIC date But these columns erroneously showed zeros on AMD hardware. This patch corrects the APIC and X2APIC [sic] columns on AMD. Signed-off-by: Len Brown --- Thanks to Prarit @ Red hat for pointing out a bug (legacy apic mask is 0xff, not 0xf) in the initial version of this patch. tools/power/x86/turbostat/turbostat.c | 93 +++++++++++++++++---------- 1 file changed, 60 insertions(+), 33 deletions(-) diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 980bd9d20646..6837a65409ba 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -1,6 +1,6 @@ /* * turbostat -- show CPU frequency and C-state residency - * on modern Intel turbo-capable processors. + * on modern Intel and AMD processors. * * Copyright (c) 2013 Intel Corporation. * Len Brown @@ -71,6 +71,8 @@ unsigned int do_irtl_snb; unsigned int do_irtl_hsw; unsigned int units = 1000000; /* MHz etc */ unsigned int genuine_intel; +unsigned int authentic_amd; +unsigned int max_level, max_extended_level; unsigned int has_invariant_tsc; unsigned int do_nhm_platform_info; unsigned int no_MSR_MISC_PWR_MGMT; @@ -1667,30 +1669,51 @@ int get_mp(int cpu, struct msr_counter *mp, unsigned long long *counterp) void get_apic_id(struct thread_data *t) { - unsigned int eax, ebx, ecx, edx, max_level; + unsigned int eax, ebx, ecx, edx; - eax = ebx = ecx = edx = 0; + if (DO_BIC(BIC_APIC)) { + eax = ebx = ecx = edx = 0; + __cpuid(1, eax, ebx, ecx, edx); - if (!genuine_intel) + t->apic_id = (ebx >> 24) & 0xff; + } + + if (!DO_BIC(BIC_X2APIC)) return; - __cpuid(0, max_level, ebx, ecx, edx); + if (authentic_amd) { + unsigned int topology_extensions; - __cpuid(1, eax, ebx, ecx, edx); - t->apic_id = (ebx >> 24) & 0xf; + if (max_extended_level < 0x8000001e) + return; - if (max_level < 0xb) + eax = ebx = ecx = edx = 0; + __cpuid(0x80000001, eax, ebx, ecx, edx); + topology_extensions = ecx & (1 << 22); + + if (topology_extensions == 0) + return; + + eax = ebx = ecx = edx = 0; + __cpuid(0x8000001e, eax, ebx, ecx, edx); + + t->x2apic_id = eax; return; + } - if (!DO_BIC(BIC_X2APIC)) + if (!genuine_intel) + return; + + if (max_level < 0xb) return; ecx = 0; __cpuid(0xb, eax, ebx, ecx, edx); t->x2apic_id = edx; - if (debug && (t->apic_id != t->x2apic_id)) - fprintf(outf, "cpu%d: apic 0x%x x2apic 0x%x\n", t->cpu_id, t->apic_id, t->x2apic_id); + if (debug && (t->apic_id != (t->x2apic_id && 0xff))) + fprintf(outf, "cpu%d: BIOS BUG: apic 0x%x x2apic 0x%x\n", + t->cpu_id, t->apic_id, t->x2apic_id); } /* @@ -4438,16 +4461,18 @@ void decode_c6_demotion_policy_msr(void) void process_cpuid() { - unsigned int eax, ebx, ecx, edx, max_level, max_extended_level; - unsigned int fms, family, model, stepping; + unsigned int eax, ebx, ecx, edx; + unsigned int fms, family, model, stepping, ecx_flags, edx_flags; unsigned int has_turbo; eax = ebx = ecx = edx = 0; __cpuid(0, max_level, ebx, ecx, edx); - if (ebx == 0x756e6547 && edx == 0x49656e69 && ecx == 0x6c65746e) + if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69) genuine_intel = 1; + else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65) + authentic_amd = 1; if (!quiet) fprintf(outf, "CPUID(0): %.4s%.4s%.4s ", @@ -4461,25 +4486,8 @@ void process_cpuid() family += (fms >> 20) & 0xff; if (family >= 6) model += ((fms >> 16) & 0xf) << 4; - - if (!quiet) { - fprintf(outf, "%d CPUID levels; family:model:stepping 0x%x:%x:%x (%d:%d:%d)\n", - max_level, family, model, stepping, family, model, stepping); - fprintf(outf, "CPUID(1): %s %s %s %s %s %s %s %s %s %s\n", - ecx & (1 << 0) ? "SSE3" : "-", - ecx & (1 << 3) ? "MONITOR" : "-", - ecx & (1 << 6) ? "SMX" : "-", - ecx & (1 << 7) ? "EIST" : "-", - ecx & (1 << 8) ? "TM2" : "-", - edx & (1 << 4) ? "TSC" : "-", - edx & (1 << 5) ? "MSR" : "-", - edx & (1 << 22) ? "ACPI-TM" : "-", - edx & (1 << 28) ? "HT" : "-", - edx & (1 << 29) ? "TM" : "-"); - } - - if (!(edx & (1 << 5))) - errx(1, "CPUID: no MSR"); + ecx_flags = ecx; + edx_flags = edx; /* * check max extended function levels of CPUID. @@ -4489,6 +4497,25 @@ void process_cpuid() ebx = ecx = edx = 0; __cpuid(0x80000000, max_extended_level, ebx, ecx, edx); + if (!quiet) { + fprintf(outf, "0x%x CPUID levels; 0x%x xlevels; family:model:stepping 0x%x:%x:%x (%d:%d:%d)\n", + max_level, max_extended_level, family, model, stepping, family, model, stepping); + fprintf(outf, "CPUID(1): %s %s %s %s %s %s %s %s %s %s\n", + ecx_flags & (1 << 0) ? "SSE3" : "-", + ecx_flags & (1 << 3) ? "MONITOR" : "-", + ecx_flags & (1 << 6) ? "SMX" : "-", + ecx_flags & (1 << 7) ? "EIST" : "-", + ecx_flags & (1 << 8) ? "TM2" : "-", + edx_flags & (1 << 4) ? "TSC" : "-", + edx_flags & (1 << 5) ? "MSR" : "-", + edx_flags & (1 << 22) ? "ACPI-TM" : "-", + edx_flags & (1 << 28) ? "HT" : "-", + edx_flags & (1 << 29) ? "TM" : "-"); + } + + if (!(edx_flags & (1 << 5))) + errx(1, "CPUID: no MSR"); + if (max_extended_level >= 0x80000007) { /*