From patchwork Mon Nov 26 20:34:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Bringmann X-Patchwork-Id: 1003471 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 433dyr3QcWz9ryk for ; Tue, 27 Nov 2018 07:37:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 433dyr1ZSvzDqQn for ; Tue, 27 Nov 2018 07:37:56 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=mwb@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 433dtn4WNczDqc8 for ; Tue, 27 Nov 2018 07:34:25 +1100 (AEDT) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wAQKYBQC073491 for ; Mon, 26 Nov 2018 15:34:23 -0500 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 2p0qm8gwwf-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 26 Nov 2018 15:34:22 -0500 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 26 Nov 2018 20:34:22 -0000 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 26 Nov 2018 20:34:19 -0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wAQKYGZa29360246 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 26 Nov 2018 20:34:17 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD110C6059; Mon, 26 Nov 2018 20:34:16 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C5665C6055; Mon, 26 Nov 2018 20:34:16 +0000 (GMT) Received: from ltczep4-lp5.aus.stglabs.ibm.com (unknown [9.40.193.67]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 26 Nov 2018 20:34:16 +0000 (GMT) Received: from ltczep4-lp5.aus.stglabs.ibm.com (localhost [IPv6:::1]) by ltczep4-lp5.aus.stglabs.ibm.com (Postfix) with ESMTP id 76108400C859; Mon, 26 Nov 2018 14:34:16 -0600 (CST) Subject: [Internal Review PATCH 1/3] powerpc/numa: Conditionally online new nodes From: Michael Bringmann To: Michael Bringmann , Michael Ellerman , Juliet Kim , Tyrel Datwyler , Thomas Falcon , Vaidyanathan Srinivasan , Srikar Dronamraju , linuxppc-dev@lists.ozlabs.org Date: Mon, 26 Nov 2018 14:34:16 -0600 In-Reply-To: <20181126203327.11326.32023.stgit@ltczep4-lp5.aus.stglabs.ibm.com> References: <20181126203327.11326.32023.stgit@ltczep4-lp5.aus.stglabs.ibm.com> User-Agent: StGit/0.18-105-g416a-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18112620-0016-0000-0000-0000095A81E1 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010125; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000270; SDB=6.01123167; UDB=6.00583042; IPR=6.00903297; MB=3.00024341; MTD=3.00000008; XFM=3.00000015; UTC=2018-11-26 20:34:20 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18112620-0017-0000-0000-00004131EBCD Message-Id: <20181126203355.11326.11389.stgit@ltczep4-lp5.aus.stglabs.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-11-26_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811260175 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add argument to allow caller to determine whether the node identified for a cpu after an associativity / affinity change should be inited. Signed-off-by: Michael Bringmann --- arch/powerpc/include/asm/topology.h | 2 +- arch/powerpc/mm/numa.c | 6 +++--- arch/powerpc/platforms/pseries/hotplug-cpu.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h index a4a718d..4621f40 100644 --- a/arch/powerpc/include/asm/topology.h +++ b/arch/powerpc/include/asm/topology.h @@ -90,7 +90,7 @@ static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node) {} extern int start_topology_update(void); extern int stop_topology_update(void); extern int prrn_is_enabled(void); -extern int find_and_online_cpu_nid(int cpu); +extern int find_and_online_cpu_nid(int cpu, bool must_online); extern int timed_topology_update(int nsecs); extern void __init shared_proc_topology_init(void); #else diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c index 3a048e9..460d60f 100644 --- a/arch/powerpc/mm/numa.c +++ b/arch/powerpc/mm/numa.c @@ -1197,7 +1197,7 @@ static long vphn_get_associativity(unsigned long cpu, return rc; } -int find_and_online_cpu_nid(int cpu) +int find_and_online_cpu_nid(int cpu, bool must_online) { __be32 associativity[VPHN_ASSOC_BUFSIZE] = {0}; int new_nid; @@ -1210,7 +1210,7 @@ int find_and_online_cpu_nid(int cpu) if (new_nid < 0 || !node_possible(new_nid)) new_nid = first_online_node; - if (NODE_DATA(new_nid) == NULL) { + if (must_online && (NODE_DATA(new_nid) == NULL)) { #ifdef CONFIG_MEMORY_HOTPLUG /* * Need to ensure that NODE_DATA is initialized for a node from @@ -1337,7 +1337,7 @@ int numa_update_cpu_topology(bool cpus_locked) continue; } - new_nid = find_and_online_cpu_nid(cpu); + new_nid = find_and_online_cpu_nid(cpu, true); if (new_nid == numa_cpu_lookup_table[cpu]) { cpumask_andnot(&cpu_associativity_changes_mask, diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c index 2f8e621..620cb57 100644 --- a/arch/powerpc/platforms/pseries/hotplug-cpu.c +++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c @@ -366,7 +366,7 @@ static int dlpar_online_cpu(struct device_node *dn) != CPU_STATE_OFFLINE); cpu_maps_update_done(); timed_topology_update(1); - find_and_online_cpu_nid(cpu); + find_and_online_cpu_nid(cpu, true); rc = device_online(get_cpu_device(cpu)); if (rc) goto out; From patchwork Mon Nov 26 20:34:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Bringmann X-Patchwork-Id: 1003475 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 433f4063jBz9s29 for ; Tue, 27 Nov 2018 07:42:24 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 433f404C7TzDqcW for ; Tue, 27 Nov 2018 07:42:24 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=mwb@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 433dvy10tFzDqbs for ; Tue, 27 Nov 2018 07:35:25 +1100 (AEDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wAQKZL53030566 for ; Mon, 26 Nov 2018 15:35:24 -0500 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 2p0mpn91bb-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 26 Nov 2018 15:35:22 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 26 Nov 2018 20:34:41 -0000 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 26 Nov 2018 20:34:38 -0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wAQKYaDc23593096 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 26 Nov 2018 20:34:36 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D1C3C605B; Mon, 26 Nov 2018 20:34:36 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 358EBC6055; Mon, 26 Nov 2018 20:34:36 +0000 (GMT) Received: from ltczep4-lp5.aus.stglabs.ibm.com (unknown [9.40.193.67]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 26 Nov 2018 20:34:36 +0000 (GMT) Received: from ltczep4-lp5.aus.stglabs.ibm.com (localhost [IPv6:::1]) by ltczep4-lp5.aus.stglabs.ibm.com (Postfix) with ESMTP id D3D2240CAA83; Mon, 26 Nov 2018 14:34:35 -0600 (CST) Subject: [Internal Review PATCH 2/3] powerpc/numa: Define mapping between HW and kernel cpus From: Michael Bringmann To: Michael Bringmann , Michael Ellerman , Srikar Dronamraju , Vaidyanathan Srinivasan , Juliet Kim , Tyrel Datwyler , Thomas Falcon , linuxppc-dev@lists.ozlabs.org Date: Mon, 26 Nov 2018 14:34:35 -0600 In-Reply-To: <20181126203327.11326.32023.stgit@ltczep4-lp5.aus.stglabs.ibm.com> References: <20181126203327.11326.32023.stgit@ltczep4-lp5.aus.stglabs.ibm.com> User-Agent: StGit/0.18-105-g416a-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18112620-8235-0000-0000-00000E2EB61E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010125; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000270; SDB=6.01123168; UDB=6.00583042; IPR=6.00903297; MB=3.00024341; MTD=3.00000008; XFM=3.00000015; UTC=2018-11-26 20:34:39 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18112620-8236-0000-0000-0000437EC9F7 Message-Id: <20181126203421.11326.5705.stgit@ltczep4-lp5.aus.stglabs.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-11-26_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811260175 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Define interface to map external powerpc cpus across multiple nodes to a range of kernel cpu values. Mapping is intended to prevent confusion within the kernel about the cpu+node mapping, and the changes in configuration that may happen due to powerpc LPAR migration or other associativity changes during the lifetime of a system. These interfaces will be used entirely within the powerpc kernel code to maintain separation between the machine and kernel contexts. Signed-off-by: Michael Bringmann --- arch/powerpc/include/asm/topology.h | 31 +++++++ arch/powerpc/platforms/pseries/Kconfig | 10 ++ arch/powerpc/platforms/pseries/Makefile | 1 arch/powerpc/platforms/pseries/cpuremap.c | 131 +++++++++++++++++++++++++++++ 4 files changed, 173 insertions(+) create mode 100644 arch/powerpc/platforms/pseries/cpuremap.c diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h index 4621f40..db11969 100644 --- a/arch/powerpc/include/asm/topology.h +++ b/arch/powerpc/include/asm/topology.h @@ -135,5 +135,36 @@ static inline void shared_proc_topology_init(void) {} #endif #endif +#define CPUREMAP_NO_CPU (~0) +#define CPUREMAP_NO_THREAD (~0) + +#ifdef CONFIG_CPUREMAP +extern int cpuremap_thread_to_cpu(int thread_index); + /* Return CPUREMAP_NO_CPU if not found */ +extern int cpuremap_map_cpu(int thread_index, int in_core_ndx, int node); + /* Return CPUREMAP_NO_CPU if fails */ +extern int cpuremap_reserve_cpu(int cpu); + /* Return CPUREMAP_NO_CPU if fails */ +extern int cpuremap_release_cpu(int cpu); + /* Return CPUREMAP_NO_CPU if fails */ +extern int cpuremap_cpu_to_thread(int cpu); + /* Return CPUREMAP_NO_THREAD if not found */ +extern void cpuremap_init(void); + /* Identify necessary constants & alloc memory at boot */ +#else +static inline int cpuremap_thread_to_cpu(int thread_index) +{ + return thread_index; +} +static inline int cpuremap_map_cpu(int thread_index, int in_core_ndx, int node) +{ + return thread_index; +} +static inline int cpuremap_reserve_cpu(int cpu) { return cpu; } +static inline int cpuremap_release_cpu(int cpu) { return cpu; } +static inline int cpuremap_cpu_to_thread(int cpu) { return cpu; } +static inline void cpuremap_init(void) {} +#endif + #endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_TOPOLOGY_H */ diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig index 2e4bd32..c35009f 100644 --- a/arch/powerpc/platforms/pseries/Kconfig +++ b/arch/powerpc/platforms/pseries/Kconfig @@ -145,3 +145,13 @@ config PAPR_SCM tristate "Support for the PAPR Storage Class Memory interface" help Enable access to hypervisor provided storage class memory. + Enable access to hypervisor provided storage class memory. + +config CPUREMAP + bool "Support for mapping hw cpu+node to kernel index" + depends on SMP && (PPC_PSERIES) + ---help--- + Say Y here to be able to remap hw cpu+node to standardized + kernel CPUs at runtime on Pseries machines. + + Say N if you are unsure. diff --git a/arch/powerpc/platforms/pseries/Makefile b/arch/powerpc/platforms/pseries/Makefile index a43ec84..ad49d8e 100644 --- a/arch/powerpc/platforms/pseries/Makefile +++ b/arch/powerpc/platforms/pseries/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_KEXEC_CORE) += kexec.o obj-$(CONFIG_PSERIES_ENERGY) += pseries_energy.o obj-$(CONFIG_HOTPLUG_CPU) += hotplug-cpu.o +obj-$(CONFIG_CPUREMAP) += cpuremap.o obj-$(CONFIG_MEMORY_HOTPLUG) += hotplug-memory.o pmem.o obj-$(CONFIG_HVC_CONSOLE) += hvconsole.o diff --git a/arch/powerpc/platforms/pseries/cpuremap.c b/arch/powerpc/platforms/pseries/cpuremap.c new file mode 100644 index 0000000..86fdf12 --- /dev/null +++ b/arch/powerpc/platforms/pseries/cpuremap.c @@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include + +struct cpuremap_cpu { + int thread_index; + /* Set to thread_index from ibm,ppc-interrupt-server#s arrays + * Don't clear when release'ed + */ + int node; + bool in_use; + /* Set to true when reserve'ed + * Don't clear when release'ed + */ +}; + +struct cpuremap_struct { + int num_nodes; + int num_cores; + int num_threads_per_core; + struct cpuremap_cpu *threads; +} cpuremap_data; + + +void cpuremap_init(void) +{ + int i, k; + + /* Identify necessary constants & alloc memory at boot */ + cpuremap_data.num_threads_per_core = 8; + cpuremap_data.num_cores = 32; + cpuremap_data.num_nodes = + nr_cpu_ids / + (cpuremap_data.num_threads_per_core * cpuremap_data.num_cores); + cpuremap_data.threads = kcalloc(nr_cpu_ids, sizeof(struct cpuremap_cpu), GFP_KERNEL); + + k = cpuremap_data.num_nodes * + cpuremap_data.num_threads_per_core * + cpuremap_data.num_cores; + for (i = 0; i < k; k++) + cpuremap_data.threads[i].thread_index = CPUREMAP_NO_THREAD; +} + +int cpuremap_thread_to_cpu(int thread_index) +{ + int i, k; + + /* Return NO_CPU if not found */ + for (i = thread_index, k = 0; k < nr_cpu_ids; k++) { + if (cpuremap_data.threads[i].in_use && + (cpuremap_data.threads[i].thread_index == thread_index)) { + cpuremap_data.threads[i].in_use = true; + cpuremap_data.threads[i].thread_index = thread_index; + return i; + } + if (i >= nr_cpu_ids) + i = 0; + } + return CPUREMAP_NO_CPU; +} + +int cpuremap_cpu_to_thread(int cpu) +{ + /* Return NO_THREAD if not found */ + if (cpuremap_data.threads[cpu].in_use) + return cpuremap_data.threads[cpu].thread_index; + return CPUREMAP_NO_THREAD; +} + +int cpuremap_map_cpu(int thread_index, int in_core_ndx, int node) +{ + int first_thread, i, k; + + /* Return NO_CPU if fails */ + first_thread = (node * + (cpuremap_data.num_threads_per_core * + cpuremap_data.num_cores)) + in_core_ndx; + + /* Alternative 0: Compressed map of cpus+nodes+threads + * assuming that no system will be fully built out. + * Alternative 1: Fully compact. Allocate new cpu ids + * as needed. No 'pretty' separation between nodes. + * Alternative 2: Also map incoming nodes from pHyp + * to virtual nodes for purposes of new cpu ids. + */ + + if (first_thread > nr_cpu_ids) + first_thread = 0 + in_core_ndx; + for (i = first_thread, k = 0; k < nr_cpu_ids; k++) { + if (!cpuremap_data.threads[i].in_use || (cpuremap_data.threads[i].thread_index == thread_index)) { + cpuremap_data.threads[i].thread_index = thread_index; + cpuremap_data.threads[i].node = node; + return i; + } + if (i >= nr_cpu_ids) + i = 0; + } + return CPUREMAP_NO_CPU; +} + +int cpuremap_reserve_cpu(int cpu) +{ + if (!cpuremap_data.threads[cpu].in_use) { + cpuremap_data.threads[cpu].in_use = true; + return cpu; + } + return CPUREMAP_NO_CPU; +} + +int cpuremap_release_cpu(int cpu) +{ + if (cpuremap_data.threads[cpu].in_use) { + cpuremap_data.threads[cpu].in_use = false; + return cpu; + } + return CPUREMAP_NO_CPU; +} + +int cpuremap_free_cpu(int cpu) +{ + /* Return NO_CPU if fails */ + if (cpuremap_data.threads[cpu].in_use) { + cpuremap_data.threads[cpu].in_use = false; + return cpu; + } + return CPUREMAP_NO_CPU; +} From patchwork Mon Nov 26 20:34:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Bringmann X-Patchwork-Id: 1003473 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 433f1D2x3gz9s29 for ; Tue, 27 Nov 2018 07:40:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 433f1D1bhVzDqNn for ; Tue, 27 Nov 2018 07:40:00 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=mwb@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 433dvV19PXzDqbx for ; Tue, 27 Nov 2018 07:35:01 +1100 (AEDT) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wAQKYAiZ073467 for ; Mon, 26 Nov 2018 15:35:00 -0500 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2p0qm8gxkt-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 26 Nov 2018 15:34:59 -0500 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 26 Nov 2018 20:34:59 -0000 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 26 Nov 2018 20:34:58 -0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wAQKYt2018088030 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 26 Nov 2018 20:34:55 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8EA2978064; Mon, 26 Nov 2018 20:34:55 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 659F27805F; Mon, 26 Nov 2018 20:34:54 +0000 (GMT) Received: from ltczep4-lp5.aus.stglabs.ibm.com (unknown [9.40.193.67]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 26 Nov 2018 20:34:54 +0000 (GMT) Received: from ltczep4-lp5.aus.stglabs.ibm.com (localhost [IPv6:::1]) by ltczep4-lp5.aus.stglabs.ibm.com (Postfix) with ESMTP id 3BC0A40CAA83; Mon, 26 Nov 2018 14:34:54 -0600 (CST) Subject: [Internal Review PATCH 3/3] powerpc/numa: Apply mapping between HW and kernel cpus From: Michael Bringmann To: Michael Bringmann , Michael Ellerman , Srikar Dronamraju , Vaidyanathan Srinivasan , Juliet Kim , Tyrel Datwyler , Thomas Falcon , linuxppc-dev@lists.ozlabs.org Date: Mon, 26 Nov 2018 14:34:54 -0600 In-Reply-To: <20181126203327.11326.32023.stgit@ltczep4-lp5.aus.stglabs.ibm.com> References: <20181126203327.11326.32023.stgit@ltczep4-lp5.aus.stglabs.ibm.com> User-Agent: StGit/0.18-105-g416a-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18112620-0020-0000-0000-00000E90804F X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010125; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000270; SDB=6.01123168; UDB=6.00583042; IPR=6.00903297; MB=3.00024341; MTD=3.00000008; XFM=3.00000015; UTC=2018-11-26 20:34:59 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18112620-0021-0000-0000-000063D8D497 Message-Id: <20181126203440.11326.53674.stgit@ltczep4-lp5.aus.stglabs.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-11-26_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811260175 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Apply new interface to map external powerpc cpus across multiple nodes to a range of kernel cpu values. Mapping is intended to prevent confusion within the kernel about the cpu+node mapping, and the changes in configuration that may happen due to powerpc LPAR migration or other associativity changes during the lifetime of a system. These interfaces exchange the thread_index provided by the 'ibm,ppc-interrupt-server#s' properties, for an internal index to be used by kernel scheduling interfaces. Signed-off-by: Michael Bringmann --- arch/powerpc/mm/numa.c | 45 +++++++++++++++++--------- arch/powerpc/platforms/pseries/hotplug-cpu.c | 15 +++++++-- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c index 460d60f..9825fc9 100644 --- a/arch/powerpc/mm/numa.c +++ b/arch/powerpc/mm/numa.c @@ -1063,7 +1063,8 @@ u64 memory_hotplug_max(void) struct topology_update_data { struct topology_update_data *next; - unsigned int cpu; + unsigned int old_cpu; + unsigned int new_cpu; int old_nid; int new_nid; }; @@ -1253,13 +1254,13 @@ static int update_cpu_topology(void *data) for (update = data; update; update = update->next) { int new_nid = update->new_nid; - if (cpu != update->cpu) + if (cpu != update->new_cpu) continue; - unmap_cpu_from_node(cpu); - map_cpu_to_node(cpu, new_nid); - set_cpu_numa_node(cpu, new_nid); - set_cpu_numa_mem(cpu, local_memory_node(new_nid)); + unmap_cpu_from_node(update->old_cpu); + map_cpu_to_node(update->new_cpu, new_nid); + set_cpu_numa_node(update->new_cpu, new_nid); + set_cpu_numa_mem(update->new_cpu, local_memory_node(new_nid)); vdso_getcpu_init(); } @@ -1283,7 +1284,7 @@ static int update_lookup_table(void *data) int nid, base, j; nid = update->new_nid; - base = cpu_first_thread_sibling(update->cpu); + base = cpu_first_thread_sibling(update->new_cpu); for (j = 0; j < threads_per_core; j++) { update_numa_cpu_lookup_table(base + j, nid); @@ -1305,7 +1306,7 @@ int numa_update_cpu_topology(bool cpus_locked) struct topology_update_data *updates, *ud; cpumask_t updated_cpus; struct device *dev; - int weight, new_nid, i = 0; + int weight, new_nid, i = 0, ii; if (!prrn_enabled && !vphn_enabled && topology_inited) return 0; @@ -1349,12 +1350,16 @@ int numa_update_cpu_topology(bool cpus_locked) continue; } + ii = 0; for_each_cpu(sibling, cpu_sibling_mask(cpu)) { ud = &updates[i++]; ud->next = &updates[i]; - ud->cpu = sibling; ud->new_nid = new_nid; ud->old_nid = numa_cpu_lookup_table[sibling]; + ud->old_cpu = sibling; + ud->new_cpu = cpuremap_map_cpu( + get_hard_smp_processor_id(sibling), + ii++, new_nid); cpumask_set_cpu(sibling, &updated_cpus); } cpu = cpu_last_thread_sibling(cpu); @@ -1370,9 +1375,10 @@ int numa_update_cpu_topology(bool cpus_locked) pr_debug("Topology update for the following CPUs:\n"); if (cpumask_weight(&updated_cpus)) { for (ud = &updates[0]; ud; ud = ud->next) { - pr_debug("cpu %d moving from node %d " - "to %d\n", ud->cpu, - ud->old_nid, ud->new_nid); + pr_debug("cpu %d, node %d moving to" + " cpu %d, node %d\n", + ud->old_cpu, ud->old_nid, + ud->new_cpu, ud->new_nid); } } @@ -1409,13 +1415,20 @@ int numa_update_cpu_topology(bool cpus_locked) cpumask_of(raw_smp_processor_id())); for (ud = &updates[0]; ud; ud = ud->next) { - unregister_cpu_under_node(ud->cpu, ud->old_nid); - register_cpu_under_node(ud->cpu, ud->new_nid); + unregister_cpu_under_node(ud->old_cpu, ud->old_nid); + register_cpu_under_node(ud->new_cpu, ud->new_nid); - dev = get_cpu_device(ud->cpu); + dev = get_cpu_device(ud->old_cpu); if (dev) kobject_uevent(&dev->kobj, KOBJ_CHANGE); - cpumask_clear_cpu(ud->cpu, &cpu_associativity_changes_mask); + cpumask_clear_cpu(ud->old_cpu, &cpu_associativity_changes_mask); + if (ud->old_cpu != ud->new_cpu) { + dev = get_cpu_device(ud->new_cpu); + if (dev) + kobject_uevent(&dev->kobj, KOBJ_CHANGE); + cpumask_clear_cpu(ud->new_cpu, + &cpu_associativity_changes_mask); + } changed = 1; } diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c index 620cb57..3a11a31 100644 --- a/arch/powerpc/platforms/pseries/hotplug-cpu.c +++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c @@ -259,8 +259,13 @@ static int pseries_add_processor(struct device_node *np) zalloc_cpumask_var(&tmp, GFP_KERNEL); nthreads = len / sizeof(u32); - for (i = 0; i < nthreads; i++) - cpumask_set_cpu(i, tmp); + for (i = 0; i < nthreads; i++) { + int thread_index = be32_to_cpu(intserv[i]); + int nid = find_and_online_cpu_nid(thread_index, false); + int cpu = cpuremap_map_cpu(thread_index, i, nid); + cpumask_set_cpu(cpu, tmp); + cpuremap_reserve_cpu(cpu); + } cpu_maps_update_begin(); @@ -333,6 +338,7 @@ static void pseries_remove_processor(struct device_node *np) set_cpu_present(cpu, false); set_hard_smp_processor_id(cpu, -1); update_numa_cpu_lookup_table(cpu, -1); + cpuremap_release_cpu(cpu); break; } if (cpu >= nr_cpu_ids) @@ -346,7 +352,7 @@ static int dlpar_online_cpu(struct device_node *dn) { int rc = 0; unsigned int cpu; - int len, nthreads, i; + int len, nthreads, i, nid; const __be32 *intserv; u32 thread; @@ -367,9 +373,11 @@ static int dlpar_online_cpu(struct device_node *dn) cpu_maps_update_done(); timed_topology_update(1); find_and_online_cpu_nid(cpu, true); + cpuremap_map_cpu(thread, i, nid); rc = device_online(get_cpu_device(cpu)); if (rc) goto out; + cpuremap_reserve_cpu(cpu); cpu_maps_update_begin(); break; @@ -541,6 +549,7 @@ static int dlpar_offline_cpu(struct device_node *dn) rc = device_offline(get_cpu_device(cpu)); if (rc) goto out; + cpuremap_release_cpu(cpu); cpu_maps_update_begin(); break;