Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 992DEC678D4 for ; Thu, 2 Mar 2023 11:13:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229496AbjCBLNK (ORCPT ); Thu, 2 Mar 2023 06:13:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230090AbjCBLM7 (ORCPT ); Thu, 2 Mar 2023 06:12:59 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DC10474E9 for ; Thu, 2 Mar 2023 03:12:41 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id l1so13087755wry.12 for ; Thu, 02 Mar 2023 03:12:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fjaPxTScJQKrmxiNh0XTGCcM5SrXr13nzGyox6O6Tb4=; b=QedY7l1048mHFXQ04p0kjVwEhd2KV7AWq0BncDQ9CN/9BF0iWZfOv9h+D97kNQWA0e +JEqrsePeYClkEXvAh/r/Cf6R0qpOY7Ip91F/6HQ1s6GEtCs+W/pYtvsmM7GdM6hZXOa ythSCUbkUvrp+QZBrbxBQGbA2QzHILmatulSjak83FxP5AI+oihv15S3Rk6i2zGrtGzu K0l1ov1u7fws5BRkzOEXLJPOhJQkauNSEkOmP+i1p91ORgGDeXlnzcisPgh2shhL1Lq2 6Y60vP1cwM/yJ0SOs68j7hBRL4QEvZF0QR0mBa+HD0CRqy+wfYXB2sOpm8hX4v0e0fST OOSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fjaPxTScJQKrmxiNh0XTGCcM5SrXr13nzGyox6O6Tb4=; b=hmRQQF4OnUf6yOrQ6nrX6YzncVoCV/d/vXEE1nR8G4mcxtb7+SWG0H7cxmYB52krgu tJ2yH7rt/jEYDEW8hMg/C6250nWJIYTrFX//ilKQapww2xonsF43qntnr4gaMPPHCtQ1 1kaVAw2y4lj5y6uQ2E7BeAuTpjEtThvatjAPlgCmQLLPiOjbuApog8nsGw8zWhk2MFQS 6FNSkBJ1u46vcgfoH/n7V4mjkj34o02wSOje7UClHAI7uU+pD7d3J16PHO7lZe8qexcs tMH6a8r/VgtNBWCVLT4lSKOdEQKp6Bv2GjN74PMqj+FjWdyFf9HjJKakDNe/BjRLT0MK uojQ== X-Gm-Message-State: AO0yUKVLav++4mF8bY5YGP/9IvIo5xvx7iRH+rjFDJSPfik1V9AXbm1s kiy3MyNJAeJzFzKf7yG4tyiArQ== X-Google-Smtp-Source: AK7set9Zhcs8c9rgVDsEr78zIqMYgJUQFdbkcC7AFzxvgSlepHG68d6PrS72KSexNTuGNtbJJr2rrw== X-Received: by 2002:a05:6000:512:b0:2cc:243a:35be with SMTP id a18-20020a056000051200b002cc243a35bemr6239461wrf.52.1677755560577; Thu, 02 Mar 2023 03:12:40 -0800 (PST) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6a:b566:0:11aa:3c13:d3e:eb29]) by smtp.gmail.com with ESMTPSA id a5-20020a5d4565000000b002c3f81c51b6sm14724830wrc.90.2023.03.02.03.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 03:12:40 -0800 (PST) From: Usama Arif To: dwmw2@infradead.org, tglx@linutronix.de, kim.phillips@amd.com, brgerst@gmail.com Cc: piotrgorski@cachyos.org, oleksandr@natalenko.name, arjan@linux.intel.com, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, x86@kernel.org, pbonzini@redhat.com, paulmck@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, rcu@vger.kernel.org, mimoja@mimoja.de, hewenliang4@huawei.com, thomas.lendacky@amd.com, seanjc@google.com, pmenzel@molgen.mpg.de, fam.zheng@bytedance.com, punit.agrawal@bytedance.com, simon.evans@bytedance.com, liangma@liangbit.com, David Woodhouse , Usama Arif , "Guilherme G . Piccoli" Subject: [PATCH v13 10/11] x86/smpboot: Send INIT/SIPI/SIPI to secondary CPUs in parallel Date: Thu, 2 Mar 2023 11:12:26 +0000 Message-Id: <20230302111227.2102545-11-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230302111227.2102545-1-usama.arif@bytedance.com> References: <20230302111227.2102545-1-usama.arif@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Woodhouse When the APs can find their own APIC ID without assistance, perform the AP bringup in parallel. Register a CPUHP_BP_PARALLEL_DYN stage "x86/cpu:kick" which just calls do_boot_cpu() to deliver INIT/SIPI/SIPI to each AP in turn before the normal native_cpu_up() does the rest of the hand-holding. The APs will then take turns through the real mode code (which has its own bitlock for exclusion) until they make it to their own stack, then proceed through the first few lines of start_secondary() and execute these parts in parallel: start_secondary() -> cr4_init() -> (some 32-bit only stuff so not in the parallel cases) -> cpu_init_secondary() -> cpu_init_exception_handling() -> cpu_init() -> wait_for_master_cpu() At this point they wait for the BSP to set their bit in cpu_callout_mask (from do_wait_cpu_initialized()), and release them to continue through the rest of cpu_init() and beyond. This reduces the time taken for bringup on my 28-thread Haswell system from about 120ms to 80ms. On a socket 96-thread Skylake it takes the bringup time from 500ms to 100ms. There is more speedup to be had by doing the remaining parts in parallel too — especially notify_cpu_starting() in which the AP takes itself through all the stages from CPUHP_BRINGUP_CPU to CPUHP_ONLINE. But those require careful auditing to ensure they are reentrant, before we can go that far. Signed-off-by: David Woodhouse Signed-off-by: Usama Arif Tested-by: Paul E. McKenney Tested-by: Kim Phillips Tested-by: Oleksandr Natalenko Tested-by: Guilherme G. Piccoli --- arch/x86/kernel/smpboot.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 19b9b89b7458..711573cd9b87 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -57,6 +57,7 @@ #include #include #include +#include #include #include @@ -1325,9 +1326,12 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle) { int ret; - ret = do_cpu_up(cpu, tidle); - if (ret) - return ret; + /* If parallel AP bringup isn't enabled, perform the first steps now. */ + if (!do_parallel_bringup) { + ret = do_cpu_up(cpu, tidle); + if (ret) + return ret; + } ret = do_wait_cpu_initialized(cpu); if (ret) @@ -1349,6 +1353,12 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle) return ret; } +/* Bringup step one: Send INIT/SIPI to the target AP */ +static int native_cpu_kick(unsigned int cpu) +{ + return do_cpu_up(cpu, idle_thread_get(cpu)); +} + /** * arch_disable_smp_support() - disables SMP support for x86 at runtime */ @@ -1566,6 +1576,11 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus) smpboot_control = STARTUP_APICID_CPUID_01; } + if (do_parallel_bringup) { + cpuhp_setup_state_nocalls(CPUHP_BP_PARALLEL_DYN, "x86/cpu:kick", + native_cpu_kick, NULL); + } + snp_set_wakeup_secondary_cpu(); } -- 2.25.1