QEMU-Devel Archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Luc Michel" <luc@lmichel.fr>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Damien Hedde" <damien.hedde@dahe.fr>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Inès Varhol" <ines.varhol@telecom-paris.fr>
Subject: [PATCH] hw/clock: Expose 'freq-hz' QOM property
Date: Wed,  8 May 2024 16:13:33 +0200	[thread overview]
Message-ID: <20240508141333.44610-1-philmd@linaro.org> (raw)

Expose the clock frequency via the QOM 'freq-hz' property,
as it might be useful for QTests.

HMP example:

  $ qemu-system-mips -S -monitor stdio -M mipssim
  (qemu) qom-get /machine/cpu-refclk freq-hz
  12000000

Inspired-by: Inès Varhol <ines.varhol@telecom-paris.fr>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/core/clock.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/hw/core/clock.c b/hw/core/clock.c
index e212865307..55f86ef483 100644
--- a/hw/core/clock.c
+++ b/hw/core/clock.c
@@ -13,6 +13,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/cutils.h"
+#include "qapi/visitor.h"
 #include "hw/clock.h"
 #include "trace.h"
 
@@ -158,6 +159,14 @@ bool clock_set_mul_div(Clock *clk, uint32_t multiplier, uint32_t divider)
     return true;
 }
 
+static void clock_prop_freq_get(Object *obj, Visitor *v, const char *name,
+                                void *opaque, Error **errp)
+{
+    Clock *clk = CLOCK(obj);
+    uint64_t freq_hz = clock_get_hz(clk);
+    visit_type_uint64(v, name, &freq_hz, errp);
+}
+
 static void clock_initfn(Object *obj)
 {
     Clock *clk = CLOCK(obj);
@@ -166,6 +175,9 @@ static void clock_initfn(Object *obj)
     clk->divider = 1;
 
     QLIST_INIT(&clk->children);
+
+    object_property_add(obj, "freq-hz", "uint64",
+                        clock_prop_freq_get, NULL, NULL, NULL);
 }
 
 static void clock_finalizefn(Object *obj)
-- 
2.41.0



             reply	other threads:[~2024-05-08 14:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08 14:13 Philippe Mathieu-Daudé [this message]
2024-05-08 17:46 ` [PATCH] hw/clock: Expose 'freq-hz' QOM property Peter Maydell
2024-05-08 21:27   ` Philippe Mathieu-Daudé

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=20240508141333.44610-1-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=damien.hedde@dahe.fr \
    --cc=ines.varhol@telecom-paris.fr \
    --cc=luc@lmichel.fr \
    --cc=peter.maydell@linaro.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 read-only IMAP folder(s) and NNTP newsgroup(s).