From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web12.19587.1611804422915711136 for ; Wed, 27 Jan 2021 19:27:03 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=n73d8u7K; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: ray.ni@intel.com) IronPort-SDR: RqWRM/VTHpxK6yivVKGFkgJ2DuyI3bwXFNd1qhEvIGJVKJ2x+6hsnsltjEHgV4Zbz+inYEufql sez3OAKPgvYQ== X-IronPort-AV: E=McAfee;i="6000,8403,9877"; a="167270346" X-IronPort-AV: E=Sophos;i="5.79,381,1602572400"; d="scan'208";a="167270346" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 19:27:01 -0800 IronPort-SDR: /lao9whUDWxkiGA432F/vZyjjJDPeja86BWmlw03hoxGIyReYDu/O8oOfv0fKYnTqOz/MiMYay VnB1XpKDiTiw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,381,1602572400"; d="scan'208";a="407363207" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmsmga002.fm.intel.com with ESMTP; 27 Jan 2021 19:27:01 -0800 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Wed, 27 Jan 2021 19:27:00 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2 via Frontend Transport; Wed, 27 Jan 2021 19:27:00 -0800 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.43) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Wed, 27 Jan 2021 19:26:59 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aNvg8Je9QORG4HRHe9+y4jTKTLqtRZ2QpxjZfJROwK/BRuZsFyJbwySr+POF/dyH2K8y+Udpv4d9ISDCI9QtYSbh5BjnkeAPYyOxmSxX1wiZ4RpmD5/Pevamiswmsp8EPcfAGR/8dnOW4VZGcbjKzbdtXo42ur6dTsmCT8AJDdTRViyzOULRAp3ztq6oIpFKHlY0Ir8eKI9U5R/95scnxNwDMm9JLUnRCdtWY8fUCFZXwbWS0lEQO/1THpCz2sUiTetkLuoBMpMAUqq7/Po+HvHQ8WMiKDvX+8htdoXQT1c0RzLDBl7C6zgR6EI/K2y5zeyGOaf0onCUudh8sdw0jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=s9ESc1fmdOrGdkyAboPv6FIOt/AdLKibX9Wq1n/hoQo=; b=fc6DdHZkibArJwsXtmt5/Fd4wr3aO8RzTy5lKnbtrvy2UGuyeiFtTubE4kQvQ/tRZOtW98yQlmxEOJltJ1egimcK57UeuA2p8RGM31fpXrPdsFrCObBYaZpgbWjQBnL5SEEo/KRliCWrfyfzjHmxrIBNOPd4m0oTn4EH+UcHHjph+/bFXuBoVcq/7Xg1xGxy4Gw49UjvOole2cB4MyRCPdjSjI7ftdGkWYuFDfrByCIgBuJ1OvHTW8TB29RmOufI1w5FDKwGGicbbSsbVhrQMH0HAu0dHf46SuYD+pBovrOFTlTHQmdJK4A3xo5e3840l6iEwZZyoFpEdOOmagS/mQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=s9ESc1fmdOrGdkyAboPv6FIOt/AdLKibX9Wq1n/hoQo=; b=n73d8u7KDggudMTUOO3HQEW6beyL90Q9hxjQjtZCBYf10I48/DRdT5KtYG+wvPM9kMEwP9FjmVVcCSMqgioIThIX0iAkxi1GJcJqnZoCoofmwF+5osyeK5bfNJJRJ3OQsjwLm1nsibSTM36fmxI0shsHAnKUihZgDWsakGJXyuc= Received: from CO1PR11MB4930.namprd11.prod.outlook.com (2603:10b6:303:9b::11) by MWHPR11MB1616.namprd11.prod.outlook.com (2603:10b6:301:d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.12; Thu, 28 Jan 2021 03:26:59 +0000 Received: from CO1PR11MB4930.namprd11.prod.outlook.com ([fe80::8d64:91ed:c259:e95]) by CO1PR11MB4930.namprd11.prod.outlook.com ([fe80::8d64:91ed:c259:e95%6]) with mapi id 15.20.3805.016; Thu, 28 Jan 2021 03:26:59 +0000 From: "Ni, Ray" To: "Dong, Eric" , Laszlo Ersek , "Kumar, Rahul1" CC: "devel@edk2.groups.io" , "Ni, Ray" Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Don't increase CpuCount in ApWakeupFunction Thread-Topic: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Don't increase CpuCount in ApWakeupFunction Thread-Index: AQHW86cytahL1AI/Xk2XOb69wmTXw6o8YvQg Date: Thu, 28 Jan 2021 03:26:58 +0000 Message-ID: References: <165DB23DD3EC13FE.27537@groups.io> In-Reply-To: <165DB23DD3EC13FE.27537@groups.io> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.194] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 255fa0aa-81ea-4fe9-fce4-08d8c33c9227 x-ms-traffictypediagnostic: MWHPR11MB1616: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6790; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: iIU6SlAPxXs4jgDh5AqfJTXd5/zSP6kCeSJb8S4ceXhsa8pFecKFBWHMig6e63p0vPXEs/dfLzlBFDVNEZh2TYNJqh5ylC4WsqCQae8IYMcqzziBirUsXDNPFkQ7ZGjTckvliY/DGjLp2QwEpWQpTIChVMmIs2bVngJRtW3za2BCJRFG5NVtpxh1sS1yEdowVGTgAQGZgp7XYwRewx1M0H/BpMdyRW77z7LqLbUhBU6sikub2RdPJRUHOaPnbCN2BIep4tCfW7k8G46dHkAxQ9gXAiL8jKYoqlD6+OQQ1KhiQuJxQ6rXQ21JcTwB2TJ/nXlHr2dVOJ+Ka0sgdHkLz/70PCm0gLB2+Em54QWzWGV7359U6ewbxrkoNLdyDmDrOpUQ8DcR0/V7DWgspyzyxtHqB6DSf18C/3lojosMqSwhzgppqwKHYeAGfXlTdRuWEHK29VXsVrJN4sXCMPGj1C09tnAOVT877QyJRAopGvmZkZhbM3AZ5kcJBTBfkSRaLjKj0jN7tdYTmCb6X7h6sT7Fv4b5gTAbCX/dROXKdhi9cel83a8yRCtPQ8BD3lZY9eiCAwcckSLaL6hhKWE7wBBz4mvb3QZfXC8y0VlY5bY= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR11MB4930.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(6029001)(4636009)(136003)(346002)(376002)(366004)(39860400002)(396003)(316002)(66946007)(107886003)(66556008)(4326008)(64756008)(66446008)(76116006)(66476007)(2906002)(52536014)(26005)(9686003)(55016002)(86362001)(83380400001)(478600001)(8676002)(53546011)(8936002)(5660300002)(186003)(33656002)(966005)(6506007)(7696005)(71200400001)(54906003)(110136005)(6636002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?rCHhuGGdTuaFst3iyNIE02ibhTjxaF3ke6OClbfdCTrqQWw/x5Y/2AKcwCoL?= =?us-ascii?Q?atLeYe9Ggf28kiQfxNAb6zjwBPLJqR/bc9or0YbGwDuIuhiCdnputMfU5Uo5?= =?us-ascii?Q?Ru5EXpIc9Vka/CYnY3vTmLynPAEzZGV1GFvFMqRnTYut1S1CoTxTH4out6pj?= =?us-ascii?Q?BdkKMAHbQD2mfFpw7B+jq4izHzsJ+z66u+Ed5vaJz8JAZ6jpRY33mpMqaPV2?= =?us-ascii?Q?nnPe7Y0ed4ynE0aB88ef7OBhZ5caLovNGU5/YVP+t+f2JY6mZHucZID4pkCD?= =?us-ascii?Q?Ee5/I5Hj4rtXlaMw2K0Uw7VB4dbp7KargI1bxzwAeIjU4EqYGxM4DuLrYZYJ?= =?us-ascii?Q?dyie/o4sghMWGIZ2BLnR5GjB2GRTB+KCmUYMfCcYnl+4Gq88dPaJbEiNxse+?= =?us-ascii?Q?+y6+IX3JzqYew/+WtJyK6PR4Ug+14d5ZfxG7OStmW8Z9NzgHkulLhp68cdcp?= =?us-ascii?Q?UtLGq8niz+0eVzvin8IYg1xaJJjFjvEOfHN1/1lXhkh/k6Tbv1VR3u+SU7ho?= =?us-ascii?Q?rouygtZV1tkjwriHIpv7Gw0tqN6KtybFkuUoQ17FGyDHVXgfBF2gSKyIaM00?= =?us-ascii?Q?M5/EzC7AjlpE/4dJ0/jMHd+Dvo2mjD2MV/i6GKR46PgYrjpprI2iOHyQeKks?= =?us-ascii?Q?UXDF73wxgFA8xYhMceUE+HnLOBWug3cSOPvYoFiqj2YSMyWuV9nSGiXGTcIc?= =?us-ascii?Q?EqQ0u/OAEI+o7vAGVOeCCoF5cWlAwij83WNN+zlzAphtBQJ51DouB7PyuThc?= =?us-ascii?Q?DXPdSgRmCEvQX+v6/voMcfSpOC1yqMCKefM+In1qTDuXEPFUawIlviQXM901?= =?us-ascii?Q?qfCEgjQNMtOLo8aALB5QIB0nHwdCCctucBP1mEH3qRi6SV3Vah4DswHwHbhY?= =?us-ascii?Q?Oh2LkAQVCi+D/Hn0tn7iu9XiFjWSul+XKntitlYPp9Shqx8ONJDBrxdIi3Je?= =?us-ascii?Q?ne7twZGdeE36vRN4vQVRjyC/RfxBixTvsxDnGCPyN3nbtHJDo0jdFuQz1l8L?= =?us-ascii?Q?xcQOQJ9Z6kGvQyZqznMqH0VRiujsyDVGYkrXwbkEfqJxAD7cVSdhK61ts6Cv?= =?us-ascii?Q?g6U9vhWO?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4930.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 255fa0aa-81ea-4fe9-fce4-08d8c33c9227 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Jan 2021 03:26:58.9477 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: p/jgbLUP2IF3wXeKEfX+TMee94+vHlrX2DO28t3HVo80yQmykIw/5c2/BPUEChq6J5dysD1Cwi7ehOQ29EgHng== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR11MB1616 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Somehow I forgot to add "Cc" tag in the patch resulting the package maintai= ners are not CCed. Add them back. > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Ni, Ray > Sent: Tuesday, January 26, 2021 1:50 PM > To: devel@edk2.groups.io > Subject: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Don't increase > CpuCount in ApWakeupFunction >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3179 >=20 > 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. >=20 > Putting them together, the 3 variables are changed in the following order= : > 1. NumApsExecuting++ // in assembly > 2. CpuCpunt++ > 4. FinishedCount++ > 3. NumApsExecuting-- // in C >=20 > 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. >=20 > Then it additionally waits for FinishedCount =3D=3D CpuCount - 1. > (FinishedCount doesn't include BSP while CpuCount includes BSP.) >=20 > 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. >=20 > This patch simplifies the code to remove "CpuCount++" in > ApWakeupFunction() and assigns FinishedCount + 1 to CpuCount after > WakeUpAP(). >=20 > Signed-off-by: Ray Ni > --- > UefiCpuPkg/Library/MpInitLib/MpLib.c | 16 +++++----------- > 1 file changed, 5 insertions(+), 11 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c > b/UefiCpuPkg/Library/MpInitLib/MpLib.c > index 8b1f7f84ba..2568986d8c 100644 > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c > @@ -1,7 +1,7 @@ > /** @file >=20 > CPU MP Initialize Library common functions. >=20 >=20 >=20 > - Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.
>=20 > + Copyright (c) 2016 - 2021, Intel Corporation. All rights reserved.
>=20 > Copyright (c) 2020, AMD Inc. All rights reserved.
>=20 >=20 >=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -485,14 +485,12 @@ CollectProcessorCount ( > CpuMpData->InitFlag =3D ApInitConfig; >=20 > WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE); >=20 > CpuMpData->InitFlag =3D ApInitDone; >=20 > - ASSERT (CpuMpData->CpuCount <=3D PcdGet32 > (PcdCpuMaxLogicalProcessorNumber)); >=20 > // >=20 > - // Wait for all APs finished the initialization >=20 > + // When InitFlag =3D=3D ApInitConfig, WakeUpAP () guarantees all APs a= re > checked in. >=20 > + // FinishedCount is the number of check-in APs. >=20 > // >=20 > - while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) { >=20 > - CpuPause (); >=20 > - } >=20 > - >=20 > + CpuMpData->CpuCount =3D CpuMpData->FinishedCount + 1; >=20 > + ASSERT (CpuMpData->CpuCount <=3D PcdGet32 > (PcdCpuMaxLogicalProcessorNumber)); >=20 >=20 >=20 > // >=20 > // Enable x2APIC mode if >=20 > @@ -751,10 +749,6 @@ ApWakeupFunction ( > CurrentApicMode =3D GetApicMode (); >=20 > while (TRUE) { >=20 > if (CpuMpData->InitFlag =3D=3D ApInitConfig) { >=20 > - // >=20 > - // Add CPU number >=20 > - // >=20 > - InterlockedIncrement ((UINT32 *) &CpuMpData->CpuCount); >=20 > ProcessorNumber =3D ApIndex; >=20 > // >=20 > // This is first time AP wakeup, get BIST information from AP stac= k >=20 > -- > 2.27.0.windows.1 >=20 >=20 >=20 > -=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/1712937 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub [ray.ni@intel.com] > -=3D-=3D-=3D-=3D-=3D-=3D >=20