qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Hao Wu <wuhaotsh@google.com>
Cc: "Corey Minyard" <minyard@acm.org>,
	"Patrick Venture" <venture@google.com>,
	"Havard Skinnemoen" <hskinnemoen@google.com>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"CS20 KFTing" <kfting@nuvoton.com>,
	qemu-arm <qemu-arm@nongnu.org>,
	"IS20 Avi Fishman" <Avi.Fishman@nuvoton.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: Re: [PATCH v4 2/6] hw/timer: Refactor NPCM7XX Timer to use CLK clock
Date: Thu, 7 Jan 2021 20:51:31 +0000	[thread overview]
Message-ID: <CAFEAcA_jEYK_e7uoJCKn=+om8c6cCRW0Xt5TKi6mzto+zE44Fg@mail.gmail.com> (raw)
In-Reply-To: <20201217004349.3740927-3-wuhaotsh@google.com>

On Thu, 17 Dec 2020 at 00:45, Hao Wu <wuhaotsh@google.com> wrote:
>
> This patch makes NPCM7XX Timer to use a the timer clock generated by the
> CLK module instead of the magic number TIMER_REF_HZ.
>
> Reviewed-by: Havard Skinnemoen <hskinnemoen@google.com>
> Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
> Signed-off-by: Hao Wu <wuhaotsh@google.com>
> ---
>  hw/arm/npcm7xx.c                 |  5 +++++
>  hw/timer/npcm7xx_timer.c         | 25 ++++++++++++++-----------
>  include/hw/misc/npcm7xx_clk.h    |  6 ------
>  include/hw/timer/npcm7xx_timer.h |  1 +
>  4 files changed, 20 insertions(+), 17 deletions(-)

> @@ -130,7 +130,7 @@ static int64_t npcm7xx_timer_count_to_ns(NPCM7xxTimer *t, uint32_t count)
>  {
>      int64_t ns = count;
>
> -    ns *= NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ;
> +    ns *= clock_get_ns(t->ctrl->clock);
>      ns *= npcm7xx_tcsr_prescaler(t->tcsr);

I'm afraid that since you wrote and sent this we've updated the
clock API (in commits 554d523785ef868 and de6a65f11d7e5a2a93f),
so clock_get_ns() doesn't exist any more. Instead there is
a new function clock_ticks_to_ns().

The idea of the new function is that clocks don't necessarily
have a period which is a whole number of nanoseconds, so
doing arithmetic on the return value from clock_get_ns()
introduces rounding errors, especially in the case of
"multiply clock_get_ns() by a tick count to get a duration".
(The worst case for this is "clock frequency >1GHz", at which
point the rounding means that clock_get_ns() returns 0...)

There is as yet no function for "convert duration to
tick count", so code like:
   count = ns / clock_get_ns(t->ctrl->clock);

should probably for the moment call clock_ticks_to_ns()
passing a tick count of 1. But I plan to write a patchset
soon which will avoid the need to do that.

Strictly speaking, even "call clock_ticks_to_ns() and
then multiply by the prescaler value" can introduce
rounding error; to deal with that I think you'd need to
either have an internal Clock object whose period you
adjusted as the prescalar value was updated by the guest,
or else do arithmetic with the return value of clock_get()
(which is in units of 2^-32 ns); I'm not sure either is
worth it.

thanks
-- PMM


  reply	other threads:[~2021-01-07 21:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-17  0:43 [PATCH v4 0/6] Additional NPCM7xx devices Hao Wu via
2020-12-17  0:43 ` [PATCH v4 1/6] hw/misc: Add clock converter in NPCM7XX CLK module Hao Wu via
2021-01-07 20:39   ` Peter Maydell
2020-12-17  0:43 ` [PATCH v4 2/6] hw/timer: Refactor NPCM7XX Timer to use CLK clock Hao Wu via
2021-01-07 20:51   ` Peter Maydell [this message]
2021-01-07 21:43     ` Hao Wu via
2020-12-17  0:43 ` [PATCH v4 3/6] hw/adc: Add an ADC module for NPCM7XX Hao Wu via
2021-01-07 21:07   ` Peter Maydell
2021-01-07 21:58     ` Hao Wu via
2020-12-17  0:43 ` [PATCH v4 4/6] hw/misc: Add a PWM " Hao Wu via
2020-12-17  0:43 ` [PATCH v4 5/6] hw/misc: Add QTest for NPCM7XX PWM Module Hao Wu via
2021-01-07 21:10   ` Peter Maydell
2020-12-17  0:43 ` [PATCH v4 6/6] hw/*: Use type casting for SysBusDevice in NPCM7XX Hao Wu via
2021-01-07 21:08   ` Peter Maydell
2021-01-05 21:56 ` [PATCH v4 0/6] Additional NPCM7xx devices Hao Wu via

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-all 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='CAFEAcA_jEYK_e7uoJCKn=+om8c6cCRW0Xt5TKi6mzto+zE44Fg@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=Avi.Fishman@nuvoton.com \
    --cc=f4bug@amsat.org \
    --cc=hskinnemoen@google.com \
    --cc=kfting@nuvoton.com \
    --cc=minyard@acm.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=venture@google.com \
    --cc=wuhaotsh@google.com \
    /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;
as well as URLs for NNTP newsgroup(s).