From: Dmitry Osipenko <digetx@gmail.com>
To: QEMU Developers <qemu-devel@nongnu.org>, qemu-arm@nongnu.org
Cc: Peter Crosthwaite <crosthwaitepeter@gmail.com>,
Peter Maydell <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PATCH v17 03/14] hw/ptimer: Add "continuous trigger" policy
Date: Sun, 2 Oct 2016 18:53:35 +0300 [thread overview]
Message-ID: <632b23dd11055d9bd5e338d66b38fac0bd51462e.1475421224.git.digetx@gmail.com> (raw)
In-Reply-To: <cover.1475421224.git.digetx@gmail.com>
In-Reply-To: <cover.1475421224.git.digetx@gmail.com>
Currently, periodic timer that has load = delta = 0 performs trigger
on timer reload and stops, printing a "period zero" error message.
Introduce new policy that makes periodic timer to continuously trigger
with a period interval in case of load = 0.
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
hw/core/ptimer.c | 30 +++++++++++++++++++++++++++---
include/hw/ptimer.h | 4 ++++
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
index 1f4122d..1aa0194 100644
--- a/hw/core/ptimer.c
+++ b/hw/core/ptimer.c
@@ -47,7 +47,8 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
ptimer_trigger(s);
delta = s->delta = s->limit;
}
- if (delta == 0 || s->period == 0) {
+
+ if (s->period == 0) {
if (!qtest_enabled()) {
fprintf(stderr, "Timer with period zero, disabling\n");
}
@@ -60,6 +61,21 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
delta += delta_adjust;
}
+ if (delta == 0 && (s->policy_mask & PTIMER_POLICY_CONTINUOUS_TRIGGER)) {
+ if (s->enabled == 1 && s->limit == 0) {
+ delta = 1;
+ }
+ }
+
+ if (delta == 0) {
+ if (!qtest_enabled()) {
+ fprintf(stderr, "Timer with delta zero, disabling\n");
+ }
+ timer_del(s->timer);
+ s->enabled = 0;
+ return;
+ }
+
/*
* Artificially limit timeout rate to something
* achievable under QEMU. Otherwise, QEMU spends all
@@ -90,7 +106,15 @@ static void ptimer_tick(void *opaque)
if (s->enabled == 2) {
s->enabled = 0;
} else {
- ptimer_reload(s, DELTA_ADJUST);
+ int delta_adjust = DELTA_ADJUST;
+
+ if (s->limit == 0) {
+ /* If a "continuous trigger" policy is not used and limit == 0,
+ we should error out. */
+ delta_adjust = 0;
+ }
+
+ ptimer_reload(s, delta_adjust);
}
}
@@ -98,7 +122,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;
int64_t last = s->last_event;
diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h
index 03441cb..b2fb4f9 100644
--- a/include/hw/ptimer.h
+++ b/include/hw/ptimer.h
@@ -39,6 +39,10 @@
* around. */
#define PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD (1 << 0)
+/* Running periodic timer that has counter = limit = 0 would continuously
+ * re-trigger every period. */
+#define PTIMER_POLICY_CONTINUOUS_TRIGGER (1 << 1)
+
/* ptimer.c */
typedef struct ptimer_state ptimer_state;
typedef void (*ptimer_cb)(void *opaque);
--
2.9.3
next prev parent reply other threads:[~2016-10-02 16:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-02 15:53 [Qemu-devel] [PATCH v17 00/14] PTimer fixes/features and ARM MPTimer conversion Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 01/14] hw/ptimer: Add "wraparound after one period" policy Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 02/14] tests: ptimer: Add tests for " Dmitry Osipenko
2016-10-02 15:53 ` Dmitry Osipenko [this message]
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 04/14] tests: ptimer: Add tests for "continuous trigger" policy Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 05/14] hw/ptimer: Add "no immediate " Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 06/14] tests: ptimer: Add tests for " Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 07/14] hw/ptimer: Add "no immediate reload" policy Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 08/14] tests: ptimer: Add tests for " Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 09/14] hw/ptimer: Add "no counter round down" policy Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 10/14] tests: ptimer: Add tests for " Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 11/14] tests: ptimer: Change the copyright comment Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 12/14] tests: ptimer: Replace 10000 with 1 Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 13/14] arm_mptimer: Convert to use ptimer Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 14/14] tests: Add tests for the ARM MPTimer Dmitry Osipenko
2016-10-24 12:23 ` [Qemu-devel] [PATCH v17 00/14] PTimer fixes/features and ARM MPTimer conversion Peter Maydell
2016-10-24 18:19 ` Dmitry Osipenko
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=632b23dd11055d9bd5e338d66b38fac0bd51462e.1475421224.git.digetx@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 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).