public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: Pankaj Bansal <pankaj.bansal@nxp.com>, edk2-devel@lists.01.org
Cc: Leif Lindholm <leif.lindholm@linaro.org>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Michael Kinney <michael.d.kinney@intel.com>
Subject: Re: [PATCH 2/2] ArmPkg/ArmArchTimerLib: Implement GetElapsedTime function of TimerLib
Date: Wed, 10 Jan 2018 15:16:26 +0100	[thread overview]
Message-ID: <cdc4486b-dd7c-2823-95d3-4b0c9a204210@redhat.com> (raw)
In-Reply-To: <1515576669-14171-2-git-send-email-pankaj.bansal@nxp.com>

Hello Pankaj,

On 01/10/18 10:31, Pankaj Bansal wrote:
> This function calculates the time elaped in Naoseconds between call to
> this function and BaseTime, which is passed as argument.
>
> This is particularly useful in detecting timeout conditions.
>
> Cc: Leif Lindholm <leif.lindholm@linaro.org>
> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
>
> diff --git a/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c b/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c
> index b81293c..0898339 100644
> --- a/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c
> +++ b/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c
> @@ -290,3 +290,39 @@ GetTimeInNanoSecond (
>
>    return NanoSeconds;
>  }
> +
> +/**
> +  Get Elapsed time in Nanoseonds w.r.t BaseTime
> +
> +  This function calculates the time elaped in Naoseconds between call to this
> +  function and BaseTime, which is passed as argument.
> +
> +  @param  BaseTime     BaseTime in NanoSeconds.
> +
> +  @return The elapsed time in nanoseconds.
> +
> +**/
> +UINT64
> +EFIAPI
> +GetElapsedTime (
> +  IN      UINT64                     BaseTime
> +  )
> +{
> +  UINT64  NanoSeconds;
> +  UINT64  Ticks;
> +
> +  //
> +  // Get current Ticks.
> +  //
> +  Ticks = GetPerformanceCounter();
> +
> +  //
> +  // Convert Ticks to Nanoseconds
> +  //
> +  NanoSeconds = GetTimeInNanoSecond (Ticks);
> +
> +  //
> +  // return the difference
> +  //
> +  return (NanoSeconds - BaseTime);
> +}
>

There are two problems with this patch set:

(1) The TimerLib.h file (in the first patch) is a public library class
header, for which several library instances (implementations) exist. So,
introducing a new API requires adding an implementation (the same
implementation, or different ones, as necessary) to *all* instances in
the edk2 tree.

(2) The calculation in your GetElapsedTime() function is wrong.
GetTimeInNanoSecond() converts a small *difference* of ticks to time. It
does not convert an absolute tick value to an absolute time.

Furthermore, tick differences are less trivial to calculate than one
might imagine, because (a) a performance counter may count down, and
*independently*, (b) the numeric low bound of the counter range may not
be zero.

Earlier I proposed a new TimerTickDiffLib class (and implementation) for
centralizing exactly this kind of calculation. Please see the thread at:

  [edk2] TimerTickDiffLib for MdePkg?
  http://mid.mail-archive.com/8cba2a58-1333-7733-031d-0883dbd844c6@redhat.com

Thanks
Laszlo


  reply	other threads:[~2018-01-10 14:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-10  9:31 [PATCH 1/2] MdePkg/TimerLib: Add a function to calculate elapsed time Pankaj Bansal
2018-01-10  9:31 ` [PATCH 2/2] ArmPkg/ArmArchTimerLib: Implement GetElapsedTime function of TimerLib Pankaj Bansal
2018-01-10 14:16   ` Laszlo Ersek [this message]
2018-01-10 16:05     ` Pankaj Bansal
2018-01-10 17:04       ` Laszlo Ersek
2018-01-11  6:28         ` Pankaj Bansal
2018-01-11  9:58           ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cdc4486b-dd7c-2823-95d3-4b0c9a204210@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox