diff mbox series

[v3,3/4] hw/clock: Expose 'qtest-clock-period' QOM property for QTests

Message ID 20240523194441.21036-4-ines.varhol@telecom-paris.fr (mailing list archive)
State New, archived
Headers show
Series Check clock connection between STM32L4x5 RCC and peripherals | expand

Commit Message

Inès Varhol May 23, 2024, 7:41 p.m. UTC
Expose the clock period via the QOM 'qtest-clock-period' property so it
can be used in QTests. This property is only accessible in QTests (not
via HMP).

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
---
 docs/devel/clocks.rst |  3 +++
 hw/core/clock.c       | 16 ++++++++++++++++
 2 files changed, 19 insertions(+)

Comments

Luc Michel May 27, 2024, 7:04 a.m. UTC | #1
On 21:41 Thu 23 May     , Inès Varhol wrote:
> Expose the clock period via the QOM 'qtest-clock-period' property so it
> can be used in QTests. This property is only accessible in QTests (not
> via HMP).
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
> ---
>  docs/devel/clocks.rst |  3 +++
>  hw/core/clock.c       | 16 ++++++++++++++++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst
> index 177ee1c90d..19e67601ec 100644
> --- a/docs/devel/clocks.rst
> +++ b/docs/devel/clocks.rst
> @@ -358,6 +358,9 @@ humans (for instance in debugging), use ``clock_display_freq()``,
>  which returns a prettified string-representation, e.g. "33.3 MHz".
>  The caller must free the string with g_free() after use.
>  
> +It's also possible to retrieve the clock period from a QTest by
> +accessing QOM property ``qtest-clock-period`` using a QMP command.
> +
>  Calculating expiry deadlines
>  ----------------------------
>  
> diff --git a/hw/core/clock.c b/hw/core/clock.c
> index e212865307..216b54b8df 100644
> --- a/hw/core/clock.c
> +++ b/hw/core/clock.c
> @@ -13,6 +13,8 @@
>  
>  #include "qemu/osdep.h"
>  #include "qemu/cutils.h"
> +#include "qapi/visitor.h"
> +#include "sysemu/qtest.h"
>  #include "hw/clock.h"
>  #include "trace.h"
>  
> @@ -158,6 +160,15 @@ bool clock_set_mul_div(Clock *clk, uint32_t multiplier, uint32_t divider)
>      return true;
>  }
>  
> +static void clock_period_prop_get(Object *obj, Visitor *v, const char *name,
> +                                void *opaque, Error **errp)
> +{
> +    Clock *clk = CLOCK(obj);
> +    uint64_t freq_hz = clock_get(clk);
> +    visit_type_uint64(v, name, &freq_hz, errp);
s/freq_hz/period

Otherwise:

Reviewed-by: Luc Michel <luc@lmichel.fr>

> +}
> +
> +
>  static void clock_initfn(Object *obj)
>  {
>      Clock *clk = CLOCK(obj);
> @@ -166,6 +177,11 @@ static void clock_initfn(Object *obj)
>      clk->divider = 1;
>  
>      QLIST_INIT(&clk->children);
> +
> +    if (qtest_enabled()) {
> +        object_property_add(obj, "qtest-clock-period", "uint64",
> +                            clock_period_prop_get, NULL, NULL, NULL);
> +    }
>  }
>  
>  static void clock_finalizefn(Object *obj)
> -- 
> 2.43.2
> 

--
Peter Maydell May 28, 2024, 2:51 p.m. UTC | #2
On Thu, 23 May 2024 at 20:44, Inès Varhol <ines.varhol@telecom-paris.fr> wrote:
>
> Expose the clock period via the QOM 'qtest-clock-period' property so it
> can be used in QTests. This property is only accessible in QTests (not
> via HMP).
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
> ---
>  docs/devel/clocks.rst |  3 +++
>  hw/core/clock.c       | 16 ++++++++++++++++
>  2 files changed, 19 insertions(+)
>
> diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst
> index 177ee1c90d..19e67601ec 100644
> --- a/docs/devel/clocks.rst
> +++ b/docs/devel/clocks.rst
> @@ -358,6 +358,9 @@ humans (for instance in debugging), use ``clock_display_freq()``,
>  which returns a prettified string-representation, e.g. "33.3 MHz".
>  The caller must free the string with g_free() after use.
>
> +It's also possible to retrieve the clock period from a QTest by
> +accessing QOM property ``qtest-clock-period`` using a QMP command.

We should add:

  This property is only present when the device is being run under
  the ``qtest`` accelerator; it is not available when QEMU is
  being run normally.

thanks
-- PMM
Philippe Mathieu-Daudé May 28, 2024, 3:17 p.m. UTC | #3
On 23/5/24 21:41, Inès Varhol wrote:
> Expose the clock period via the QOM 'qtest-clock-period' property so it
> can be used in QTests. This property is only accessible in QTests (not
> via HMP).
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Addressing Luc and Peter comments, you can replace that line by:

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Thanks!

> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
> ---
>   docs/devel/clocks.rst |  3 +++
>   hw/core/clock.c       | 16 ++++++++++++++++
>   2 files changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst
index 177ee1c90d..19e67601ec 100644
--- a/docs/devel/clocks.rst
+++ b/docs/devel/clocks.rst
@@ -358,6 +358,9 @@  humans (for instance in debugging), use ``clock_display_freq()``,
 which returns a prettified string-representation, e.g. "33.3 MHz".
 The caller must free the string with g_free() after use.
 
+It's also possible to retrieve the clock period from a QTest by
+accessing QOM property ``qtest-clock-period`` using a QMP command.
+
 Calculating expiry deadlines
 ----------------------------
 
diff --git a/hw/core/clock.c b/hw/core/clock.c
index e212865307..216b54b8df 100644
--- a/hw/core/clock.c
+++ b/hw/core/clock.c
@@ -13,6 +13,8 @@ 
 
 #include "qemu/osdep.h"
 #include "qemu/cutils.h"
+#include "qapi/visitor.h"
+#include "sysemu/qtest.h"
 #include "hw/clock.h"
 #include "trace.h"
 
@@ -158,6 +160,15 @@  bool clock_set_mul_div(Clock *clk, uint32_t multiplier, uint32_t divider)
     return true;
 }
 
+static void clock_period_prop_get(Object *obj, Visitor *v, const char *name,
+                                void *opaque, Error **errp)
+{
+    Clock *clk = CLOCK(obj);
+    uint64_t freq_hz = clock_get(clk);
+    visit_type_uint64(v, name, &freq_hz, errp);
+}
+
+
 static void clock_initfn(Object *obj)
 {
     Clock *clk = CLOCK(obj);
@@ -166,6 +177,11 @@  static void clock_initfn(Object *obj)
     clk->divider = 1;
 
     QLIST_INIT(&clk->children);
+
+    if (qtest_enabled()) {
+        object_property_add(obj, "qtest-clock-period", "uint64",
+                            clock_period_prop_get, NULL, NULL, NULL);
+    }
 }
 
 static void clock_finalizefn(Object *obj)