All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] qdev-clock: Minor improvements to the Clock API
@ 2020-09-27  9:08 Philippe Mathieu-Daudé
  2020-09-27  9:08 ` [PATCH 1/3] util/cutils: Introduce freq_to_str() to display Hertz units Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-27  9:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: Damien Hedde, Edgar E . Iglesias, Luc Michel, Eduardo Habkost,
	Peter Maydell, Havard Skinnemoen, Philippe Mathieu-Daudé,
	Tyrone Ting, Alistair Francis

Handy patches while using the Clock API:
- display frequency in SI scaled unit
- display error hint when device lack clock support

Philippe Mathieu-Daudé (3):
  util/cutils: Introduce freq_to_str() to display Hertz units
  qdev-monitor: Display frequencies scaled to SI unit
  hw/qdev-clock: Display error hint when clock is missing from device

 include/qemu/cutils.h | 12 ++++++++++++
 hw/core/qdev-clock.c  | 11 +++++++++++
 qdev-monitor.c        |  8 +++++---
 util/cutils.c         | 10 ++++++++++
 4 files changed, 38 insertions(+), 3 deletions(-)

-- 
2.26.2



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

* [PATCH 1/3] util/cutils: Introduce freq_to_str() to display Hertz units
  2020-09-27  9:08 [PATCH 0/3] qdev-clock: Minor improvements to the Clock API Philippe Mathieu-Daudé
@ 2020-09-27  9:08 ` Philippe Mathieu-Daudé
  2020-09-28  7:50   ` Luc Michel
  2020-09-27  9:08 ` [PATCH 2/3] qdev-monitor: Display frequencies scaled to SI unit Philippe Mathieu-Daudé
  2020-09-27  9:08 ` [PATCH 3/3] hw/qdev-clock: Display error hint when clock is missing from device Philippe Mathieu-Daudé
  2 siblings, 1 reply; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-27  9:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: Damien Hedde, Edgar E . Iglesias, Luc Michel, Eduardo Habkost,
	Peter Maydell, Havard Skinnemoen, Philippe Mathieu-Daudé,
	Tyrone Ting, Alistair Francis

Introduce freq_to_str() to convert frequency values in human
friendly units using the SI units for Hertz.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/qemu/cutils.h | 12 ++++++++++++
 util/cutils.c         | 10 ++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index eb59852dfdf..0186c846e9c 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -158,6 +158,18 @@ int qemu_strtosz_metric(const char *nptr, const char **end, uint64_t *result);
 
 char *size_to_str(uint64_t val);
 
+/**
+ * freq_to_str:
+ * @freq_hz: frequency to stringify
+ *
+ * Return human readable string for frequency @freq_hz.
+ * Use SI units like KHz, MHz, and so forth.
+ *
+ * The caller is responsible for releasing the value returned with g_free()
+ * after use.
+ */
+char *freq_to_str(uint64_t freq_hz);
+
 /* used to print char* safely */
 #define STR_OR_NULL(str) ((str) ? (str) : "null")
 
diff --git a/util/cutils.c b/util/cutils.c
index 36ce712271f..dab837fd8b8 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -885,6 +885,16 @@ char *size_to_str(uint64_t val)
     return g_strdup_printf("%0.3g %sB", (double)val / div, suffixes[i]);
 }
 
+char *freq_to_str(uint64_t freq_hz)
+{
+    static const char *suffixes[] = { "", "K", "M", "G", "T", "P", "E" };
+    unsigned unit_index = log10(freq_hz) / 3;
+
+    return g_strdup_printf("%0.3g %sHz",
+                           freq_hz / pow(10.0, unit_index * 3.0),
+                           suffixes[unit_index]);
+}
+
 int qemu_pstrcmp0(const char **str1, const char **str2)
 {
     return g_strcmp0(*str1, *str2);
-- 
2.26.2



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

* [PATCH 2/3] qdev-monitor: Display frequencies scaled to SI unit
  2020-09-27  9:08 [PATCH 0/3] qdev-clock: Minor improvements to the Clock API Philippe Mathieu-Daudé
  2020-09-27  9:08 ` [PATCH 1/3] util/cutils: Introduce freq_to_str() to display Hertz units Philippe Mathieu-Daudé
@ 2020-09-27  9:08 ` Philippe Mathieu-Daudé
  2020-09-28  7:52   ` Luc Michel
  2020-09-27  9:08 ` [PATCH 3/3] hw/qdev-clock: Display error hint when clock is missing from device Philippe Mathieu-Daudé
  2 siblings, 1 reply; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-27  9:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: Damien Hedde, Edgar E . Iglesias, Luc Michel, Eduardo Habkost,
	Peter Maydell, Havard Skinnemoen, Philippe Mathieu-Daudé,
	Tyrone Ting, Alistair Francis, Daniel P. Berrangé,
	Paolo Bonzini

Since commit 9f2ff99c7f2 ("qdev-monitor: print the device's clock
with info qtree") we can display the clock frequencies in the
monitor. Use the recently introduced freq_to_str() to display
the frequencies using the closest SI unit (human friendlier).

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: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 qdev-monitor.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index e9b7228480d..a0301cfca81 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -747,11 +747,13 @@ 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 = NULL;
+
+        freq = freq_to_str(clock_get_hz(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);
     }
     class = object_get_class(OBJECT(dev));
     do {
-- 
2.26.2



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

* [PATCH 3/3] hw/qdev-clock: Display error hint when clock is missing from device
  2020-09-27  9:08 [PATCH 0/3] qdev-clock: Minor improvements to the Clock API Philippe Mathieu-Daudé
  2020-09-27  9:08 ` [PATCH 1/3] util/cutils: Introduce freq_to_str() to display Hertz units Philippe Mathieu-Daudé
  2020-09-27  9:08 ` [PATCH 2/3] qdev-monitor: Display frequencies scaled to SI unit Philippe Mathieu-Daudé
@ 2020-09-27  9:08 ` Philippe Mathieu-Daudé
  2020-09-28  7:53   ` Luc Michel
  2 siblings, 1 reply; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-27  9:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: Damien Hedde, Edgar E . Iglesias, Luc Michel, Eduardo Habkost,
	Peter Maydell, Havard Skinnemoen, Philippe Mathieu-Daudé,
	Tyrone Ting, Alistair Francis, Daniel P. Berrangé,
	Paolo Bonzini

Instead of directly aborting, display a hint to help the developer
figure out the problem (likely trying to connect a clock to a device
pre-dating the Clock API, thus not expecting clocks).

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/core/qdev-clock.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c
index 47ecb5b4fae..33bd4a9d520 100644
--- a/hw/core/qdev-clock.c
+++ b/hw/core/qdev-clock.c
@@ -12,6 +12,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/error-report.h"
 #include "hw/qdev-clock.h"
 #include "hw/qdev-core.h"
 #include "qapi/error.h"
@@ -153,6 +154,11 @@ Clock *qdev_get_clock_in(DeviceState *dev, const char *name)
     assert(name);
 
     ncl = qdev_get_clocklist(dev, name);
+    if (!ncl) {
+        error_report("can not find clock-in '%s' for device type '%s'",
+                     name, object_get_typename(OBJECT(dev)));
+        abort();
+    }
     assert(!ncl->output);
 
     return ncl->clock;
@@ -165,6 +171,11 @@ Clock *qdev_get_clock_out(DeviceState *dev, const char *name)
     assert(name);
 
     ncl = qdev_get_clocklist(dev, name);
+    if (!ncl) {
+        error_report("can not find clock-out '%s' for device type '%s'",
+                     name, object_get_typename(OBJECT(dev)));
+        abort();
+    }
     assert(ncl->output);
 
     return ncl->clock;
-- 
2.26.2



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

* Re: [PATCH 1/3] util/cutils: Introduce freq_to_str() to display Hertz units
  2020-09-27  9:08 ` [PATCH 1/3] util/cutils: Introduce freq_to_str() to display Hertz units Philippe Mathieu-Daudé
@ 2020-09-28  7:50   ` Luc Michel
  2020-09-28 13:04     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 11+ messages in thread
From: Luc Michel @ 2020-09-28  7:50 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Damien Hedde, Edgar E . Iglesias, Eduardo Habkost, Peter Maydell,
	qemu-devel, Havard Skinnemoen, Tyrone Ting, Alistair Francis

Hi Philippe,

On 11:08 Sun 27 Sep     , Philippe Mathieu-Daudé wrote:
> Introduce freq_to_str() to convert frequency values in human
> friendly units using the SI units for Hertz.
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  include/qemu/cutils.h | 12 ++++++++++++
>  util/cutils.c         | 10 ++++++++++
>  2 files changed, 22 insertions(+)
> 
> diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
> index eb59852dfdf..0186c846e9c 100644
> --- a/include/qemu/cutils.h
> +++ b/include/qemu/cutils.h
> @@ -158,6 +158,18 @@ int qemu_strtosz_metric(const char *nptr, const char **end, uint64_t *result);
>  
>  char *size_to_str(uint64_t val);
>  
> +/**
> + * freq_to_str:
> + * @freq_hz: frequency to stringify
> + *
> + * Return human readable string for frequency @freq_hz.
> + * Use SI units like KHz, MHz, and so forth.
> + *
> + * The caller is responsible for releasing the value returned with g_free()
> + * after use.
> + */
> +char *freq_to_str(uint64_t freq_hz);
> +
>  /* used to print char* safely */
>  #define STR_OR_NULL(str) ((str) ? (str) : "null")
>  
> diff --git a/util/cutils.c b/util/cutils.c
> index 36ce712271f..dab837fd8b8 100644
> --- a/util/cutils.c
> +++ b/util/cutils.c
> @@ -885,6 +885,16 @@ char *size_to_str(uint64_t val)
>      return g_strdup_printf("%0.3g %sB", (double)val / div, suffixes[i]);
>  }
>  
> +char *freq_to_str(uint64_t freq_hz)
> +{
> +    static const char *suffixes[] = { "", "K", "M", "G", "T", "P", "E" };
> +    unsigned unit_index = log10(freq_hz) / 3;
> +
> +    return g_strdup_printf("%0.3g %sHz",
> +                           freq_hz / pow(10.0, unit_index * 3.0),
> +                           suffixes[unit_index]);

You could end up going out of your 'suffixes' array if freq_hz is very
high. Also, to avoid the complexity of log10/pow, maybe something like:

    double freq = freq_hz;
    size_t idx = 0;

    while (freq >= 1000.0 && idx < ARRAY_LENGTH(suffixes)) {
        freq /= 1000.0;
        idx++;
    }

    return g_strdup_printf("%0.3g %sHz", freq, suffixes[idx]);

is enough?

-- 
Luc

> +}
> +
>  int qemu_pstrcmp0(const char **str1, const char **str2)
>  {
>      return g_strcmp0(*str1, *str2);
> -- 
> 2.26.2
> 


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

* Re: [PATCH 2/3] qdev-monitor: Display frequencies scaled to SI unit
  2020-09-27  9:08 ` [PATCH 2/3] qdev-monitor: Display frequencies scaled to SI unit Philippe Mathieu-Daudé
@ 2020-09-28  7:52   ` Luc Michel
  2020-09-28  8:45     ` Damien Hedde
  0 siblings, 1 reply; 11+ messages in thread
From: Luc Michel @ 2020-09-28  7:52 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Damien Hedde, Edgar E . Iglesias, Daniel P. Berrangé,
	Eduardo Habkost, Peter Maydell, qemu-devel, Havard Skinnemoen,
	Tyrone Ting, Alistair Francis, Paolo Bonzini

On 11:08 Sun 27 Sep     , Philippe Mathieu-Daudé wrote:
> Since commit 9f2ff99c7f2 ("qdev-monitor: print the device's clock
> with info qtree") we can display the clock frequencies in the
> monitor. Use the recently introduced freq_to_str() to display
> the frequencies using the closest SI unit (human friendlier).
> 
> 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: Philippe Mathieu-Daudé <f4bug@amsat.org>

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

> ---
>  qdev-monitor.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/qdev-monitor.c b/qdev-monitor.c
> index e9b7228480d..a0301cfca81 100644
> --- a/qdev-monitor.c
> +++ b/qdev-monitor.c
> @@ -747,11 +747,13 @@ 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 = NULL;
> +
> +        freq = freq_to_str(clock_get_hz(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);
>      }
>      class = object_get_class(OBJECT(dev));
>      do {
> -- 
> 2.26.2
> 


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

* Re: [PATCH 3/3] hw/qdev-clock: Display error hint when clock is missing from device
  2020-09-27  9:08 ` [PATCH 3/3] hw/qdev-clock: Display error hint when clock is missing from device Philippe Mathieu-Daudé
@ 2020-09-28  7:53   ` Luc Michel
  2020-09-28 10:45     ` Damien Hedde
  0 siblings, 1 reply; 11+ messages in thread
From: Luc Michel @ 2020-09-28  7:53 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Damien Hedde, Edgar E . Iglesias, Daniel P. Berrangé,
	Eduardo Habkost, Peter Maydell, qemu-devel, Havard Skinnemoen,
	Tyrone Ting, Alistair Francis, Paolo Bonzini

On 11:08 Sun 27 Sep     , Philippe Mathieu-Daudé wrote:
> Instead of directly aborting, display a hint to help the developer
> figure out the problem (likely trying to connect a clock to a device
> pre-dating the Clock API, thus not expecting clocks).
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

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

> ---
>  hw/core/qdev-clock.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c
> index 47ecb5b4fae..33bd4a9d520 100644
> --- a/hw/core/qdev-clock.c
> +++ b/hw/core/qdev-clock.c
> @@ -12,6 +12,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/error-report.h"
>  #include "hw/qdev-clock.h"
>  #include "hw/qdev-core.h"
>  #include "qapi/error.h"
> @@ -153,6 +154,11 @@ Clock *qdev_get_clock_in(DeviceState *dev, const char *name)
>      assert(name);
>  
>      ncl = qdev_get_clocklist(dev, name);
> +    if (!ncl) {
> +        error_report("can not find clock-in '%s' for device type '%s'",
> +                     name, object_get_typename(OBJECT(dev)));
> +        abort();
> +    }
>      assert(!ncl->output);
>  
>      return ncl->clock;
> @@ -165,6 +171,11 @@ Clock *qdev_get_clock_out(DeviceState *dev, const char *name)
>      assert(name);
>  
>      ncl = qdev_get_clocklist(dev, name);
> +    if (!ncl) {
> +        error_report("can not find clock-out '%s' for device type '%s'",
> +                     name, object_get_typename(OBJECT(dev)));
> +        abort();
> +    }
>      assert(ncl->output);
>  
>      return ncl->clock;
> -- 
> 2.26.2
> 


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

* Re: [PATCH 2/3] qdev-monitor: Display frequencies scaled to SI unit
  2020-09-28  7:52   ` Luc Michel
@ 2020-09-28  8:45     ` Damien Hedde
  0 siblings, 0 replies; 11+ messages in thread
From: Damien Hedde @ 2020-09-28  8:45 UTC (permalink / raw)
  To: Luc Michel, Philippe Mathieu-Daudé
  Cc: Edgar E . Iglesias, Peter Maydell, Daniel P. Berrangé,
	Eduardo Habkost, Havard Skinnemoen, qemu-devel, Tyrone Ting,
	Alistair Francis, Paolo Bonzini



On 9/28/20 9:52 AM, Luc Michel wrote:
> On 11:08 Sun 27 Sep     , Philippe Mathieu-Daudé wrote:
>> Since commit 9f2ff99c7f2 ("qdev-monitor: print the device's clock
>> with info qtree") we can display the clock frequencies in the
>> monitor. Use the recently introduced freq_to_str() to display
>> the frequencies using the closest SI unit (human friendlier).
>>
>> 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: Philippe Mathieu-Daudé <f4bug@amsat.org>
> 
> Reviewed-by: Luc Michel <luc@lmichel.fr>

Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
> 
>> ---
>>  qdev-monitor.c | 8 +++++---
>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/qdev-monitor.c b/qdev-monitor.c
>> index e9b7228480d..a0301cfca81 100644
>> --- a/qdev-monitor.c
>> +++ b/qdev-monitor.c
>> @@ -747,11 +747,13 @@ 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 = NULL;
>> +
>> +        freq = freq_to_str(clock_get_hz(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);
>>      }
>>      class = object_get_class(OBJECT(dev));
>>      do {
>> -- 
>> 2.26.2
>>


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

* Re: [PATCH 3/3] hw/qdev-clock: Display error hint when clock is missing from device
  2020-09-28  7:53   ` Luc Michel
@ 2020-09-28 10:45     ` Damien Hedde
  2020-09-28 10:48       ` Edgar E. Iglesias
  0 siblings, 1 reply; 11+ messages in thread
From: Damien Hedde @ 2020-09-28 10:45 UTC (permalink / raw)
  To: Luc Michel, Philippe Mathieu-Daudé
  Cc: Edgar E . Iglesias, Peter Maydell, Daniel P. Berrangé,
	Eduardo Habkost, Havard Skinnemoen, qemu-devel, Tyrone Ting,
	Alistair Francis, Paolo Bonzini



On 9/28/20 9:53 AM, Luc Michel wrote:
> On 11:08 Sun 27 Sep     , Philippe Mathieu-Daudé wrote:
>> Instead of directly aborting, display a hint to help the developer
>> figure out the problem (likely trying to connect a clock to a device
>> pre-dating the Clock API, thus not expecting clocks).
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> 
> Reviewed-by: Luc Michel <luc@lmichel.fr>

Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>

> 
>> ---
>>  hw/core/qdev-clock.c | 11 +++++++++++
>>  1 file changed, 11 insertions(+)
>>
>> diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c
>> index 47ecb5b4fae..33bd4a9d520 100644
>> --- a/hw/core/qdev-clock.c
>> +++ b/hw/core/qdev-clock.c
>> @@ -12,6 +12,7 @@
>>   */
>>  
>>  #include "qemu/osdep.h"
>> +#include "qemu/error-report.h"
>>  #include "hw/qdev-clock.h"
>>  #include "hw/qdev-core.h"
>>  #include "qapi/error.h"
>> @@ -153,6 +154,11 @@ Clock *qdev_get_clock_in(DeviceState *dev, const char *name)
>>      assert(name);
>>  
>>      ncl = qdev_get_clocklist(dev, name);
>> +    if (!ncl) {
>> +        error_report("can not find clock-in '%s' for device type '%s'",
>> +                     name, object_get_typename(OBJECT(dev)));
>> +        abort();
>> +    }
>>      assert(!ncl->output);
>>  
>>      return ncl->clock;
>> @@ -165,6 +171,11 @@ Clock *qdev_get_clock_out(DeviceState *dev, const char *name)
>>      assert(name);
>>  
>>      ncl = qdev_get_clocklist(dev, name);
>> +    if (!ncl) {
>> +        error_report("can not find clock-out '%s' for device type '%s'",
>> +                     name, object_get_typename(OBJECT(dev)));
>> +        abort();
>> +    }
>>      assert(ncl->output);
>>  
>>      return ncl->clock;
>> -- 
>> 2.26.2
>>


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

* Re: [PATCH 3/3] hw/qdev-clock: Display error hint when clock is missing from device
  2020-09-28 10:45     ` Damien Hedde
@ 2020-09-28 10:48       ` Edgar E. Iglesias
  0 siblings, 0 replies; 11+ messages in thread
From: Edgar E. Iglesias @ 2020-09-28 10:48 UTC (permalink / raw)
  To: Damien Hedde
  Cc: Peter Maydell, Luc Michel, Eduardo Habkost,
	Philippe Mathieu-Daudé,
	qemu-devel, Tyrone Ting, Alistair Francis,
	Daniel P. Berrangé,
	Paolo Bonzini, Havard Skinnemoen

On Mon, Sep 28, 2020 at 12:45:15PM +0200, Damien Hedde wrote:
> 
> 
> On 9/28/20 9:53 AM, Luc Michel wrote:
> > On 11:08 Sun 27 Sep     , Philippe Mathieu-Daudé wrote:
> >> Instead of directly aborting, display a hint to help the developer
> >> figure out the problem (likely trying to connect a clock to a device
> >> pre-dating the Clock API, thus not expecting clocks).
> >>
> >> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> > 
> > Reviewed-by: Luc Michel <luc@lmichel.fr>
> 
> Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>

Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>


> 
> > 
> >> ---
> >>  hw/core/qdev-clock.c | 11 +++++++++++
> >>  1 file changed, 11 insertions(+)
> >>
> >> diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c
> >> index 47ecb5b4fae..33bd4a9d520 100644
> >> --- a/hw/core/qdev-clock.c
> >> +++ b/hw/core/qdev-clock.c
> >> @@ -12,6 +12,7 @@
> >>   */
> >>  
> >>  #include "qemu/osdep.h"
> >> +#include "qemu/error-report.h"
> >>  #include "hw/qdev-clock.h"
> >>  #include "hw/qdev-core.h"
> >>  #include "qapi/error.h"
> >> @@ -153,6 +154,11 @@ Clock *qdev_get_clock_in(DeviceState *dev, const char *name)
> >>      assert(name);
> >>  
> >>      ncl = qdev_get_clocklist(dev, name);
> >> +    if (!ncl) {
> >> +        error_report("can not find clock-in '%s' for device type '%s'",
> >> +                     name, object_get_typename(OBJECT(dev)));
> >> +        abort();
> >> +    }
> >>      assert(!ncl->output);
> >>  
> >>      return ncl->clock;
> >> @@ -165,6 +171,11 @@ Clock *qdev_get_clock_out(DeviceState *dev, const char *name)
> >>      assert(name);
> >>  
> >>      ncl = qdev_get_clocklist(dev, name);
> >> +    if (!ncl) {
> >> +        error_report("can not find clock-out '%s' for device type '%s'",
> >> +                     name, object_get_typename(OBJECT(dev)));
> >> +        abort();
> >> +    }
> >>      assert(ncl->output);
> >>  
> >>      return ncl->clock;
> >> -- 
> >> 2.26.2
> >>


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

* Re: [PATCH 1/3] util/cutils: Introduce freq_to_str() to display Hertz units
  2020-09-28  7:50   ` Luc Michel
@ 2020-09-28 13:04     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-28 13:04 UTC (permalink / raw)
  To: Luc Michel
  Cc: Damien Hedde, Edgar E . Iglesias, Eduardo Habkost, Peter Maydell,
	qemu-devel, Havard Skinnemoen, Tyrone Ting, Alistair Francis

On 9/28/20 9:50 AM, Luc Michel wrote:
> Hi Philippe,
> 
> On 11:08 Sun 27 Sep     , Philippe Mathieu-Daudé wrote:
>> Introduce freq_to_str() to convert frequency values in human
>> friendly units using the SI units for Hertz.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>>  include/qemu/cutils.h | 12 ++++++++++++
>>  util/cutils.c         | 10 ++++++++++
>>  2 files changed, 22 insertions(+)
>>
>> diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
>> index eb59852dfdf..0186c846e9c 100644
>> --- a/include/qemu/cutils.h
>> +++ b/include/qemu/cutils.h
>> @@ -158,6 +158,18 @@ int qemu_strtosz_metric(const char *nptr, const char **end, uint64_t *result);
>>  
>>  char *size_to_str(uint64_t val);
>>  
>> +/**
>> + * freq_to_str:
>> + * @freq_hz: frequency to stringify
>> + *
>> + * Return human readable string for frequency @freq_hz.
>> + * Use SI units like KHz, MHz, and so forth.
>> + *
>> + * The caller is responsible for releasing the value returned with g_free()
>> + * after use.
>> + */
>> +char *freq_to_str(uint64_t freq_hz);
>> +
>>  /* used to print char* safely */
>>  #define STR_OR_NULL(str) ((str) ? (str) : "null")
>>  
>> diff --git a/util/cutils.c b/util/cutils.c
>> index 36ce712271f..dab837fd8b8 100644
>> --- a/util/cutils.c
>> +++ b/util/cutils.c
>> @@ -885,6 +885,16 @@ char *size_to_str(uint64_t val)
>>      return g_strdup_printf("%0.3g %sB", (double)val / div, suffixes[i]);
>>  }
>>  
>> +char *freq_to_str(uint64_t freq_hz)
>> +{
>> +    static const char *suffixes[] = { "", "K", "M", "G", "T", "P", "E" };
>> +    unsigned unit_index = log10(freq_hz) / 3;
>> +
>> +    return g_strdup_printf("%0.3g %sHz",
>> +                           freq_hz / pow(10.0, unit_index * 3.0),
>> +                           suffixes[unit_index]);
> 
> You could end up going out of your 'suffixes' array if freq_hz is very
> high.

Oh, good point.

> Also, to avoid the complexity of log10/pow, maybe something like:
> 
>     double freq = freq_hz;
>     size_t idx = 0;
> 
>     while (freq >= 1000.0 && idx < ARRAY_LENGTH(suffixes)) {
>         freq /= 1000.0;
>         idx++;
>     }

KISS, I like it :)

> 
>     return g_strdup_printf("%0.3g %sHz", freq, suffixes[idx]);
> 
> is enough?
> 

I'll respin, thanks!

Phil.


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

end of thread, other threads:[~2020-09-28 13:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-27  9:08 [PATCH 0/3] qdev-clock: Minor improvements to the Clock API Philippe Mathieu-Daudé
2020-09-27  9:08 ` [PATCH 1/3] util/cutils: Introduce freq_to_str() to display Hertz units Philippe Mathieu-Daudé
2020-09-28  7:50   ` Luc Michel
2020-09-28 13:04     ` Philippe Mathieu-Daudé
2020-09-27  9:08 ` [PATCH 2/3] qdev-monitor: Display frequencies scaled to SI unit Philippe Mathieu-Daudé
2020-09-28  7:52   ` Luc Michel
2020-09-28  8:45     ` Damien Hedde
2020-09-27  9:08 ` [PATCH 3/3] hw/qdev-clock: Display error hint when clock is missing from device Philippe Mathieu-Daudé
2020-09-28  7:53   ` Luc Michel
2020-09-28 10:45     ` Damien Hedde
2020-09-28 10:48       ` Edgar E. Iglesias

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.