Received: by 10.223.176.46 with SMTP id f43csp4265504wra; Tue, 23 Jan 2018 06:55:35 -0800 (PST) X-Google-Smtp-Source: AH8x225Ax9u8xhYOXYfQqcTqCND7kdPYUdS+7aGO1f6Rj+qsX1csSMgmWjDb++AVtDnGamu/OmZk X-Received: by 2002:a17:902:a985:: with SMTP id bh5-v6mr5766482plb.23.1516719335202; Tue, 23 Jan 2018 06:55:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516719335; cv=none; d=google.com; s=arc-20160816; b=kR6anOeE/jrU4d++PckyIuzK7Dr6MSkzG40PAGwsoj7qavmqjAT3WxqfAMnjkf5/eC Qg0UPNkvWDgnHQ8Ad1FZIaYuCSIo2cevOr/zoQQ3H0u6sZhYomMq94jlZmG1cPdrA5rx COo8zOJ+yUJ2UecPBijZbdjgAbqNsjf5mU0E1yHx4xWo4bhvlPxIpS32KjfzYXJXwLA7 J8Hg2u7KAT3ZAd7Ww77N1rOxDoR/9V7mKZr4RrL5tKEC0n2bSNNdO7ppqgvUqUctomzv x7vdc41QAezIgkysjv+D4VMFgoW2gJ7/WRWXaatTN1fnlOhG9/oeTmexT1V7zGhOTx7D y52Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from :dkim-signature:arc-authentication-results; bh=36vZypK2yKwq7i9+nh2CWIV28k/SKZwCWNNFiQww4cM=; b=PD2eEg5NeuOeXAH+I2RxaOnPRM5AT0JhH1rcKKhXBxc+zDDAXE3zrPxGoIfDLWqpvT PCi3wPr2sAmab0aqxvWc2WEPceNNtEjROceto4F1+ACp1T/bllfnZt8V5FvOEX7vJqdS zun1QuMWAsazssR5OdI2DWjtZFJ2azpTsbIrXTjpeDs3js8DIh4WFj+DXHyJoXm14ytf DsdCoGDDeTfIS60iPyegw6zUYb64/SEN6neiqR5QxaL9iTfIHa9HjrONmCtXF1GL9EU3 E4SLo83Jk1WgidweUSRluGF3tI1JLsiyKIVbAgUlLop3lJEtBpy9VTGvsB0i6pegYVNd cdmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.co.uk header.s=amazon201209 header.b=jPKX565z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w31-v6si3061491pla.402.2018.01.23.06.55.20; Tue, 23 Jan 2018 06:55:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.co.uk header.s=amazon201209 header.b=jPKX565z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752100AbeAWOyg (ORCPT + 99 others); Tue, 23 Jan 2018 09:54:36 -0500 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:36259 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751967AbeAWOyf (ORCPT ); Tue, 23 Jan 2018 09:54:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.uk; i=@amazon.co.uk; q=dns/txt; s=amazon201209; t=1516719275; x=1548255275; h=from:to:subject:date:message-id; bh=36vZypK2yKwq7i9+nh2CWIV28k/SKZwCWNNFiQww4cM=; b=jPKX565zn/PZ/JyXONvXVZLwSj212Gcn7pI8zveZeRguNaUpyrWD6ySk y7d32KIDzkG2BMsuQkJAzixC4uTzFfQge/qpOajpJklwRWTmS+FSb//nt //7c52qwhabFoxFG8Ruptu6CM0aCLjwwQLkrU4KpVyoRU6SyjgnvHUFLs c=; X-IronPort-AV: E=Sophos;i="5.46,401,1511827200"; d="scan'208";a="720681031" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2c-a11fcaa7.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 23 Jan 2018 14:53:54 +0000 Received: from uc8d3ff76b9bc5848a9cc.ant.amazon.com (pdx2-ws-svc-lb17-vlan3.amazon.com [10.247.140.70]) by email-inbound-relay-2c-a11fcaa7.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w0NErcUi054707 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 23 Jan 2018 14:53:40 GMT Received: from uc8d3ff76b9bc5848a9cc.ant.amazon.com (localhost [127.0.0.1]) by uc8d3ff76b9bc5848a9cc.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id w0NErbwT007319; Tue, 23 Jan 2018 14:53:37 GMT Received: (from dwmw@localhost) by uc8d3ff76b9bc5848a9cc.ant.amazon.com (8.15.2/8.15.2/Submit) id w0NErbAk007316; Tue, 23 Jan 2018 14:53:37 GMT From: David Woodhouse To: x86@kernel.org, bp@alien8.de, linux-kernel@vger.kernel.org Subject: [PATCH] x86/cpuid: Fewer CPUID invocations in init_scattered_cpuid_features() Date: Tue, 23 Jan 2018 14:53:33 +0000 Message-Id: <1516719213-7199-1-git-send-email-dwmw@amazon.co.uk> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We were doing a fresh CPUID for every single bit in every single output register. Do it once and then harvest *all* the bits we want. We were also doing the max_level check with a new CPUID invocation for every single bit. Stop that too. Signed-off-by: David Woodhouse --- Spotted this in my travels; it offended me. arch/x86/kernel/cpu/scattered.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c index df11f5d..26c15fb 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -23,8 +23,8 @@ static const struct cpuid_bit cpuid_bits[] = { { X86_FEATURE_EPB, CPUID_ECX, 3, 0x00000006, 0 }, { X86_FEATURE_CAT_L3, CPUID_EBX, 1, 0x00000010, 0 }, { X86_FEATURE_CAT_L2, CPUID_EBX, 2, 0x00000010, 0 }, - { X86_FEATURE_CDP_L3, CPUID_ECX, 2, 0x00000010, 1 }, { X86_FEATURE_MBA, CPUID_EBX, 3, 0x00000010, 0 }, + { X86_FEATURE_CDP_L3, CPUID_ECX, 2, 0x00000010, 1 }, { X86_FEATURE_HW_PSTATE, CPUID_EDX, 7, 0x80000007, 0 }, { X86_FEATURE_CPB, CPUID_EDX, 9, 0x80000007, 0 }, { X86_FEATURE_PROC_FEEDBACK, CPUID_EDX, 11, 0x80000007, 0 }, @@ -38,20 +38,35 @@ void init_scattered_cpuid_features(struct cpuinfo_x86 *c) u32 regs[4]; const struct cpuid_bit *cb; + /* Max level for basic CPUID leaves */ + max_level = cpuid_eax(0); + for (cb = cpuid_bits; cb->feature; cb++) { + /* Are we on to extended CPUID leaves yet? */ + if (cb->level >= 0x80000000 && max_level < 0x80000000) { + max_level = cpuid_eax(0x80000000); + if (max_level < 0x80000000 || max_level > 0x8000ffff) { + /* No extended leaves are supported */ + break; + } + } + /* Verify that the level is valid */ - max_level = cpuid_eax(cb->level & 0xffff0000); - if (max_level < cb->level || - max_level > (cb->level | 0xffff)) + if (cb->level > max_level) continue; cpuid_count(cb->level, cb->sub_leaf, ®s[CPUID_EAX], ®s[CPUID_EBX], ®s[CPUID_ECX], ®s[CPUID_EDX]); - if (regs[cb->reg] & (1 << cb->bit)) - set_cpu_cap(c, cb->feature); + do { + if (regs[cb->reg] & (1 << cb->bit)) + set_cpu_cap(c, cb->feature); + + } while (cb[1].level == cb[0].level && + cb[1].sub_leaf == cb[0].sub_leaf && + cb++); } } -- 2.7.4