From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8FC2F2112DF58 for ; Wed, 6 Jun 2018 13:32:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD7874023156; Wed, 6 Jun 2018 20:32:51 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-124.rdu2.redhat.com [10.10.120.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F73A11301E8; Wed, 6 Jun 2018 20:32:50 +0000 (UTC) To: edk2-devel@lists.01.org References: Cc: Mohammad Younas Khan Pathan , "Leif Lindholm (Linaro address)" , Michael Kinney , Andrew Fish , Brian Richardson , Ruiyu Ni From: Laszlo Ersek Message-ID: <200d1795-908a-94af-b936-a5de6718bc00@redhat.com> Date: Wed, 6 Jun 2018 22:32:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 06 Jun 2018 20:32:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 06 Jun 2018 20:32:51 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: Re: Bug 868 - Need to add several functions related to date and time in BaseLib. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jun 2018 20:32:52 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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