From: Dmitry Osipenko <digetx@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Peter Crosthwaite <crosthwaitepeter@gmail.com>,
qemu-arm <qemu-arm@nongnu.org>,
QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-arm] [PATCH v16 05/16] hw/ptimer: Add "wraparound after one period" policy
Date: Tue, 20 Sep 2016 23:57:33 +0300 [thread overview]
Message-ID: <f89e38b1-1e8b-d7ea-4618-57bed00a2936@gmail.com> (raw)
In-Reply-To: <CAFEAcA_4xVH0PzytZpvyCTCgxm2TORg20C=UKHVApeVdkMvneA@mail.gmail.com>
On 20.09.2016 20:20, Peter Maydell wrote:
> On 7 September 2016 at 14:22, Dmitry Osipenko <digetx@gmail.com> wrote:
>> Currently, periodic counter wraps around immediately once counter reaches
>> "0", this is wrong behaviour for some of the timers, resulting in one period
>> being lost. Add new ptimer policy that provides correct behaviour for such
>> timers, so that counter stays with "0" for a one period before wrapping
>> around.
>
> This says it's just adding a new policy...
>
>> @@ -91,7 +96,7 @@ uint64_t ptimer_get_count(ptimer_state *s)
>> {
>> uint64_t counter;
>>
>> - if (s->enabled) {
>> + if (s->enabled && s->delta != 0) {
>> int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>> int64_t next = s->next_event;
>> bool expired = (now - next >= 0);
>> @@ -145,6 +150,14 @@ uint64_t ptimer_get_count(ptimer_state *s)
>> div += 1;
>> }
>> counter = rem / div;
>> +
>> + if (!oneshot && s->delta == s->limit) {
>> + /* Before wrapping around, timer should stay with counter = 0
>> + for a one period. The delta has been adjusted by +1 for
>> + the wrapped around counter, so taking a modulo of limit + 1
>> + gives that period. */
>> + counter %= s->limit + 1;
>> + }
>> }
>> } else {
>> counter = s->delta;
>
> ...but the changes in this function look like they affect
> behaviour even if that policy flag isn't set.
>
No, the delta value is adjusted only when PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD is
set.
+ if (s->policy_mask & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD) {
+ delta += delta_adjust;
+ }
+
That adjustment is applied only on reload of the periodic timer.
@@ -83,7 +88,7 @@ static void ptimer_tick(void *opaque)
if (s->enabled == 2) {
s->enabled = 0;
} else {
- ptimer_reload(s);
+ ptimer_reload(s, 1);
}
}
All other ptimer_reload's are ptimer_reload(s, 0).
The periodic timer is reloaded with the limit value. When s->delta == s->limit,
we can assume that timer is free running. When delta is adjusted by +1 on
reload, the counter = limit + 1 (counter value is calculated based on elapsed
QEMU time) and that "counter %= s->limit + 1" modulo gives counter = 0 while in
fact the counter = adjusted delta (limit + 1).
When delta is *not* adjusted, the modulo returns the actual counter value, since
counter value is always less than s->limit + 1.
So, this patch doesn't affect old behaviour at all.
Looking more at it now, I think "counter %= s->limit + 1" should be changed to
"counter %= s->limit" in this patch and +1 added in the "no counter round down"
patch, since the counter value is always rounded down here. Instead of the
"staying with counter = 0 for a one period" it would wraparound to the limit
value if "wraparound after one period" policy is used. I'll change it in V17.
--
Dmitry
WARNING: multiple messages have this Message-ID (diff)
From: Dmitry Osipenko <digetx@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
qemu-arm <qemu-arm@nongnu.org>,
Peter Crosthwaite <crosthwaitepeter@gmail.com>
Subject: Re: [Qemu-devel] [PATCH v16 05/16] hw/ptimer: Add "wraparound after one period" policy
Date: Tue, 20 Sep 2016 23:57:33 +0300 [thread overview]
Message-ID: <f89e38b1-1e8b-d7ea-4618-57bed00a2936@gmail.com> (raw)
In-Reply-To: <CAFEAcA_4xVH0PzytZpvyCTCgxm2TORg20C=UKHVApeVdkMvneA@mail.gmail.com>
On 20.09.2016 20:20, Peter Maydell wrote:
> On 7 September 2016 at 14:22, Dmitry Osipenko <digetx@gmail.com> wrote:
>> Currently, periodic counter wraps around immediately once counter reaches
>> "0", this is wrong behaviour for some of the timers, resulting in one period
>> being lost. Add new ptimer policy that provides correct behaviour for such
>> timers, so that counter stays with "0" for a one period before wrapping
>> around.
>
> This says it's just adding a new policy...
>
>> @@ -91,7 +96,7 @@ uint64_t ptimer_get_count(ptimer_state *s)
>> {
>> uint64_t counter;
>>
>> - if (s->enabled) {
>> + if (s->enabled && s->delta != 0) {
>> int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>> int64_t next = s->next_event;
>> bool expired = (now - next >= 0);
>> @@ -145,6 +150,14 @@ uint64_t ptimer_get_count(ptimer_state *s)
>> div += 1;
>> }
>> counter = rem / div;
>> +
>> + if (!oneshot && s->delta == s->limit) {
>> + /* Before wrapping around, timer should stay with counter = 0
>> + for a one period. The delta has been adjusted by +1 for
>> + the wrapped around counter, so taking a modulo of limit + 1
>> + gives that period. */
>> + counter %= s->limit + 1;
>> + }
>> }
>> } else {
>> counter = s->delta;
>
> ...but the changes in this function look like they affect
> behaviour even if that policy flag isn't set.
>
No, the delta value is adjusted only when PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD is
set.
+ if (s->policy_mask & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD) {
+ delta += delta_adjust;
+ }
+
That adjustment is applied only on reload of the periodic timer.
@@ -83,7 +88,7 @@ static void ptimer_tick(void *opaque)
if (s->enabled == 2) {
s->enabled = 0;
} else {
- ptimer_reload(s);
+ ptimer_reload(s, 1);
}
}
All other ptimer_reload's are ptimer_reload(s, 0).
The periodic timer is reloaded with the limit value. When s->delta == s->limit,
we can assume that timer is free running. When delta is adjusted by +1 on
reload, the counter = limit + 1 (counter value is calculated based on elapsed
QEMU time) and that "counter %= s->limit + 1" modulo gives counter = 0 while in
fact the counter = adjusted delta (limit + 1).
When delta is *not* adjusted, the modulo returns the actual counter value, since
counter value is always less than s->limit + 1.
So, this patch doesn't affect old behaviour at all.
Looking more at it now, I think "counter %= s->limit + 1" should be changed to
"counter %= s->limit" in this patch and +1 added in the "no counter round down"
patch, since the counter value is always rounded down here. Instead of the
"staying with counter = 0 for a one period" it would wraparound to the limit
value if "wraparound after one period" policy is used. I'll change it in V17.
--
Dmitry
next prev parent reply other threads:[~2016-09-20 21:19 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-07 13:22 [Qemu-devel] [PATCH v16 00/16] PTimer fixes/features and ARM MPTimer conversion Dmitry Osipenko
2016-09-07 13:22 ` Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-arm] [PATCH v16 01/16] hw/ptimer: Actually stop the timer in case of error Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] " Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-arm] [PATCH v16 02/16] hw/ptimer: Introduce timer policy feature Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] " Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] [PATCH v16 03/16] tests: Add ptimer tests Dmitry Osipenko
2016-09-07 13:22 ` Dmitry Osipenko
2016-09-07 21:32 ` [Qemu-arm] " Eric Blake
2016-09-07 21:32 ` Eric Blake
2016-09-07 22:32 ` [Qemu-arm] " Dmitry Osipenko
2016-09-07 22:32 ` Dmitry Osipenko
2016-09-07 23:04 ` [Qemu-arm] " Peter Maydell
2016-09-07 23:04 ` Peter Maydell
2016-09-07 23:25 ` [Qemu-arm] " Dmitry Osipenko
2016-09-07 23:25 ` Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] [PATCH v16 04/16] hw/ptimer: Suppress error messages under qtest Dmitry Osipenko
2016-09-07 13:22 ` Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] [PATCH v16 05/16] hw/ptimer: Add "wraparound after one period" policy Dmitry Osipenko
2016-09-07 13:22 ` Dmitry Osipenko
2016-09-20 17:20 ` [Qemu-arm] " Peter Maydell
2016-09-20 17:20 ` [Qemu-devel] " Peter Maydell
2016-09-20 20:57 ` Dmitry Osipenko [this message]
2016-09-20 20:57 ` Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] [PATCH v16 06/16] tests: ptimer: Add tests for " Dmitry Osipenko
2016-09-07 13:22 ` Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-arm] [PATCH v16 07/16] hw/ptimer: Add "continuous trigger" policy Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] " Dmitry Osipenko
2016-09-20 17:21 ` [Qemu-arm] " Peter Maydell
2016-09-20 17:21 ` [Qemu-devel] " Peter Maydell
2016-09-20 21:06 ` [Qemu-arm] " Dmitry Osipenko
2016-09-20 21:06 ` [Qemu-devel] " Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-arm] [PATCH v16 08/16] tests: ptimer: Add tests for " Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] " Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] [PATCH v16 09/16] hw/ptimer: Add "no immediate " Dmitry Osipenko
2016-09-07 13:22 ` Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] [PATCH v16 10/16] tests: ptimer: Add tests for " Dmitry Osipenko
2016-09-07 13:22 ` Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] [PATCH v16 11/16] hw/ptimer: Add "no immediate reload" policy Dmitry Osipenko
2016-09-07 13:22 ` Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-arm] [PATCH v16 12/16] tests: ptimer: Add tests for " Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] " Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] [PATCH v16 13/16] hw/ptimer: Add "no counter round down" policy Dmitry Osipenko
2016-09-07 13:22 ` Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] [PATCH v16 14/16] tests: ptimer: Add tests for " Dmitry Osipenko
2016-09-07 13:22 ` Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] [PATCH v16 15/16] arm_mptimer: Convert to use ptimer Dmitry Osipenko
2016-09-07 13:22 ` Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-arm] [PATCH v16 16/16] tests: Add tests for the ARM MPTimer Dmitry Osipenko
2016-09-07 13:22 ` [Qemu-devel] " Dmitry Osipenko
2016-09-20 17:25 ` [Qemu-devel] [PATCH v16 00/16] PTimer fixes/features and ARM MPTimer conversion Peter Maydell
2016-09-20 17:25 ` 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=f89e38b1-1e8b-d7ea-4618-57bed00a2936@gmail.com \
--to=digetx@gmail.com \
--cc=crosthwaitepeter@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.