All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/1] qemu_timer.c: add timer_deadline_ms() helper
@ 2021-03-01 12:41 Daniel Henrique Barboza
  2021-03-01 12:41 ` [PATCH v2 1/1] " Daniel Henrique Barboza
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Henrique Barboza @ 2021-03-01 12:41 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, groug, david

Changes from v1:
- Added Paolo's ACK
- Changed the helper to get the clock via timer->timer_list->clock->type
  instead of assuming QEMU_CLOCK_VIRTUAL, as suggested by Greg 
- v1 link: https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg08097.html

Daniel Henrique Barboza (1):
  qemu_timer.c: add timer_deadline_ms() helper

 hw/ppc/spapr_drc.c   |  5 ++---
 include/qemu/timer.h |  8 ++++++++
 util/qemu-timer.c    | 13 +++++++++++++
 3 files changed, 23 insertions(+), 3 deletions(-)

-- 
2.29.2



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/1] qemu_timer.c: add timer_deadline_ms() helper
  2021-03-01 12:41 [PATCH v2 0/1] qemu_timer.c: add timer_deadline_ms() helper Daniel Henrique Barboza
@ 2021-03-01 12:41 ` Daniel Henrique Barboza
  2021-03-01 13:31   ` Greg Kurz
  2021-03-02  2:13   ` David Gibson
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Henrique Barboza @ 2021-03-01 12:41 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Daniel Henrique Barboza, qemu-ppc, groug, david

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 <pbonzini@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 hw/ppc/spapr_drc.c   |  5 ++---
 include/qemu/timer.h |  8 ++++++++
 util/qemu-timer.c    | 13 +++++++++++++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
index 8c4997d795..98b626acf9 100644
--- a/hw/ppc/spapr_drc.c
+++ b/hw/ppc/spapr_drc.c
@@ -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;
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 1678238384..5e76e3f8c2 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -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
  */
diff --git a/util/qemu-timer.c b/util/qemu-timer.c
index 81c28af517..02424bc1b6 100644
--- a/util/qemu-timer.c
+++ b/util/qemu-timer.c
@@ -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
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] qemu_timer.c: add timer_deadline_ms() helper
  2021-03-01 12:41 ` [PATCH v2 1/1] " Daniel Henrique Barboza
@ 2021-03-01 13:31   ` Greg Kurz
  2021-03-02  2:13   ` David Gibson
  1 sibling, 0 replies; 4+ messages in thread
From: Greg Kurz @ 2021-03-01 13:31 UTC (permalink / raw)
  To: Daniel Henrique Barboza; +Cc: Paolo Bonzini, qemu-ppc, qemu-devel, david

On Mon,  1 Mar 2021 09:41:33 -0300
Daniel Henrique Barboza <danielhb413@gmail.com> wrote:

> 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 <pbonzini@redhat.com>
> Acked-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
> ---

Reviewed-by: Greg Kurz <groug@kaod.org>

>  hw/ppc/spapr_drc.c   |  5 ++---
>  include/qemu/timer.h |  8 ++++++++
>  util/qemu-timer.c    | 13 +++++++++++++
>  3 files changed, 23 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
> index 8c4997d795..98b626acf9 100644
> --- a/hw/ppc/spapr_drc.c
> +++ b/hw/ppc/spapr_drc.c
> @@ -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;
> diff --git a/include/qemu/timer.h b/include/qemu/timer.h
> index 1678238384..5e76e3f8c2 100644
> --- a/include/qemu/timer.h
> +++ b/include/qemu/timer.h
> @@ -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
>   */
> diff --git a/util/qemu-timer.c b/util/qemu-timer.c
> index 81c28af517..02424bc1b6 100644
> --- a/util/qemu-timer.c
> +++ b/util/qemu-timer.c
> @@ -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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] qemu_timer.c: add timer_deadline_ms() helper
  2021-03-01 12:41 ` [PATCH v2 1/1] " Daniel Henrique Barboza
  2021-03-01 13:31   ` Greg Kurz
@ 2021-03-02  2:13   ` David Gibson
  1 sibling, 0 replies; 4+ messages in thread
From: David Gibson @ 2021-03-02  2:13 UTC (permalink / raw)
  To: Daniel Henrique Barboza; +Cc: Paolo Bonzini, qemu-ppc, qemu-devel, groug

[-- Attachment #1: Type: text/plain, Size: 3021 bytes --]

On Mon, Mar 01, 2021 at 09:41:33AM -0300, Daniel Henrique Barboza wrote:
> 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 <pbonzini@redhat.com>
> Acked-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>

Applied to ppc-for-6.0, replacing the earlier version.

> ---
>  hw/ppc/spapr_drc.c   |  5 ++---
>  include/qemu/timer.h |  8 ++++++++
>  util/qemu-timer.c    | 13 +++++++++++++
>  3 files changed, 23 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
> index 8c4997d795..98b626acf9 100644
> --- a/hw/ppc/spapr_drc.c
> +++ b/hw/ppc/spapr_drc.c
> @@ -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;
> diff --git a/include/qemu/timer.h b/include/qemu/timer.h
> index 1678238384..5e76e3f8c2 100644
> --- a/include/qemu/timer.h
> +++ b/include/qemu/timer.h
> @@ -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
>   */
> diff --git a/util/qemu-timer.c b/util/qemu-timer.c
> index 81c28af517..02424bc1b6 100644
> --- a/util/qemu-timer.c
> +++ b/util/qemu-timer.c
> @@ -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

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-02  2:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-01 12:41 [PATCH v2 0/1] qemu_timer.c: add timer_deadline_ms() helper Daniel Henrique Barboza
2021-03-01 12:41 ` [PATCH v2 1/1] " Daniel Henrique Barboza
2021-03-01 13:31   ` Greg Kurz
2021-03-02  2:13   ` David Gibson

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.