From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Luc Michel" <luc.michel@greensocs.com>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: [PATCH v2 4/4] clock: Define and use new clock_display_freq()
Date: Tue, 15 Dec 2020 15:09:29 +0000 [thread overview]
Message-ID: <20201215150929.30311-5-peter.maydell@linaro.org> (raw)
In-Reply-To: <20201215150929.30311-1-peter.maydell@linaro.org>
It's common to want to print a human-readable indication of a clock's
frequency. Provide a utility function in the clock API to return a
string which is a displayable representation of the frequency,
and use it in qdev-monitor.c.
Before:
(qemu) info qtree
[...]
dev: xilinx,zynq_slcr, id ""
clock-in "ps_clk" freq_hz=3.333333e+07
mmio 00000000f8000000/0000000000001000
After:
dev: xilinx,zynq_slcr, id ""
clock-in "ps_clk" freq_hz=33.3 MHz
mmio 00000000f8000000/0000000000001000
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Luc Michel <luc@lmichel.fr>
---
This is based on Philippe's patch
"qdev-monitor: Display frequencies scaled to SI unit"
but I have abstracted out the "prettified string" into the clock API.
---
docs/devel/clocks.rst | 5 +++++
include/hw/clock.h | 12 ++++++++++++
hw/core/clock.c | 6 ++++++
softmmu/qdev-monitor.c | 6 +++---
4 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst
index 2d317ff32f2..2548d842322 100644
--- a/docs/devel/clocks.rst
+++ b/docs/devel/clocks.rst
@@ -267,6 +267,11 @@ Here is an example:
clock_get(dev->my_clk_input));
}
+If you are only interested in the frequency for displaying it to
+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.
+
Calculating expiry deadlines
----------------------------
diff --git a/include/hw/clock.h b/include/hw/clock.h
index 852c636961e..6382f346569 100644
--- a/include/hw/clock.h
+++ b/include/hw/clock.h
@@ -264,4 +264,16 @@ static inline bool clock_is_enabled(const Clock *clk)
return clock_get(clk) != 0;
}
+/**
+ * clock_display_freq: return human-readable representation of clock frequency
+ * @clk: clock
+ *
+ * Return a string which has a human-readable representation of the
+ * clock's frequency, e.g. "33.3 MHz". This is intended for debug
+ * and display purposes.
+ *
+ * The caller is responsible for freeing the string with g_free().
+ */
+char *clock_display_freq(Clock *clk);
+
#endif /* QEMU_HW_CLOCK_H */
diff --git a/hw/core/clock.c b/hw/core/clock.c
index 8c6af223e7c..76b5f468b6e 100644
--- a/hw/core/clock.c
+++ b/hw/core/clock.c
@@ -12,6 +12,7 @@
*/
#include "qemu/osdep.h"
+#include "qemu/cutils.h"
#include "hw/clock.h"
#include "trace.h"
@@ -111,6 +112,11 @@ static void clock_disconnect(Clock *clk)
QLIST_REMOVE(clk, sibling);
}
+char *clock_display_freq(Clock *clk)
+{
+ return freq_to_str(clock_get_hz(clk));
+}
+
static void clock_initfn(Object *obj)
{
Clock *clk = CLOCK(obj);
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index 832e2548424..fb6c94eaeaf 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -732,11 +732,11 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
}
}
QLIST_FOREACH(ncl, &dev->clocks, node) {
- qdev_printf("clock-%s%s \"%s\" freq_hz=%e\n",
+ g_autofree char *freq_str = clock_display_freq(ncl->clock);
+ qdev_printf("clock-%s%s \"%s\" freq_hz=%s\n",
ncl->output ? "out" : "in",
ncl->alias ? " (alias)" : "",
- ncl->name,
- CLOCK_PERIOD_TO_HZ(1.0 * clock_get(ncl->clock)));
+ ncl->name, freq_str);
}
class = object_get_class(OBJECT(dev));
do {
--
2.20.1
next prev parent reply other threads:[~2020-12-15 15:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-15 15:09 [PATCH v2 0/4] clock: Get rid of clock_get_ns() Peter Maydell
2020-12-15 15:09 ` [PATCH v2 1/4] clock: Introduce clock_ticks_to_ns() Peter Maydell
2020-12-15 15:21 ` Richard Henderson
2020-12-15 19:48 ` Luc Michel
2020-12-15 15:09 ` [PATCH v2 2/4] target/mips: Don't use clock_get_ns() in clock period calculation Peter Maydell
2020-12-15 15:09 ` [PATCH v2 3/4] clock: Remove clock_get_ns() Peter Maydell
2020-12-15 15:09 ` Peter Maydell [this message]
2020-12-15 15:29 ` [PATCH v2 0/4] clock: Get rid of clock_get_ns() Philippe Mathieu-Daudé
2020-12-15 23:08 ` Philippe Mathieu-Daudé
2021-01-01 20:35 ` Philippe Mathieu-Daudé
2021-01-03 13:47 ` 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=20201215150929.30311-5-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=aleksandar.rikalo@syrmia.com \
--cc=f4bug@amsat.org \
--cc=jiaxun.yang@flygoat.com \
--cc=luc.michel@greensocs.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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 NNTP newsgroup(s).