On 06/06/18 10:21, Mohammad Younas Khan Pathan wrote:
> Hi All,
> 
> If there is any generic library function, then we do not need to have
> 2 or more definitions for same function like IsLeapYear().
> 
> Searching for 'isleapyear'
> By Mask:
>                       *.c
> ArmPlatformPkg\Library\PL031RealTimeClockLib\PL031RealTimeClockLib.c(199)
> :IsLeapYear (
> ArmPlatformPkg\Library\PL031RealTimeClockLib\PL031RealTimeClockLib.c(227)
> :      (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))
> EmbeddedPkg\Library\HalRuntimeServicesExampleLib\Rtc.c(134) :IsLeapYear (
> EmbeddedPkg\Library\HalRuntimeServicesExampleLib\Rtc.c(163) :
> (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))
> EmulatorPkg\RealTimeClockRuntimeDxe\RealTimeClock.c(33) :IsLeapYear (
> EmulatorPkg\RealTimeClockRuntimeDxe\RealTimeClock.c(279) :
> (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))
> EmulatorPkg\RealTimeClockRuntimeDxe\RealTimeClock.c(288) :IsLeapYear (
> Nt32Pkg\RealTimeClockRuntimeDxe\RealTimeClock.c(37) :IsLeapYear (
> Nt32Pkg\RealTimeClockRuntimeDxe\RealTimeClock.c(356) :
> (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))
> Nt32Pkg\RealTimeClockRuntimeDxe\RealTimeClock.c(365) :IsLeapYear (
> PcAtChipsetPkg\PcatRealTimeClockRuntimeDxe\PcRtc.c(1021) :
> (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))
> PcAtChipsetPkg\PcatRealTimeClockRuntimeDxe\PcRtc.c(1038) :IsLeapYear (
> PcAtChipsetPkg\PcatRealTimeClockRuntimeDxe\PcRtc.c(1178) :      if
> ((From->Month == 2) && !IsLeapYear(From)) {
> 
> Similarly for other functions, can we have the common functions used
> for time in BaseLib or some common library?
> 
> Can we move them to BaseLib or any other common library?
> 
> Bug link:
> https://bugzilla.tianocore.org/show_bug.cgi?id=868
> 
> Please provide your suggestions on the same.

Not sure about BaseLib (or even TimerLib), but we should indeed move
this function to a generic utility package -- maybe a
"TimeCalculationLib" class that manipulates pure time concepts and
values, without any hardware accesses (even abstracted ones).

(

For that same library class, I would probably nominate a function that I
posted earlier, under "TimerTickDiffLib", namely the GetTickDifference()
function.

Because, values returned by TimerLib's GetPerformanceCounter() function
cannot simply be subtracted from each other, because (a) counters don't
necessarily increment until they wrap around (they can be decrementing
too), and (b) the wrap-around's *low* bound may not be zero.

Such differences are needed all over the tree, and even recently a buggy
subtraction was added, as far as I remember...

... Yes: see the GetElapsedTick() function in commit 0edb7ec5ced0,
"MdeModulePkg/PciHostBridge: Count the (mm)io overhead when polling",
2018-05-09. The GetElapsedTick() function does not consider issue (b) above.

The exact same issue can be seen in IsSyncTimerTimeout(),
"UefiCpuPkg/PiSmmCpuDxeSmm/SyncTimer.c".

For comparison, see the GetTickDifference() function here (you'll have
to scroll down a bit):

http://mid.mail-archive.com/8cba2a58-1333-7733-031d-0883dbd844c6@redhat.com

)

Thanks
Laszlo
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to