Received: by 10.213.65.68 with SMTP id h4csp305711imn; Tue, 20 Mar 2018 04:09:15 -0700 (PDT) X-Google-Smtp-Source: AG47ELsDxc4gW/Kmz0/h2wz3Z3B2I0X5g26Qi7K8ckWzpxeNLqbPAH/SGl7bpciran7gunKCvc3F X-Received: by 10.99.100.132 with SMTP id y126mr11584112pgb.77.1521544155319; Tue, 20 Mar 2018 04:09:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521544155; cv=none; d=google.com; s=arc-20160816; b=0roUeejduRUX76ry/ZZdDSwFuLo+j2/1VWSeMa4gQ6XobBr/RRhN4PX7/4YHheoo2T 5jdQlPgc+KOCc5INncK51XUv428cX2e2Gr4bfOLQ7WZxbv0Jjf7olMOdkk1av3YbYbO9 Q1OTvzu/cLrR81YfSzQdZlNW1tm1QuSPlFdogYG7BDVmIva7xYLqqCh2X89OiIJ31JlH tU9ePrFeN78PsltkNWtPNazw54ig8ceZvBke2KwF7zqr6l1Gw4wPryIwcMreXDX2Tkpq w4TCPyeNFp5azgGGF1Dl3ncwxzyHdMATbdJRM+hoRePZLzOqRg+tCPg6XNABOS2LopcR V/EQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=cO/ytQwWCKDZLkGgG1/Sy36riErl2WJiB0+7pfChdsQ=; b=a+sgZ88kLp/E/XF8wQQKrscTo5Xh4V5Ujf0YPUbR3YyTyrWz9gBBx3A4LCdXHQliju MgR3HxgOvvbMRsKtacvYJ0C4+N+feNwj9BQCgkYxnZo9EhUUZu81V9n3CDi3C8UnIObN y23EdC2GMrY0xv/1Bu2B0y4kpWa9GICaYq38em8CHJzbsywFbu5se8j+bVo22TAyR/je oF5OuQ2TlWCz74Cqi6EbOAYw7AoM2XYtWABnvRXW8S6J8iTpZBN7iavMC2+I6tfQQ7uL VNKWaSOIjX9MyUioEIAQwcav+p9bCQzVh6kSPgWumWuNmBLEA2GkWCE/iNhwtfjHB29Q KT/g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3-v6si1458591plb.147.2018.03.20.04.09.01; Tue, 20 Mar 2018 04:09:15 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752838AbeCTLHU (ORCPT + 99 others); Tue, 20 Mar 2018 07:07:20 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:43692 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752843AbeCTLFT (ORCPT ); Tue, 20 Mar 2018 07:05:19 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38002752" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 20 Mar 2018 19:05:12 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 55ECE48AE76E; Tue, 20 Mar 2018 19:05:13 +0800 (CST) Received: from localhost.localdomain (10.167.226.106) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 20 Mar 2018 19:05:12 +0800 From: Dou Liyang To: , , , CC: , , , , , , , Dou Liyang Subject: [PATCH 3/5] x86/smpboot: Make the check code more clear in prefill_possible_map() Date: Tue, 20 Mar 2018 19:04:30 +0800 Message-ID: <20180320110432.28127-4-douly.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180320110432.28127-1-douly.fnst@cn.fujitsu.com> References: <20180320110432.28127-1-douly.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.167.226.106] X-yoursite-MailScanner-ID: 55ECE48AE76E.A2F08 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: douly.fnst@cn.fujitsu.com X-Spam-Status: No Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In prefill_possible_map(), Kernel need to get the number of possible CPUs to reset cpu_possible_map. The number is related to the options: -nosmp, maxcpus, possible_cpus, nr_cpus ... which need to be checked. Currentlly, the check code mixed these options together in confusion and hard to follow. Isolate them, and check them linearly. No functionary change, Prepare for cutting the number of possible CPUs Signed-off-by: Dou Liyang --- Situations: setup_possible_cpus == -1 | setup_max_cpus == 0 | CONFIG_HOTPLUG_CPU == y | yes | yes | yes | no | no | no | Test cases: Cases | the number of possible cpus | (the same with or w/o this patch) case 1: no | no | no | --> min (setup_possible_cpus, nr_cpu_ids, setup_max_cpus) case 2: no | no | yes| --> min (setup_possible_cpus, nr_cpu_ids) case 3: no | yes | no | --> 1 case 4: no | yes | yes| --> 1 case 5: yes | no | no | --> min (num_processors, nr_cpu_ids, setup_max_cpus) case 6: yes | no | yes| --> min (num_processors + disabled_cpus, nr_cpu_ids) case 7: yes | yes | no | --> 1 case 8: yes | yes | yes| --> 1 arch/x86/kernel/smpboot.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index ff99e2b6fc54..2fdda8567bf9 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1334,7 +1334,7 @@ early_param("possible_cpus", _setup_possible_cpus); * We do this because additional CPUs waste a lot of memory. * -AK */ -__init void prefill_possible_map(void) +void __init prefill_possible_map(void) { int i, possible; @@ -1356,18 +1356,22 @@ __init void prefill_possible_map(void) num_processors = 1; } - i = setup_max_cpus ?: 1; + /* The SMP kernel could be acted as an UP kernel via nosmp/maxcpus=0 */ + if (!setup_max_cpus) { + possible = 1; + total_cpus = num_processors + disabled_cpus; + goto set_cpu_possible_mask; + } + + /* Possible CPUs could be overwrited via possible_cpus= */ if (setup_possible_cpus == -1) { possible = num_processors; #ifdef CONFIG_HOTPLUG_CPU - if (setup_max_cpus) - possible += disabled_cpus; -#else - if (possible > i) - possible = i; + possible += disabled_cpus; #endif - } else + } else { possible = setup_possible_cpus; + } total_cpus = max_t(int, possible, num_processors + disabled_cpus); @@ -1378,15 +1382,16 @@ __init void prefill_possible_map(void) possible = nr_cpu_ids; } -#ifdef CONFIG_HOTPLUG_CPU - if (!setup_max_cpus) -#endif - if (possible > i) { +#ifndef CONFIG_HOTPLUG_CPU + /* Possible CPUs could be reduced via max_cpus= */ + if (possible > setup_max_cpus) { pr_warn("%d Processors exceeds max_cpus limit of %u\n", possible, setup_max_cpus); - possible = i; + possible = setup_max_cpus; } +#endif +set_cpu_possible_mask: nr_cpu_ids = possible; pr_info("Allowing %d CPUs, %d hotplug CPUs\n", -- 2.14.3