From patchwork Thu Mar 15 04:41:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 886118 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 401wzc0TBBz9sCV for ; Thu, 15 Mar 2018 15:46:52 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Vn+Ht51n"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 401wzb5crwzF0qS for ; Thu, 15 Mar 2018 15:46:51 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Vn+Ht51n"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c00::241; helo=mail-pf0-x241.google.com; envelope-from=kernelfans@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Vn+Ht51n"; dkim-atps=neutral Received: from mail-pf0-x241.google.com (mail-pf0-x241.google.com [IPv6:2607:f8b0:400e:c00::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 401wt86KCyzF12j for ; Thu, 15 Mar 2018 15:42:08 +1100 (AEDT) Received: by mail-pf0-x241.google.com with SMTP id u5so2400763pfh.6 for ; Wed, 14 Mar 2018 21:42:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9AnwKwgkFl4bcUGR/MG23titnRy+Z3eFGwMsSTNh8OA=; b=Vn+Ht51nS2ISdkCfzLPVCuEB2yBbudQIPc8icGeUce6GTt+YnquNIcrKIslmnUsh9j 6A2xpu3EkY+jeejo3cYFw5jCSoHWhaioCnBtzbx9hpeHALH95uZ/NkVmG/OlzxfdbL0h 8hYgSLpGSdcD/FGtCJgbh0drmw9xpsGiiAb205rRMYXI2vDhbJVgurL35vY0q9SCkQ3s 1RuIkMMR53dRqt8S5gy2PcVxac1+znBSddbSAV1BWFnNRglDBFiBFuWz1KojEqeY4On0 u7PzhlBxxG2+sE/t8oRn0vA86AgI4aCmxwpufxh4yE1FlhDRRDDZC9E3PjZTszzYFT1Y +GpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9AnwKwgkFl4bcUGR/MG23titnRy+Z3eFGwMsSTNh8OA=; b=O1J7xSHnxPP4Kw/SL4EAv51jfpVuXWfiEd9jmfhQ4hzzwVTWllDvEztDP5+FknlmXX SbjVThYQHP3gdENrTvL5Dgb20yASDBCVKMQdd8QnvkLZ7rDFM7IoutIpqWlq4ycEb/xO w347zrhPdEejtTVLpngf1uuIqRNHb7P2OHAIcOA3u6WgItHYAxSBZaOC1SWRPp7AZ9Lo y/nNEIsDfkkfMxZSxma9VmjcghFfeMA/f4YxCCBTwCKOoZuUhNkY43D/08m489YAb0Sx hIgoKvloFGjQ5G/fKvFqd6w4reSdkmiC3CjxD+UOGofU9+SgyuTEdC0suYa1UweDL+qj JKFA== X-Gm-Message-State: AElRT7EPPN7SfHtvSIn7qcqNOmO7b1kZVTmbCiWKQBP7WSyAYNL7fzd/ CbBtd/Dd8XA0MzE8voefxBqw X-Google-Smtp-Source: AG47ELuTfU2FqykAD83h52uxLw3iV7Njg7a5Qim+T3Hxy1SdWFZetP9H+wdI1tM2XJhdsn4t2BgsBQ== X-Received: by 10.99.125.19 with SMTP id y19mr5702526pgc.125.1521088926650; Wed, 14 Mar 2018 21:42:06 -0700 (PDT) Received: from mylaptop.nay.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id v4sm6856781pgq.8.2018.03.14.21.42.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 21:42:06 -0700 (PDT) From: Pingfan Liu To: linuxppc-dev@lists.ozlabs.org Subject: [PATCHv5 1/3] powerpc, cpu: partially unbind the mapping between cpu logical id and its seq in dt Date: Thu, 15 Mar 2018 12:41:50 +0800 Message-Id: <1521088912-31742-2-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521088912-31742-1-git-send-email-kernelfans@gmail.com> References: <1521088912-31742-1-git-send-email-kernelfans@gmail.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cascardo@canonical.com, gpiccoli@linux.vnet.ibm.com, kexec@lists.infradead.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" For kexec -p, the boot cpu can be not the cpu0, this causes the problem to alloc paca[]. In theory, there is no requirement to assign cpu's logical id as its present seq by device tree. But we have something like cpu_first_thread_sibling(), which makes assumption on the mapping inside a core. Hence partially changing the mapping, i.e. unbind the mapping of core while keep the mapping inside a core. After this patch, boot-cpu will always be mapped into the range [0,threads_per_core). Signed-off-by: Pingfan Liu --- arch/powerpc/include/asm/smp.h | 2 ++ arch/powerpc/kernel/prom.c | 27 ++++++++++++++++----------- arch/powerpc/kernel/setup-common.c | 28 +++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h index fac963e..920a927 100644 --- a/arch/powerpc/include/asm/smp.h +++ b/arch/powerpc/include/asm/smp.h @@ -30,6 +30,8 @@ #include extern int boot_cpuid; +extern int boot_cpuhwid; +extern int boot_dn_nthreads; extern int spinning_secondaries; extern void cpu_die(void); diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index da67606..aca15c1 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -315,8 +315,7 @@ static int __init early_init_dt_scan_cpus(unsigned long node, const __be32 *intserv; int i, nthreads; int len; - int found = -1; - int found_thread = 0; + bool found = false; /* We are scanning "cpu" nodes only */ if (type == NULL || strcmp(type, "cpu") != 0) @@ -341,8 +340,12 @@ static int __init early_init_dt_scan_cpus(unsigned long node, if (fdt_version(initial_boot_params) >= 2) { if (be32_to_cpu(intserv[i]) == fdt_boot_cpuid_phys(initial_boot_params)) { - found = boot_cpu_count; - found_thread = i; + /* always map the boot-cpu logical id into the + * the range of [0, thread_per_core) + */ + boot_cpuid = i; + boot_dn_nthreads = nthreads; + found = true; } } else { /* @@ -351,8 +354,11 @@ static int __init early_init_dt_scan_cpus(unsigned long node, * off secondary threads. */ if (of_get_flat_dt_prop(node, - "linux,boot-cpu", NULL) != NULL) - found = boot_cpu_count; + "linux,boot-cpu", NULL) != NULL) { + boot_cpuid = i; + boot_dn_nthreads = nthreads; + found = true; + } } #ifdef CONFIG_SMP /* logical cpu id is always 0 on UP kernels */ @@ -361,13 +367,12 @@ static int __init early_init_dt_scan_cpus(unsigned long node, } /* Not the boot CPU */ - if (found < 0) + if (!found) return 0; - DBG("boot cpu: logical %d physical %d\n", found, - be32_to_cpu(intserv[found_thread])); - boot_cpuid = found; - set_hard_smp_processor_id(found, be32_to_cpu(intserv[found_thread])); + boot_cpuhwid = be32_to_cpu(intserv[boot_cpuid]); + DBG("boot cpu: logical %d physical %d\n", boot_cpuid, boot_cpuhwid); + set_hard_smp_processor_id(boot_cpuid, boot_cpuhwid); /* * PAPR defines "logical" PVR values for cpus that diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c index 66f7cc6..a683ed1 100644 --- a/arch/powerpc/kernel/setup-common.c +++ b/arch/powerpc/kernel/setup-common.c @@ -86,7 +86,11 @@ struct machdep_calls *machine_id; EXPORT_SYMBOL(machine_id); int boot_cpuid = -1; +int boot_cpuhwid = -1; +int boot_dn_nthreads = -1; EXPORT_SYMBOL_GPL(boot_cpuid); +EXPORT_SYMBOL_GPL(boot_cpuhwid); +EXPORT_SYMBOL_GPL(boot_dn_nthreads); /* * These are used in binfmt_elf.c to put aux entries on the stack @@ -461,6 +465,9 @@ void __init smp_setup_cpu_maps(void) struct device_node *dn; int cpu = 0; int nthreads = 1; + int online_num = 0; + int next_cpu = boot_dn_nthreads; + bool btdn_handled = false; DBG("smp_setup_cpu_maps()\n"); @@ -488,7 +495,21 @@ void __init smp_setup_cpu_maps(void) nthreads = len / sizeof(int); - for (j = 0; j < nthreads && cpu < nr_cpu_ids; j++) { + if (boot_cpuid < nthreads && + be32_to_cpu(intserv[boot_cpuid]) == boot_cpuhwid) { + cpu = 0; + btdn_handled = true; + } else if ( !btdn_handled && + nr_cpu_ids - online_num <= boot_dn_nthreads) + /* online threads in boot dn before using up quota */ + continue; + else { + cpu = next_cpu; + next_cpu += nthreads; + } + + + for (j = 0; j < nthreads && online_num < nr_cpu_ids; j++) { bool avail; DBG(" thread %d -> cpu %d (hard id %d)\n", @@ -503,12 +524,13 @@ void __init smp_setup_cpu_maps(void) set_hard_smp_processor_id(cpu, be32_to_cpu(intserv[j])); set_cpu_possible(cpu, true); cpu++; + online_num++; } - - if (cpu >= nr_cpu_ids) { + if (online_num >= nr_cpu_ids) { of_node_put(dn); break; } + } /* If no SMT supported, nthreads is forced to 1 */