qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anup Patel <anup@brainfault.org>
To: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Cc: Alistair Francis <Alistair.Francis@wdc.com>,
	 Frederik Du Toit Lotter <fred.lotter@canonical.com>,
	qemu-riscv@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [PATCH 1/1] goldfish_rtc: keep time offset when resetting
Date: Fri, 21 Mar 2025 21:30:55 +0530	[thread overview]
Message-ID: <CAAhSdy0-we9B19wRRqk_rRFkjY2LPPMRGaTdE=_4Ge_pCR4Y4Q@mail.gmail.com> (raw)
In-Reply-To: <20250321081255.30564-1-heinrich.schuchardt@canonical.com>

On Fri, Mar 21, 2025 at 1:43 PM Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> Currently resetting leads to resynchronizing the Goldfish RTC with the
> system clock of the host. In real hardware an RTC reset would not change
> the wall time. Other RTCs like pl031 do not show this behavior.
>
> Move the synchronization of the RTC with the system clock to the instance
> realization.
>
> Reported-by: Frederik Du Toit Lotter <fred.lotter@canonical.com>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

LGTM.

Reviewed-by: Anup Patel <anup@brainfault.org>

Regards,
Anup

> ---
>  hw/rtc/goldfish_rtc.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/hw/rtc/goldfish_rtc.c b/hw/rtc/goldfish_rtc.c
> index 0f1b53e0e4..203a343511 100644
> --- a/hw/rtc/goldfish_rtc.c
> +++ b/hw/rtc/goldfish_rtc.c
> @@ -239,15 +239,8 @@ static const VMStateDescription goldfish_rtc_vmstate = {
>  static void goldfish_rtc_reset(DeviceState *dev)
>  {
>      GoldfishRTCState *s = GOLDFISH_RTC(dev);
> -    struct tm tm;
>
>      timer_del(s->timer);
> -
> -    qemu_get_timedate(&tm, 0);
> -    s->tick_offset = mktimegm(&tm);
> -    s->tick_offset *= NANOSECONDS_PER_SECOND;
> -    s->tick_offset -= qemu_clock_get_ns(rtc_clock);
> -    s->tick_offset_vmstate = 0;
>      s->alarm_next = 0;
>      s->alarm_running = 0;
>      s->irq_pending = 0;
> @@ -258,6 +251,7 @@ static void goldfish_rtc_realize(DeviceState *d, Error **errp)
>  {
>      SysBusDevice *dev = SYS_BUS_DEVICE(d);
>      GoldfishRTCState *s = GOLDFISH_RTC(d);
> +    struct tm tm;
>
>      memory_region_init_io(&s->iomem, OBJECT(s),
>                            &goldfish_rtc_ops[s->big_endian], s,
> @@ -267,6 +261,12 @@ static void goldfish_rtc_realize(DeviceState *d, Error **errp)
>      sysbus_init_irq(dev, &s->irq);
>
>      s->timer = timer_new_ns(rtc_clock, goldfish_rtc_interrupt, s);
> +
> +    qemu_get_timedate(&tm, 0);
> +    s->tick_offset = mktimegm(&tm);
> +    s->tick_offset *= NANOSECONDS_PER_SECOND;
> +    s->tick_offset -= qemu_clock_get_ns(rtc_clock);
> +    s->tick_offset_vmstate = 0;
>  }
>
>  static const Property goldfish_rtc_properties[] = {
> --
> 2.48.1
>
>


  reply	other threads:[~2025-03-21 16:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-21  8:12 [PATCH 1/1] goldfish_rtc: keep time offset when resetting Heinrich Schuchardt
2025-03-21 16:00 ` Anup Patel [this message]
2025-03-21 16:08 ` [PATCH-for-10.0 " Philippe Mathieu-Daudé
2025-03-21 16:10   ` Heinrich Schuchardt
2025-03-21 17:43     ` Philippe Mathieu-Daudé

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='CAAhSdy0-we9B19wRRqk_rRFkjY2LPPMRGaTdE=_4Ge_pCR4Y4Q@mail.gmail.com' \
    --to=anup@brainfault.org \
    --cc=Alistair.Francis@wdc.com \
    --cc=fred.lotter@canonical.com \
    --cc=heinrich.schuchardt@canonical.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    /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).