Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-21 Thread Donald Kuo
Thanks Liming help :)

Donald
> -Original Message-
> From: Gao, Liming
> Sent: Wednesday, August 21, 2019 9:46 PM
> To: Zeng, Star ; Kuo, Donald ;
> devel@edk2.groups.io; ler...@redhat.com; Dong, Eric
> 
> Cc: Ni, Ray ; Chan, Amy ;
> Chaganty, Rangasai V ; Lai, Luke
> ; Li, Kevin Y ;
> leif.lindh...@linaro.org; af...@apple.com; Kinney, Michael D
> 
> Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by
> using CPUID(0x15) TSC leaf
> 
> Done. And, push @30781febe2106cc0d7186e70136120353cd67df2
> 
> Thanks
> Liming
> > -Original Message-
> > From: Zeng, Star
> > Sent: Tuesday, August 20, 2019 10:00 PM
> > To: Gao, Liming ; Kuo, Donald
> > ; devel@edk2.groups.io; ler...@redhat.com;
> Dong,
> > Eric 
> > Cc: Ni, Ray ; Chan, Amy ;
> > Chaganty, Rangasai V ; Lai, Luke
> > ; Li, Kevin Y ;
> > leif.lindh...@linaro.org; af...@apple.com; Kinney, Michael D
> > ; Zeng, Star 
> > Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library
> > by using CPUID(0x15) TSC leaf
> >
> > Remember to add entry for it at
> https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Release-
> Planning.
> >
> > > -Original Message-
> > > From: Gao, Liming
> > > Sent: Tuesday, August 20, 2019 7:56 PM
> > > To: Kuo, Donald ; devel@edk2.groups.io;
> > > ler...@redhat.com; Dong, Eric 
> > > Cc: Ni, Ray ; Zeng, Star ;
> > > Chan, Amy ; Chaganty, Rangasai V
> > > ; Lai, Luke ; Li,
> > > Kevin Y ; leif.lindh...@linaro.org;
> > > af...@apple.com; Kinney, Michael D 
> > > Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC
> > > library by using CPUID(0x15) TSC leaf
> > >
> > > Donald:
> > >   Thanks for your update. If no other comment, I will help push this
> > > patch tomorrow.
> > >
> > > Thanks
> > > Liming
> > > > -Original Message-
> > > > From: Kuo, Donald
> > > > Sent: Tuesday, August 20, 2019 3:22 PM
> > > > To: Gao, Liming ; devel@edk2.groups.io;
> > > > ler...@redhat.com; Dong, Eric 
> > > > Cc: Ni, Ray ; Zeng, Star ;
> > > > Chan, Amy ; Chaganty, Rangasai V
> > > > ; Lai, Luke ;
> > > > Li, Kevin Y ; leif.lindh...@linaro.org;
> > > > af...@apple.com; Kinney, Michael D 
> > > > Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC
> > > > library by using CPUID(0x15) TSC leaf
> > > >
> > > > Hi Liming,
> > > >
> > > > Done.
> > > >
> > > > Patch is attached to
> > > > https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> > > >
> > > > Another BZ to apply CpuTimerLib will be tracking on:
> > > > https://bugzilla.tianocore.org/show_bug.cgi?id=2096
> > > >
> > > > Thanks,
> > > > Donald
> > > >
> > > > > -Original Message-
> > > > > From: Gao, Liming
> > > > > Sent: Tuesday, August 20, 2019 2:51 PM
> > > > > To: Kuo, Donald ; devel@edk2.groups.io;
> > > > > ler...@redhat.com; Dong, Eric 
> > > > > Cc: Ni, Ray ; Zeng, Star
> > > > > ; Chan, Amy ;
> Chaganty,
> > > > > Rangasai V ; Lai, Luke
> > > > > ; Li, Kevin Y ;
> > > > > leif.lindh...@linaro.org; af...@apple.com; Kinney, Michael D
> > > > > 
> > > > > Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC
> > > > > library by using CPUID(0x15) TSC leaf
> > > > >
> > > > > Donald:
> > > > >   Please also attach the patch linker in BZs.
> > > > >
> > > > >   And, please submit another BZ for edk2-
> > > > > platforms\Platform\Intel\KabylakeOpenBoardPkg to apply this new
> > > > > library instance.
> > > > >
> > > > > Thanks
> > > > > Liming
> > > > > >-Original Message-
> > > > > >From: Kuo, Donald
> > > > > >Sent: Tuesday, August 20, 2019 10:44 AM
> > > > > >To: devel@edk2.groups.io; ler...@redhat.com; Gao, Liming
> > > > > >; Dong, Eric 
> > > > > >Cc: Ni, Ray ; Zeng, Star
> > > > > >; Chan, Amy ;
> > > > > >Chaganty, Rangasai V ; Lai, Luke
> > > > > >; Li, Kevin Y ;
> > > > > >leif.lindh...@linaro.org; af...@appl

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-21 Thread Liming Gao
Done. And, push @30781febe2106cc0d7186e70136120353cd67df2

Thanks
Liming
> -Original Message-
> From: Zeng, Star
> Sent: Tuesday, August 20, 2019 10:00 PM
> To: Gao, Liming ; Kuo, Donald ; 
> devel@edk2.groups.io; ler...@redhat.com; Dong, Eric
> 
> Cc: Ni, Ray ; Chan, Amy ; Chaganty, 
> Rangasai V ; Lai, Luke
> ; Li, Kevin Y ; 
> leif.lindh...@linaro.org; af...@apple.com; Kinney, Michael D
> ; Zeng, Star 
> Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by 
> using CPUID(0x15) TSC leaf
> 
> Remember to add entry for it at 
> https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Release-Planning.
> 
> > -Original Message-
> > From: Gao, Liming
> > Sent: Tuesday, August 20, 2019 7:56 PM
> > To: Kuo, Donald ; devel@edk2.groups.io;
> > ler...@redhat.com; Dong, Eric 
> > Cc: Ni, Ray ; Zeng, Star ; Chan, Amy
> > ; Chaganty, Rangasai V
> > ; Lai, Luke ; Li, Kevin Y
> > ; leif.lindh...@linaro.org; af...@apple.com; Kinney,
> > Michael D 
> > Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by
> > using CPUID(0x15) TSC leaf
> >
> > Donald:
> >   Thanks for your update. If no other comment, I will help push this patch
> > tomorrow.
> >
> > Thanks
> > Liming
> > > -Original Message-
> > > From: Kuo, Donald
> > > Sent: Tuesday, August 20, 2019 3:22 PM
> > > To: Gao, Liming ; devel@edk2.groups.io;
> > > ler...@redhat.com; Dong, Eric 
> > > Cc: Ni, Ray ; Zeng, Star ;
> > > Chan, Amy ; Chaganty, Rangasai V
> > > ; Lai, Luke ; Li,
> > > Kevin Y ; leif.lindh...@linaro.org;
> > > af...@apple.com; Kinney, Michael D 
> > > Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library
> > > by using CPUID(0x15) TSC leaf
> > >
> > > Hi Liming,
> > >
> > > Done.
> > >
> > > Patch is attached to
> > > https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> > >
> > > Another BZ to apply CpuTimerLib will be tracking on:
> > > https://bugzilla.tianocore.org/show_bug.cgi?id=2096
> > >
> > > Thanks,
> > > Donald
> > >
> > > > -Original Message-
> > > > From: Gao, Liming
> > > > Sent: Tuesday, August 20, 2019 2:51 PM
> > > > To: Kuo, Donald ; devel@edk2.groups.io;
> > > > ler...@redhat.com; Dong, Eric 
> > > > Cc: Ni, Ray ; Zeng, Star ;
> > > > Chan, Amy ; Chaganty, Rangasai V
> > > > ; Lai, Luke ; Li,
> > > > Kevin Y ; leif.lindh...@linaro.org;
> > > > af...@apple.com; Kinney, Michael D 
> > > > Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC
> > > > library by using CPUID(0x15) TSC leaf
> > > >
> > > > Donald:
> > > >   Please also attach the patch linker in BZs.
> > > >
> > > >   And, please submit another BZ for edk2-
> > > > platforms\Platform\Intel\KabylakeOpenBoardPkg to apply this new
> > > > library instance.
> > > >
> > > > Thanks
> > > > Liming
> > > > >-Original Message-
> > > > >From: Kuo, Donald
> > > > >Sent: Tuesday, August 20, 2019 10:44 AM
> > > > >To: devel@edk2.groups.io; ler...@redhat.com; Gao, Liming
> > > > >; Dong, Eric 
> > > > >Cc: Ni, Ray ; Zeng, Star ;
> > > > >Chan, Amy ; Chaganty, Rangasai V
> > > > >; Lai, Luke ;
> > > > >Li, Kevin Y ; leif.lindh...@linaro.org;
> > > > >af...@apple.com; Kinney, Michael D 
> > > > >Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC
> > > > >library by using CPUID(0x15) TSC leaf
> > > > >
> > > > >Thanks Laszlo help to review and great feedbacks. That we did miss
> > > > >to fulfil
> > > > BZ.
> > > > >
> > > > >I had updated Bugzilla
> > > > >https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> > > > >for more documentation.
> > > > >
> > > > >As I know for the edk2-platforms should be consumed as KBL (7th
> > > > >Generation) platform in Client, and this feature based on SDM is
> > > > >supported on SKL (6th Generation, Family 06h) onwards. So it's ok
> > > > >to use as TimerLib instances for edk2-platforms.
> > > > >
> > > > >And I think the library is new instances for TimerLib for support

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-20 Thread Zeng, Star
Remember to add entry for it at 
https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Release-Planning.

> -Original Message-
> From: Gao, Liming
> Sent: Tuesday, August 20, 2019 7:56 PM
> To: Kuo, Donald ; devel@edk2.groups.io;
> ler...@redhat.com; Dong, Eric 
> Cc: Ni, Ray ; Zeng, Star ; Chan, Amy
> ; Chaganty, Rangasai V
> ; Lai, Luke ; Li, Kevin Y
> ; leif.lindh...@linaro.org; af...@apple.com; Kinney,
> Michael D 
> Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by
> using CPUID(0x15) TSC leaf
> 
> Donald:
>   Thanks for your update. If no other comment, I will help push this patch
> tomorrow.
> 
> Thanks
> Liming
> > -Original Message-
> > From: Kuo, Donald
> > Sent: Tuesday, August 20, 2019 3:22 PM
> > To: Gao, Liming ; devel@edk2.groups.io;
> > ler...@redhat.com; Dong, Eric 
> > Cc: Ni, Ray ; Zeng, Star ;
> > Chan, Amy ; Chaganty, Rangasai V
> > ; Lai, Luke ; Li,
> > Kevin Y ; leif.lindh...@linaro.org;
> > af...@apple.com; Kinney, Michael D 
> > Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library
> > by using CPUID(0x15) TSC leaf
> >
> > Hi Liming,
> >
> > Done.
> >
> > Patch is attached to
> > https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> >
> > Another BZ to apply CpuTimerLib will be tracking on:
> > https://bugzilla.tianocore.org/show_bug.cgi?id=2096
> >
> > Thanks,
> > Donald
> >
> > > -Original Message-
> > > From: Gao, Liming
> > > Sent: Tuesday, August 20, 2019 2:51 PM
> > > To: Kuo, Donald ; devel@edk2.groups.io;
> > > ler...@redhat.com; Dong, Eric 
> > > Cc: Ni, Ray ; Zeng, Star ;
> > > Chan, Amy ; Chaganty, Rangasai V
> > > ; Lai, Luke ; Li,
> > > Kevin Y ; leif.lindh...@linaro.org;
> > > af...@apple.com; Kinney, Michael D 
> > > Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC
> > > library by using CPUID(0x15) TSC leaf
> > >
> > > Donald:
> > >   Please also attach the patch linker in BZs.
> > >
> > >   And, please submit another BZ for edk2-
> > > platforms\Platform\Intel\KabylakeOpenBoardPkg to apply this new
> > > library instance.
> > >
> > > Thanks
> > > Liming
> > > >-Original Message-----
> > > >From: Kuo, Donald
> > > >Sent: Tuesday, August 20, 2019 10:44 AM
> > > >To: devel@edk2.groups.io; ler...@redhat.com; Gao, Liming
> > > >; Dong, Eric 
> > > >Cc: Ni, Ray ; Zeng, Star ;
> > > >Chan, Amy ; Chaganty, Rangasai V
> > > >; Lai, Luke ;
> > > >Li, Kevin Y ; leif.lindh...@linaro.org;
> > > >af...@apple.com; Kinney, Michael D 
> > > >Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC
> > > >library by using CPUID(0x15) TSC leaf
> > > >
> > > >Thanks Laszlo help to review and great feedbacks. That we did miss
> > > >to fulfil
> > > BZ.
> > > >
> > > >I had updated Bugzilla
> > > >https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> > > >for more documentation.
> > > >
> > > >As I know for the edk2-platforms should be consumed as KBL (7th
> > > >Generation) platform in Client, and this feature based on SDM is
> > > >supported on SKL (6th Generation, Family 06h) onwards. So it's ok
> > > >to use as TimerLib instances for edk2-platforms.
> > > >
> > > >And I think the library is new instances for TimerLib for supported
> > > >CPU, and those non-supported CPU will still keep using AcpiTimerlib
> > > >as TimerLib instances.
> > > >
> > > >Thanks,
> > > >Donald
> > > >
> > > >> -Original Message-
> > > >> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On
> > > >> Behalf Of Laszlo Ersek
> > > >> Sent: Saturday, August 17, 2019 4:40 AM
> > > >> To: Gao, Liming ; Kuo, Donald
> > > >> ; Dong, Eric ;
> > > >> devel@edk2.groups.io
> > > >> Cc: Ni, Ray ; Zeng, Star ;
> > > >> Chan, Amy ; Chaganty, Rangasai V
> > > >> ; Lai, Luke ;
> > > >> Li, Kevin Y ; leif.lindh...@linaro.org;
> > > >> af...@apple.com;
> > > >Kinney,
> > > >> Michael D 
> > > >> Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC
> > > >> library by using CPUID(0x1

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-20 Thread Liming Gao
Donald:
  Thanks for your update. If no other comment, I will help push this patch 
tomorrow. 

Thanks
Liming
> -Original Message-
> From: Kuo, Donald
> Sent: Tuesday, August 20, 2019 3:22 PM
> To: Gao, Liming ; devel@edk2.groups.io; 
> ler...@redhat.com; Dong, Eric 
> Cc: Ni, Ray ; Zeng, Star ; Chan, Amy 
> ; Chaganty, Rangasai V
> ; Lai, Luke ; Li, Kevin Y 
> ; leif.lindh...@linaro.org;
> af...@apple.com; Kinney, Michael D 
> Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by 
> using CPUID(0x15) TSC leaf
> 
> Hi Liming,
> 
> Done.
> 
> Patch is attached to https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> 
> Another BZ to apply CpuTimerLib will be tracking on:  
> https://bugzilla.tianocore.org/show_bug.cgi?id=2096
> 
> Thanks,
> Donald
> 
> > -Original Message-
> > From: Gao, Liming
> > Sent: Tuesday, August 20, 2019 2:51 PM
> > To: Kuo, Donald ; devel@edk2.groups.io;
> > ler...@redhat.com; Dong, Eric 
> > Cc: Ni, Ray ; Zeng, Star ; Chan,
> > Amy ; Chaganty, Rangasai V
> > ; Lai, Luke ; Li, Kevin
> > Y ; leif.lindh...@linaro.org; af...@apple.com; Kinney,
> > Michael D 
> > Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by
> > using CPUID(0x15) TSC leaf
> >
> > Donald:
> >   Please also attach the patch linker in BZs.
> >
> >   And, please submit another BZ for edk2-
> > platforms\Platform\Intel\KabylakeOpenBoardPkg to apply this new library
> > instance.
> >
> > Thanks
> > Liming
> > >-Original Message-
> > >From: Kuo, Donald
> > >Sent: Tuesday, August 20, 2019 10:44 AM
> > >To: devel@edk2.groups.io; ler...@redhat.com; Gao, Liming
> > >; Dong, Eric 
> > >Cc: Ni, Ray ; Zeng, Star ; Chan,
> > >Amy ; Chaganty, Rangasai V
> > >; Lai, Luke ; Li,
> > >Kevin Y ; leif.lindh...@linaro.org;
> > >af...@apple.com; Kinney, Michael D 
> > >Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library
> > >by using CPUID(0x15) TSC leaf
> > >
> > >Thanks Laszlo help to review and great feedbacks. That we did miss to 
> > >fulfil
> > BZ.
> > >
> > >I had updated Bugzilla
> > >https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> > >for more documentation.
> > >
> > >As I know for the edk2-platforms should be consumed as KBL (7th
> > >Generation) platform in Client, and this feature based on SDM is
> > >supported on SKL (6th Generation, Family 06h) onwards. So it's ok to
> > >use as TimerLib instances for edk2-platforms.
> > >
> > >And I think the library is new instances for TimerLib for supported
> > >CPU, and those non-supported CPU will still keep using AcpiTimerlib as
> > >TimerLib instances.
> > >
> > >Thanks,
> > >Donald
> > >
> > >> -----Original Message-
> > >> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> > >> Laszlo Ersek
> > >> Sent: Saturday, August 17, 2019 4:40 AM
> > >> To: Gao, Liming ; Kuo, Donald
> > >> ; Dong, Eric ;
> > >> devel@edk2.groups.io
> > >> Cc: Ni, Ray ; Zeng, Star ;
> > >> Chan, Amy ; Chaganty, Rangasai V
> > >> ; Lai, Luke ; Li,
> > >> Kevin Y ; leif.lindh...@linaro.org;
> > >> af...@apple.com;
> > >Kinney,
> > >> Michael D 
> > >> Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC
> > >> library by using CPUID(0x15) TSC leaf
> > >>
> > >> On 08/16/19 18:16, Laszlo Ersek wrote:
> > >> > On 08/15/19 06:02, Gao, Liming wrote:
> > >> >> Donald: This change is a new feature. Now, it is not in edk2
> > >> >> feature planning list. If you want to catch it into 201908 stable
> > >> >> tag, please get approve from Stewards first. I have cc this mail to 
> > >> >> all
> > Stewards.
> > >> > - I don't mind adding a new feature, as long as it gets properly
> > >> > reviewed by package owners before we enter the soft feature freeze.
> > >> >
> > >> > - Looking at the BZ
> > >> > <https://bugzilla.tianocore.org/show_bug.cgi?id=1909>, a bit more
> > >> > documentation would be nice.
> > >> >
> > >> > - On the negative side, I'm very much *not* a fan of adding
> > >> > features to the open source edk2 tree without actua

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-20 Thread Donald Kuo
Hi Liming,

Done.

Patch is attached to https://bugzilla.tianocore.org/show_bug.cgi?id=1909

Another BZ to apply CpuTimerLib will be tracking on:  
https://bugzilla.tianocore.org/show_bug.cgi?id=2096

Thanks,
Donald

> -Original Message-
> From: Gao, Liming
> Sent: Tuesday, August 20, 2019 2:51 PM
> To: Kuo, Donald ; devel@edk2.groups.io;
> ler...@redhat.com; Dong, Eric 
> Cc: Ni, Ray ; Zeng, Star ; Chan,
> Amy ; Chaganty, Rangasai V
> ; Lai, Luke ; Li, Kevin
> Y ; leif.lindh...@linaro.org; af...@apple.com; Kinney,
> Michael D 
> Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by
> using CPUID(0x15) TSC leaf
> 
> Donald:
>   Please also attach the patch linker in BZs.
> 
>   And, please submit another BZ for edk2-
> platforms\Platform\Intel\KabylakeOpenBoardPkg to apply this new library
> instance.
> 
> Thanks
> Liming
> >-Original Message-
> >From: Kuo, Donald
> >Sent: Tuesday, August 20, 2019 10:44 AM
> >To: devel@edk2.groups.io; ler...@redhat.com; Gao, Liming
> >; Dong, Eric 
> >Cc: Ni, Ray ; Zeng, Star ; Chan,
> >Amy ; Chaganty, Rangasai V
> >; Lai, Luke ; Li,
> >Kevin Y ; leif.lindh...@linaro.org;
> >af...@apple.com; Kinney, Michael D 
> >Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library
> >by using CPUID(0x15) TSC leaf
> >
> >Thanks Laszlo help to review and great feedbacks. That we did miss to fulfil
> BZ.
> >
> >I had updated Bugzilla
> >https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> >for more documentation.
> >
> >As I know for the edk2-platforms should be consumed as KBL (7th
> >Generation) platform in Client, and this feature based on SDM is
> >supported on SKL (6th Generation, Family 06h) onwards. So it's ok to
> >use as TimerLib instances for edk2-platforms.
> >
> >And I think the library is new instances for TimerLib for supported
> >CPU, and those non-supported CPU will still keep using AcpiTimerlib as
> >TimerLib instances.
> >
> >Thanks,
> >Donald
> >
> >> -Original Message-
> >> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> >> Laszlo Ersek
> >> Sent: Saturday, August 17, 2019 4:40 AM
> >> To: Gao, Liming ; Kuo, Donald
> >> ; Dong, Eric ;
> >> devel@edk2.groups.io
> >> Cc: Ni, Ray ; Zeng, Star ;
> >> Chan, Amy ; Chaganty, Rangasai V
> >> ; Lai, Luke ; Li,
> >> Kevin Y ; leif.lindh...@linaro.org;
> >> af...@apple.com;
> >Kinney,
> >> Michael D 
> >> Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC
> >> library by using CPUID(0x15) TSC leaf
> >>
> >> On 08/16/19 18:16, Laszlo Ersek wrote:
> >> > On 08/15/19 06:02, Gao, Liming wrote:
> >> >> Donald: This change is a new feature. Now, it is not in edk2
> >> >> feature planning list. If you want to catch it into 201908 stable
> >> >> tag, please get approve from Stewards first. I have cc this mail to all
> Stewards.
> >> > - I don't mind adding a new feature, as long as it gets properly
> >> > reviewed by package owners before we enter the soft feature freeze.
> >> >
> >> > - Looking at the BZ
> >> > <https://bugzilla.tianocore.org/show_bug.cgi?id=1909>, a bit more
> >> > documentation would be nice.
> >> >
> >> > - On the negative side, I'm very much *not* a fan of adding
> >> > features to the open source edk2 tree without actually *consuming*
> >> > the feature in an open source tree. Are the new library instances
> >> > going to be put to use in edk2-platforms, perhaps?
> >> >
> >> > We discussed this topic earlier on some of the stewards' calls. On
> >> > one hand, it's not uncommon to see library instances from Intel
> >> > enter core
> >> > edk2 packages without any dependent platform code, or even a
> >> > detailed problem statement / purpose description (see e.g. commit
> >> > 5c9bb86f171c and its surrounding commits). On the other hand,
> >> > attempts in the past, to add libraries with well demonstrated and
> >> > direct in-tree use cases, to
> >> > edk2 core, have been rejected, from other submitters. (Here's one
> >> > example: <https://bugzilla.tianocore.org/show_bug.cgi?id=957>.) I'm
> >> > not prying at proprietary platform information, but a new library
> >> > added to
> >> > edk2 core *should* be well-justified.
> >> >
> >&

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-20 Thread Liming Gao
Donald:
  Please also attach the patch linker in BZs. 

  And, please submit another BZ for 
edk2-platforms\Platform\Intel\KabylakeOpenBoardPkg to apply this new library 
instance. 

Thanks
Liming
>-Original Message-
>From: Kuo, Donald
>Sent: Tuesday, August 20, 2019 10:44 AM
>To: devel@edk2.groups.io; ler...@redhat.com; Gao, Liming
>; Dong, Eric 
>Cc: Ni, Ray ; Zeng, Star ; Chan, Amy
>; Chaganty, Rangasai V
>; Lai, Luke ; Li, Kevin Y
>; leif.lindh...@linaro.org; af...@apple.com; Kinney,
>Michael D 
>Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by
>using CPUID(0x15) TSC leaf
>
>Thanks Laszlo help to review and great feedbacks. That we did miss to fulfil 
>BZ.
>
>I had updated Bugzilla https://bugzilla.tianocore.org/show_bug.cgi?id=1909
>for more documentation.
>
>As I know for the edk2-platforms should be consumed as KBL (7th Generation)
>platform in Client, and this feature based on SDM is supported on SKL (6th
>Generation, Family 06h) onwards. So it's ok to use as TimerLib instances for
>edk2-platforms.
>
>And I think the library is new instances for TimerLib for supported CPU, and
>those non-supported CPU will still keep using AcpiTimerlib as TimerLib
>instances.
>
>Thanks,
>Donald
>
>> -Original Message-
>> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
>> Laszlo Ersek
>> Sent: Saturday, August 17, 2019 4:40 AM
>> To: Gao, Liming ; Kuo, Donald
>> ; Dong, Eric ;
>> devel@edk2.groups.io
>> Cc: Ni, Ray ; Zeng, Star ; Chan,
>> Amy ; Chaganty, Rangasai V
>> ; Lai, Luke ; Li, Kevin
>> Y ; leif.lindh...@linaro.org; af...@apple.com;
>Kinney,
>> Michael D 
>> Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by
>> using CPUID(0x15) TSC leaf
>>
>> On 08/16/19 18:16, Laszlo Ersek wrote:
>> > On 08/15/19 06:02, Gao, Liming wrote:
>> >> Donald: This change is a new feature. Now, it is not in edk2 feature
>> >> planning list. If you want to catch it into 201908 stable tag, please
>> >> get approve from Stewards first. I have cc this mail to all Stewards.
>> > - I don't mind adding a new feature, as long as it gets properly
>> > reviewed by package owners before we enter the soft feature freeze.
>> >
>> > - Looking at the BZ
>> > <https://bugzilla.tianocore.org/show_bug.cgi?id=1909>, a bit more
>> > documentation would be nice.
>> >
>> > - On the negative side, I'm very much *not* a fan of adding features
>> > to the open source edk2 tree without actually *consuming* the feature
>> > in an open source tree. Are the new library instances going to be put
>> > to use in edk2-platforms, perhaps?
>> >
>> > We discussed this topic earlier on some of the stewards' calls. On one
>> > hand, it's not uncommon to see library instances from Intel enter core
>> > edk2 packages without any dependent platform code, or even a detailed
>> > problem statement / purpose description (see e.g. commit 5c9bb86f171c
>> > and its surrounding commits). On the other hand, attempts in the past,
>> > to add libraries with well demonstrated and direct in-tree use cases,
>> > to
>> > edk2 core, have been rejected, from other submitters. (Here's one
>> > example: <https://bugzilla.tianocore.org/show_bug.cgi?id=957>.) I'm
>> > not prying at proprietary platform information, but a new library
>> > added to
>> > edk2 core *should* be well-justified.
>> >
>> > The commit message on this patch is empty. It only references
>> > <https://bugzilla.tianocore.org/show_bug.cgi?id=1909>. And if I open
>> > the BZ, this is all I get:
>> >
>> > Need a new TSC library to check the CPUID leaf (EAX=0x15) for TSC.
>> > For new platform (start from SKL) can use CPUID and retire/remove
>> > the current override from AcpiTimerLib.
>> >
>> > Does this read like an actual feature request? (TimerLib is an MdePkg
>> > library class, so not exactly "niche".)
>>
>> In comparison, the following email does read like a feature request:
>>
>> [edk2-devel] Determining TSC frequency programmatically
>> https://edk2.groups.io/g/devel/message/45750
>> http://mid.mail-archive.com/8EC14D0D-DFA5-412D-A4E1-
>> 4d641576d...@protonmail.com
>>
>> If the posting is related to TianoCore#1909, then I urge the BZ assignee to
>> please reference the message in the TianoCore BZ.
>>
>> Thanks
>> Laszlo
>>
>> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#46082): https://edk2.groups.io/g/devel/message/46082
Mute This Topic: https://groups.io/mt/32839184/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-19 Thread Donald Kuo
Thanks Laszlo help to review and great feedbacks. That we did miss to fulfil 
BZ. 

I had updated Bugzilla https://bugzilla.tianocore.org/show_bug.cgi?id=1909 for 
more documentation.

As I know for the edk2-platforms should be consumed as KBL (7th Generation) 
platform in Client, and this feature based on SDM is supported on SKL (6th 
Generation, Family 06h) onwards. So it's ok to use as TimerLib instances for 
edk2-platforms.

And I think the library is new instances for TimerLib for supported CPU, and 
those non-supported CPU will still keep using AcpiTimerlib as TimerLib 
instances.

Thanks,
Donald

> -Original Message-
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Laszlo Ersek
> Sent: Saturday, August 17, 2019 4:40 AM
> To: Gao, Liming ; Kuo, Donald
> ; Dong, Eric ;
> devel@edk2.groups.io
> Cc: Ni, Ray ; Zeng, Star ; Chan,
> Amy ; Chaganty, Rangasai V
> ; Lai, Luke ; Li, Kevin
> Y ; leif.lindh...@linaro.org; af...@apple.com; Kinney,
> Michael D 
> Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by
> using CPUID(0x15) TSC leaf
> 
> On 08/16/19 18:16, Laszlo Ersek wrote:
> > On 08/15/19 06:02, Gao, Liming wrote:
> >> Donald: This change is a new feature. Now, it is not in edk2 feature
> >> planning list. If you want to catch it into 201908 stable tag, please
> >> get approve from Stewards first. I have cc this mail to all Stewards.
> > - I don't mind adding a new feature, as long as it gets properly
> > reviewed by package owners before we enter the soft feature freeze.
> >
> > - Looking at the BZ
> > <https://bugzilla.tianocore.org/show_bug.cgi?id=1909>, a bit more
> > documentation would be nice.
> >
> > - On the negative side, I'm very much *not* a fan of adding features
> > to the open source edk2 tree without actually *consuming* the feature
> > in an open source tree. Are the new library instances going to be put
> > to use in edk2-platforms, perhaps?
> >
> > We discussed this topic earlier on some of the stewards' calls. On one
> > hand, it's not uncommon to see library instances from Intel enter core
> > edk2 packages without any dependent platform code, or even a detailed
> > problem statement / purpose description (see e.g. commit 5c9bb86f171c
> > and its surrounding commits). On the other hand, attempts in the past,
> > to add libraries with well demonstrated and direct in-tree use cases,
> > to
> > edk2 core, have been rejected, from other submitters. (Here's one
> > example: <https://bugzilla.tianocore.org/show_bug.cgi?id=957>.) I'm
> > not prying at proprietary platform information, but a new library
> > added to
> > edk2 core *should* be well-justified.
> >
> > The commit message on this patch is empty. It only references
> > <https://bugzilla.tianocore.org/show_bug.cgi?id=1909>. And if I open
> > the BZ, this is all I get:
> >
> > Need a new TSC library to check the CPUID leaf (EAX=0x15) for TSC.
> > For new platform (start from SKL) can use CPUID and retire/remove
> > the current override from AcpiTimerLib.
> >
> > Does this read like an actual feature request? (TimerLib is an MdePkg
> > library class, so not exactly "niche".)
> 
> In comparison, the following email does read like a feature request:
> 
> [edk2-devel] Determining TSC frequency programmatically
> https://edk2.groups.io/g/devel/message/45750
> http://mid.mail-archive.com/8EC14D0D-DFA5-412D-A4E1-
> 4d641576d...@protonmail.com
> 
> If the posting is related to TianoCore#1909, then I urge the BZ assignee to
> please reference the message in the TianoCore BZ.
> 
> Thanks
> Laszlo
> 
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#46074): https://edk2.groups.io/g/devel/message/46074
Mute This Topic: https://groups.io/mt/32839184/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-16 Thread Laszlo Ersek
On 08/16/19 18:16, Laszlo Ersek wrote:
> On 08/15/19 06:02, Gao, Liming wrote:
>> Donald: This change is a new feature. Now, it is not in edk2 feature
>> planning list. If you want to catch it into 201908 stable tag, please
>> get approve from Stewards first. I have cc this mail to all Stewards.
> - I don't mind adding a new feature, as long as it gets properly
> reviewed by package owners before we enter the soft feature freeze.
> 
> - Looking at the BZ
> , a bit more
> documentation would be nice.
> 
> - On the negative side, I'm very much *not* a fan of adding features to
> the open source edk2 tree without actually *consuming* the feature in an
> open source tree. Are the new library instances going to be put to use
> in edk2-platforms, perhaps?
> 
> We discussed this topic earlier on some of the stewards' calls. On one
> hand, it's not uncommon to see library instances from Intel enter core
> edk2 packages without any dependent platform code, or even a detailed
> problem statement / purpose description (see e.g. commit 5c9bb86f171c
> and its surrounding commits). On the other hand, attempts in the past,
> to add libraries with well demonstrated and direct in-tree use cases, to
> edk2 core, have been rejected, from other submitters. (Here's one
> example: .) I'm not
> prying at proprietary platform information, but a new library added to
> edk2 core *should* be well-justified.
> 
> The commit message on this patch is empty. It only references
> . And if I open the
> BZ, this is all I get:
> 
> Need a new TSC library to check the CPUID leaf (EAX=0x15) for TSC.
> For new platform (start from SKL) can use CPUID and retire/remove
> the current override from AcpiTimerLib.
> 
> Does this read like an actual feature request? (TimerLib is an MdePkg
> library class, so not exactly "niche".)

In comparison, the following email does read like a feature request:

[edk2-devel] Determining TSC frequency programmatically
https://edk2.groups.io/g/devel/message/45750
8EC14D0D-DFA5-412D-A4E1-4D641576D58E@protonmail.com">http://mid.mail-archive.com/8EC14D0D-DFA5-412D-A4E1-4D641576D58E@protonmail.com

If the posting is related to TianoCore#1909, then I urge the BZ assignee to 
please reference the message in the TianoCore BZ.

Thanks
Laszlo

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45857): https://edk2.groups.io/g/devel/message/45857
Mute This Topic: https://groups.io/mt/32839184/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-16 Thread Laszlo Ersek
On 08/15/19 06:02, Gao, Liming wrote:
> Donald: This change is a new feature. Now, it is not in edk2 feature
> planning list. If you want to catch it into 201908 stable tag, please
> get approve from Stewards first. I have cc this mail to all Stewards.
- I don't mind adding a new feature, as long as it gets properly
reviewed by package owners before we enter the soft feature freeze.

- Looking at the BZ
, a bit more
documentation would be nice.

- On the negative side, I'm very much *not* a fan of adding features to
the open source edk2 tree without actually *consuming* the feature in an
open source tree. Are the new library instances going to be put to use
in edk2-platforms, perhaps?

We discussed this topic earlier on some of the stewards' calls. On one
hand, it's not uncommon to see library instances from Intel enter core
edk2 packages without any dependent platform code, or even a detailed
problem statement / purpose description (see e.g. commit 5c9bb86f171c
and its surrounding commits). On the other hand, attempts in the past,
to add libraries with well demonstrated and direct in-tree use cases, to
edk2 core, have been rejected, from other submitters. (Here's one
example: .) I'm not
prying at proprietary platform information, but a new library added to
edk2 core *should* be well-justified.

The commit message on this patch is empty. It only references
. And if I open the
BZ, this is all I get:

Need a new TSC library to check the CPUID leaf (EAX=0x15) for TSC.
For new platform (start from SKL) can use CPUID and retire/remove
the current override from AcpiTimerLib.

Does this read like an actual feature request? (TimerLib is an MdePkg
library class, so not exactly "niche".)

Plus, the BZ isn't even marked as a feature request, to begin with (the
Product field is wrong, it says "EDK2", which is for bugs, not
features). Also, the patch is on the list, and the status is still
CONFIRMED, and not IN_PROGRESS.

Why are we making a joke of bug tracking? The purpose of a public
bugzilla instance on the web is not just more red tape, not just to have
one more administrative tool that we can abuse, ignore, and write off
with make-believe actions.

It's not like another issue tracker system (JIRA, Launchpad, GitHub,
GitLab, you name it) would properly work with this level of neglect, either.

In summary: I don't mind the feature, but the documentation around it
should be *much* better.

Thanks
Laszlo

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45826): https://edk2.groups.io/g/devel/message/45826
Mute This Topic: https://groups.io/mt/32839184/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-16 Thread Vitaly Cheptsov via Groups.Io
Donald, Michael,

Yes, I see that such a use is quite new and unexpected very well by know. I 
expanded my thoughts in a separate e-mail thread[1] as the consideration opened 
up an apparently separate problem partially related to the patch. Perhaps, we 
could continue the discussion there some time later.

Best regards,
Vitaly

[1] Determining TSC frequency programmatically
https://edk2.groups.io/g/devel/topic/determining_tsc_frequency/32891598?p=,,,100,0,0,0::recentpostdate%2Fsticky,,,100,2,0,32891598

> 16 авг. 2019 г., в 9:56, Kuo, Donald  написал(а):
> 
> Hi Vitaly,
>
> UEFI Application does be another scope. And regards your question on “a way 
> to dynamically determine the difference between Xeon client and server” … is 
> not in current design-in, for long term goal we could consider if there is 
> proper way to identify CPU SKU dynamically.
>
> Thanks for sharing your thought and it could be an enhancement on TimerLib in 
> the future. J
>
> Thanks,
> Donald
>   <>
>  <>From: Kinney, Michael D 
> Sent: Friday, August 16, 2019 12:23 AM
> To: devel@edk2.groups.io; vit9...@protonmail.com; Kuo, Donald 
> ; Kinney, Michael D 
> Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by 
> using CPUID(0x15) TSC leaf
>
> Vitaly,
>
> When implementing a UEFI Application, if you want maximum compatibility, you 
> should use UEFI Services/Protocols and minimize as many HW assumptions as 
> possible.
>
> I understand, especially for accurate time and clock related services, the 
> that the UEFI Specification defined Services/Protocols can be challenging to 
> use.
>
> When adding content that uses HW such as TSC or CPUID the UEFI App should be 
> implemented with good detection logic to know it is safe to use that HW, and 
> contain the fallback logic to use an alternate mechanism if the required HW 
> is not present.  This is a very different approach than some early FW 
> initialization code that can safely make some HW assumptions that helps keep 
> the FW init code small and efficient.  This does imply that different 
> libraries may be required for FW init and UEFI Applications.
>
> Thanks,
>
> Mike
>
> From: devel@edk2.groups.io <mailto:devel@edk2.groups.io> 
> [mailto:devel@edk2.groups.io <mailto:devel@edk2.groups.io>] On Behalf Of 
> Vitaly Cheptsov via Groups.Io
> Sent: Thursday, August 15, 2019 5:10 AM
> To: Kuo, Donald mailto:donald....@intel.com>>
> Cc: devel@edk2.groups.io <mailto:devel@edk2.groups.io>
> Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by 
> using CPUID(0x15) TSC leaf
>
> Hi Donald,
> 
> Glad to hear it helped a little, and sorry for some outdated quotes.
> 
> Your clarification regarding model range is very helpful. Xeon W being client 
> and thus having client clock makes sense, though I must say it was quite not 
> obvious. I was referring to the same SDM table, and it would have been great 
> to have vertical range binding instead of the misleading CPUID.
> 
> With that, however, I still do not see a way to dynamically determine the 
> difference between Xeon client and server.
> 
> For us it is needed as we use TimerLib differently. For you TimerLib is a 
> part of BSP, so you face no issue statically setting the clock frequency as a 
> PCD. For us TimerLib is used as a part of an UEFI application compatible with 
> different hardware, and in fact not just Intel. We have such "generic 
> TimerLib" library, and to determine CPU frequency, as a fallback to CPUID 
> 15H, it relies on ACPI PM timer. This is not great for two reasons:
> - we have to maintain it ourselves, while we would have liked that be part of 
> EDK II with different vendors contributing to the project.
> - we still cannot find an obvious way to determine crystal clock when it is 
> not reported, in particular for Xeon W and Xeon Scalable case.
> 
> I guess this is now out of the scope of this patch and perhaps even this 
> exact library, but it will be helpful to hear relevant technical details on 
> the issue and opinions on such "generic TimerLib" library to later appear in 
> EDK II.
> 
> Best regards,
> Vitaly
> 
> 15 авг. 2019 г., в 11:40, Kuo, Donald  <mailto:donald@intel.com>> написал(а):
>
> Hi Vitaly,
>
> Appreciated for reviewing very detail. And looks your captured some piece of 
> code is older version. And should be ok, I do got your point.
>
> Item #1
> -  I do missed RegEax error handling in case for 
> CpuidCoreClockCalculateTscFrequency () should return 0 and EFI_UNSUPPORTED. 
> AR: Will update it.
>
> Item #2:
> -  Actually the information is from SDM Table 18-85
> o   As

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-16 Thread Donald Kuo
Hi Vitaly,

UEFI Application does be another scope. And regards your question on “a way to 
dynamically determine the difference between Xeon client and server” … is not 
in current design-in, for long term goal we could consider if there is proper 
way to identify CPU SKU dynamically.

Thanks for sharing your thought and it could be an enhancement on TimerLib in 
the future. ☺

Thanks,
Donald

From: Kinney, Michael D
Sent: Friday, August 16, 2019 12:23 AM
To: devel@edk2.groups.io; vit9...@protonmail.com; Kuo, Donald 
; Kinney, Michael D 
Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using 
CPUID(0x15) TSC leaf

Vitaly,

When implementing a UEFI Application, if you want maximum compatibility, you 
should use UEFI Services/Protocols and minimize as many HW assumptions as 
possible.

I understand, especially for accurate time and clock related services, the that 
the UEFI Specification defined Services/Protocols can be challenging to use.

When adding content that uses HW such as TSC or CPUID the UEFI App should be 
implemented with good detection logic to know it is safe to use that HW, and 
contain the fallback logic to use an alternate mechanism if the required HW is 
not present.  This is a very different approach than some early FW 
initialization code that can safely make some HW assumptions that helps keep 
the FW init code small and efficient.  This does imply that different libraries 
may be required for FW init and UEFI Applications.

Thanks,

Mike

From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
[mailto:devel@edk2.groups.io] On Behalf Of Vitaly Cheptsov via Groups.Io
Sent: Thursday, August 15, 2019 5:10 AM
To: Kuo, Donald mailto:donald@intel.com>>
Cc: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using 
CPUID(0x15) TSC leaf

Hi Donald,

Glad to hear it helped a little, and sorry for some outdated quotes.

Your clarification regarding model range is very helpful. Xeon W being client 
and thus having client clock makes sense, though I must say it was quite not 
obvious. I was referring to the same SDM table, and it would have been great to 
have vertical range binding instead of the misleading CPUID.

With that, however, I still do not see a way to dynamically determine the 
difference between Xeon client and server.

For us it is needed as we use TimerLib differently. For you TimerLib is a part 
of BSP, so you face no issue statically setting the clock frequency as a PCD. 
For us TimerLib is used as a part of an UEFI application compatible with 
different hardware, and in fact not just Intel. We have such "generic TimerLib" 
library, and to determine CPU frequency, as a fallback to CPUID 15H, it relies 
on ACPI PM timer. This is not great for two reasons:
- we have to maintain it ourselves, while we would have liked that be part of 
EDK II with different vendors contributing to the project.
- we still cannot find an obvious way to determine crystal clock when it is not 
reported, in particular for Xeon W and Xeon Scalable case.

I guess this is now out of the scope of this patch and perhaps even this exact 
library, but it will be helpful to hear relevant technical details on the issue 
and opinions on such "generic TimerLib" library to later appear in EDK II.

Best regards,
Vitaly
15 авг. 2019 г., в 11:40, Kuo, Donald 
mailto:donald@intel.com>> написал(а):

Hi Vitaly,

Appreciated for reviewing very detail. And looks your captured some piece of 
code is older version. And should be ok, I do got your point.

Item #1
-  I do missed RegEax error handling in case for 
CpuidCoreClockCalculateTscFrequency () should return 0 and EFI_UNSUPPORTED. AR: 
Will update it.

Item #2:
-  Actually the information is from SDM Table 18-85
o   As we know CPUID signature could be hard to identify processor XTAL 
frequency is? So we only check CPUID Leaf 0x15
o   And the PCD will be defined depends on platform specific and during project 
early development. Based on SDM, Intel processor for CPUID.15h EAX and EBX is 
enumerated, but ECX could be possible not enumerated. So that is why we based 
on  SDM Table 18-85 to create PCD as below:
•  Intel Xeon Server family: 25MHz
•  Intel Core and Intel Xeon W family: 24MHz
•  Intel Atom : 19.2MHz
•  So regards the “06_55h” might cause the confused, we could review it whether 
remove it??
Item #3:
-  Again, the XTAL frequency is optional and should be define in early 
phase of new project. Default should still use AcpiTimer.
oPlatform / developer owner should well know the CPU generation XTAL 
frequency is? Server / Client / Atom ?
o   For those CPU not supported should still use AcpiTimerLib (default)

Thanks,
Donald

From: vit9696 via [] [mailto:vit9696=protonmail.com<http://protonmail.com/>@[]]
Sent: Thursday, August 15, 2019 3:20 PM
To: Kuo, Donald mailto:donald@in

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-15 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Kuo, Donald
> Sent: Thursday, August 15, 2019 5:11 PM
> To: devel@edk2.groups.io
> Cc: Ni, Ray ; Zeng, Star ; Dong, Eric
> ; Chan, Amy ; Chaganty,
> Rangasai V 
> Subject: [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15)
> TSC leaf
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> 
> Cc: Ray Ni 
> Cc: Star Zeng 
> Cc: Eric Dong 
> Cc: Amy Chan 
> Cc: Rangasai V Chaganty 
> Signed-off-by: Donald Kuo 
> ---
>  UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c   |  41 +++
>  UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf |  35 +++
> UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni |  17 ++
>  UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c   | 279
> +
>  UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c|  85 +++
>  UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf  |  37 +++
> UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni  |  17 ++
>  UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c|  58 +
>  UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf  |  36 +++
> UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni  |  17 ++
>  UefiCpuPkg/UefiCpuPkg.dec  |   8 +
>  UefiCpuPkg/UefiCpuPkg.dsc  |   3 +
>  UefiCpuPkg/UefiCpuPkg.uni  |  10 +
>  13 files changed, 643 insertions(+)
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni
> 
> diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> new file mode 100644
> index 00..6ddf917bad
> --- /dev/null
> +++ b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> @@ -0,0 +1,41 @@
> +/** @file
> +  CPUID Leaf 0x15 for Core Crystal Clock frequency instance as Base Timer
> Library.
> +
> +  Copyright (c) 2019 Intel Corporation. All rights reserved.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include 
> +#include 
> +#include 
> +
> +/**
> +  CPUID Leaf 0x15 for Core Crystal Clock Frequency.
> +
> +  The TSC counting frequency is determined by using CPUID leaf 0x15.
> Frequency in MHz = Core XTAL frequency * EBX/EAX.
> +  In newer flavors of the CPU, core xtal frequency is returned in ECX or 0 
> if not
> supported.
> +  @return The number of TSC counts per second.
> +
> +**/
> +UINT64
> +CpuidCoreClockCalculateTscFrequency (
> +  VOID
> +  );
> +
> +/**
> +  Internal function to retrieves the 64-bit frequency in Hz.
> +
> +  Internal function to retrieves the 64-bit frequency in Hz.
> +
> +  @return The frequency in Hz.
> +
> +**/
> +UINT64
> +InternalGetPerformanceCounterFrequency (
> +  VOID
> +  )
> +{
> +  return CpuidCoreClockCalculateTscFrequency (); }
> +
> diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
> b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
> new file mode 100644
> index 00..fd93adc5f1
> --- /dev/null
> +++ b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
> @@ -0,0 +1,35 @@
> +## @file
> +#  Base CPU Timer Library
> +#
> +#  Provides basic timer support using CPUID Leaf 0x15 XTAL frequency.
> +The performance #  counter features are provided by the processors time
> stamp counter.
> +#
> +#  Copyright (c) 2019, Intel Corporation. All rights reserved. #
> +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> +
> +[Defines]
> +  INF_VERSION= 0x00010005
> +  BASE_NAME  = BaseCpuTimerLib
> +  FILE_GUID  = F10B5B91-D15A-496C-B044-B5235721AA08
> +  MODULE_TYPE= BASE
> +  VERSION_STRING = 1.0
> +  LIBRARY_CLASS  = TimerLib|SEC PEI_CORE PEIM
> +  MODULE_UNI_FILE= BaseCpuTimerLib.uni
> +
> +[Sources]
> +  CpuTimerLib.c
> +  BaseCpuTimerLib.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  UefiCpuPkg/UefiCpuPkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  PcdLib
> +  DebugLib
> +
> +[Pcd]
> +  gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency  ##
> +CONSUMES
> diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni
> b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni
> new file mode 100644
> index 00..fcf2b0fbcb
> --- /dev/null
> +++ b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni
> @@ -0,0 +1,17 @@
> +// /** @file
> +// Base CPU Timer Library

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-15 Thread Michael D Kinney
Vitaly,

When implementing a UEFI Application, if you want maximum compatibility, you 
should use UEFI Services/Protocols and minimize as many HW assumptions as 
possible.

I understand, especially for accurate time and clock related services, the that 
the UEFI Specification defined Services/Protocols can be challenging to use.

When adding content that uses HW such as TSC or CPUID the UEFI App should be 
implemented with good detection logic to know it is safe to use that HW, and 
contain the fallback logic to use an alternate mechanism if the required HW is 
not present.  This is a very different approach than some early FW 
initialization code that can safely make some HW assumptions that helps keep 
the FW init code small and efficient.  This does imply that different libraries 
may be required for FW init and UEFI Applications.

Thanks,

Mike

From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of Vitaly 
Cheptsov via Groups.Io
Sent: Thursday, August 15, 2019 5:10 AM
To: Kuo, Donald 
Cc: devel@edk2.groups.io
Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using 
CPUID(0x15) TSC leaf

Hi Donald,

Glad to hear it helped a little, and sorry for some outdated quotes.

Your clarification regarding model range is very helpful. Xeon W being client 
and thus having client clock makes sense, though I must say it was quite not 
obvious. I was referring to the same SDM table, and it would have been great to 
have vertical range binding instead of the misleading CPUID.

With that, however, I still do not see a way to dynamically determine the 
difference between Xeon client and server.

For us it is needed as we use TimerLib differently. For you TimerLib is a part 
of BSP, so you face no issue statically setting the clock frequency as a PCD. 
For us TimerLib is used as a part of an UEFI application compatible with 
different hardware, and in fact not just Intel. We have such "generic TimerLib" 
library, and to determine CPU frequency, as a fallback to CPUID 15H, it relies 
on ACPI PM timer. This is not great for two reasons:
- we have to maintain it ourselves, while we would have liked that be part of 
EDK II with different vendors contributing to the project.
- we still cannot find an obvious way to determine crystal clock when it is not 
reported, in particular for Xeon W and Xeon Scalable case.

I guess this is now out of the scope of this patch and perhaps even this exact 
library, but it will be helpful to hear relevant technical details on the issue 
and opinions on such "generic TimerLib" library to later appear in EDK II.

Best regards,
Vitaly
15 авг. 2019 г., в 11:40, Kuo, Donald 
mailto:donald@intel.com>> написал(а):

Hi Vitaly,

Appreciated for reviewing very detail. And looks your captured some piece of 
code is older version. And should be ok, I do got your point.

Item #1
-  I do missed RegEax error handling in case for 
CpuidCoreClockCalculateTscFrequency () should return 0 and EFI_UNSUPPORTED. AR: 
Will update it.

Item #2:
-  Actually the information is from SDM Table 18-85
o   As we know CPUID signature could be hard to identify processor XTAL 
frequency is? So we only check CPUID Leaf 0x15
o   And the PCD will be defined depends on platform specific and during project 
early development. Based on SDM, Intel processor for CPUID.15h EAX and EBX is 
enumerated, but ECX could be possible not enumerated. So that is why we based 
on  SDM Table 18-85 to create PCD as below:
•  Intel Xeon Server family: 25MHz
•  Intel Core and Intel Xeon W family: 24MHz
•  Intel Atom : 19.2MHz
•  So regards the “06_55h” might cause the confused, we could review it whether 
remove it??
Item #3:
-  Again, the XTAL frequency is optional and should be define in early 
phase of new project. Default should still use AcpiTimer.
oPlatform / developer owner should well know the CPU generation XTAL 
frequency is? Server / Client / Atom ?
o   For those CPU not supported should still use AcpiTimerLib (default)

Thanks,
Donald

From: vit9696 via [] [mailto:vit9696=protonmail.com<http://protonmail.com/>@[]]
Sent: Thursday, August 15, 2019 3:20 PM
To: Kuo, Donald mailto:donald@intel.com>>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using 
CPUID(0x15) TSC leaf

Hello,

Thank you for the patch! I reviewed the code and noticed select issues 
explained below.

1. The following construction:

if (RegEbx == 0) {
DEBUG ((DEBUG_ERROR, "The CPU is not capble for Core Crystal Clock Frequency 
!!\n"));
ASSERT (RegEbx != 0);
}

Does not look good to me, and in my opinion, should be written differently:

if (RegEbx == 0 || RegEax == 0) {
DEBUG ((DEBUG_ERROR, "The CPU is not capble for Core Crystal Clock Frequency 
!!\n"));
ASSERT (RegEbx != 0);
  ASSERT (RegEax != 0);
  return 0;
}

The reason for the above code b

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-15 Thread Vitaly Cheptsov via Groups.Io
Hi Donald,

Glad to hear it helped a little, and sorry for some outdated quotes.

Your clarification regarding model range is very helpful. Xeon W being client 
and thus having client clock makes sense, though I must say it was quite not 
obvious. I was referring to the same SDM table, and it would have been great to 
have vertical range binding instead of the misleading CPUID.

With that, however, I still do not see a way to dynamically determine the 
difference between Xeon client and server.

For us it is needed as we use TimerLib differently. For you TimerLib is a part 
of BSP, so you face no issue statically setting the clock frequency as a PCD. 
For us TimerLib is used as a part of an UEFI application compatible with 
different hardware, and in fact not just Intel. We have such "generic TimerLib" 
library, and to determine CPU frequency, as a fallback to CPUID 15H, it relies 
on ACPI PM timer. This is not great for two reasons:
- we have to maintain it ourselves, while we would have liked that be part of 
EDK II with different vendors contributing to the project.
- we still cannot find an obvious way to determine crystal clock when it is not 
reported, in particular for Xeon W and Xeon Scalable case.

I guess this is now out of the scope of this patch and perhaps even this exact 
library, but it will be helpful to hear relevant technical details on the issue 
and opinions on such "generic TimerLib" library to later appear in EDK II.

Best regards,
Vitaly

> 15 авг. 2019 г., в 11:40, Kuo, Donald  написал(а):
> 
> Hi Vitaly,
>
> Appreciated for reviewing very detail. And looks your captured some piece of 
> code is older version. And should be ok, I do got your point.
>
> Item #1
> -  I do missed RegEax error handling in case for 
> CpuidCoreClockCalculateTscFrequency () should return 0 and EFI_UNSUPPORTED. 
> AR: Will update it.
>
> Item #2:
> -  Actually the information is from SDM Table 18-85
> o   As we know CPUID signature could be hard to identify processor XTAL 
> frequency is? So we only check CPUID Leaf 0x15
> o   And the PCD will be defined depends on platform specific and during 
> project early development. Based on SDM, Intel processor for CPUID.15h EAX 
> and EBX is enumerated, but ECX could be possible not enumerated. So that is 
> why we based on  SDM Table 18-85 to create PCD as below:
> §  Intel Xeon Server family: 25MHz
> §  Intel Core and Intel Xeon W family: 24MHz
> §  Intel Atom : 19.2MHz
> §  So regards the “06_55h” might cause the confused, we could review it 
> whether remove it??
> Item #3:
> -  Again, the XTAL frequency is optional and should be define in 
> early phase of new project. Default should still use AcpiTimer.
> oPlatform / developer owner should well know the CPU generation XTAL 
> frequency is? Server / Client / Atom ?
> o   For those CPU not supported should still use AcpiTimerLib (default)
>
> Thanks,
> Donald
>   <>
>  <>From: vit9696 via [] [mailto:vit9696=protonmail.com 
> <http://protonmail.com/>@[]] 
> Sent: Thursday, August 15, 2019 3:20 PM
> To: Kuo, Donald mailto:donald....@intel.com>>; 
> devel@edk2.groups.io <mailto:devel@edk2.groups.io>
> Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by 
> using CPUID(0x15) TSC leaf
>
> Hello,
> 
> Thank you for the patch! I reviewed the code and noticed select issues 
> explained below.
> 
> 1. The following construction:
> 
> if (RegEbx == 0) {
> DEBUG ((DEBUG_ERROR, "The CPU is not capble for Core Crystal Clock Frequency 
> !!\n"));
> ASSERT (RegEbx != 0);
> }
> 
> Does not look good to me, and in my opinion, should be written differently:
> 
> if (RegEbx == 0 || RegEax == 0) {
> DEBUG ((DEBUG_ERROR, "The CPU is not capble for Core Crystal Clock Frequency 
> !!\n"));
> ASSERT (RegEbx != 0);
>   ASSERT (RegEax != 0);
>   return 0;
> }
> 
> The reason for the above code being wrong is potential division by zero 
> below, which behaviour is undefined (and in fact unknown due to unspecified 
> interrupt table state). Even though the intent is to not permit the use of 
> this library on an unsupported platform, runtime checks and assertions are 
> essentially NO-OPs, should be separate and not confused. For this to work 
> properly the call to CpuidCoreClockCalculateTscFrequency should happen in 
> library constructor with EFI_UNSUPPORTED return on 
> CpuidCoreClockCalculateTscFrequency returning 0.
> 
> 2. The notes about crystal clock frequency for 06_55H CPU signature:
> "2500 - Intel Xeon Processor Scalable Family with CPUID signature 
> 06_55H(25MHz).\n"
> # Intel Xeon Processor Scalable Family with CPUID signature 06_55H = 2500 
> (2

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-15 Thread Donald Kuo
Hi Vitaly,

Appreciated for reviewing very detail. And looks your captured some piece of 
code is older version. And should be ok, I do got your point.

Item #1

-  I do missed RegEax error handling in case for 
CpuidCoreClockCalculateTscFrequency () should return 0 and EFI_UNSUPPORTED. AR: 
Will update it.

Item #2:

-  Actually the information is from SDM Table 18-85

o   As we know CPUID signature could be hard to identify processor XTAL 
frequency is? So we only check CPUID Leaf 0x15

o   And the PCD will be defined depends on platform specific and during project 
early development. Based on SDM, Intel processor for CPUID.15h EAX and EBX is 
enumerated, but ECX could be possible not enumerated. So that is why we based 
on  SDM Table 18-85 to create PCD as below:

§  Intel Xeon Server family: 25MHz

§  Intel Core and Intel Xeon W family: 24MHz

§  Intel Atom : 19.2MHz

§  So regards the “06_55h” might cause the confused, we could review it whether 
remove it??
Item #3:

-  Again, the XTAL frequency is optional and should be define in early 
phase of new project. Default should still use AcpiTimer.

oPlatform / developer owner should well know the CPU generation XTAL 
frequency is? Server / Client / Atom ?

o   For those CPU not supported should still use AcpiTimerLib (default)

Thanks,
Donald

From: vit9696 via [] [mailto:vit9696=protonmail.com@[]]
Sent: Thursday, August 15, 2019 3:20 PM
To: Kuo, Donald ; devel@edk2.groups.io
Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using 
CPUID(0x15) TSC leaf

Hello,

Thank you for the patch! I reviewed the code and noticed select issues 
explained below.

1. The following construction:

if (RegEbx == 0) {
DEBUG ((DEBUG_ERROR, "The CPU is not capble for Core Crystal Clock Frequency 
!!\n"));
ASSERT (RegEbx != 0);
}

Does not look good to me, and in my opinion, should be written differently:

if (RegEbx == 0 || RegEax == 0) {
DEBUG ((DEBUG_ERROR, "The CPU is not capble for Core Crystal Clock Frequency 
!!\n"));
ASSERT (RegEbx != 0);
  ASSERT (RegEax != 0);
  return 0;
}

The reason for the above code being wrong is potential division by zero below, 
which behaviour is undefined (and in fact unknown due to unspecified interrupt 
table state). Even though the intent is to not permit the use of this library 
on an unsupported platform, runtime checks and assertions are essentially 
NO-OPs, should be separate and not confused. For this to work properly the call 
to CpuidCoreClockCalculateTscFrequency should happen in library constructor 
with EFI_UNSUPPORTED return on CpuidCoreClockCalculateTscFrequency returning 0.

2. The notes about crystal clock frequency for 06_55H CPU signature:
"2500 - Intel Xeon Processor Scalable Family with CPUID signature 
06_55H(25MHz).\n"
# Intel Xeon Processor Scalable Family with CPUID signature 06_55H = 2500 
(25MHz)

are misleading in both this library and Intel SDM. Intel Xeon W processors have 
the same CPUID signature (06_55H), they report 0 crystal clock frequency, and 
their crystal clock frequency is 24 MHz. This should at least be mentioned in 
the lower part mentioning Intel Xeon W Processor Family(24MHz).

Actually, given that many Intel guys are here, I wonder whether anybody knows 
if there is any better approach to distinguish Xeon Scalable CPUs and Xeon W 
CPUs besides using brand string or using marketing frequency from CPUID 16H to 
determine crystal clock frequency (this is what Linux does at the moment)?

3. Intel Atom Denverton with CPUID signature (06_5FH), also known as Goldmont 
X, reports 0 crystal clock frequency as well, and has 25 MHz frequency. This is 
missing from SDM, but once again I believe it should be included in the two 
places from the above to avoid confusion.

Besides these 3 points, honestly, the library itself appears to be very limited 
for anything but embedding it into the firmware with known hardware, which 
already works just fine by defining the PCD. Missing 0 crystal clock frequency 
handling in runtime with hardcoding the PCD value looks very bad, because the 
number of modern Intel CPU models reporting 0 crystal clock frequency and 
having non 24 MHz frequency is quite far from 0. This makes the library 
essentially impossible to use in any UEFI application or third-party product 
even when targeting Skylake+ generation. To resolute this I vote for additional 
detection functionality to be added to the library to obtain crystal clock 
frequency when the CPUID reports 0. The PCD could be the last resort when no 
other method works. My opinion is that this should be resolved prior to merging 
the patch.

Best regards,
Vitaly

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45699): https://edk2.groups.io/g/devel/message/45699
Mute This Topic: https://groups.io/mt/32839184/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https:

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-15 Thread Vitaly Cheptsov via Groups.Io
Hello,

Thank you for the patch! I reviewed the code and noticed select issues 
explained below.

1. The following construction:

if (RegEbx == 0) {
DEBUG ((DEBUG_ERROR, "The CPU is not capble for Core Crystal Clock Frequency 
!!\n"));
ASSERT (RegEbx != 0);
}

Does not look good to me, and in my opinion, should be written differently:

if (RegEbx == 0 || RegEax == 0 ) {
DEBUG ((DEBUG_ERROR, "The CPU is not capble for Core Crystal Clock Frequency 
!!\n"));
ASSERT (RegEbx != 0);
ASSERT (RegEax != 0);
return 0;
}

The reason for the above code being wrong is potential division by zero below, 
which behaviour is undefined (and in fact unknown due to unspecified interrupt 
table state). Even though the intent is to not permit the use of this library 
on an unsupported platform, runtime checks and assertions are essentially 
NO-OPs, should be separate and not confused. For this to work properly the call 
to CpuidCoreClockCalculateTscFrequency should happen in library constructor 
with EFI_UNSUPPORTED return on CpuidCoreClockCalculateTscFrequency returning 0.

2. The notes about crystal clock frequency for 06_55H CPU signature:
"2500 - Intel Xeon Processor Scalable Family with CPUID signature 
06_55H(25MHz).\n"
# Intel Xeon Processor Scalable Family with CPUID signature 06_55H = 2500 
(25MHz)

are misleading in both this library and Intel SDM. Intel Xeon W processors have 
the same CPUID signature ( 06_55H) , they report 0 crystal clock frequency, and 
their crystal clock frequency is 24 MHz. This should at least be mentioned in 
the lower part mentioning Intel Xeon W Processor Family(24MHz).

Actually, given that many Intel guys are here, I wonder whether anybody knows 
if there is any better approach to distinguish Xeon Scalable CPUs and Xeon W 
CPUs besides using brand string or using marketing frequency from CPUID 16H to 
determine crystal clock frequency (this is what Linux does at the moment)?

3. Intel Atom Denverton with CPUID signature (06_5FH), also known as Goldmont 
X, reports 0 crystal clock frequency as well, and has 25 MHz frequency. This is 
missing from SDM, but once again I believe it should be included in the two 
places from the above to avoid confusion.

Besides these 3 points, honestly, the library itself appears to be very limited 
for anything but embedding it into the firmware with known hardware, which 
already works just fine by defining the PCD. Missing 0 crystal clock frequency 
handling in runtime with hardcoding the PCD value looks very bad, because the 
number of modern Intel CPU models reporting 0 crystal clock frequency and 
having non 24 MHz frequency is quite far from 0. This makes the library 
essentially impossible to use in any UEFI application or third-party product 
even when targeting Skylake+ generation. To resolute this I vote for additional 
detection functionality to be added to the library to obtain crystal clock 
frequency when the CPUID reports 0. The PCD could be the last resort when no 
other method works. My opinion is that this should be resolved prior to merging 
the patch.

Best regards,
Vitaly

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45689): https://edk2.groups.io/g/devel/message/45689
Mute This Topic: https://groups.io/mt/32839184/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-14 Thread Donald Kuo
Thanks Liming for review.

Update UefiCpuPkg.uni for review again.

Thanks,
Donald

> -Original Message-
> From: Gao, Liming
> Sent: Thursday, August 15, 2019 12:03 PM
> To: Kuo, Donald ; Dong, Eric
> ; devel@edk2.groups.io
> Cc: Ni, Ray ; Zeng, Star ; Chan,
> Amy ; Chaganty, Rangasai V
> ; Lai, Luke ; Li, Kevin
> Y ; Laszlo Ersek (ler...@redhat.com)
> ; leif.lindh...@linaro.org; af...@apple.com; Kinney,
> Michael D 
> Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by
> using CPUID(0x15) TSC leaf
> 
> Donald:
>   This change is a new feature. Now, it is not in edk2 feature planning list. 
> If
> you want to catch it into 201908 stable tag, please get approve from
> Stewards first. I have cc this mail to all Stewards.
> 
>   For this patch, I have one minor comment. You add one PCD in UefiCpuPkg
> DEC. Please also add this PCD into UefiCpuPkg.uni.
> 
> Thanks
> Liming
> > -Original Message-
> > From: Kuo, Donald
> > Sent: Thursday, August 15, 2019 11:02 AM
> > To: Dong, Eric ; devel@edk2.groups.io; Gao,
> > Liming 
> > Cc: Ni, Ray ; Zeng, Star ;
> > Chan, Amy ; Chaganty, Rangasai V
> > ; Lai, Luke ; Li,
> > Kevin Y 
> > Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library
> > by using CPUID(0x15) TSC leaf
> >
> > Hi Liming,
> >
> > As we plan to add new TimerLib to use CPUID Leaf 0x15 (CPU XTAL clock
> > frequency) to calculate TSC to resolve performance value unreliable
> concern.
> >
> > As the code review had got approved and planning into 201908 stable
> > tag. Please help to review whether any concern for 201908 stable tag.
> >
> > Thanks,
> > Donald
> >
> > > -Original Message-
> > > From: Dong, Eric
> > > Sent: Thursday, August 15, 2019 10:46 AM
> > > To: devel@edk2.groups.io; Kuo, Donald 
> > > Cc: Ni, Ray ; Zeng, Star ;
> > > Chan, Amy ; Chaganty, Rangasai V
> > > 
> > > Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC
> > > library by using CPUID(0x15) TSC leaf
> > >
> > > Reviewed-by: Eric Dong 
> > >
> > > > -Original Message-
> > > > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf
> > > > Of Donald Kuo
> > > > Sent: Tuesday, August 13, 2019 6:53 PM
> > > > To: devel@edk2.groups.io
> > > > Cc: Ni, Ray ; Zeng, Star ;
> > > > Dong, Eric ; Chan, Amy ;
> > > > Chaganty, Rangasai V 
> > > > Subject: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library
> > > > by using
> > > > CPUID(0x15) TSC leaf
> > > >
> > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> > > >
> > > > Cc: Ray Ni 
> > > > Cc: Star Zeng 
> > > > Cc: Eric Dong 
> > > > Cc: Amy Chan 
> > > > Cc: Rangasai V Chaganty 
> > > > Signed-off-by: Donald Kuo 
> > > > ---
> > > >  UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c   |  41 +++
> > > >  UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf |  35 +++
> > > > UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni |  17 ++
> > > >  UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c   | 274
> > > > +
> > > >  UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c|  81 ++
> > > >  UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf  |  37 +++
> > > > UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni  |  17 ++
> > > >  UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c|  58 +
> > > >  UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf  |  36 +++
> > > > UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni  |  17 ++
> > > >  UefiCpuPkg/UefiCpuPkg.dec  |   8 +
> > > >  UefiCpuPkg/UefiCpuPkg.dsc  |   3 +
> > > >  12 files changed, 624 insertions(+)  create mode 100644
> > > > UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> > > >  create mode 100644
> > > UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
> > > >  create mode 100644
> > > UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni
> > > >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c
> > > >  create mode 100644
> > > > UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c
> > > >  create mode 100644
> > > > UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf
> > > >  create mode 1006

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-14 Thread Liming Gao
Donald:
  This change is a new feature. Now, it is not in edk2 feature planning list. 
If you want to catch it into 201908 stable tag, please get approve from 
Stewards first. I have cc this mail to all Stewards. 

  For this patch, I have one minor comment. You add one PCD in UefiCpuPkg DEC. 
Please also add this PCD into UefiCpuPkg.uni. 

Thanks
Liming
> -Original Message-
> From: Kuo, Donald
> Sent: Thursday, August 15, 2019 11:02 AM
> To: Dong, Eric ; devel@edk2.groups.io; Gao, Liming 
> 
> Cc: Ni, Ray ; Zeng, Star ; Chan, Amy 
> ; Chaganty, Rangasai V
> ; Lai, Luke ; Li, Kevin Y 
> 
> Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by 
> using CPUID(0x15) TSC leaf
> 
> Hi Liming,
> 
> As we plan to add new TimerLib to use CPUID Leaf 0x15 (CPU XTAL clock 
> frequency) to calculate TSC to resolve performance value
> unreliable concern.
> 
> As the code review had got approved and planning into 201908 stable tag. 
> Please help to review whether any concern for 201908 stable
> tag.
> 
> Thanks,
> Donald
> 
> > -Original Message-
> > From: Dong, Eric
> > Sent: Thursday, August 15, 2019 10:46 AM
> > To: devel@edk2.groups.io; Kuo, Donald 
> > Cc: Ni, Ray ; Zeng, Star ; Chan,
> > Amy ; Chaganty, Rangasai V
> > 
> > Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by
> > using CPUID(0x15) TSC leaf
> >
> > Reviewed-by: Eric Dong 
> >
> > > -Original Message-
> > > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> > > Donald Kuo
> > > Sent: Tuesday, August 13, 2019 6:53 PM
> > > To: devel@edk2.groups.io
> > > Cc: Ni, Ray ; Zeng, Star ;
> > > Dong, Eric ; Chan, Amy ;
> > > Chaganty, Rangasai V 
> > > Subject: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by
> > > using
> > > CPUID(0x15) TSC leaf
> > >
> > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> > >
> > > Cc: Ray Ni 
> > > Cc: Star Zeng 
> > > Cc: Eric Dong 
> > > Cc: Amy Chan 
> > > Cc: Rangasai V Chaganty 
> > > Signed-off-by: Donald Kuo 
> > > ---
> > >  UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c   |  41 +++
> > >  UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf |  35 +++
> > > UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni |  17 ++
> > >  UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c   | 274
> > > +
> > >  UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c|  81 ++
> > >  UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf  |  37 +++
> > > UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni  |  17 ++
> > >  UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c|  58 +
> > >  UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf  |  36 +++
> > > UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni  |  17 ++
> > >  UefiCpuPkg/UefiCpuPkg.dec  |   8 +
> > >  UefiCpuPkg/UefiCpuPkg.dsc  |   3 +
> > >  12 files changed, 624 insertions(+)
> > >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> > >  create mode 100644
> > UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
> > >  create mode 100644
> > UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni
> > >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c
> > >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c
> > >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf
> > >  create mode 100644
> > UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni
> > >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c
> > >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf
> > >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni
> > >
> > > diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> > > b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> > > new file mode 100644
> > > index 00..6ddf917bad
> > > --- /dev/null
> > > +++ b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> > > @@ -0,0 +1,41 @@
> > > +/** @file
> > > +  CPUID Leaf 0x15 for Core Crystal Clock frequency instance as Base
> > > +Timer
> > > Library.
> > > +
> > > +  Copyright (c) 2019 Intel Corporation. All rights reserved.
> > > +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > +
> > > +**/
> > >

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-14 Thread Donald Kuo
Hi Liming,

As we plan to add new TimerLib to use CPUID Leaf 0x15 (CPU XTAL clock 
frequency) to calculate TSC to resolve performance value unreliable concern.

As the code review had got approved and planning into 201908 stable tag. Please 
help to review whether any concern for 201908 stable tag.

Thanks,
Donald

> -Original Message-
> From: Dong, Eric
> Sent: Thursday, August 15, 2019 10:46 AM
> To: devel@edk2.groups.io; Kuo, Donald 
> Cc: Ni, Ray ; Zeng, Star ; Chan,
> Amy ; Chaganty, Rangasai V
> 
> Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by
> using CPUID(0x15) TSC leaf
> 
> Reviewed-by: Eric Dong 
> 
> > -Original Message-
> > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> > Donald Kuo
> > Sent: Tuesday, August 13, 2019 6:53 PM
> > To: devel@edk2.groups.io
> > Cc: Ni, Ray ; Zeng, Star ;
> > Dong, Eric ; Chan, Amy ;
> > Chaganty, Rangasai V 
> > Subject: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by
> > using
> > CPUID(0x15) TSC leaf
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> >
> > Cc: Ray Ni 
> > Cc: Star Zeng 
> > Cc: Eric Dong 
> > Cc: Amy Chan 
> > Cc: Rangasai V Chaganty 
> > Signed-off-by: Donald Kuo 
> > ---
> >  UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c   |  41 +++
> >  UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf |  35 +++
> > UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni |  17 ++
> >  UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c   | 274
> > +
> >  UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c|  81 ++
> >  UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf  |  37 +++
> > UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni  |  17 ++
> >  UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c|  58 +
> >  UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf  |  36 +++
> > UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni  |  17 ++
> >  UefiCpuPkg/UefiCpuPkg.dec  |   8 +
> >  UefiCpuPkg/UefiCpuPkg.dsc  |   3 +
> >  12 files changed, 624 insertions(+)
> >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> >  create mode 100644
> UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
> >  create mode 100644
> UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni
> >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c
> >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c
> >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf
> >  create mode 100644
> UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni
> >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c
> >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf
> >  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni
> >
> > diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> > b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> > new file mode 100644
> > index 00..6ddf917bad
> > --- /dev/null
> > +++ b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> > @@ -0,0 +1,41 @@
> > +/** @file
> > +  CPUID Leaf 0x15 for Core Crystal Clock frequency instance as Base
> > +Timer
> > Library.
> > +
> > +  Copyright (c) 2019 Intel Corporation. All rights reserved.
> > +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > +
> > +**/
> > +
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/**
> > +  CPUID Leaf 0x15 for Core Crystal Clock Frequency.
> > +
> > +  The TSC counting frequency is determined by using CPUID leaf 0x15.
> > Frequency in MHz = Core XTAL frequency * EBX/EAX.
> > +  In newer flavors of the CPU, core xtal frequency is returned in ECX
> > + or 0 if
> > not supported.
> > +  @return The number of TSC counts per second.
> > +
> > +**/
> > +UINT64
> > +CpuidCoreClockCalculateTscFrequency (
> > +  VOID
> > +  );
> > +
> > +/**
> > +  Internal function to retrieves the 64-bit frequency in Hz.
> > +
> > +  Internal function to retrieves the 64-bit frequency in Hz.
> > +
> > +  @return The frequency in Hz.
> > +
> > +**/
> > +UINT64
> > +InternalGetPerformanceCounterFrequency (
> > +  VOID
> > +  )
> > +{
> > +  return CpuidCoreClockCalculateTscFrequency (); }
> > +
> > diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
> > b/UefiCpuPkg/L

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-14 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Donald Kuo
> Sent: Tuesday, August 13, 2019 6:53 PM
> To: devel@edk2.groups.io
> Cc: Ni, Ray ; Zeng, Star ; Dong, Eric
> ; Chan, Amy ; Chaganty,
> Rangasai V 
> Subject: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using
> CPUID(0x15) TSC leaf
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> 
> Cc: Ray Ni 
> Cc: Star Zeng 
> Cc: Eric Dong 
> Cc: Amy Chan 
> Cc: Rangasai V Chaganty 
> Signed-off-by: Donald Kuo 
> ---
>  UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c   |  41 +++
>  UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf |  35 +++
> UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni |  17 ++
>  UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c   | 274
> +
>  UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c|  81 ++
>  UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf  |  37 +++
> UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni  |  17 ++
>  UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c|  58 +
>  UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf  |  36 +++
> UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni  |  17 ++
>  UefiCpuPkg/UefiCpuPkg.dec  |   8 +
>  UefiCpuPkg/UefiCpuPkg.dsc  |   3 +
>  12 files changed, 624 insertions(+)
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf
>  create mode 100644 UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni
> 
> diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> new file mode 100644
> index 00..6ddf917bad
> --- /dev/null
> +++ b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
> @@ -0,0 +1,41 @@
> +/** @file
> +  CPUID Leaf 0x15 for Core Crystal Clock frequency instance as Base Timer
> Library.
> +
> +  Copyright (c) 2019 Intel Corporation. All rights reserved.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include 
> +#include 
> +#include 
> +
> +/**
> +  CPUID Leaf 0x15 for Core Crystal Clock Frequency.
> +
> +  The TSC counting frequency is determined by using CPUID leaf 0x15.
> Frequency in MHz = Core XTAL frequency * EBX/EAX.
> +  In newer flavors of the CPU, core xtal frequency is returned in ECX or 0 if
> not supported.
> +  @return The number of TSC counts per second.
> +
> +**/
> +UINT64
> +CpuidCoreClockCalculateTscFrequency (
> +  VOID
> +  );
> +
> +/**
> +  Internal function to retrieves the 64-bit frequency in Hz.
> +
> +  Internal function to retrieves the 64-bit frequency in Hz.
> +
> +  @return The frequency in Hz.
> +
> +**/
> +UINT64
> +InternalGetPerformanceCounterFrequency (
> +  VOID
> +  )
> +{
> +  return CpuidCoreClockCalculateTscFrequency (); }
> +
> diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
> b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
> new file mode 100644
> index 00..fd93adc5f1
> --- /dev/null
> +++ b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
> @@ -0,0 +1,35 @@
> +## @file
> +#  Base CPU Timer Library
> +#
> +#  Provides basic timer support using CPUID Leaf 0x15 XTAL frequency.
> +The performance #  counter features are provided by the processors time
> stamp counter.
> +#
> +#  Copyright (c) 2019, Intel Corporation. All rights reserved. #
> +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> +
> +[Defines]
> +  INF_VERSION= 0x00010005
> +  BASE_NAME  = BaseCpuTimerLib
> +  FILE_GUID  = F10B5B91-D15A-496C-B044-B5235721AA08
> +  MODULE_TYPE= BASE
> +  VERSION_STRING = 1.0
> +  LIBRARY_CLASS  = TimerLib|SEC PEI_CORE PEIM
> +  MODULE_UNI_FILE= BaseCpuTimerLib.uni
> +
> +[Sources]
> +  CpuTimerLib.c
> +  BaseCpuTimerLib.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  UefiCpuPkg/UefiCpuPkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  PcdLib
> +  DebugLib
> +
> +[Pcd]
> +  gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency  ##
> +CONSUMES
> diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni
> b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni
> new file mode 100644
> index 00..fcf2b0fbcb
> --- /dev/null
> +++ b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.uni
> @@ -0,0 +1,17 @@
> +// /** @file
> +// Base CPU 

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-12 Thread Dong, Eric
Hi Donald,

Thanks for your explanation.  In this case, Reviewed-by: Eric Dong 


Thanks,
Eric
> -Original Message-
> From: Kuo, Donald
> Sent: Tuesday, August 13, 2019 11:26 AM
> To: Dong, Eric ; devel@edk2.groups.io
> Cc: Ni, Ray ; Zeng, Star ; Chan,
> Amy ; Chaganty, Rangasai V
> 
> Subject: RE: [PATCH] UefiCpuPkg: Adding a new TSC library by using
> CPUID(0x15) TSC leaf
> 
> Hi Eric,
> 
> The CPUID Leaf 0x1:EDX.TSC[bit 4] is to check capability for
> IA32_TIME_STAMP_COUNTER MSR and RDTSC instruction which defined in
> IA32 SDM chapter 17.17
> 
> And what we implement is based on IA32 SDM Chapter 18.7 for CPU core
> XTAL clock frequency which is from CPUID Leaf 0x15 and new TSC frequency
> = (ECX, Core XTAL Frequency) * EBX/EAX
> 
> So no need to check CPUID(0x01).
> 
> Thanks,
> Donald
> 
> > -Original Message-
> > From: Dong, Eric
> > Sent: Tuesday, August 13, 2019 10:27 AM
> > To: Kuo, Donald ; devel@edk2.groups.io
> > Cc: Ni, Ray ; Zeng, Star ;
> > Chan, Amy ; Chaganty, Rangasai V
> > 
> > Subject: RE: [PATCH] UefiCpuPkg: Adding a new TSC library by using
> > CPUID(0x15) TSC leaf
> >
> > Hi Donald,
> >
> > Do you think it's necessary to check the TIME_STAMP_COUNTER capability
> > before using it? I see SDM has CPUID(0x01) which return the capability
> > of TIME_STAMP_COUNTER.
> >
> > Thanks,
> > Eric
> >
> > > -Original Message-
> > > From: Kuo, Donald
> > > Sent: Monday, August 12, 2019 7:23 PM
> > > To: devel@edk2.groups.io
> > > Cc: Ni, Ray ; Zeng, Star ;
> > > Dong, Eric ; Chan, Amy ;
> > > Chaganty, Rangasai V 
> > > Subject: [PATCH] UefiCpuPkg: Adding a new TSC library by using
> > > CPUID(0x15) TSC leaf
> > >
> > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> > >
> > > Cc: Ray Ni 
> > > Cc: Star Zeng 
> > > Cc: Eric Dong 
> > > Cc: Amy Chan 
> > > Cc: Rangasai V Chaganty 
> > > Signed-off-by: Donald Kuo 
> > > ---
> > >  .../Library/BaseCpuTimerLib/BaseCpuTimerLib.c  |  40 +++
> > >  .../Library/BaseCpuTimerLib/BaseCpuTimerLib.inf|  35 +++
> > >  .../Library/BaseCpuTimerLib/BaseCpuTimerLib.uni|  16 ++
> > >  UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c   | 272
> > > +
> > >  UefiCpuPkg/UefiCpuPkg.dec  |   8 +
> > >  UefiCpuPkg/UefiCpuPkg.dsc  |   1 +
> > >  6 files changed, 372 insertions(+)
> > >  create mode 100644
> > > UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c
> > >  create mode 100644
> > > UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf
> > >  create mode 100644
> > > UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.uni
> > >  create mode 100644
> UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c
> > >
> > > diff --git a/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c
> > > b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c
> > > new file mode 100644
> > > index 00..ccb92a95d3
> > > --- /dev/null
> > > +++ b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c
> > > @@ -0,0 +1,40 @@
> > > +/** @file
> > > +  CPUID Leaf 0x15 for Core Crystal Clock frequency instance of
> > > +Timer
> > Library.
> > > +
> > > +  Copyright (c) 2019 Intel Corporation. All rights reserved.
> > > +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > +
> > > +**/
> > > +
> > > +#include 
> > > +#include 
> > > +#include 
> > > +
> > > +/**
> > > +  CPUID Leaf 0x15 for Core Crystal Clock Frequency.
> > > +
> > > +  The TSC counting frequency is determined by using CPUID leaf 0x15.
> > > Frequency in MHz = Core XTAL frequency * EBX/EAX.
> > > +  In newer flavors of the CPU, core xtal frequency is returned in
> > > + ECX or 0 if
> > > not supported.
> > > +  @return The number of TSC counts per second.
> > > +
> > > +**/
> > > +UINT64
> > > +CpuidCoreClockCalculateTscFrequency (
> > > +  VOID
> > > +  );
> > > +
> > > +/**
> > > +  Internal function to retrieves the 64-bit frequency in Hz.
> > > +
> > > +  Internal function to retrieves the 64-bit frequency in Hz.
> > > +
> > > +  @return The frequency in Hz.
> > > +
> > > +**/
> > > +UINT64
> > > +InternalGetPerformanceCounterFrequency (
> > > +  VOID
> > > +  )
> > > +{
> > > +  return CpuidCoreClockCalculateTscFrequency (); }
> > > diff --git a/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf
> > > b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf
> > > new file mode 100644
> > > index 00..7e27a55c90
> > > --- /dev/null
> > > +++ b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf
> > > @@ -0,0 +1,35 @@
> > > +## @file
> > > +#  Base CPU Timer Library
> > > +#
> > > +#  Provides basic timer support using CPUID Leaf 0x15 XTAL frequency.
> > > +The performance #  counter features are provided by the processors
> > > +time
> > > stamp counter.
> > > +#
> > > +#  Copyright (c) 2019, Intel Corporation. All rights reserved.
> > > +#
> > > +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> > > +
> > > +[Defines]
> > > +  INF_VERSION= 0x00010005
> > > +  BASE_NAME  

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-12 Thread Donald Kuo
Hi Eric,

The CPUID Leaf 0x1:EDX.TSC[bit 4] is to check capability for 
IA32_TIME_STAMP_COUNTER MSR and RDTSC instruction which defined in IA32 SDM 
chapter 17.17

And what we implement is based on IA32 SDM Chapter 18.7 for CPU core XTAL clock 
frequency which is from CPUID Leaf 0x15 and new TSC frequency = (ECX, Core XTAL 
Frequency) * EBX/EAX

So no need to check CPUID(0x01).

Thanks,
Donald

> -Original Message-
> From: Dong, Eric
> Sent: Tuesday, August 13, 2019 10:27 AM
> To: Kuo, Donald ; devel@edk2.groups.io
> Cc: Ni, Ray ; Zeng, Star ; Chan,
> Amy ; Chaganty, Rangasai V
> 
> Subject: RE: [PATCH] UefiCpuPkg: Adding a new TSC library by using
> CPUID(0x15) TSC leaf
> 
> Hi Donald,
> 
> Do you think it's necessary to check the TIME_STAMP_COUNTER capability
> before using it? I see SDM has CPUID(0x01) which return the capability of
> TIME_STAMP_COUNTER.
> 
> Thanks,
> Eric
> 
> > -Original Message-
> > From: Kuo, Donald
> > Sent: Monday, August 12, 2019 7:23 PM
> > To: devel@edk2.groups.io
> > Cc: Ni, Ray ; Zeng, Star ;
> > Dong, Eric ; Chan, Amy ;
> > Chaganty, Rangasai V 
> > Subject: [PATCH] UefiCpuPkg: Adding a new TSC library by using
> > CPUID(0x15) TSC leaf
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> >
> > Cc: Ray Ni 
> > Cc: Star Zeng 
> > Cc: Eric Dong 
> > Cc: Amy Chan 
> > Cc: Rangasai V Chaganty 
> > Signed-off-by: Donald Kuo 
> > ---
> >  .../Library/BaseCpuTimerLib/BaseCpuTimerLib.c  |  40 +++
> >  .../Library/BaseCpuTimerLib/BaseCpuTimerLib.inf|  35 +++
> >  .../Library/BaseCpuTimerLib/BaseCpuTimerLib.uni|  16 ++
> >  UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c   | 272
> > +
> >  UefiCpuPkg/UefiCpuPkg.dec  |   8 +
> >  UefiCpuPkg/UefiCpuPkg.dsc  |   1 +
> >  6 files changed, 372 insertions(+)
> >  create mode 100644
> > UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c
> >  create mode 100644
> > UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf
> >  create mode 100644
> > UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.uni
> >  create mode 100644 UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c
> >
> > diff --git a/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c
> > b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c
> > new file mode 100644
> > index 00..ccb92a95d3
> > --- /dev/null
> > +++ b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c
> > @@ -0,0 +1,40 @@
> > +/** @file
> > +  CPUID Leaf 0x15 for Core Crystal Clock frequency instance of Timer
> Library.
> > +
> > +  Copyright (c) 2019 Intel Corporation. All rights reserved.
> > +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > +
> > +**/
> > +
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/**
> > +  CPUID Leaf 0x15 for Core Crystal Clock Frequency.
> > +
> > +  The TSC counting frequency is determined by using CPUID leaf 0x15.
> > Frequency in MHz = Core XTAL frequency * EBX/EAX.
> > +  In newer flavors of the CPU, core xtal frequency is returned in ECX
> > + or 0 if
> > not supported.
> > +  @return The number of TSC counts per second.
> > +
> > +**/
> > +UINT64
> > +CpuidCoreClockCalculateTscFrequency (
> > +  VOID
> > +  );
> > +
> > +/**
> > +  Internal function to retrieves the 64-bit frequency in Hz.
> > +
> > +  Internal function to retrieves the 64-bit frequency in Hz.
> > +
> > +  @return The frequency in Hz.
> > +
> > +**/
> > +UINT64
> > +InternalGetPerformanceCounterFrequency (
> > +  VOID
> > +  )
> > +{
> > +  return CpuidCoreClockCalculateTscFrequency (); }
> > diff --git a/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf
> > b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf
> > new file mode 100644
> > index 00..7e27a55c90
> > --- /dev/null
> > +++ b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf
> > @@ -0,0 +1,35 @@
> > +## @file
> > +#  Base CPU Timer Library
> > +#
> > +#  Provides basic timer support using CPUID Leaf 0x15 XTAL frequency.
> > +The performance #  counter features are provided by the processors
> > +time
> > stamp counter.
> > +#
> > +#  Copyright (c) 2019, Intel Corporation. All rights reserved. #
> > +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> > +
> > +[Defines]
> > +  INF_VERSION= 0x00010005
> > +  BASE_NAME  = BaseCpuTimerLib
> > +  FILE_GUID  = F10B5B91-D15A-496C-B044-B5235721AA08
> > +  MODULE_TYPE= BASE
> > +  VERSION_STRING = 1.0
> > +  LIBRARY_CLASS  = TimerLib
> > +  MODULE_UNI_FILE= BaseCpuTimerLib.uni
> > +
> > +[Sources]
> > +  CpuTimerLib.c
> > +  BaseCpuTimerLib.c
> > +
> > +[Packages]
> > +  MdePkg/MdePkg.dec
> > +  UefiCpuPkg/UefiCpuPkg.dec
> > +
> > +[LibraryClasses]
> > +  BaseLib
> > +  PcdLib
> > +  DebugLib
> > +
> > +[Pcd]
> > +  gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency  ##
> > +CONSUMES
> > diff --git 

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-12 Thread Dong, Eric
Hi Donald,

Do you think it's necessary to check the TIME_STAMP_COUNTER capability before 
using it? I see SDM has CPUID(0x01) which return the capability of 
TIME_STAMP_COUNTER.

Thanks,
Eric 

> -Original Message-
> From: Kuo, Donald
> Sent: Monday, August 12, 2019 7:23 PM
> To: devel@edk2.groups.io
> Cc: Ni, Ray ; Zeng, Star ; Dong, Eric
> ; Chan, Amy ; Chaganty,
> Rangasai V 
> Subject: [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15)
> TSC leaf
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> 
> Cc: Ray Ni 
> Cc: Star Zeng 
> Cc: Eric Dong 
> Cc: Amy Chan 
> Cc: Rangasai V Chaganty 
> Signed-off-by: Donald Kuo 
> ---
>  .../Library/BaseCpuTimerLib/BaseCpuTimerLib.c  |  40 +++
>  .../Library/BaseCpuTimerLib/BaseCpuTimerLib.inf|  35 +++
>  .../Library/BaseCpuTimerLib/BaseCpuTimerLib.uni|  16 ++
>  UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c   | 272
> +
>  UefiCpuPkg/UefiCpuPkg.dec  |   8 +
>  UefiCpuPkg/UefiCpuPkg.dsc  |   1 +
>  6 files changed, 372 insertions(+)
>  create mode 100644
> UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c
>  create mode 100644
> UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf
>  create mode 100644
> UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.uni
>  create mode 100644 UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c
> 
> diff --git a/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c
> b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c
> new file mode 100644
> index 00..ccb92a95d3
> --- /dev/null
> +++ b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c
> @@ -0,0 +1,40 @@
> +/** @file
> +  CPUID Leaf 0x15 for Core Crystal Clock frequency instance of Timer Library.
> +
> +  Copyright (c) 2019 Intel Corporation. All rights reserved.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include 
> +#include 
> +#include 
> +
> +/**
> +  CPUID Leaf 0x15 for Core Crystal Clock Frequency.
> +
> +  The TSC counting frequency is determined by using CPUID leaf 0x15.
> Frequency in MHz = Core XTAL frequency * EBX/EAX.
> +  In newer flavors of the CPU, core xtal frequency is returned in ECX or 0 if
> not supported.
> +  @return The number of TSC counts per second.
> +
> +**/
> +UINT64
> +CpuidCoreClockCalculateTscFrequency (
> +  VOID
> +  );
> +
> +/**
> +  Internal function to retrieves the 64-bit frequency in Hz.
> +
> +  Internal function to retrieves the 64-bit frequency in Hz.
> +
> +  @return The frequency in Hz.
> +
> +**/
> +UINT64
> +InternalGetPerformanceCounterFrequency (
> +  VOID
> +  )
> +{
> +  return CpuidCoreClockCalculateTscFrequency (); }
> diff --git a/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf
> b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf
> new file mode 100644
> index 00..7e27a55c90
> --- /dev/null
> +++ b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf
> @@ -0,0 +1,35 @@
> +## @file
> +#  Base CPU Timer Library
> +#
> +#  Provides basic timer support using CPUID Leaf 0x15 XTAL frequency.
> +The performance #  counter features are provided by the processors time
> stamp counter.
> +#
> +#  Copyright (c) 2019, Intel Corporation. All rights reserved. #
> +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> +
> +[Defines]
> +  INF_VERSION= 0x00010005
> +  BASE_NAME  = BaseCpuTimerLib
> +  FILE_GUID  = F10B5B91-D15A-496C-B044-B5235721AA08
> +  MODULE_TYPE= BASE
> +  VERSION_STRING = 1.0
> +  LIBRARY_CLASS  = TimerLib
> +  MODULE_UNI_FILE= BaseCpuTimerLib.uni
> +
> +[Sources]
> +  CpuTimerLib.c
> +  BaseCpuTimerLib.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  UefiCpuPkg/UefiCpuPkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  PcdLib
> +  DebugLib
> +
> +[Pcd]
> +  gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency  ##
> +CONSUMES
> diff --git a/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.uni
> b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.uni
> new file mode 100644
> index 00..6e5c3ef70e
> --- /dev/null
> +++ b/UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.uni
> @@ -0,0 +1,16 @@
> +// /** @file
> +// Base CPU Timer Library
> +//
> +// Provides basic timer support using CPUID Leaf 0x15 XTAL frequency.
> +The performance // counter features are provided by the processors time
> stamp counter.
> +//
> +// Copyright (c) 2019, Intel Corporation. All rights reserved. //
> +// SPDX-License-Identifier: BSD-2-Clause-Patent // // **/
> +
> +
> +#string STR_MODULE_ABSTRACT #language en-US "CPU Timer
> Library"
> +
> +#string STR_MODULE_DESCRIPTION  #language en-US "Provides basic
> timer support using CPUID Leaf 0x15 XTAL frequency."
> diff --git a/UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c
> b/UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c
> new file mode 100644
> index 

Re: [edk2-devel] [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf

2019-08-12 Thread Zeng, Star
Some comments below.

> -Original Message-
> From: Kuo, Donald
> Sent: Monday, August 12, 2019 1:57 PM
> To: devel@edk2.groups.io
> Cc: Ni, Ray ; Zeng, Star ; Dong, Eric
> 
> Subject: [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15)
> TSC leaf
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1909
> 
> Cc: Ray Ni 
> Cc: Star Zeng 
> Cc: Eric Dong 
> Signed-off-by: Donald Kuo 
> ---
>  .../Library/BaseCpuTimerLib/BaseCpuTimerLib.c  |  40 +++
>  .../Library/BaseCpuTimerLib/BaseCpuTimerLib.inf|  35 +++
>  .../Library/BaseCpuTimerLib/BaseCpuTimerLib.uni|  17 ++
>  UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c   | 290
> +
>  UefiCpuPkg/UefiCpuPkg.dec  |   8 +
>  UefiCpuPkg/UefiCpuPkg.dsc  |   4 +-
>  6 files changed, 393 insertions(+), 1 deletion(-)  create mode 100644
> UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c
>  create mode 100644
> UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf
>  create mode 100644
> UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.uni
>  create mode 100644 UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c
> 


[Trimmed]


> +
> diff --git a/UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c
> b/UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c
> new file mode 100644
> index 00..5ed01146cf
> --- /dev/null
> +++ b/UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c
> @@ -0,0 +1,290 @@
> +/** @file
> +  CPUID Leaf 0x15 for Core Crystal Clock frequency instance of Timer Library.
> +
> +  Copyright (c) 2019 Intel Corporation. All rights reserved.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/**
> +  Internal function to retrieves the 64-bit frequency in Hz.
> +
> +  Internal function to retrieves the 64-bit frequency in Hz.
> +
> +  @return The frequency in Hz.
> +
> +**/
> +UINT64
> +InternalGetPerformanceCounterFrequency (
> +  VOID
> +  );
> +
> +/**
> +  CPUID Leaf 0x15 for Core Crystal Clock Frequency.
> +
> +  The TSC counting frequency is determined by using CPUID leaf 0x15.
> Frequency in MHz = Core XTAL frequency * EBX/EAX.
> +  In newer flavors of the CPU, core xtal frequency is returned in ECX or 0 if
> not supported.
> +  @return The number of TSC counts per second.
> +
> +**/
> +UINT64
> +CpuidCoreClockCalculateTscFrequency (
> +  VOID
> +  )
> +{
> +  CPUID_VERSION_INFO_EAX Eax;
> +  UINT64 TscFrequency;
> +  UINT64 CoreXtalFrequency;
> +  UINT32 RegEax;
> +  UINT32 RegEbx;
> +  UINT32 RegEcx;
> +
> +  //
> +  // Display CPU FAMILY / MODEL / STEPPING ID Info  //  AsmCpuid
> + (CPUID_VERSION_INFO, , NULL, NULL, NULL);  DEBUG
> + ((DEBUG_INFO, "CPUID = %X\n", (Eax.Uint32 & 0x0FFF0FFF)));

Suggest removing this debugging code block.

> +
> +  //
> +  // Use CPUID leaf 0x15 Time Stamp Counter and Nominal Core Crystal
> + Clock Information  // EBX returns 0 if not supported. ECX, if non zero,
> provides Core Xtal Frequency in hertz.
> +  // TSC frequency = (ECX, Core Xtal Frequency) * EBX/EAX.
> +  //
> +  AsmCpuid (CPUID_TIME_STAMP_COUNTER, , , ,
> NULL);
> + DEBUG ((DEBUG_INFO, "Denominator of the TSC ratio = %d\n", RegEax));
> + DEBUG ((DEBUG_INFO, "Numerator of the TSC ratio = %d\n", RegEbx));
> + DEBUG ((DEBUG_INFO, "Nominal frequency (hertz) = %d\n", RegEcx));

Suggest removing this debug message codes as the timerlib may be used by AP.

> +
> +  //
> +  // If EBX returns 0, the XTAL ratio is not enumerated.
> +  //
> +  if (RegEbx == 0) {
> +DEBUG ((DEBUG_ERROR, "The CPU is not capble for Core Crystal Clock
> Frequency !!\n"));

Suggest removing this debug message codes as the timerlib may be used by AP.
Then the if condition can be also removed.

> +ASSERT (RegEbx != 0);
> +  }
> +  //
> +  // If ECX returns 0, the XTAL frequency is not enumerated.
> +  //
> +  if (RegEcx == 0) {
> +DEBUG ((DEBUG_ERROR, "The CPU is not capble for Core Crystal Clock
> Frequency !!\n"));

Suggest removing this debug message codes as the timerlib may be used by AP.

> +CoreXtalFrequency = PcdGet64 (PcdCpuCoreCrystalClockFrequency);
> +DEBUG ((DEBUG_INFO, "CoreXtalFrequency (hertz) from PCD = %d\n",
> CoreXtalFrequency));

Suggest removing this debug message codes as the timerlib may be used by AP.

> +//ASSERT (RegEcx != 0);

Suggest removing this line

> +  } else {
> +CoreXtalFrequency = (UINT64) RegEcx;  }
> +
> +  //
> +  // Calculate TSC frequency = (ECX, Core Xtal Frequency) * EBX/EAX  //
> + TscFrequency = DivU64x32 (MultU64x32 (CoreXtalFrequency, RegEbx) +
> + (UINT64)(RegEax >> 1), RegEax);
> +
> +  return TscFrequency;
> +}
> +

[Trimmed]

> --- a/UefiCpuPkg/UefiCpuPkg.dsc
> +++ b/UefiCpuPkg/UefiCpuPkg.dsc
> @@ -42,7 +42,7 @@
>PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
>