All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Damien Hedde" <damien.hedde@greensocs.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Luc Michel" <luc.michel@greensocs.com>
Subject: [RFC PATCH 4/4] hw/clock: Inline and remove CLOCK_PERIOD_TO_NS()
Date: Tue, 20 Oct 2020 20:20:08 +0200	[thread overview]
Message-ID: <20201020182008.2240590-5-f4bug@amsat.org> (raw)
In-Reply-To: <20201020182008.2240590-1-f4bug@amsat.org>

This macro is only used once. Inline caring about 64-bit
multiplication, and remove it.

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/hw/clock.h | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/hw/clock.h b/include/hw/clock.h
index b58038f1e7d..f329fcf0ea5 100644
--- a/include/hw/clock.h
+++ b/include/hw/clock.h
@@ -16,6 +16,7 @@
 
 #include "qom/object.h"
 #include "qemu/queue.h"
+#include "qemu/host-utils.h"
 
 #define TYPE_CLOCK "clock"
 OBJECT_DECLARE_SIMPLE_TYPE(Clock, CLOCK)
@@ -38,7 +39,6 @@ typedef void ClockCallback(void *opaque);
  * macro helpers to convert to hertz / nanosecond
  */
 #define CLOCK_PERIOD_FROM_NS(ns) ((ns) * (CLOCK_PERIOD_1SEC / 1000000000llu))
-#define CLOCK_PERIOD_TO_NS(per) ((per) / (CLOCK_PERIOD_1SEC / 1000000000llu))
 #define CLOCK_PERIOD_FROM_HZ(hz) (((hz) != 0) ? CLOCK_PERIOD_1SEC / (hz) : 0u)
 
 /**
@@ -210,9 +210,14 @@ static inline uint64_t clock_get_hz(Clock *clk)
     return CLOCK_PERIOD_1SEC / clk->period;
 }
 
-static inline unsigned clock_get_ns(Clock *clk)
+static inline uint64_t clock_get_ns(Clock *clk)
 {
-    return CLOCK_PERIOD_TO_NS(clock_get(clk));
+    uint64_t lo, hi;
+
+    mulu64(&lo, &hi, clock_get(clk), 1000000000llu);
+    divu128(&lo, &hi, CLOCK_PERIOD_1SEC);
+
+    return lo;
 }
 
 /**
-- 
2.26.2



  parent reply	other threads:[~2020-10-20 18:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-20 18:20 [PATCH 0/4] hw/clock: Inline and remove CLOCK_PERIOD_TO_HZ/CLOCK_PERIOD_TO_NS macro Philippe Mathieu-Daudé
2020-10-20 18:20 ` [PATCH 1/4] qdev-monitor: Display frequencies scaled to SI unit Philippe Mathieu-Daudé
2020-10-20 20:32   ` Peter Maydell
2020-10-20 18:20 ` [PATCH 2/4] hw/core/clock: trace clock values in Hz instead of ns Philippe Mathieu-Daudé
2020-10-20 18:20 ` [PATCH 3/4] hw/clock: Inline and remove CLOCK_PERIOD_TO_HZ() Philippe Mathieu-Daudé
2020-10-20 18:20 ` Philippe Mathieu-Daudé [this message]
2020-10-20 20:25   ` [RFC PATCH 4/4] hw/clock: Inline and remove CLOCK_PERIOD_TO_NS() Peter Maydell

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=20201020182008.2240590-5-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=berrange@redhat.com \
    --cc=damien.hedde@greensocs.com \
    --cc=ehabkost@redhat.com \
    --cc=luc.michel@greensocs.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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 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.