From nobody Thu May 2 22:01:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+70757+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+70757+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1611640221; cv=none; d=zohomail.com; s=zohoarc; b=FiFLfHBBQvpzYPeIh6+6G8AC2U8vd757C0hY6SF/knO1H5I64Y05EdS4o9cyhJiQRllv+05ms/xMqJRXPrSv1H7Svqszc6/qdPV5nPpn29RU3RdTBw5hepjPsh4K8LbY2ofGuP8d2l/Hc3fgJBvFEzECi/nkBx00RXILJ21Cz6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611640221; h=Content-Transfer-Encoding:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=VgYYDAwCxagqabeavwXH/e/XNmMc3cxJHQnMtl2W/rE=; b=R7Os3p0qnxcixi2CNYmWZPzMdPQQ5ArdBcmVJ6B/u1RiVM+bBou8aCBfhE4arUJ9dNMoInUaKjnajGCiJopBlsUmHRiFS0soVwyosfN5MnnUSEi4DbCLp94p9VPWpQ4yCMLKFglOdJh2wm4UU9rZwhFi3zolVMq53MikoaObfxY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+70757+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1611640221065568.2260539305952; Mon, 25 Jan 2021 21:50:21 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id uGqoYY1788612xu4roS0u1Y1; Mon, 25 Jan 2021 21:50:20 -0800 X-Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web12.8499.1611640220106690392 for ; Mon, 25 Jan 2021 21:50:20 -0800 IronPort-SDR: EY99ozFP7LO3QBhK0sxJU8+KG/VgNBBug7ZCaQPZse8F9uojpemWHvfu0w6qZFP2ZXZz2dsa3Z qpv4U9fqVXkg== X-IronPort-AV: E=McAfee;i="6000,8403,9875"; a="264676090" X-IronPort-AV: E=Sophos;i="5.79,375,1602572400"; d="scan'208";a="264676090" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2021 21:50:18 -0800 IronPort-SDR: 2ZcmBJ5i/mHR9fike95WKQdeArxCSMDs+vzM8x42SNKk2n+CvzPYPfAWLiAZKBwqK193n/IRGi Zo9J5Corkk7A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,375,1602572400"; d="scan'208";a="429578385" X-Received: from ray-dev.ccr.corp.intel.com ([10.239.158.87]) by orsmga001.jf.intel.com with ESMTP; 25 Jan 2021 21:50:17 -0800 From: "Ni, Ray" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Don't increase CpuCount in ApWakeupFunction Date: Tue, 26 Jan 2021 13:50:15 +0800 Message-Id: <20210126055015.633-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ray.ni@intel.com X-Gm-Message-State: co9AsACOXhutmwdOoUHM5WX5x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1611640220; bh=kYdsrm6R60H7SeQKltTwyzwLqtxo4FwJTsarTzrSTqo=; h=Date:From:Reply-To:Subject:To; b=hlFOZqlrA4o2SHKxW180Y6rpQZ5ahUJvj/gl6rqzcC12psnW+kw5N9AgthvihphVKki aztTY0iYDPCoFuz3Oe7ZLkdx7y5NYOsYzwIWomyV7iVpg+ECKAkEUWM8undXLDIZtN74f qHPOFQLkPaur4AKO27j2TEjxv04SaGmJUd8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3179 When BSP first time wakes all APs, each AP atomically increases CpuMpData->CpuCount and CpuMpData->FinishedCount. Each AP atomically increases CpuMpData->NumApsExecuting in early assembly code and decreases it before it enters to HLT or MWAIT state. Putting them together, the 3 variables are changed in the following order: 1. NumApsExecuting++ // in assembly 2. CpuCpunt++ 4. FinishedCount++ 3. NumApsExecuting-- // in C BSP waits for a certain timeout and then polls NumApsExecuting until it drops to zero. It assumes all APs are waken up concurrently and NumApsExecuting only drops to zero when all APs have checked in. Then it additionally waits for FinishedCount =3D=3D CpuCount - 1. (FinishedCount doesn't include BSP while CpuCount includes BSP.) There is no need to additionally wait for FinishedCount =3D=3D CpuCount - 1 because when NumApsExecuting =3D=3D 0, the number of increments of FinishedCount and CpuCount should equal. This patch simplifies the code to remove "CpuCount++" in ApWakeupFunction() and assigns FinishedCount + 1 to CpuCount after WakeUpAP(). Signed-off-by: Ray Ni Acked-by: Laszlo Ersek --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 8b1f7f84ba..2568986d8c 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1,7 +1,7 @@ /** @file CPU MP Initialize Library common functions. =20 - Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2021, Intel Corporation. All rights reserved.
Copyright (c) 2020, AMD Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -485,14 +485,12 @@ CollectProcessorCount ( CpuMpData->InitFlag =3D ApInitConfig; WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE); CpuMpData->InitFlag =3D ApInitDone; - ASSERT (CpuMpData->CpuCount <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumb= er)); // - // Wait for all APs finished the initialization + // When InitFlag =3D=3D ApInitConfig, WakeUpAP () guarantees all APs are= checked in. + // FinishedCount is the number of check-in APs. // - while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) { - CpuPause (); - } - + CpuMpData->CpuCount =3D CpuMpData->FinishedCount + 1; + ASSERT (CpuMpData->CpuCount <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumb= er)); =20 // // Enable x2APIC mode if @@ -751,10 +749,6 @@ ApWakeupFunction ( CurrentApicMode =3D GetApicMode (); while (TRUE) { if (CpuMpData->InitFlag =3D=3D ApInitConfig) { - // - // Add CPU number - // - InterlockedIncrement ((UINT32 *) &CpuMpData->CpuCount); ProcessorNumber =3D ApIndex; // // This is first time AP wakeup, get BIST information from AP stack --=20 2.27.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#70757): https://edk2.groups.io/g/devel/message/70757 Mute This Topic: https://groups.io/mt/80124850/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-