Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1522846ybm; Thu, 23 May 2019 02:28:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqw0WES0sUrG7OHsO8dd9z8Y73R6UWBgL+YMnL8+kXDQ8Gz8Ad0u8Bk/9HZuCmpztDbjxslC X-Received: by 2002:a17:902:24c7:: with SMTP id l7mr46860095plg.192.1558603689482; Thu, 23 May 2019 02:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558603689; cv=none; d=google.com; s=arc-20160816; b=FKvBMQpv7NWU/UBFLHF/FJd9e17gmoyEzF4uTWOTi6JsHE/COiTZv5Q9MVJpyh1b83 WHtBde7ZoJzGVRyVajkai0xIhwF3LxygHvZp2fM+kooqT1jVX69QOeFv8mz/26xD6jkz 9IPRoOzqf2Vp+rENKSwsqgTXLMJJKNyHlsS+P698M26+X2pW1Zf36AMzJ2Rdnd0Y6zZ4 MCqNECDRI5h+jGX73L+PvEfxVMu4VBBCFsP5yMXO2x2/EmxGmzEpuQnuxYss8tjriw/N 9aRfjrunR2JEi9DhICUrmRQ4pR73ZxmGbnRJ5CnnrZY5EfUXd/yHsCU9Bb+r3BG/LwUK tHKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=gDSxH/dOq0Mo4yZFGZo8eh1TvZhxTNPkbYNuqMD9JcI=; b=o78N+E7d23Jk6c38q6oshjBW17miDBhRUgd1IZKJYw0I1SQOY5w1eekX22pN3fR5pp wbhPdlDJ5J3p5CiiSEeO4XGfq8gIpW0HuLIxW7T/pl2ZDeQkZ9SCpvSG+rkNASFSyCI1 yUcT7UVEWuB7HMLLR9DwBmVEW8zwK49M4/URT3HAcLXWaCjJ5UtKvtaRBDy6ctz4i5rH iCP6qXNqTy9XktJ1LoffrUo7eOCmkdhV/EbLnARaP7TXJdz+q7XVIXI46HwaSNiBGqiZ 8nLPDcBe6K0JVAD7PszRHH9HJteaPj8l4pBVjOevZpQ+RTVkKA675scwCyn+YcwynP/z tVDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019051801 header.b=RsTPvam+; 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=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4si24662108pfn.197.2019.05.23.02.27.54; Thu, 23 May 2019 02:28:09 -0700 (PDT) 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=@zytor.com header.s=2019051801 header.b=RsTPvam+; 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=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730202AbfEWJZo (ORCPT + 99 others); Thu, 23 May 2019 05:25:44 -0400 Received: from terminus.zytor.com ([198.137.202.136]:40009 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726081AbfEWJZo (ORCPT ); Thu, 23 May 2019 05:25:44 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x4N9PWAk4041701 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 23 May 2019 02:25:32 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x4N9PWAk4041701 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019051801; t=1558603533; bh=gDSxH/dOq0Mo4yZFGZo8eh1TvZhxTNPkbYNuqMD9JcI=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=RsTPvam+DNBAJToQmfZNS+5s2Nk0IBUn2avkFkddXiwktRBykQ0DcQu2illaJn6VY FBrRJsuqLJzy/wo6Gtt/D5tEFkYyJM9YyX7Nk0Gpnqxu4QxEvnOIqbFixGp8d/0vXN m9yS7g0VMTEX/K3mBO+ESG9RIrNvKd2OQ0gFBZx84BBtiUw9eRvijJVe+9h+k6zNKK lM0ZHEDaJen7FDh6fqTjAChVbw832MGQaeQF0Ver4adPT866WF/O8QhCnpwW6aweEf eN9OFx23SxHIeFJsqyFUYq07tMwGRF7zYoN9fltVoC9pQDYp6gxJJj2VMypaE8esJO reC1fPlya3lpw== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x4N9PWCW4041698; Thu, 23 May 2019 02:25:32 -0700 Date: Thu, 23 May 2019 02:25:32 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Len Brown Message-ID: Cc: mingo@kernel.org, rui.zhang@intel.com, linux-kernel@vger.kernel.org, peterz@infradead.org, tglx@linutronix.de, len.brown@intel.com, hpa@zytor.com Reply-To: linux-kernel@vger.kernel.org, mingo@kernel.org, rui.zhang@intel.com, tglx@linutronix.de, peterz@infradead.org, hpa@zytor.com, len.brown@intel.com In-Reply-To: <2f3526e25ae14fbeff26fb26e877d159df8946d9.1557769318.git.len.brown@intel.com> References: <2f3526e25ae14fbeff26fb26e877d159df8946d9.1557769318.git.len.brown@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/topology] x86/topology: Define topology_logical_die_id() Git-Commit-ID: 212bf4fdb7f9eeeb99afd97ebad677d43e7b55ac X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 212bf4fdb7f9eeeb99afd97ebad677d43e7b55ac Gitweb: https://git.kernel.org/tip/212bf4fdb7f9eeeb99afd97ebad677d43e7b55ac Author: Len Brown AuthorDate: Mon, 13 May 2019 13:58:49 -0400 Committer: Thomas Gleixner CommitDate: Thu, 23 May 2019 10:08:32 +0200 x86/topology: Define topology_logical_die_id() Define topology_logical_die_id() ala existing topology_logical_package_id() Signed-off-by: Len Brown Signed-off-by: Thomas Gleixner Tested-by: Zhang Rui Reviewed-by: Ingo Molnar Acked-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/2f3526e25ae14fbeff26fb26e877d159df8946d9.1557769318.git.len.brown@intel.com --- arch/x86/include/asm/processor.h | 1 + arch/x86/include/asm/topology.h | 5 +++++ arch/x86/kernel/cpu/common.c | 1 + arch/x86/kernel/smpboot.c | 45 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 7c17343946dd..6aba36bde57f 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -118,6 +118,7 @@ struct cpuinfo_x86 { /* Core id: */ u16 cpu_core_id; u16 cpu_die_id; + u16 logical_die_id; /* Index into per_cpu list: */ u16 cpu_index; u32 microcode; diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h index 3777dbe9c0ff..9de16b4f6023 100644 --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -106,6 +106,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu); #define topology_logical_package_id(cpu) (cpu_data(cpu).logical_proc_id) #define topology_physical_package_id(cpu) (cpu_data(cpu).phys_proc_id) +#define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id) #define topology_die_id(cpu) (cpu_data(cpu).cpu_die_id) #define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id) @@ -131,13 +132,17 @@ static inline int topology_max_smt_threads(void) } int topology_update_package_map(unsigned int apicid, unsigned int cpu); +int topology_update_die_map(unsigned int dieid, unsigned int cpu); int topology_phys_to_logical_pkg(unsigned int pkg); +int topology_phys_to_logical_die(unsigned int die, unsigned int cpu); bool topology_is_primary_thread(unsigned int cpu); bool topology_smt_supported(void); #else #define topology_max_packages() (1) static inline int topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; } +static inline int +topology_update_die_map(unsigned int dieid, unsigned int cpu) { return 0; } static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; } static inline int topology_phys_to_logical_die(unsigned int die, unsigned int cpu) { return 0; } diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index d7f55ad2dfb1..8cdca1223b0f 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1298,6 +1298,7 @@ static void validate_apic_and_package_id(struct cpuinfo_x86 *c) cpu, apicid, c->initial_apicid); } BUG_ON(topology_update_package_map(c->phys_proc_id, cpu)); + BUG_ON(topology_update_die_map(c->cpu_die_id, cpu)); #else c->logical_proc_id = 0; #endif diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 40ffe23249c0..a6e01b6c2709 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -101,6 +101,7 @@ EXPORT_PER_CPU_SYMBOL(cpu_info); unsigned int __max_logical_packages __read_mostly; EXPORT_SYMBOL(__max_logical_packages); static unsigned int logical_packages __read_mostly; +static unsigned int logical_die __read_mostly; /* Maximum number of SMT threads on any online core */ int __read_mostly __max_smt_threads = 1; @@ -302,6 +303,26 @@ int topology_phys_to_logical_pkg(unsigned int phys_pkg) return -1; } EXPORT_SYMBOL(topology_phys_to_logical_pkg); +/** + * topology_phys_to_logical_die - Map a physical die id to logical + * + * Returns logical die id or -1 if not found + */ +int topology_phys_to_logical_die(unsigned int die_id, unsigned int cur_cpu) +{ + int cpu; + int proc_id = cpu_data(cur_cpu).phys_proc_id; + + for_each_possible_cpu(cpu) { + struct cpuinfo_x86 *c = &cpu_data(cpu); + + if (c->initialized && c->cpu_die_id == die_id && + c->phys_proc_id == proc_id) + return c->logical_die_id; + } + return -1; +} +EXPORT_SYMBOL(topology_phys_to_logical_die); /** * topology_update_package_map - Update the physical to logical package map @@ -326,6 +347,29 @@ found: cpu_data(cpu).logical_proc_id = new; return 0; } +/** + * topology_update_die_map - Update the physical to logical die map + * @die: The die id as retrieved via CPUID + * @cpu: The cpu for which this is updated + */ +int topology_update_die_map(unsigned int die, unsigned int cpu) +{ + int new; + + /* Already available somewhere? */ + new = topology_phys_to_logical_die(die, cpu); + if (new >= 0) + goto found; + + new = logical_die++; + if (new != die) { + pr_info("CPU %u Converting physical %u to logical die %u\n", + cpu, die, new); + } +found: + cpu_data(cpu).logical_die_id = new; + return 0; +} void __init smp_store_boot_cpu_info(void) { @@ -335,6 +379,7 @@ void __init smp_store_boot_cpu_info(void) *c = boot_cpu_data; c->cpu_index = id; topology_update_package_map(c->phys_proc_id, id); + topology_update_die_map(c->cpu_die_id, id); c->initialized = true; }