From: "Andrew Jeffery" <andrew@aj.id.au>
To: "Cédric Le Goater" <clg@kaod.org>,
"Peter Maydell" <peter.maydell@linaro.org>
Cc: "Philippe Mathieu-Daudé via" <qemu-arm@nongnu.org>,
"Cameron Esfahani via" <qemu-devel@nongnu.org>,
"Joel Stanley" <joel@jms.id.au>
Subject: Re: [Qemu-devel] [PATCH 08/19] aspeed/timer: Fix behaviour running Linux
Date: Mon, 25 Sep 2023 17:24:49 +0930 [thread overview]
Message-ID: <d383d716-2c9a-4d37-a35d-6f62bff9bf1e@app.fastmail.com> (raw)
In-Reply-To: <a4a62040-0127-4f39-4fc3-a1795e4daad8@kaod.org>
On Fri, 22 Sep 2023, at 22:51, Cédric Le Goater wrote:
> Joel, Andrew,
>
> On 5/25/19 17:12, Cédric Le Goater wrote:
>> From: Joel Stanley <joel@jms.id.au>
>>
>> The Linux kernel driver was updated in commit 4451d3f59f2a
>> ("clocksource/drivers/fttmr010: Fix set_next_event handler) to fix an
>> issue observed on hardware:
>>
>> > RELOAD register is loaded into COUNT register when the aspeed timer
>> > is enabled, which means the next event may be delayed because timer
>> > interrupt won't be generated until <0xFFFFFFFF - current_count +
>> > cycles>.
>>
>> When running under Qemu, the system appeared "laggy". The guest is now
>> scheduling timer events too regularly, starving the host of CPU time.
>>
>> This patch modifies the timer model to attempt to schedule the timer
>> expiry as the guest requests, but if we have missed the deadline we
>> re interrupt and try again, which allows the guest to catch up.
>>
>> Provides expected behaviour with old and new guest code.
>>
>> Fixes: c04bd47db6b9 ("hw/timer: Add ASPEED timer device model")
>> Signed-off-by: Joel Stanley <joel@jms.id.au>
>> [clg: - merged a fix from Andrew Jeffery <andrew@aj.id.au>
>> "Fire interrupt on failure to meet deadline"
>> https://lists.ozlabs.org/pipermail/openbmc/2019-January/014641.html
>> - adapted commit log
>> - checkpatch fixes ]
>> Signed-off-by: Cédric Le Goater <clg@kaod.org>
>> ---
>> hw/timer/aspeed_timer.c | 59 ++++++++++++++++++++++-------------------
>> 1 file changed, 31 insertions(+), 28 deletions(-)
>>
>> diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
>> index 5c786e512815..9ffd8e09f670 100644
>> --- a/hw/timer/aspeed_timer.c
>> +++ b/hw/timer/aspeed_timer.c
>> @@ -109,37 +109,40 @@ static inline uint64_t calculate_time(struct AspeedTimer *t, uint32_t ticks)
>>
>> static uint64_t calculate_next(struct AspeedTimer *t)
>> {
>> - uint64_t next = 0;
>> - uint32_t rate = calculate_rate(t);
>> + uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>> + uint64_t next;
>>
>> - while (!next) {
>> - /* We don't know the relationship between the values in the match
>> - * registers, so sort using MAX/MIN/zero. We sort in that order as the
>> - * timer counts down to zero. */
>> - uint64_t seq[] = {
>> - calculate_time(t, MAX(t->match[0], t->match[1])),
>> - calculate_time(t, MIN(t->match[0], t->match[1])),
>> - calculate_time(t, 0),
>> - };
>> - uint64_t reload_ns;
>> - uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>> -
>> - if (now < seq[0]) {
>> - next = seq[0];
>> - } else if (now < seq[1]) {
>> - next = seq[1];
>> - } else if (now < seq[2]) {
>> - next = seq[2];
>> - } else if (t->reload) {
>> - reload_ns = muldiv64(t->reload, NANOSECONDS_PER_SECOND, rate);
>> - t->start = now - ((now - t->start) % reload_ns);
>> - } else {
>> - /* no reload value, return 0 */
>> - break;
>> - }
>> + /*
>> + * We don't know the relationship between the values in the match
>> + * registers, so sort using MAX/MIN/zero. We sort in that order as
>> + * the timer counts down to zero.
>> + */
>> +
>> + next = calculate_time(t, MAX(t->match[0], t->match[1]));
>> + if (now < next) {
>> + return next;
>> + }
>> +
>> + next = calculate_time(t, MIN(t->match[0], t->match[1]));
>> + if (now < next) {
>> + return next;
>> + }
>> +
>> + next = calculate_time(t, 0);
>> + if (now < next) {
>> + return next;
>> + }
>> +
>> + /* We've missed all deadlines, fire interrupt and try again */
>> + timer_del(&t->timer);
>> +
>> + if (timer_overflow_interrupt(t)) {
>> + t->level = !t->level;
>> + qemu_set_irq(t->irq, t->level);
>> }
>>
>> - return next;
>> + t->start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>> + return calculate_time(t, MAX(MAX(t->match[0], t->match[1]), 0));
>
> This MAX(MAX(x, y), 0) looks strange to me. Would you remember where it comes
> from ? Thanks,
The inner MAX() deals with the lack of ordering constraints between the match values. I think the outer MAX() is redundant. We should probably remove it. The match member is type uint32_t so it can't be negative. You did steal that from an RFC patch :D
Andrew
next prev parent reply other threads:[~2023-09-25 7:55 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-25 15:12 [Qemu-devel] [PATCH 00/19] aspeed: machine extensions and fixes Cédric Le Goater
2019-05-25 15:12 ` [Qemu-devel] [PATCH 01/19] hw/arm/aspeed: Use object_initialize_child for correct ref. counting Cédric Le Goater
2019-05-25 15:12 ` [Qemu-devel] [PATCH 02/19] aspeed: add a per SoC mapping for the interrupt space Cédric Le Goater
2019-05-25 15:12 ` [Qemu-devel] [PATCH 03/19] aspeed: add a per SoC mapping for the memory space Cédric Le Goater
2019-05-25 15:12 ` [Qemu-devel] [PATCH 04/19] hw: timer: Add ASPEED RTC device Cédric Le Goater
2019-05-25 15:12 ` [Qemu-devel] [PATCH 05/19] hw/arm/aspeed: Add RTC to SoC Cédric Le Goater
2019-05-25 15:12 ` [Qemu-devel] [PATCH 06/19] aspeed: introduce a configurable number of CPU per machine Cédric Le Goater
2019-06-12 1:32 ` Joel Stanley
2019-06-12 8:03 ` Cédric Le Goater
2019-05-25 15:12 ` [Qemu-devel] [PATCH 07/19] aspeed: add support for multiple NICs Cédric Le Goater
2019-05-26 1:01 ` Keno Fischer
2019-05-26 17:10 ` Cédric Le Goater
2019-05-25 15:12 ` [Qemu-devel] [PATCH 08/19] aspeed/timer: Fix behaviour running Linux Cédric Le Goater
2023-09-22 13:21 ` Cédric Le Goater
2023-09-25 7:54 ` Andrew Jeffery [this message]
2023-09-25 9:20 ` Cédric Le Goater
2023-09-26 1:37 ` Andrew Jeffery
2023-09-27 2:12 ` Joel Stanley
2023-09-27 5:44 ` Cédric Le Goater
2023-09-27 6:46 ` Markus Armbruster
2019-05-25 15:12 ` [Qemu-devel] [PATCH 09/19] aspeed/timer: Status register contains reload for stopped timer Cédric Le Goater
2019-05-25 15:12 ` [Qemu-devel] [PATCH 10/19] aspeed/timer: Fix match calculations Cédric Le Goater
2019-05-25 15:12 ` [Qemu-devel] [PATCH 11/19] aspeed/timer: Provide back-pressure information for short periods Cédric Le Goater
2019-05-25 15:12 ` [Qemu-devel] [PATCH 12/19] aspeed/timer: Ensure positive muldiv delta Cédric Le Goater
2019-05-25 15:12 ` [Qemu-devel] [PATCH 13/19] aspeed/smc: add a 'sdram_base' propertie Cédric Le Goater
2019-06-12 1:34 ` Joel Stanley
2019-06-13 14:32 ` Philippe Mathieu-Daudé
2019-06-14 11:49 ` Cédric Le Goater
2019-05-25 15:12 ` [Qemu-devel] [PATCH 14/19] aspeed: remove the "ram" link Cédric Le Goater
2019-06-12 1:35 ` Joel Stanley
2019-05-25 15:12 ` [Qemu-devel] [PATCH 15/19] aspeed: add a RAM memory region container Cédric Le Goater
2019-06-12 1:36 ` Joel Stanley
2019-05-25 15:12 ` [Qemu-devel] [PATCH 16/19] aspeed/smc: add support for DMAs Cédric Le Goater
2019-06-12 1:38 ` Joel Stanley
2019-05-25 15:12 ` [Qemu-devel] [PATCH 17/19] aspeed/smc: add DMA calibration settings Cédric Le Goater
2019-06-12 1:40 ` Joel Stanley
2019-05-25 15:12 ` [Qemu-devel] [PATCH 18/19] aspeed/smc: inject errors in DMA checksum Cédric Le Goater
2019-06-12 1:41 ` Joel Stanley
2019-06-13 14:31 ` Philippe Mathieu-Daudé
2019-06-14 12:02 ` Cédric Le Goater
2019-06-14 12:35 ` Philippe Mathieu-Daudé
2019-05-25 15:12 ` [Qemu-devel] [PATCH 19/19] aspeed/smc: Calculate checksum on normal DMA Cédric Le Goater
2019-06-12 1:42 ` Joel Stanley
2019-06-07 10:10 ` [Qemu-devel] [PATCH 00/19] aspeed: machine extensions and fixes Peter Maydell
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=d383d716-2c9a-4d37-a35d-6f62bff9bf1e@app.fastmail.com \
--to=andrew@aj.id.au \
--cc=clg@kaod.org \
--cc=joel@jms.id.au \
--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).