OvmfXen: Set PcdFSBClock at runtime
cover OvmfXen: Set PcdFSBClock at runtime
Patch series available in this git branch:git://xenbits.xen.org/people/aperard/ovmf.git br.apic-timer-freq-v1
Hi,
OvmfXen uses the APIC timer, but with an hard-coded frequency that may change as pointed out here:
https://edk2.groups.io/g/devel/message/45185
<20190808134423.ybqg3qkpw5ucfzk4@Air-de-Roger>
This series changes that so the frequency is calculated at runtime.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2490
There is also one cleanup patch that has nothing to do with the rest.
Cheers,
Anthony PERARD (5):
OvmfPkg/XenResetVector: Silent a warning from nasm
MdePkg: Allow PcdFSBClock to by Dynamic OvmfPkg/IndustryStandard/Xen: Apply EDK2 coding style to
XEN_VCPU_TIME_INFO
OvmfPkg/XenPlatformPei: Calibrate APIC timer frequency OvmfPkg/OvmfXen: Set PcdFSBClock
MdePkg/MdePkg.dec | 8 +- OvmfPkg/OvmfXen.dsc | 4 +- OvmfPkg/XenPlatformPei/XenPlatformPei.inf | 2 + OvmfPkg/Include/IndustryStandard/Xen/xen.h | 17 +-- OvmfPkg/XenPlatformPei/Platform.h | 5 + OvmfPkg/XenPlatformPei/Platform.c | 1 + OvmfPkg/XenPlatformPei/Xen.c | 127 +++++++++++++++++++++ OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm | 2 +- 8 files changed, 150 insertions(+), 16 deletions(-)
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/5 OvmfPkg/XenResetVector: Silent a warning from nasm
To avoid nasm generating a warning, replace the macro by the value expected to be stored in eax.
Ia32/XenPVHMain.asm:76: warning: dword data exceeds bounds
--- OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm +1 -1
@@ -73,7 +73,7 @@ xenPVHMain: ; ; parameter for Flat32SearchForBfvBase ; - mov eax, ADDR_OF(fourGigabytes) + mov eax, 0 ; ADDR_OF(fourGigabytes) add eax, edx ; add delta ;
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/5] OvmfPkg/XenResetVector: Silent a warning from nasm
Quoted 16 lines · Anthony PERARD
To avoid nasm generating a warning, replace the macro by the value expected to be stored in eax.
Ia32/XenPVHMain.asm:76: warning: dword data exceeds boundsReported-by Laszlo Ersek <[email protected]>Signed-off-by Anthony PERARD <[email protected]>--- OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm +0
-0
OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm xenPVHMain: · line 79
Quoted 8 lines
OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm +1
-1@@ -73,7 +73,7 @@ xenPVHMain: ; ; parameter for Flat32SearchForBfvBase ; - mov eax, ADDR_OF(fourGigabytes) + mov eax, 0 ; ADDR_OF(fourGigabytes) add eax, edx ; add delta ;
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/5 MdePkg: Allow PcdFSBClock to by Dynamic
In reply to Anthony PERARDWe are going to want to change the value of PcdFSBClock at run time in OvmfXen, so move it to the PcdsDynamic section.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2490
---
CC: Bob Feng <[email protected]>
CC: Liming Gao <[email protected]>
--- MdePkg/MdePkg.dec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
MdePkg/MdePkg.dec +4 -4
@@ -2194,10 +2194,6 @@ [PcdsFixedAtBuild,PcdsPatchableInModule] # @ValidList 0x80000001 | 8, 16, 32 gEfiMdePkgTokenSpaceGuid.PcdPort80DataWidth|8|UINT8|0x0000002d - ## This value is used to configure X86 Processor FSB clock. - # @Prompt FSB Clock. - gEfiMdePkgTokenSpaceGuid.PcdFSBClock|200000000|UINT32|0x0000000c - ## The maximum printable number of characters. UefLib functions: AsciiPrint(), AsciiErrorPrint(), # PrintXY(), AsciiPrintXY(), Print(), ErrorPrint() base on this PCD value to print characters. # @Prompt Maximum Printable Number of Characters.
@@ -2297,5 +2293,9 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] # @Prompt Boot Timeout (s) gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|0xffff|UINT16|0x0000002c + ## This value is used to configure X86 Processor FSB clock. + # @Prompt FSB Clock. + gEfiMdePkgTokenSpaceGuid.PcdFSBClock|200000000|UINT32|0x0000000c + [UserExtensions.TianoCore."ExtraFiles"] MdePkgExtra.uni
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/5] MdePkg: Allow PcdFSBClock to by Dynamic
Quoted 29 lines · Anthony PERARD
We are going to want to change the value of PcdFSBClock at run time in OvmfXen, so move it to the PcdsDynamic section.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2490
Signed-off-by Anthony PERARD <[email protected]>---
CC: Bob Feng <[email protected]>
CC: Liming Gao <[email protected]>--- MdePkg/MdePkg.dec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)MdePkg/MdePkg.dec +0
-4@@ -2194,10 +2194,6 @@ [PcdsFixedAtBuild,PcdsPatchableInModule] # @ValidList 0x80000001 | 8, 16, 32 gEfiMdePkgTokenSpaceGuid.PcdPort80DataWidth|8|UINT8|0x0000002d - ## This value is used to configure X86 Processor FSB clock. - # @Prompt FSB Clock. - gEfiMdePkgTokenSpaceGuid.PcdFSBClock|200000000|UINT32|0x0000000c - ## The maximum printable number of characters. UefLib functions: AsciiPrint(), AsciiErrorPrint(), # PrintXY(), AsciiPrintXY(), Print(), ErrorPrint() base on this PCD value to print characters. # @Prompt Maximum Printable Number of Characters.
MdePkg/MdePkg.dec [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] · line 2301
Quoted 9 lines
MdePkg/MdePkg.dec +4
-0@@ -2297,5 +2293,9 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] # @Prompt Boot Timeout (s) gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|0xffff|UINT16|0x0000002c + ## This value is used to configure X86 Processor FSB clock. + # @Prompt FSB Clock. + gEfiMdePkgTokenSpaceGuid.PcdFSBClock|200000000|UINT32|0x0000000c + [UserExtensions.TianoCore."ExtraFiles"] MdePkgExtra.uni
Looks good to me:
Mike or Liming will have to ACK.
Thanks!
Laszlo
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/5] MdePkg: Allow PcdFSBClock to by Dynamic
Anthony:
This change is OK to me. But if this PCD is configured as Dynamic, its value will be got from PCD service. This operation will take some time and cause the inaccurate time delay. Have you measured its impact?
Thanks
Liming
Quoted 51 lines
-----Original Message-----
From: Laszlo Ersek <[email protected]>
Sent: Thursday, January 30, 2020 12:11 AM
To: Anthony PERARD <[email protected]>; [email protected]
Cc: Kinney, Michael D <[email protected]>; Ard Biesheuvel <[email protected]>; [email protected]; Gao, Liming <[email protected]>; Justen, Jordan L <[email protected]>; Julien Grall <[email protected]>; Feng, Bob C <[email protected]>
Subject: Re: [PATCH 2/5] MdePkg: Allow PcdFSBClock to by DynamicQuoted 29 lines · Anthony PERARD
We are going to want to change the value of PcdFSBClock at run time in OvmfXen, so move it to the PcdsDynamic section.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2490
Signed-off-by Anthony PERARD <[email protected]>---
CC: Bob Feng <[email protected]>
CC: Liming Gao <[email protected]>--- MdePkg/MdePkg.dec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)MdePkg/MdePkg.dec +0
-4@@ -2194,10 +2194,6 @@ [PcdsFixedAtBuild,PcdsPatchableInModule] # @ValidList 0x80000001 | 8, 16, 32 gEfiMdePkgTokenSpaceGuid.PcdPort80DataWidth|8|UINT8|0x0000002d - ## This value is used to configure X86 Processor FSB clock. - # @Prompt FSB Clock. - gEfiMdePkgTokenSpaceGuid.PcdFSBClock|200000000|UINT32|0x0000000c - ## The maximum printable number of characters. UefLib functions: AsciiPrint(), AsciiErrorPrint(), # PrintXY(), AsciiPrintXY(), Print(), ErrorPrint() base on this PCD value to print characters. # @Prompt Maximum Printable Number of Characters.MdePkg/MdePkg.dec [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] · line 2301
Quoted 9 lines
MdePkg/MdePkg.dec +4
-0@@ -2297,5 +2293,9 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] # @Prompt Boot Timeout (s) gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|0xffff|UINT16|0x0000002c + ## This value is used to configure X86 Processor FSB clock. + # @Prompt FSB Clock. + gEfiMdePkgTokenSpaceGuid.PcdFSBClock|200000000|UINT32|0x0000000c + [UserExtensions.TianoCore."ExtraFiles"] MdePkgExtra.uniLooks good to me:
Quoted 6 lines
Reviewed-by Laszlo Ersek <[email protected]>Mike or Liming will have to ACK.
Thanks!
Laszlo
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/5] MdePkg: Allow PcdFSBClock to by Dynamic
Quoted 2 lines · Liming
Anthony:
This change is OK to me. But if this PCD is configured as Dynamic, its value will be got from PCD service. This operation will take some time and cause the inaccurate time delay. Have you measured its impact?
No, I haven't. But I don't think it matter in a Xen guest, the APIC timer is emulated anyway, so reading from a register of the APIC is going to be slower than getting the value from the PCD services, I think. (Hopefully, I'm not too wrong.)
But I'll give it at measuring the difference, it would be interesting to know.
Thanks,
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/5] MdePkg: Allow PcdFSBClock to by Dynamic
Quoted 11 lines · Anthony PERARD
Quoted 2 lines · Liming
Anthony:
This change is OK to me. But if this PCD is configured as Dynamic, its value will be got from PCD service. This operation will take some time and cause the inaccurate time delay. Have you measured its impact?No, I haven't. But I don't think it matter in a Xen guest, the APIC timer is emulated anyway, so reading from a register of the APIC is going to be slower than getting the value from the PCD services, I think. (Hopefully, I'm not too wrong.)
But I'll give it at measuring the difference, it would be interesting to know.
Now that I've given a try, having the value as Dynamic doesn't change anything in a Xen guest.
On my test machine, simply running GetPerformanceCounter (); takes between 10000 ns and 20000 ns. Reading the dynamic value from PCD on the other hand takes about 350ns. (10ns if it's static.)
When I run NanoSecondDelay() with different values, I have:
- with static pcd:
63894 ns to delay by 1 ns
66611 ns to delay by 10 ns
43927 ns to delay by 100 ns
71367 ns to delay by 1000 ns
55881 ns to delay by 10000 ns
147716 ns to delay by 100000 ns
1048335 ns to delay by 1000000 ns
10041179 ns to delay by 10000000 ns
- with a dynamic pcd:
40949 ns to delay by 1 ns
84832 ns to delay by 10 ns
82745 ns to delay by 100 ns
59848 ns to delay by 1000 ns
52647 ns to delay by 10000 ns
137051 ns to delay by 100000 ns
1042492 ns to delay by 1000000 ns
10036306 ns to delay by 10000000 nsSo, the kind of PCD used for PcdFSBClock on Xen (with OvmfXen) doesn't really matter.
Anyway, thanks for the feedback.
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [edk2-devel] [PATCH 2/5] MdePkg: Allow PcdFSBClock to by Dynamic
Thanks for your data. Seemly, those data is acceptable on OvmfXen. For this patch, Reviewed-by: Liming Gao <[email protected]>
Thanks
Liming
Quoted 58 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Anthony PERARD
Sent: Tuesday, February 4, 2020 1:26 AM
To: Gao, Liming <[email protected]>
Cc: Laszlo Ersek <[email protected]>; [email protected]; Kinney, Michael D <[email protected]>; Ard Biesheuvel <[email protected]>; [email protected]; Justen, Jordan L <[email protected]>; Julien Grall <[email protected]>; Feng, Bob C <[email protected]>
Subject: Re: [edk2-devel] [PATCH 2/5] MdePkg: Allow PcdFSBClock to by DynamicQuoted 3 lines · Anthony PERARD
Quoted 2 lines · Liming
Anthony:
This change is OK to me. But if this PCD is configured as Dynamic, its value will be got from PCD service. This operation will takesome time and cause the inaccurate time delay. Have you measured its impact?
Quoted 8 lines
No, I haven't. But I don't think it matter in a Xen guest, the APIC timer is emulated anyway, so reading from a register of the APIC is going to be slower than getting the value from the PCD services, I think. (Hopefully, I'm not too wrong.)
But I'll give it at measuring the difference, it would be interesting to know.
Now that I've given a try, having the value as Dynamic doesn't change anything in a Xen guest.
On my test machine, simply running GetPerformanceCounter (); takes between 10000 ns and 20000 ns. Reading the dynamic value from PCD on the other hand takes about 350ns. (10ns if it's static.)
When I run
NanoSecondDelay()with different values, I have:
- with static pcd:63894 ns to delay by 1 ns 66611 ns to delay by 10 ns 43927 ns to delay by 100 ns 71367 ns to delay by 1000 ns 55881 ns to delay by 10000 ns 147716 ns to delay by 100000 ns 1048335 ns to delay by 1000000 ns 10041179 ns to delay by 10000000 ns - with a dynamic pcd: 40949 ns to delay by 1 ns 84832 ns to delay by 10 ns 82745 ns to delay by 100 ns 59848 ns to delay by 1000 ns 52647 ns to delay by 10000 ns 137051 ns to delay by 100000 ns 1042492 ns to delay by 1000000 ns 10036306 ns to delay by 10000000 nsSo, the kind of PCD used for PcdFSBClock on Xen (with OvmfXen) doesn't really matter.
Anyway, thanks for the feedback.
--
Anthony PERARD
Quoted 8 lines
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.View/Reply Online (#53675): https://edk2.groups.io/g/devel/message/53675
Mute This Topic: https://groups.io/mt/70239981/1759384
Group Owner: [email protected]
Unsubscribe: https://edk2.groups.io/g/devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/5 OvmfPkg/IndustryStandard/Xen: Apply EDK2 coding style to XEN_VCPU_TIME_INFO
In reply to Anthony PERARDWe are going to use new fields from the Xen headers. Apply the EDK2 coding style so that the code that is going to use it doesn't look out of place.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2490
--- OvmfPkg/Include/IndustryStandard/Xen/xen.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
OvmfPkg/Include/IndustryStandard/Xen/xen.h +9 -8
@@ -183,10 +183,10 @@ struct vcpu_time_info {* The correct way to interact with the version number is similar to * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry. */ -UINT32 version; +UINT32 Version;UINT32 pad0; -UINT64 tsc_timestamp;/* TSC at last update of time vals. */ -UINT64 system_time;/* Time, in nanosecs, since boot. */ +UINT64 TSCTimestamp;/* TSC at last update of time vals. */ +UINT64 SystemTime;/* Time, in nanosecs, since boot. */ /* * Current system time: * system_time +
@@ -194,11 +194,11 @@ struct vcpu_time_info {* CPU frequency (Hz): * ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift */ -UINT32 tsc_to_system_mul; -INT8 tsc_shift; +UINT32 TSCToSystemMultiplier; +INT8 TSCShift;INT8 pad1[3 ]; };/* 32 bytes */ -typedef struct vcpu_time_info vcpu_time_info_t ; +typedef struct vcpu_time_info XEN_VCPU_TIME_INFO ;struct vcpu_info {/*
@@ -234,7 +234,7 @@ struct vcpu_info {#endif /* XEN_HAVE_PV_UPCALL_MASK */ xen_ulong_t evtchn_pending_sel;struct arch_vcpu_info arch; -struct vcpu_time_info time; +struct vcpu_time_info Time; };/* 64 bytes (x86) */ #ifndef __XEN__typedef struct vcpu_info vcpu_info_t ;
@@ -250,7 +250,7 @@ typedef struct vcpu_info vcpu_info_t;* of this structure remaining constant. */ struct shared_info { -struct vcpu_info vcpu_info[XEN_LEGACY_MAX_VCPUS ]; +struct vcpu_info VcpuInfo[XEN_LEGACY_MAX_VCPUS ];/* * A domain can create "event channels" on which it can send and receive
@@ -299,6 +299,7 @@ struct shared_info { };#ifndef __XEN__typedef struct shared_info shared_info_t ; +typedef struct shared_info XEN_SHARED_INFO ;#endif /* Turn a plain number into a C UINTN constant. */
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 3/5] OvmfPkg/IndustryStandard/Xen: Apply EDK2 coding style to XEN_VCPU_TIME_INFO
Quoted 9 lines · Anthony PERARD
We are going to use new fields from the Xen headers. Apply the EDK2 coding style so that the code that is going to use it doesn't look out of place.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2490
Signed-off-by Anthony PERARD <[email protected]>--- OvmfPkg/Include/IndustryStandard/Xen/xen.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
This is highly appreciated. Comments below:
Quoted 6 lines
OvmfPkg/Include/IndustryStandard/Xen/xen.h +0
-0
OvmfPkg/Include/IndustryStandard/Xen/xen.h struct vcpu_time_info { · line 188
Quoted 9 lines
OvmfPkg/Include/IndustryStandard/Xen/xen.h +2
-3@@ -183,10 +183,10 @@ struct vcpu_time_info {* The correct way to interact with the version number is similar to * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry. */ -UINT32 version; +UINT32 Version;UINT32 pad0; -UINT64 tsc_timestamp;/* TSC at last update of time vals. */ -UINT64 system_time;/* Time, in nanosecs, since boot. */ +UINT64 TSCTimestamp;/* TSC at last update of time vals. */
(1) Should be "TscTimestamp". Acronyms are de-capitalized when composed into longer identifiers, to maintain a consistent CamelCase.
OvmfPkg/Include/IndustryStandard/Xen/xen.h struct vcpu_time_info { · line 198
Quoted 12 lines
OvmfPkg/Include/IndustryStandard/Xen/xen.h +3
-2+UINT64 SystemTime;/* Time, in nanosecs, since boot. */ /* * Current system time: * system_time + @@ -194,11 +194,11 @@ struct vcpu_time_info {* CPU frequency (Hz): * ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift */ -UINT32 tsc_to_system_mul; -INT8 tsc_shift; +UINT32 TSCToSystemMultiplier; +INT8 TSCShift;
(2) Ditto (both fields).
Quoted 17 lines
OvmfPkg/Include/IndustryStandard/Xen/xen.h +2
-2INT8 pad1[3 ]; };/* 32 bytes */ -typedef struct vcpu_time_info vcpu_time_info_t ; +typedef struct vcpu_time_info XEN_VCPU_TIME_INFO ;struct vcpu_info {/* @@ -234,7 +234,7 @@ struct vcpu_info {#endif /* XEN_HAVE_PV_UPCALL_MASK */ xen_ulong_t evtchn_pending_sel;struct arch_vcpu_info arch; -struct vcpu_time_info time; +struct vcpu_time_info Time; };/* 64 bytes (x86) */ #ifndef __XEN__typedef struct vcpu_info vcpu_info_t ;
OvmfPkg/Include/IndustryStandard/Xen/xen.h typedef struct vcpu_info vcpu_info_t; · line 253
Quoted 5 lines
OvmfPkg/Include/IndustryStandard/Xen/xen.h +1
-1@@ -250,7 +250,7 @@ typedef struct vcpu_info vcpu_info_t;* of this structure remaining constant. */ struct shared_info { -struct vcpu_info vcpu_info[XEN_LEGACY_MAX_VCPUS ]; +struct vcpu_info VcpuInfo[XEN_LEGACY_MAX_VCPUS ];
Yes, this is a good example. "Vcpu" and not "VCPU" or "VCpu".
OvmfPkg/Include/IndustryStandard/Xen/xen.h struct shared_info { · line 305
Quoted 12 lines
OvmfPkg/Include/IndustryStandard/Xen/xen.h +1
-0/* * A domain can create "event channels" on which it can send and receive @@ -299,6 +299,7 @@ struct shared_info { };#ifndef __XEN__typedef struct shared_info shared_info_t ; +typedef struct shared_info XEN_SHARED_INFO ;#endif /* Turn a plain number into a C UINTN constant. */
Assuming the OVMF platforms continue to build at this stage into the series, and provided that (1) and (2) are fixed:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 3/5] OvmfPkg/IndustryStandard/Xen: Apply EDK2 coding style to XEN_VCPU_TIME_INFO
Quoted 3 lines · Laszlo Ersek
On 01/29/20 13:12, Anthony PERARD wrote:
Assuming the OVMF platforms continue to build at this stage into the series, and provided that (1) and (2) are fixed:
I'll fix (1) and (2).
I've build tests both OvmfXen and OvmfPkgX64, and I've grep for some of those field, and the struct name, so I think ArmVirtXen will also continue to build.
Quoted 1 line
Reviewed-by Laszlo Ersek <[email protected]>
Thanks,
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 4/5 OvmfPkg/XenPlatformPei: Calibrate APIC timer frequency
In reply to Anthony PERARDCalculate the frequency of the APIC timer that Xen provides.
Even though the frequency is currently hard-coded, it isn't part of the public ABI that Xen provides and thus may change at any time. OVMF needs to determine the frequency by an other mean.
Fortunately, Xen provides a way to determines the frequency of the TSC, so we can use TSC to calibrate the frequency of the APIC timer. That information is found in the shared_info page which we map and unmap once done (XenBusDxe is going to map the page somewhere else).
The calculated frequency is only logged in this patch, it will be used in a following patch.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2490
---
CC: Roger Pau Monné <[email protected]>
--- OvmfPkg/XenPlatformPei/XenPlatformPei.inf | 1 + OvmfPkg/XenPlatformPei/Platform.h | 5 + OvmfPkg/XenPlatformPei/Platform.c | 1 + OvmfPkg/XenPlatformPei/Xen.c | 123 ++++++++++++++++++++++ 4 files changed, 130 insertions(+)
OvmfPkg/XenPlatformPei/XenPlatformPei.inf +1 -0
@@ -52,6 +52,7 @@ [LibraryClasses] DebugLib HobLib IoLib + LocalApicLib PciLib ResourcePublicationLib PeiServicesLib
OvmfPkg/XenPlatformPei/Platform.h +5 -0
@@ -127,6 +127,11 @@ XenGetE820Map (UINT32 *Count ); +VOID +CalibrateLapicTimer ( +VOID + ); +extern EFI_BOOT_MODE mBootMode;extern UINT8 mPhysMemAddressWidth;
OvmfPkg/XenPlatformPei/Platform.c +1 -0
@@ -448,6 +448,7 @@ InitializeXenPlatform (InitializeRamRegions ();InitializeXen (); +CalibrateLapicTimer ();if (mBootMode !=BOOT_ON_S3_RESUME ) {ReserveEmuVariableNvStore ();
OvmfPkg/XenPlatformPei/Xen.c +123 -0
132 lines not on this page · raw message
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 4/5] OvmfPkg/XenPlatformPei: Calibrate APIC timer frequency
Quoted 16 lines · Anthony PERARD
Calculate the frequency of the APIC timer that Xen provides.
Even though the frequency is currently hard-coded, it isn't part of the public ABI that Xen provides and thus may change at any time. OVMF needs to determine the frequency by an other mean.
Fortunately, Xen provides a way to determines the frequency of the TSC, so we can use TSC to calibrate the frequency of the APIC timer. That information is found in the
shared_infopage which we map and unmap once done (XenBusDxe is going to map the page somewhere else).The calculated frequency is only logged in this patch, it will be used in a following patch.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2490
Signed-off-by Anthony PERARD <[email protected]>
Quoted 8 lines
---
CC: Roger Pau Monné <[email protected]>--- OvmfPkg/XenPlatformPei/XenPlatformPei.inf | 1 + OvmfPkg/XenPlatformPei/Platform.h | 5 + OvmfPkg/XenPlatformPei/Platform.c | 1 + OvmfPkg/XenPlatformPei/Xen.c | 123 ++++++++++++++++++++++ 4 files changed, 130 insertions(+)
I'll review this superficially; it should be approved by someone from xen-devel:
Quoted 60 lines
OvmfPkg/XenPlatformPei/XenPlatformPei.inf +1
-0@@ -52,6 +52,7 @@ [LibraryClasses] DebugLib HobLib IoLib + LocalApicLib PciLib ResourcePublicationLib PeiServicesLibOvmfPkg/XenPlatformPei/Platform.h +5
-0@@ -127,6 +127,11 @@ XenGetE820Map (UINT32 *Count ); +VOID +CalibrateLapicTimer ( +VOID + ); +extern EFI_BOOT_MODE mBootMode;extern UINT8 mPhysMemAddressWidth;OvmfPkg/XenPlatformPei/Platform.c +1
-0@@ -448,6 +448,7 @@ InitializeXenPlatform (InitializeRamRegions ();InitializeXen (); +CalibrateLapicTimer ();if (mBootMode !=BOOT_ON_S3_RESUME ) {ReserveEmuVariableNvStore ();OvmfPkg/XenPlatformPei/Xen.c +5
-0@@ -19,6 +19,7 @@// #include <Library/DebugLib.h> #include <Library/HobLib.h> +#include <Library/LocalApicLib.h> #include <Library/MemoryAllocationLib.h> #include <Library/PcdLib.h> #include <Guid/XenInfo.h> @@ -386,3 +387,125 @@ InitializeXen (return EFI_SUCCESS ; } + + +EFI_STATUS +MapSharedInfoPage (
OvmfPkg/XenPlatformPei/Xen.c InitializeXen ( · line 403
Quoted 10 lines
OvmfPkg/XenPlatformPei/Xen.c +10
-0+ IN VOID *PagePtr + ) +{ +xen_add_to_physmap_t Parameters; +INTN ReturnCode; + + Parameters.domid =DOMID_SELF ; + Parameters.space = XENMAPSPACE_shared_info; + Parameters.idx =0 ; + Parameters.gpfn = (UINTN ) PagePtr >>EFI_PAGE_SHIFT ;
(1) Please remove the space character from "(UINTN) PagePtr". Inserting a space character is a bad and confusing habit in edk2, because it masks the fact that the cast operator has one of the strongest bindings in the C language. So I try to keep it out of OvmfPkg and ArmVirtPkg.
Quoted 7 lines
OvmfPkg/XenPlatformPei/Xen.c +7
-0+ ReturnCode =XenHypercallMemoryOp (XENMEM_add_to_physmap, &Parameters); +if (ReturnCode !=0 ) { +return EFI_NO_MAPPING ; + } +return EFI_SUCCESS ; +} +
OvmfPkg/XenPlatformPei/Xen.c InitializeXen ( · line 420
Quoted 10 lines
OvmfPkg/XenPlatformPei/Xen.c +10
-0+VOID +UnmapXenPage ( + IN VOID *PagePtr + ) +{ +xen_remove_from_physmap_t Parameters; +INTN ReturnCode; + + Parameters.domid =DOMID_SELF ; + Parameters.gpfn = (UINTN ) PagePtr >>EFI_PAGE_SHIFT ;
(2) Ditto.
Quoted 15 lines
OvmfPkg/XenPlatformPei/Xen.c +15
-0+ ReturnCode =XenHypercallMemoryOp (XENMEM_remove_from_physmap, &Parameters); +ASSERT (ReturnCode ==0 ); +} + + +STATIC +UINT64 +GetCPUFreq ( + IN XEN_VCPU_TIME_INFO *VcpuTime + ) +{ +UINT32 Version; +UINT32 TSCToSystemMultiplier; +INT8 TSCShift; +UINT64 CPUFreq;
OvmfPkg/XenPlatformPei/Xen.c InitializeXen ( · line 445
Quoted 10 lines
OvmfPkg/XenPlatformPei/Xen.c +10
-0+ +do { + Version = VcpuTime->Version; +MemoryFence (); + TSCToSystemMultiplier = VcpuTime->TSCToSystemMultiplier; + TSCShift = VcpuTime->TSCShift; +MemoryFence (); + }while (((Version &1 ) !=0 ) && (Version != VcpuTime->Version)); + + CPUFreq = (1000000000ULL <<32 ) / TSCToSystemMultiplier;
(3) I understand that OvmfXen is X64, and so this code will not be built for IA32 in practice. Still, for sticking with the coding style, it's better to use LShiftU64() here, and then DivU64x32().
OvmfPkg/XenPlatformPei/Xen.c InitializeXen ( · line 450
Quoted 5 lines
OvmfPkg/XenPlatformPei/Xen.c +5
-0+if (TSCShift >=0 ) { + CPUFreq >>= VcpuTime->TSCShift; + }else { + CPUFreq <<= -VcpuTime->TSCShift; + }
(4) Please use LShiftU64() and RShiftU64().
(5) I think there's a typo here: you just fished out "TscShift" from the shared info page; we should used that cached value, and not access the shared info page again. Is that right?
OvmfPkg/XenPlatformPei/Xen.c InitializeXen ( · line 463
Quoted 13 lines
OvmfPkg/XenPlatformPei/Xen.c +13
-0+return CPUFreq; +} + +VOID +XenDelay ( + IN XEN_VCPU_TIME_INFO *VcpuTimeInfo, + IN UINT64 DelayNs + ) +{ +UINT64 Tick; + + Tick =AsmReadTsc (); + Tick += (DelayNs *GetCPUFreq (VcpuTimeInfo)) /1000000000ULL ;
(6) Please use MultU64x64() and DivU64x32(). (1,000,000,000 fits in a UINT32.)
Quoted 12 lines
OvmfPkg/XenPlatformPei/Xen.c +12
-0+while (AsmReadTsc () <= Tick) { +CpuPause (); + } +} + + +/** +Calculate the frequency of the Local Apic Timer +**/ +VOID +CalibrateLapicTimer ( + VOID
OvmfPkg/XenPlatformPei/Xen.c InitializeXen ( · line 485
Quoted 10 lines
OvmfPkg/XenPlatformPei/Xen.c +10
-0+ ) +{ +XEN_SHARED_INFO *SharedInfo; +XEN_VCPU_TIME_INFO *VcpuTimeInfo; +UINT32 TimerTick, TimerTick2; +UINT64 TscTick, TscTick2; +UINT64 Freq; +EFI_STATUS Status; + + SharedInfo =AllocatePages (1 );
(7) Can you check if this succeeds?
Quoted 9 lines
OvmfPkg/XenPlatformPei/Xen.c +9
-0+ Status =MapSharedInfoPage (SharedInfo); +ASSERT_EFI_ERROR (Status); +if (EFI_ERROR (Status)) { + goto Exit; + } + + VcpuTimeInfo = &SharedInfo->VcpuInfo[0 ].Time; + +InitializeApicTimer (1 ,MAX_UINT32 , TRUE,0 );
OvmfPkg/XenPlatformPei/Xen.c InitializeXen ( · line 504
Quoted 10 lines
OvmfPkg/XenPlatformPei/Xen.c +10
-0+DisableApicTimerInterrupt (); + + TimerTick =GetApicTimerCurrentCount (); + TscTick =AsmReadTsc (); +XenDelay (VcpuTimeInfo,1000000ULL ); + TimerTick2 =GetApicTimerCurrentCount (); + TscTick2 =AsmReadTsc (); + + Freq = (GetCPUFreq (VcpuTimeInfo) * (TimerTick - TimerTick2)) + / (TscTick2 - TscTick);
(8) Please use the above-mentioned U64 multiplication and division helpers.
(9) In case we are concerned about U64 overflows anywhere in this patch:
SafeIntLib has range-checked functions, for example SafeUint64Mult().
Thanks!
Laszlo
OvmfPkg/XenPlatformPei/Xen.c InitializeXen ( · line 511
Quoted 8 lines
OvmfPkg/XenPlatformPei/Xen.c +7
-0+DEBUG ((DEBUG_INFO ,"APIC Freq % 8lu Hz\n" , Freq)); + +UnmapXenPage (SharedInfo); + +Exit: +FreePages (SharedInfo,1 ); +}
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 4/5] OvmfPkg/XenPlatformPei: Calibrate APIC timer frequency
In reply to Anthony PERARDQuoted 11 lines · Anthony PERARD
Calculate the frequency of the APIC timer that Xen provides.
Even though the frequency is currently hard-coded, it isn't part of the public ABI that Xen provides and thus may change at any time. OVMF needs to determine the frequency by an other mean.
Fortunately, Xen provides a way to determines the frequency of the TSC, so we can use TSC to calibrate the frequency of the APIC timer. That information is found in the
shared_infopage which we map and unmap once done (XenBusDxe is going to map the page somewhere else).
Quoted 5 lines
The calculated frequency is only logged in this patch, it will be used in a following patch.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2490
Signed-off-by Anthony PERARD <[email protected]>
Thanks! Some comments below on the implementation.
Quoted 87 lines
---
CC: Roger Pau Monné <[email protected]>--- OvmfPkg/XenPlatformPei/XenPlatformPei.inf | 1 + OvmfPkg/XenPlatformPei/Platform.h | 5 + OvmfPkg/XenPlatformPei/Platform.c | 1 + OvmfPkg/XenPlatformPei/Xen.c | 123 ++++++++++++++++++++++ 4 files changed, 130 insertions(+)OvmfPkg/XenPlatformPei/XenPlatformPei.inf +1
-0@@ -52,6 +52,7 @@ [LibraryClasses] DebugLib HobLib IoLib + LocalApicLib PciLib ResourcePublicationLib PeiServicesLibOvmfPkg/XenPlatformPei/Platform.h +5
-0@@ -127,6 +127,11 @@ XenGetE820Map (UINT32 *Count ); +VOID +CalibrateLapicTimer ( +VOID + ); +extern EFI_BOOT_MODE mBootMode;extern UINT8 mPhysMemAddressWidth;OvmfPkg/XenPlatformPei/Platform.c +1
-0@@ -448,6 +448,7 @@ InitializeXenPlatform (InitializeRamRegions ();InitializeXen (); +CalibrateLapicTimer ();if (mBootMode !=BOOT_ON_S3_RESUME ) {ReserveEmuVariableNvStore ();OvmfPkg/XenPlatformPei/Xen.c +23
-0@@ -19,6 +19,7 @@// #include <Library/DebugLib.h> #include <Library/HobLib.h> +#include <Library/LocalApicLib.h> #include <Library/MemoryAllocationLib.h> #include <Library/PcdLib.h> #include <Guid/XenInfo.h> @@ -386,3 +387,125 @@ InitializeXen (return EFI_SUCCESS ; } + + +EFI_STATUS +MapSharedInfoPage ( + IN VOID *PagePtr + ) +{ +xen_add_to_physmap_t Parameters; +INTN ReturnCode; + + Parameters.domid =DOMID_SELF ; + Parameters.space = XENMAPSPACE_shared_info; + Parameters.idx =0 ; + Parameters.gpfn = (UINTN ) PagePtr >>EFI_PAGE_SHIFT ; + ReturnCode =XenHypercallMemoryOp (XENMEM_add_to_physmap, &Parameters); +if (ReturnCode !=0 ) { +return EFI_NO_MAPPING ; + } +return EFI_SUCCESS ; +} + +VOID
OvmfPkg/XenPlatformPei/Xen.c InitializeXen ( · line 421
Quoted 10 lines
OvmfPkg/XenPlatformPei/Xen.c +10
-0+UnmapXenPage ( + IN VOID *PagePtr + ) +{ +xen_remove_from_physmap_t Parameters; +INTN ReturnCode; + + Parameters.domid =DOMID_SELF ; + Parameters.gpfn = (UINTN ) PagePtr >>EFI_PAGE_SHIFT ; + ReturnCode =XenHypercallMemoryOp (XENMEM_remove_from_physmap, &Parameters);
I'm afraid this will leave a hole in the p2m, and hence freeing the page back to OVMF is wrong (I assume this is what FreePages does in CalibrateLapicTimer), as the physical address would be unpopulated after the call to XENMEM_remove_from_physmap.
Quoted 54 lines
OvmfPkg/XenPlatformPei/Xen.c +54
-0+ASSERT (ReturnCode ==0 ); +} + + +STATIC +UINT64 +GetCPUFreq ( + IN XEN_VCPU_TIME_INFO *VcpuTime + ) +{ +UINT32 Version; +UINT32 TSCToSystemMultiplier; +INT8 TSCShift; +UINT64 CPUFreq; + +do { + Version = VcpuTime->Version; +MemoryFence (); + TSCToSystemMultiplier = VcpuTime->TSCToSystemMultiplier; + TSCShift = VcpuTime->TSCShift; +MemoryFence (); + }while (((Version &1 ) !=0 ) && (Version != VcpuTime->Version)); + + CPUFreq = (1000000000ULL <<32 ) / TSCToSystemMultiplier; +if (TSCShift >=0 ) { + CPUFreq >>= VcpuTime->TSCShift; + }else { + CPUFreq <<= -VcpuTime->TSCShift; + } +return CPUFreq; +} + +VOID +XenDelay ( + IN XEN_VCPU_TIME_INFO *VcpuTimeInfo, + IN UINT64 DelayNs + ) +{ +UINT64 Tick; + + Tick =AsmReadTsc (); + Tick += (DelayNs *GetCPUFreq (VcpuTimeInfo)) /1000000000ULL ; +while (AsmReadTsc () <= Tick) { +CpuPause (); + } +} + + +/** +Calculate the frequency of the Local Apic Timer +**/ +VOID +CalibrateLapicTimer ( + VOID
OvmfPkg/XenPlatformPei/Xen.c InitializeXen ( · line 485
Quoted 10 lines
OvmfPkg/XenPlatformPei/Xen.c +10
-0+ ) +{ +XEN_SHARED_INFO *SharedInfo; +XEN_VCPU_TIME_INFO *VcpuTimeInfo; +UINT32 TimerTick, TimerTick2; +UINT64 TscTick, TscTick2; +UINT64 Freq; +EFI_STATUS Status; + + SharedInfo =AllocatePages (1 );
Hm, it's not the best approach to use a regular memory page to map the shared info: mapping it is very likely to cause superpage shattering, and once unmapped it leaves a hole in the p2m.
As a reference you could map the shared info page at maximum physical address allowed (after checking it's not populated) like Wei is doing for the Xen on HyperV work.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 4/5] OvmfPkg/XenPlatformPei: Calibrate APIC timer frequency
Quoted 9 lines · Roger Pau Monné
OvmfPkg/XenPlatformPei/Xen.c InitializeXen ( · line 421
Quoted 3 lines · Anthony PERARD
OvmfPkg/XenPlatformPei/Xen.c +3
-0+ Parameters.domid =DOMID_SELF ; + Parameters.gpfn = (UINTN ) PagePtr >>EFI_PAGE_SHIFT ; + ReturnCode =XenHypercallMemoryOp (XENMEM_remove_from_physmap, &Parameters);I'm afraid this will leave a hole in the p2m, and hence freeing the page back to OVMF is wrong (I assume this is what FreePages does in CalibrateLapicTimer), as the physical address would be unpopulated after the call to
XENMEM_remove_from_physmap.
I guess there's more refactoring to do in OVMF, there are other's of this kind of call, mostly in the PV drivers, XenBusDxe.
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + SharedInfo = AllocatePages (1);Hm, it's not the best approach to use a regular memory page to map the shared info: mapping it is very likely to cause superpage shattering, and once unmapped it leaves a hole in the p2m.
:-(
Quoted 3 lines
As a reference you could map the shared info page at maximum physical address allowed (after checking it's not populated) like Wei is doing for the Xen on HyperV work.
I'll look at what can be done with OVMF.
Is there some kind of information that Xen could give? Or is it all information that OVMF should keep track of? Or if Xen only have XENMEM_memory_map, then OVMF already have this information.
Thanks,
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 4/5] OvmfPkg/XenPlatformPei: Calibrate APIC timer frequency
Quoted 19 lines · Anthony PERARD
Quoted 8 lines · Roger Pau Monné
OvmfPkg/XenPlatformPei/Xen.c InitializeXen ( · line 421
Quoted 3 lines · Anthony PERARD
OvmfPkg/XenPlatformPei/Xen.c +3
-0+ Parameters.domid =DOMID_SELF ; + Parameters.gpfn = (UINTN ) PagePtr >>EFI_PAGE_SHIFT ; + ReturnCode =XenHypercallMemoryOp (XENMEM_remove_from_physmap, &Parameters);I'm afraid this will leave a hole in the p2m, and hence freeing the page back to OVMF is wrong (I assume this is what FreePages does in CalibrateLapicTimer), as the physical address would be unpopulated after the call to
XENMEM_remove_from_physmap.I guess there's more refactoring to do in OVMF, there are other's of this kind of call, mostly in the PV drivers, XenBusDxe.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + SharedInfo = AllocatePages (1);Hm, it's not the best approach to use a regular memory page to map the shared info: mapping it is very likely to cause superpage shattering, and once unmapped it leaves a hole in the p2m.
:-(
Quoted 8 lines
Quoted 3 lines
As a reference you could map the shared info page at maximum physical address allowed (after checking it's not populated) like Wei is doing for the Xen on HyperV work.
I'll look at what can be done with OVMF.
Is there some kind of information that Xen could give? Or is it all information that OVMF should keep track of? Or if Xen only have
XENMEM_memory_map, then OVMF already have this information.
We need to actually tackle the memory problem, and provide something correct via XENMEM_memory_map (/similar).
So far, noone has actually started to try fixing the problem. Perhaps now is a good enough kick to get started.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 5/5 OvmfPkg/OvmfXen: Set PcdFSBClock
In reply to Anthony PERARDUpdate gEfiMdePkgTokenSpaceGuid.PcdFSBClock so it can have the correct value when SecPeiDxeTimerLibCpu start to use it for the APIC timer.
Currently, nothing appear to use the value in PcdFSBClock before XenPlatformPei had a chance to set it even though TimerLib is included in modules runned before XenPlatformPei.
XenPlatformPei doesn't use any of the functions that would use that value. No other modules in the PEI phase seems to use the TimerLib before PcdFSBClock is set. There are currently two other modules in the PEI phase that needs the TimerLib:
- S3Resume2Pei, but only because LocalApicLib needs it, but nothing is using the value from PcdFSBClock.
- CpuMpPei, but I believe it only runs after XenPlatformPei
Before the PEI phase, there's the SEC phase, and SecMain needs TimerLib because of LocalApicLib. And it initialise the APIC timers for the debug agent. But I don't think any of the DebugLib that OvmfXen could use are actually using the *Delay functions in TimerLib, and so would not use the value from PcdFSBClock which would be uninitialised.
A simple runtime test showed that TimerLib doesn't use PcdFSBClock value before it is set.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2490
--- OvmfPkg/OvmfXen.dsc | 4 +--- OvmfPkg/XenPlatformPei/XenPlatformPei.inf | 1 + OvmfPkg/XenPlatformPei/Xen.c | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-)
OvmfPkg/OvmfXen.dsc +1 -3
@@ -442,9 +442,6 @@ [PcdsFixedAtBuild] # Point to the MdeModulePkg/Application/UiApp/UiApp.inf gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 } - ## Xen vlapic's frequence is 100 MHz - gEfiMdePkgTokenSpaceGuid.PcdFSBClock|100000000 - ################################################################################ # # Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform
@@ -468,6 +465,7 @@ [PcdsDynamicDefault] gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Base|0x0 gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size|0x800000000 + gEfiMdePkgTokenSpaceGuid.PcdFSBClock gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|0 # Set video resolution for text setup.
OvmfPkg/XenPlatformPei/XenPlatformPei.inf +1 -0
@@ -83,6 +83,7 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask + gEfiMdePkgTokenSpaceGuid.PcdFSBClock gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress
OvmfPkg/XenPlatformPei/Xen.c +4 -0
@@ -504,6 +504,10 @@ CalibrateLapicTimer ( / (TscTick2 - TscTick);DEBUG ((DEBUG_INFO ,"APIC Freq % 8lu Hz\n" , Freq)); +ASSERT (Freq <=MAX_UINT32 ); + Status =PcdSet32S (PcdFSBClock, Freq); +ASSERT_RETURN_ERROR (Status); +UnmapXenPage (SharedInfo); Exit:
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 5/5] OvmfPkg/OvmfXen: Set PcdFSBClock
Quoted 48 lines · Anthony PERARD
Update gEfiMdePkgTokenSpaceGuid.PcdFSBClock so it can have the correct value when SecPeiDxeTimerLibCpu start to use it for the APIC timer.
Currently, nothing appear to use the value in PcdFSBClock before XenPlatformPei had a chance to set it even though TimerLib is included in modules runned before XenPlatformPei.
XenPlatformPei doesn't use any of the functions that would use that value. No other modules in the PEI phase seems to use the TimerLib before PcdFSBClock is set. There are currently two other modules in the PEI phase that needs the TimerLib:
- S3Resume2Pei, but only because LocalApicLib needs it, but nothing is using the value from PcdFSBClock.
- CpuMpPei, but I believe it only runs after XenPlatformPeiBefore the PEI phase, there's the SEC phase, and SecMain needs TimerLib because of LocalApicLib. And it initialise the APIC timers for the debug agent. But I don't think any of the DebugLib that OvmfXen could use are actually using the *Delay functions in TimerLib, and so would not use the value from PcdFSBClock which would be uninitialised.
A simple runtime test showed that TimerLib doesn't use PcdFSBClock value before it is set.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2490
Signed-off-by Anthony PERARD <[email protected]>--- OvmfPkg/OvmfXen.dsc | 4 +--- OvmfPkg/XenPlatformPei/XenPlatformPei.inf | 1 + OvmfPkg/XenPlatformPei/Xen.c | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-)OvmfPkg/OvmfXen.dsc +0
-3@@ -442,9 +442,6 @@ [PcdsFixedAtBuild] # Point to the MdeModulePkg/Application/UiApp/UiApp.inf gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 } - ## Xen vlapic's frequence is 100 MHz - gEfiMdePkgTokenSpaceGuid.PcdFSBClock|100000000 - ################################################################################ # # Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform
OvmfPkg/OvmfXen.dsc [PcdsDynamicDefault] · line 468
Quoted 4 lines
OvmfPkg/OvmfXen.dsc +1
-0@@ -468,6 +465,7 @@ [PcdsDynamicDefault] gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Base|0x0 gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size|0x800000000 + gEfiMdePkgTokenSpaceGuid.PcdFSBClock
(1) This syntax looks strange; I thought it was mandatory to provide a default value too.
https://edk2-docs.gitbooks.io/edk-ii-dsc-specification/content/2_dsc_overview/28_pcd_sections.html
---------
2.8.3.1 PcdsDynamicDefault
[...]
The format for a boolean or numeric datum type PCD entry in this section is:
PcdTokenSpaceGuidCName.PcdCName|Value
---------
I'm not sure if the "build" utility accepts this intentionally, or by mistake.
Can you simply keep the "|100000000" part too?
Otherwise, I'm OK with the argument laid out in the commit message. (Thank you for the detailed commit message!)
With (1) fixed:
Thanks!
Laszlo
Quoted 21 lines
OvmfPkg/OvmfXen.dsc +0
-0gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|0 # Set video resolution for text setup.OvmfPkg/XenPlatformPei/XenPlatformPei.inf +1
-0@@ -83,6 +83,7 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask + gEfiMdePkgTokenSpaceGuid.PcdFSBClock gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddressOvmfPkg/XenPlatformPei/Xen.c +0
-0
OvmfPkg/XenPlatformPei/Xen.c CalibrateLapicTimer ( · line 513
Quoted 10 lines
OvmfPkg/XenPlatformPei/Xen.c +4
-0@@ -504,6 +504,10 @@ CalibrateLapicTimer ( / (TscTick2 - TscTick);DEBUG ((DEBUG_INFO ,"APIC Freq % 8lu Hz\n" , Freq)); +ASSERT (Freq <=MAX_UINT32 ); + Status =PcdSet32S (PcdFSBClock, Freq); +ASSERT_RETURN_ERROR (Status); +UnmapXenPage (SharedInfo); Exit:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel