From: Dmitry Osipenko <digetx@gmail.com>
To: QEMU Developers <qemu-devel@nongnu.org>, qemu-arm@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Peter Crosthwaite <crosthwaitepeter@gmail.com>
Subject: [Qemu-devel] [PATCH v17 05/14] hw/ptimer: Add "no immediate trigger" policy
Date: Sun, 2 Oct 2016 18:53:37 +0300 [thread overview]
Message-ID: <72c0319cf2ec599f22397b7da280c06c34dc40dd.1475421224.git.digetx@gmail.com> (raw)
In-Reply-To: <cover.1475421224.git.digetx@gmail.com>
In-Reply-To: <cover.1475421224.git.digetx@gmail.com>
Performing trigger on setting (or starting to run with) counter = 0 could
be a wrong behaviour for some of the timers, provide "no immediate trigger"
policy to maintain correct behaviour for such timers.
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
hw/core/ptimer.c | 20 ++++++++++++++++----
include/hw/ptimer.h | 4 ++++
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
index 1aa0194..ed3fb6c 100644
--- a/hw/core/ptimer.c
+++ b/hw/core/ptimer.c
@@ -13,7 +13,8 @@
#include "sysemu/replay.h"
#include "sysemu/qtest.h"
-#define DELTA_ADJUST 1
+#define DELTA_ADJUST 1
+#define DELTA_NO_ADJUST -1
struct ptimer_state
{
@@ -43,8 +44,11 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
uint64_t period = s->period;
uint64_t delta = s->delta;
- if (delta == 0) {
+ if (delta == 0 && !(s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER)) {
ptimer_trigger(s);
+ }
+
+ if (delta == 0) {
delta = s->delta = s->limit;
}
@@ -58,7 +62,9 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
}
if (s->policy_mask & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD) {
- delta += delta_adjust;
+ if (delta_adjust != DELTA_NO_ADJUST) {
+ delta += delta_adjust;
+ }
}
if (delta == 0 && (s->policy_mask & PTIMER_POLICY_CONTINUOUS_TRIGGER)) {
@@ -67,6 +73,12 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
}
}
+ if (delta == 0 && (s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER)) {
+ if (delta_adjust != DELTA_NO_ADJUST) {
+ delta = 1;
+ }
+ }
+
if (delta == 0) {
if (!qtest_enabled()) {
fprintf(stderr, "Timer with delta zero, disabling\n");
@@ -111,7 +123,7 @@ static void ptimer_tick(void *opaque)
if (s->limit == 0) {
/* If a "continuous trigger" policy is not used and limit == 0,
we should error out. */
- delta_adjust = 0;
+ delta_adjust = DELTA_NO_ADJUST;
}
ptimer_reload(s, delta_adjust);
diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h
index b2fb4f9..911cc11 100644
--- a/include/hw/ptimer.h
+++ b/include/hw/ptimer.h
@@ -43,6 +43,10 @@
* re-trigger every period. */
#define PTIMER_POLICY_CONTINUOUS_TRIGGER (1 << 1)
+/* Starting to run with/setting counter to "0" won't trigger immediately,
+ * but after a one period for both oneshot and periodic modes. */
+#define PTIMER_POLICY_NO_IMMEDIATE_TRIGGER (1 << 2)
+
/* 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:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-02 15:53 [Qemu-arm] [PATCH v17 00/14] PTimer fixes/features and ARM MPTimer conversion Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-arm] [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 ` [Qemu-devel] [PATCH v17 03/14] hw/ptimer: Add "continuous trigger" policy Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-devel] [PATCH v17 04/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 06/14] tests: ptimer: Add tests for "no immediate " Dmitry Osipenko
2016-10-02 15:53 ` [Qemu-arm] [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-arm] [PATCH v17 14/14] tests: Add tests for the ARM MPTimer Dmitry Osipenko
2016-10-24 12:23 ` [Qemu-arm] [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=72c0319cf2ec599f22397b7da280c06c34dc40dd.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).