From: Richard Henderson <richard.henderson@linaro.org>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>, qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Luc Michel <luc@lmichel.fr>,
Andrew Baumann <Andrew.Baumann@microsoft.com>,
Paul Zimmerman <pauldzim@gmail.com>,
Niek Linnenbank <nieklinnenbank@gmail.com>,
qemu-arm@nongnu.org
Subject: Re: [PATCH v3 3/4] hw/timer/bcm2835: Support the timer COMPARE registers
Date: Sat, 3 Oct 2020 12:17:52 -0500 [thread overview]
Message-ID: <c47c8248-0bfe-5747-1ec1-073fb755f039@linaro.org> (raw)
In-Reply-To: <20201002164216.1741110-4-f4bug@amsat.org>
On 10/2/20 11:42 AM, Philippe Mathieu-Daudé wrote:
> @@ -78,16 +71,29 @@ static void bcm2835_systmr_write(void *opaque, hwaddr offset,
> uint64_t value, unsigned size)
> {
> BCM2835SystemTimerState *s = BCM2835_SYSTIMER(opaque);
> + int index;
> + uint64_t now;
> + uint64_t triggers_delay_us;
>
> trace_bcm2835_systmr_write(offset, value);
> switch (offset) {
> case A_CTRL_STATUS:
> s->reg.ctrl_status &= ~value; /* Ack */
> - bcm2835_systmr_update_irq(s);
> + for (index = 0; index < ARRAY_SIZE(s->tmr); index++) {
> + if (extract32(value, index, 1)) {
> + trace_bcm2835_systmr_irq_ack(index);
> + qemu_set_irq(s->tmr[index].irq, 0);
> + }
I think it might be instructive to have the parameter be uint64_t value64, and
the immediately do
uint32_t value = value64;
That matches up better with extract32, the trace arguments...
> + }
> break;
> case A_COMPARE0 ... A_COMPARE3:
> - s->reg.compare[(offset - A_COMPARE0) >> 2] = value;
> - bcm2835_systmr_update_compare(s, (offset - A_COMPARE0) >> 2);
> + index = (offset - A_COMPARE0) >> 2;
> + s->reg.compare[index] = value;
> + now = qemu_clock_get_us(QEMU_CLOCK_VIRTUAL);
> + /* Compare lower 32-bits of the free-running counter. */
> + triggers_delay_us = value - (now & UINT32_MAX);
> + trace_bcm2835_systmr_run(index, triggers_delay_us);
> + timer_mod(&s->tmr[index].timer, now + triggers_delay_us);
... and here.
Also, the arithmetic looks off.
Consider when you want a long timeout, and pass in a value slightly below now.
So, e.g.
now = 0xabcdffffffff;
value = 0x0000fffffffe;
since triggers_delay_us is uint64_t, that comparison becomes
triggers_delay_us = 0x0000fffffffe - 0xffffffff;
= 0xffffffffffffffff;
Then you add back in now, and do *not* get a value in the future:
now + triggers_delay_us
= 0xabcdffffffff + 0xffffffffffffffff
= 0xabcdfffffffe
What I think you want is
uint32_t triggers_delay_us = value - now
= 0xffffffff;
which then zero-extends when you add back to now to get
now + triggers_delay_us
= 0xabcdffffffff + 0xffffffff
= 0xabcefffffffe
which is indeed in the future.
r~
next prev parent reply other threads:[~2020-10-03 17:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-02 16:42 [PATCH v3 0/4] hw/arm/raspi: Fix SYS_timer to unbrick Linux kernels v3.7+ Philippe Mathieu-Daudé
2020-10-02 16:42 ` [PATCH v3 1/4] hw/timer/bcm2835: Introduce BCM2835_SYSTIMER_COUNT definition Philippe Mathieu-Daudé
2020-10-03 16:42 ` Richard Henderson
2020-10-02 16:42 ` [PATCH v3 2/4] hw/timer/bcm2835: Rename variable holding CTRL_STATUS register Philippe Mathieu-Daudé
2020-10-03 16:42 ` Richard Henderson
2020-10-02 16:42 ` [PATCH v3 3/4] hw/timer/bcm2835: Support the timer COMPARE registers Philippe Mathieu-Daudé
2020-10-03 17:17 ` Richard Henderson [this message]
2020-10-10 20:15 ` Philippe Mathieu-Daudé
2020-10-02 16:42 ` [PATCH v3 4/4] hw/arm/bcm2835_peripherals: Correctly wire the SYS_timer IRQs Philippe Mathieu-Daudé
2020-10-03 17:18 ` Richard Henderson
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=c47c8248-0bfe-5747-1ec1-073fb755f039@linaro.org \
--to=richard.henderson@linaro.org \
--cc=Andrew.Baumann@microsoft.com \
--cc=f4bug@amsat.org \
--cc=luc@lmichel.fr \
--cc=nieklinnenbank@gmail.com \
--cc=pauldzim@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@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).