]> Git Repo - qemu.git/commitdiff
qemu_timer.c: add timer_deadline_ms() helper
authorDaniel Henrique Barboza <[email protected]>
Mon, 1 Mar 2021 12:41:33 +0000 (09:41 -0300)
committerDavid Gibson <[email protected]>
Tue, 9 Mar 2021 22:07:09 +0000 (09:07 +1100)
The pSeries machine is using QEMUTimer internals to return the timeout
in seconds for a timer object, in hw/ppc/spapr.c, function
spapr_drc_unplug_timeout_remaining_sec().

Create a helper in qemu-timer.c to retrieve the deadline for a QEMUTimer
object, in ms, to avoid exposing timer internals to the PPC code.

CC: Paolo Bonzini <[email protected]>
Acked-by: Paolo Bonzini <[email protected]>
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Message-Id: <20210301124133[email protected]>
Reviewed-by: Greg Kurz <[email protected]>
Signed-off-by: David Gibson <[email protected]>
hw/ppc/spapr_drc.c
include/qemu/timer.h
util/qemu-timer.c

index 8c4997d7957128abc2feb4cda6662cee972dd7ab..98b626acf92a40682c6be36d0debd57479e44547 100644 (file)
@@ -421,9 +421,8 @@ void spapr_drc_unplug_request(SpaprDrc *drc)
 
 int spapr_drc_unplug_timeout_remaining_sec(SpaprDrc *drc)
 {
-    if (drc->unplug_requested && timer_pending(drc->unplug_timeout_timer)) {
-        return (qemu_timeout_ns_to_ms(drc->unplug_timeout_timer->expire_time) -
-                qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL)) / 1000;
+    if (drc->unplug_requested) {
+        return timer_deadline_ms(drc->unplug_timeout_timer) / 1000;
     }
 
     return 0;
index 1678238384fca4fcef6e3ddc4636436e55165e34..5e76e3f8c2286d8b00c52615d91f9f3ab88e152f 100644 (file)
@@ -795,6 +795,14 @@ static inline int64_t get_max_clock_jump(void)
     return 60 * NANOSECONDS_PER_SECOND;
 }
 
+/**
+ * timer_deadline_ms:
+ *
+ * Returns the remaining miliseconds for @timer to expire, or zero
+ * if the timer is no longer pending.
+ */
+int64_t timer_deadline_ms(QEMUTimer *timer);
+
 /*
  * Low level clock functions
  */
index 81c28af517e2a0aa399d854eb97d9f411138b5f4..02424bc1b67b0debed32fd723f497ab071d3ae38 100644 (file)
@@ -243,6 +243,19 @@ int64_t timerlist_deadline_ns(QEMUTimerList *timer_list)
     return delta;
 }
 
+/*
+ * Returns the time remaining for the deadline, in ms.
+ */
+int64_t timer_deadline_ms(QEMUTimer *timer)
+{
+    if (timer_pending(timer)) {
+        return qemu_timeout_ns_to_ms(timer->expire_time) -
+               qemu_clock_get_ms(timer->timer_list->clock->type);
+    }
+
+    return 0;
+}
+
 /* Calculate the soonest deadline across all timerlists attached
  * to the clock. This is used for the icount timeout so we
  * ignore whether or not the clock should be used in deadline
This page took 0.025399 seconds and 4 git commands to generate.