From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752554AbcHLM0j (ORCPT ); Fri, 12 Aug 2016 08:26:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36168 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751895AbcHLM0i (ORCPT ); Fri, 12 Aug 2016 08:26:38 -0400 Date: Fri, 12 Aug 2016 14:24:57 +0200 From: Jiri Olsa To: Peter Zijlstra Cc: Thomas Gleixner , Andi Kleen , linux-kernel@vger.kernel.org, Andi Kleen , x86@kernel.org, Ingo Molnar , Frank Ramsay , Prarit Bhargava Subject: Re: [PATCH] x86/smp: Fix __max_logical_packages value setup Message-ID: <20160812122457.GC8062@krava> References: <20160803162358.GA10890@krava> <20160810135417.GP30192@twins.programming.kicks-ass.net> <20160810140033.GA23798@krava> <20160810141538.GA28551@krava> <20160810155205.GR30192@twins.programming.kicks-ass.net> <20160810161417.GA11369@krava> <20160811124839.GQ6879@twins.programming.kicks-ass.net> <20160811130521.GA22741@krava> <20160811134651.GW30192@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160811134651.GW30192@twins.programming.kicks-ass.net> User-Agent: Mutt/1.6.2 (2016-07-01) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 12 Aug 2016 12:25:00 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 11, 2016 at 03:46:51PM +0200, Peter Zijlstra wrote: > On Thu, Aug 11, 2016 at 03:05:21PM +0200, Jiri Olsa wrote: > > hum, so we either need some acpi solution to get number of all > > sockets or > > This.. So the problem here is that the BIOS completely screws us over. > > It wrecks the ACPI-ID table with that option to limit the number of CPUs > exposed to the OS (note that it didn't need to do that, it could have > enumerated them as empty, instead of not there at all) while keeping the > CPUID of the CPUs as reporting they have many (12? was it) cores. > > This results in inconsistent state, and we're left with nothing useful. > > > fix the uncore code to initialize pmu boxes on cpu hotplug as well > > Can't.. it uses the boxes at STARTING time, and we can't do allocs > there. Not can we alloc earlier, because we don't know max_packages is > going to increase. I still need to test this, but would this be something like you proposed on irc? thanks, jirka --- diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 2a6e84a30a54..4296beb8fdd3 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -100,10 +100,11 @@ EXPORT_PER_CPU_SYMBOL(cpu_info); /* Logical package management. We might want to allocate that dynamically */ static int *physical_to_logical_pkg __read_mostly; static unsigned long *physical_package_map __read_mostly;; -static unsigned long *logical_package_map __read_mostly; static unsigned int max_physical_pkg_id __read_mostly; unsigned int __max_logical_packages __read_mostly; EXPORT_SYMBOL(__max_logical_packages); +static unsigned int logical_packages __read_mostly; +static bool logical_packages_frozen __read_mostly; /* Maximum number of SMT threads on any online core */ int __max_smt_threads __read_mostly; @@ -277,14 +278,14 @@ int topology_update_package_map(unsigned int apicid, unsigned int cpu) if (test_and_set_bit(pkg, physical_package_map)) goto found; - new = find_first_zero_bit(logical_package_map, __max_logical_packages); - if (new >= __max_logical_packages) { + if (logical_packages_frozen) { physical_to_logical_pkg[pkg] = -1; - pr_warn("APIC(%x) Package %u exceeds logical package map\n", + pr_warn("APIC(%x) Package %u exceeds logical package max\n", apicid, pkg); return -ENOSPC; } - set_bit(new, logical_package_map); + + new = logical_packages++; pr_info("APIC(%x) Converting physical %u to logical package %u\n", apicid, pkg, new); physical_to_logical_pkg[pkg] = new; @@ -341,6 +342,7 @@ static void __init smp_init_package_map(void) } __max_logical_packages = DIV_ROUND_UP(total_cpus, ncpus); + logical_packages = 0; /* * Possibly larger than what we need as the number of apic ids per @@ -352,10 +354,6 @@ static void __init smp_init_package_map(void) memset(physical_to_logical_pkg, 0xff, size); size = BITS_TO_LONGS(max_physical_pkg_id) * sizeof(unsigned long); physical_package_map = kzalloc(size, GFP_KERNEL); - size = BITS_TO_LONGS(__max_logical_packages) * sizeof(unsigned long); - logical_package_map = kzalloc(size, GFP_KERNEL); - - pr_info("Max logical packages: %u\n", __max_logical_packages); for_each_present_cpu(cpu) { unsigned int apicid = apic->cpu_present_to_apicid(cpu); @@ -369,6 +367,15 @@ static void __init smp_init_package_map(void) set_cpu_possible(cpu, false); set_cpu_present(cpu, false); } + + if (logical_packages > __max_logical_packages) { + pr_warn("Detected more packages (%u), then computed by BIOS data (%u).\n", + logical_packages, __max_logical_packages); + logical_packages_frozen = true; + __max_logical_packages = logical_packages; + } + + pr_info("Max logical packages: %u\n", __max_logical_packages); } void __init smp_store_boot_cpu_info(void)