From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 06D5A74004C for ; Fri, 31 May 2024 09:59:26 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=WIMG8DhFijQVz/5EnsWl+E9Rf91Q43Vy98MS2Se6bHY=; c=relaxed/simple; d=groups.io; h=MIME-version:Subject:From:In-reply-to:Date:Cc:Message-id:References:To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-type; s=20240206; t=1717149566; v=1; b=E+lHNqldMb8wPzxDLvfmIHW5rbDcgNrSXedwekULNv5eme21Zydo5hR1veQpSINZmQ//z7B6 1NS3SydQVn16AZA5BfK1iHAWlsFn4uAPHzxSkLB4JlGR0GVFiu633+bzOjIuyeF7joQizsZRQzv 6DdORRDxnz1ab91iWkBcUTUUj2d0A/rW0lPouTyzxcAtfoB/jbz5s/JgnehW/wB48kjB7HWK2bk RFGHuyTCiRfTyAsDnQEL04rYifg2wyTvwMqek831o8r/W1AlbKFk+ZI6q8TZG6FTRyf/x/GYHk4 SUw8qcPtmqYa4u83VSVgrZVcXN90pd1PH2j0EV6fc7PJQ== X-Received: by 127.0.0.2 with SMTP id uQeKYY7687511xga9AlFh8Ym; Fri, 31 May 2024 02:59:25 -0700 X-Received: from ma-mailsvcp-mx-lapp03.apple.com (ma-mailsvcp-mx-lapp03.apple.com [17.32.222.24]) by mx.groups.io with SMTP id smtpd.web11.7890.1717149564735863701 for ; Fri, 31 May 2024 02:59:24 -0700 X-Received: from ma-mailsvcp-mta-lapp04.corp.apple.com (ma-mailsvcp-mta-lapp04.corp.apple.com [10.226.18.136]) by ma-mailsvcp-mx-lapp03.apple.com (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28 2023)) with ESMTPS id <0SEC005BUH2ZE810@ma-mailsvcp-mx-lapp03.apple.com> for devel@edk2.groups.io; Fri, 31 May 2024 02:59:24 -0700 (PDT) X-Received: from ma-mailsvcp-mmp-lapp01.apple.com (ma-mailsvcp-mmp-lapp01.apple.com [17.32.222.14]) by ma-mailsvcp-mta-lapp04.corp.apple.com (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28 2023)) with ESMTPS id <0SEC00K8QH2Z1K50@ma-mailsvcp-mta-lapp04.corp.apple.com>; Fri, 31 May 2024 02:59:23 -0700 (PDT) X-Received: from process_milters-daemon.ma-mailsvcp-mmp-lapp01.apple.com by ma-mailsvcp-mmp-lapp01.apple.com (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28 2023)) id <0SEC00G00GEHPF00@ma-mailsvcp-mmp-lapp01.apple.com>; Fri, 31 May 2024 02:59:23 -0700 (PDT) X-Va-A: X-Va-T-CD: 023dda12a5ac1b2af0721fca699b8cf5 X-Va-E-CD: 565d08fc96bfb0973ef5be270ccdb446 X-Va-R-CD: 4f6064923a0e64b50d125a364eb00a3c X-Va-ID: 42bfb9ea-9467-45cd-a05d-4b6ab386e59e X-Va-CD: 0 X-V-A: X-V-T-CD: 023dda12a5ac1b2af0721fca699b8cf5 X-V-E-CD: 565d08fc96bfb0973ef5be270ccdb446 X-V-R-CD: 4f6064923a0e64b50d125a364eb00a3c X-V-ID: abe2ea41-e58e-40f3-9e7c-8df683d10167 X-V-CD: 0 X-Received: from smtpclient.apple (unknown [17.235.85.100]) by ma-mailsvcp-mmp-lapp01.apple.com (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28 2023)) with ESMTPSA id <0SEC00Y4EH2Y5U00@ma-mailsvcp-mmp-lapp01.apple.com>; Fri, 31 May 2024 02:59:23 -0700 (PDT) MIME-version: 1.0 (Mac OS X Mail 16.0 \(3774.300.61.1.2\)) Subject: Re: [edk2-devel] Is DEBUG output function safe for MP case? From: "Andrew Fish via groups.io" X-Priority: 3 In-reply-to: <2024053114334025493514@byosoft.com.cn> Date: Fri, 31 May 2024 04:59:11 -0500 Cc: yoshinoyatoko Message-id: <1571BBB4-BEC2-4C73-8E96-C366A5C938A2@apple.com> References: <2d8e2935.5b57.18fcd506481.Coremail.yoshinoyatoko@163.com> <2024053114334025493514@byosoft.com.cn> To: devel@edk2.groups.io, fanjianfeng@byosoft.com.cn Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Fri, 31 May 2024 02:59:25 -0700 Resent-From: afish@apple.com Reply-To: devel@edk2.groups.io,afish@apple.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: vbkLQYDyuA5eq7vOMcopLJBix7686176AA= Content-type: multipart/alternative; boundary="Apple-Mail=_E3094F40-0918-412A-938F-99D46C5928DF" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=E+lHNqld; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io --Apple-Mail=_E3094F40-0918-412A-938F-99D46C5928DF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 I think the generic answer is no DEBUG() is not guaranteed to be MP safe.= =20 Jeff is pointing out in the edk2 your platform build can control what libra= ries are used to implement DEBUG(), so you might be able to make it work in= your case.=20 Base libs are libraries that don=E2=80=99t depend on other things so they h= ave a much better chance of working but they will have at least 2 issue: 1) The are not MP safe so the output could get intermixed and things could = get lost as multiple agents try to to write to the UART in parallel 2) A Base lib that goes after a x86 IO port has a chance of working at runt= ime, but an ARM UART driver that uses an MMIO address is not going to work = as the that MMIO range would need a virtual mapping and a Base lib is not g= oing to request that. You can search for instances of the DebugLib (that implements DEBUG) by gre= pping the inf files.=20 /Volumes/Case/edk2(master)>git grep DebugLib -- \*.inf | grep LIBRARY_CLASS= | grep DXE_RUNTIME_DRIVER ArmPkg/Library/SemiHostingDebugLib/SemiHostingDebugLib.inf:19: LIBRARY_CLA= SS =3D DebugLib|BASE SEC DXE_CORE DXE_DRIVER DXE_RUNTIME_D= RIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER ArmVirtPkg/Library/DebugLibFdtPL011Uart/DxeRuntimeDebugLibFdtPL011Uart.inf:= 23: LIBRARY_CLASS =3D DebugLib|DXE_RUNTIME_DRIVER MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportSta= tusCode.inf:19: LIBRARY_CLASS =3D DebugLib|DXE_CORE DXE_D= RIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER SMM_CORE PEIM SEC PEI_CORE UEFI_APP= LICATION UEFI_DRIVER MM_STANDALONE MdePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.in= f:22: LIBRARY_CLASS =3D DebugLib|DXE_RUNTIME_DRIVER MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf:22: LIBRARY_CLASS= =3D DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_= APPLICATION UEFI_DRIVER MdePkg/Library/UefiDebugLibDebugPortProtocol/UefiDebugLibDebugPortProtocol.= inf:22: LIBRARY_CLASS =3D DebugLib|DXE_CORE DXE_DRIVER DX= E_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf:22: LIBRARY_CLASS= =3D DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_= APPLICATION UEFI_DRIVER OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf:19: LIBR= ARY_CLASS =3D DebugLib|PEI_CORE PEIM DXE_CORE DXE_DRIVER D= XE_RUNTIME_DRIVER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION Note: DXE_RUNTIME_DRIVE may not imply the the DEBUG works at running, and i= t may only support DEBUG print a Boot Services time. But if you look at the= list you will see some of the libs are designed to used at runtime. So tha= t should imply they deal with virtual address mapping and locks.=20 Thanks, Andrew Fish > On May 31, 2024, at 1:33=E2=80=AFAM, Jeff Fan via groups.io wrote: >=20 > AP cannot run any UEFI Service. Please make sure AP code use base-typed D= ebugLib instance (Such as BaseDebugLibSerialport.inf from MdePkg) >=20 >=20 > fanjianfeng@byosoft.com.cn > =20 > =E5=8F=91=E4=BB=B6=E4=BA=BA=EF=BC=9A Yoshinoya > =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4=EF=BC=9A 2024-05-31 14:22 > =E6=94=B6=E4=BB=B6=E4=BA=BA=EF=BC=9A devel@edk2.groups.io > =E4=B8=BB=E9=A2=98=EF=BC=9A [edk2-devel] Is DEBUG output function safe fo= r MP case? > Hello > I ask for help for debug output in multi-core case. >=20 > Is the current DEBUG marco safe for AP Cores to output message? > If the output message is too long, it takes too much time, will it cause = some abnormal exception? >=20 > Thanks >=20 -=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 (#119409): https://edk2.groups.io/g/devel/message/119409 Mute This Topic: https://groups.io/mt/106405010/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --Apple-Mail=_E3094F40-0918-412A-938F-99D46C5928DF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 I think the generic answer is no = DEBUG() is not guaranteed to be MP safe. 

Jeff is p= ointing out in the edk2 your platform build can control what libraries are = used to implement DEBUG(), so you might be able to make it work in your cas= e. 

Base libs are libraries that don=E2=80=99= t depend on other things so they have a much better chance of working but t= hey will have at least 2 issue:
1) The are not MP safe so the out= put could get intermixed and things could get lost as multiple agents try t= o to write to the UART in parallel
2) A Base lib that goes after = a x86 IO port has a chance of working at runtime, but an ARM UART driver th= at uses an MMIO address is not going to work as the that MMIO range would n= eed a virtual mapping and a Base lib is not going to request that.

You can search for instances of the DebugLib (that impleme= nts DEBUG) by grepping the inf files. 

/Volumes/Case/edk2(master)>git grep D= ebugLib -- \*.inf | grep LIBRARY_CLASS | grep DXE_RUNTIME_DRIVER

ArmPkg/Library/SemiHostingDebugLib/SemiHostingDebugLib.inf:19:&nb= sp; LIBRARY_CLASS                &n= bsp; =3D DebugLib|BASE SEC DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_D= RIVER UEFI_APPLICATION UEFI_DRIVER

ArmVirtPkg/Library/DebugLibFdtPL011Uart/DxeRuntimeDebugLibFdtPL01= 1Uart.inf:23:  LIBRARY_CLASS  =3D DebugLib|DXE_RUNTIME_DRIVER

MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLi= bReportStatusCode.inf:19:  LIBRARY_CLASS        &n= bsp;         =3D DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTI= ME_DRIVER DXE_SMM_DRIVER SMM_CORE PEIM SEC PEI_CORE UEFI_APPLICATION UEFI_D= RIVER MM_STANDALONE

MdePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSer= ialPort.inf:22:  LIBRARY_CLASS           = ;       =3D DebugLib|DXE_RUNTIME_DRIVER

MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf:22: = ; LIBRARY_CLASS                &nbs= p; =3D DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEF= I_DRIVER

MdePkg/Library/UefiDebugLibDebugPortProtocol/UefiDebugLibDebugPor= tProtocol.inf:22:  LIBRARY_CLASS          &nb= sp;       =3D DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVE= R UEFI_APPLICATION UEFI_DRIVER

MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf:22: = ; LIBRARY_CLASS                &nbs= p; =3D DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEF= I_DRIVER

OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf= :19:  LIBRARY_CLASS              &n= bsp;   =3D DebugLib|PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIV= ER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION


Note: DXE_RUNTIME_DRIVE may not imply the the DEBUG works at = running, and it may only support DEBUG print a Boot Services time. But if y= ou look at the list you will see some of the libs are designed to used at r= untime. So that should imply they deal with virtual address mapping and loc= ks. 

Thanks,

Andrew = Fish

On May 31, 2024, at 1:33= =E2=80=AFAM, Jeff Fan via groups.io <fanjianfeng=3Dbyosoft.com.cn@groups= .io> wrote:

A= P cannot run any UEFI Service. Please make sure AP code use base-typed= DebugLib instance (Such as BaseDebugLibSerialport.inf from MdePkg)



 
=E5=8F=91=E4=BB= =B6=E4=BA=BA=EF=BC=9A Yos= hinoya
=E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4=EF=BC=9A&n= bsp;2024-05-31 14:22
=E6=94=B6=E4=BB=B6=E4=BA=BA=EF=BC=9A=  devel@edk2.groups.io<= /div>
=E4=B8=BB=E9=A2=98=EF=BC=9A [edk2-devel] Is DEBUG out= put function safe for MP case?
Hello
I ask for help for debug output in multi-core case.

Is the current DEBU= G marco safe for AP Cores to output message?
If the output message is too long, it takes too much time, will it cause= some abnormal exception?

Thanks

_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#119409) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--Apple-Mail=_E3094F40-0918-412A-938F-99D46C5928DF--