From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: "Cédric Le Goater" <clg@kaod.org>,
"Peter Maydell" <peter.maydell@linaro.org>
Cc: Andrew Jeffery <andrew@aj.id.au>,
qemu-devel@nongnu.org, qemu-arm@nongnu.org,
Joel Stanley <joel@jms.id.au>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH for 4.1] aspeed/timer: Provide back-pressure information for short periods
Date: Thu, 4 Jul 2019 11:26:53 +0200 [thread overview]
Message-ID: <cd1f8a48-27cb-5cc5-1fd2-46f1597a7094@redhat.com> (raw)
In-Reply-To: <20190704055150.4899-1-clg@kaod.org>
CC'ing Stefan & Paolo for a non-ARM view on this...
On 7/4/19 7:51 AM, Cédric Le Goater wrote:
> From: Andrew Jeffery <andrew@aj.id.au>
>
> First up: This is not the way the hardware behaves.
>
> However, it helps resolve real-world problems with short periods being
> used under Linux. Commit 4451d3f59f2a ("clocksource/drivers/fttmr010:
> Fix set_next_event handler") in Linux fixed the timer driver to
> correctly schedule the next event for the Aspeed controller, and in
> combination with 5daa8212c08e ("ARM: dts: aspeed: Describe random number
> device") Linux will now set a timer with a period as low as 1us.
>
> Configuring a qemu timer with such a short period results in spending
> time handling the interrupt in the model rather than executing guest
> code, leading to noticeable "sticky" behaviour in the guest.
>
> The behaviour of Linux is correct with respect to the hardware, so we
> need to improve our handling under emulation. The approach chosen is to
> provide back-pressure information by calculating an acceptable minimum
> number of ticks to be set on the model. Under Linux an additional read
> is added in the timer configuration path to detect back-pressure, which
> will never occur on hardware. However if back-pressure is observed, the
> driver alerts the clock event subsystem, which then performs its own
> next event dilation via a config option - d1748302f70b ("clockevents:
> Make minimum delay adjustments configurable")
>
> A minimum period of 5us was experimentally determined on a Lenovo
> T480s, which I've increased to 20us for "safety".
>
> Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
> [clg: - changed the computation of min_ticks to be done each time the
> timer value is reloaded. It removes the ordering issue of the
> timer and scu reset handlers but is slightly slower ]
> - introduced TIMER_MIN_NS
> - introduced calculate_min_ticks() ]
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> ---
>
> This is fixing a serious slowdown issue with recent Linux.
>
> hw/timer/aspeed_timer.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
> index 29cc5e807081..217d59fa7885 100644
> --- a/hw/timer/aspeed_timer.c
> +++ b/hw/timer/aspeed_timer.c
> @@ -42,6 +42,13 @@ enum timer_ctrl_op {
> op_pulse_enable
> };
>
> +/*
> + * Minimum value of the reload register to filter out short period
> + * timers which have a noticeable impact in emulation. 5us should be
> + * enough, use 20us for "safety".
> + */
> +#define TIMER_MIN_NS (20 * SCALE_US)
> +
> /**
> * Avoid mutual references between AspeedTimerCtrlState and AspeedTimer
> * structs, as it's a waste of memory. The ptimer BH callback needs to know
> @@ -96,6 +103,14 @@ static inline uint32_t calculate_ticks(struct AspeedTimer *t, uint64_t now_ns)
> return t->reload - MIN(t->reload, ticks);
> }
>
> +static uint32_t calculate_min_ticks(AspeedTimer *t, uint32_t value)
> +{
> + uint32_t rate = calculate_rate(t);
> + uint32_t min_ticks = muldiv64(TIMER_MIN_NS, rate, NANOSECONDS_PER_SECOND);
> +
> + return value < min_ticks ? min_ticks : value;
> +}
> +
> static inline uint64_t calculate_time(struct AspeedTimer *t, uint32_t ticks)
> {
> uint64_t delta_ns;
> @@ -259,7 +274,7 @@ static void aspeed_timer_set_value(AspeedTimerCtrlState *s, int timer, int reg,
> switch (reg) {
> case TIMER_REG_RELOAD:
> old_reload = t->reload;
> - t->reload = value;
> + t->reload = calculate_min_ticks(t, value);
>
> /* If the reload value was not previously set, or zero, and
> * the current value is valid, try to start the timer if it is
>
next prev parent reply other threads:[~2019-07-04 9:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-04 5:51 [Qemu-devel] [PATCH for 4.1] aspeed/timer: Provide back-pressure information for short periods Cédric Le Goater
2019-07-04 6:27 ` no-reply
2019-07-04 9:26 ` Philippe Mathieu-Daudé [this message]
2019-07-04 10:13 ` Stefan Hajnoczi
2019-07-04 12:26 ` Paolo Bonzini
2019-07-16 6:54 ` Joel Stanley
2019-07-16 7:00 ` Joel Stanley
2019-07-16 7:02 ` Philippe Mathieu-Daudé
2019-08-21 3:16 ` Joel Stanley
2019-08-27 15:37 ` 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=cd1f8a48-27cb-5cc5-1fd2-46f1597a7094@redhat.com \
--to=philmd@redhat.com \
--cc=andrew@aj.id.au \
--cc=clg@kaod.org \
--cc=joel@jms.id.au \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).