qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: boost.lists@gmail.com, victor.clement@openwide.fr,
	pavel.dovgaluk@ispras.ru, pbonzini@redhat.com,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Richard Henderson" <rth@twiddle.net>
Subject: [PATCH  v1 1/2] qemu-timer: gracefully handle the end of time
Date: Tue, 28 Jul 2020 15:10:04 +0100	[thread overview]
Message-ID: <20200728141005.28664-2-alex.bennee@linaro.org> (raw)
In-Reply-To: <20200728141005.28664-1-alex.bennee@linaro.org>

The previous behaviour was rather user hostile as timers set for
INT64_MAX would continually re-arm leaving the system locked in a loop
and the console unavailable. With this patch we detect the situation
and gracefully suspend the machine.

NB: we need a proper fix before the 23rd century.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 include/sysemu/cpus.h |  2 ++
 softmmu/cpus.c        | 13 +++++++++++++
 util/qemu-timer.c     | 16 ++++++++++++++++
 stubs/Makefile.objs   |  1 +
 4 files changed, 32 insertions(+)

diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h
index 3c1da6a0183..7da3a5b60b5 100644
--- a/include/sysemu/cpus.h
+++ b/include/sysemu/cpus.h
@@ -15,6 +15,8 @@ void configure_icount(QemuOpts *opts, Error **errp);
 extern int use_icount;
 extern int icount_align_option;
 
+void qemu_handle_outa_time(void);
+
 /* drift information for info jit command */
 extern int64_t max_delay;
 extern int64_t max_advance;
diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index a802e899abb..46b6f346370 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -657,6 +657,19 @@ static bool shift_state_needed(void *opaque)
     return use_icount == 2;
 }
 
+/* Handler for reaching the end of time */
+void qemu_handle_outa_time(void)
+{
+    static bool reported = false;
+    if (runstate_is_running()) {
+        if (!reported) {
+            error_report("ran out of time, suspending emulation");
+            reported = true;
+        }
+        vm_stop(RUN_STATE_PAUSED);
+    }
+}
+
 /*
  * Subsection for warp timer migration is optional, because may not be created
  */
diff --git a/util/qemu-timer.c b/util/qemu-timer.c
index f62b4feecdb..06f6818eb3d 100644
--- a/util/qemu-timer.c
+++ b/util/qemu-timer.c
@@ -540,6 +540,22 @@ bool timerlist_run_timers(QEMUTimerList *timer_list)
      * done".
      */
     current_time = qemu_clock_get_ns(timer_list->clock->type);
+
+    /*
+     * Check to see if we have run out of time. Most of our time
+     * sources are nanoseconds since epoch (some time around the fall
+     * of Babylon 5, the start of the Enterprises five year mission
+     * and just before the arrival of the great evil ~ 2262CE).
+     * Although icount based time is ns since the start of emulation
+     * it is able to skip forward if the device is sleeping (think IoT
+     * device with a very long heartbeat). Either way we don't really
+     * handle running out of time so lets catch it and report it here.
+     */
+    if (current_time == INT64_MAX) {
+        qemu_handle_outa_time();
+        goto out;
+    }
+
     qemu_mutex_lock(&timer_list->active_timers_lock);
     while ((ts = timer_list->active_timers)) {
         if (!timer_expired_ns(ts, current_time)) {
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index d42046afe4e..d363d8b551b 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -1,5 +1,6 @@
 stub-obj-y += blk-commit-all.o
 stub-obj-y += cmos.o
+stub-obj-y += cpus.o
 stub-obj-y += cpu-get-clock.o
 stub-obj-y += cpu-get-icount.o
 stub-obj-y += dump.o
-- 
2.20.1



  reply	other threads:[~2020-07-28 14:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28 14:10 [PATCH v1 0/2] clean-ups for sleep=off behaviour Alex Bennée
2020-07-28 14:10 ` Alex Bennée [this message]
2020-07-28 14:42   ` [PATCH v1 1/2] qemu-timer: gracefully handle the end of time Paolo Bonzini
2020-07-28 16:08     ` Alex Bennée
2020-07-28 16:58       ` Paolo Bonzini
2020-07-28 14:10 ` [PATCH v1 2/2] target/arm: only set the nexttick timer if !ISTATUS Alex Bennée
2020-07-28 14:16   ` Peter Maydell
2020-07-28 16:11     ` Alex Bennée
2020-07-28 16:23       ` 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=20200728141005.28664-2-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=boost.lists@gmail.com \
    --cc=pavel.dovgaluk@ispras.ru \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=victor.clement@openwide.fr \
    /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).