Skip to contentSkip to conversation

hw/clock: Only propagate clock changes if the clock is changed

PATCH Applied Philippe Mathieu-Daudé 3 participants 8 messages Aug 6, 2020 – Aug 24, 2020

lore
Share & tools
lore
#0 lore raw

cover hw/clock: Only propagate clock changes if the clock is changed

Trivial patches for the clock API:
- remove unused code
- only propagate clock update when a clock change

Philippe Mathieu-Daudé (3):
hw/clock: Remove unused clock_init*() functions hw/clock: Let clock_set() return boolean value hw/clock: Only propagate clock changes if the clock is changed

 include/hw/clock.h | 30 ++++++++++--------------------
 hw/core/clock.c    |  7 ++++++-
 2 files changed, 16 insertions(+), 21 deletions(-)
Signature · 1 line
2.21.3
#1 lore raw

PATCH 1/3 hw/clock: Remove unused clock_init*() functions

clock_init*() inlined funtions are simple wrappers around clock_set*() and are not used. Remove them in favor of clock_set*().

---
 include/hw/clock.h | 13 -------------
 1 file changed, 13 deletions(-)
include/hw/clock.h +0 -13
index f822a94220..468fed0996 100644
@@ -209,17 +209,4 @@ static inline bool clock_is_enabled(const Clock *clk)
     return clock_get(clk) != 0;
 }
 
-static inline void clock_init(Clock *clk, uint64_t value)
-{
-    clock_set(clk, value);
-}
-static inline void clock_init_hz(Clock *clk, uint64_t value)
-{
-    clock_set_hz(clk, value);
-}
-static inline void clock_init_ns(Clock *clk, uint64_t value)
-{
-    clock_set_ns(clk, value);
-}
-
 #endif /* QEMU_HW_CLOCK_H */
Signature · 1 line
2.21.3
#3 lore raw

PATCH 2/3 hw/clock: Let clock_set() return boolean value

In reply to Philippe Mathieu-Daudé

Let clock_set() return a boolean value whether the clock has been updated or not.

---
 include/hw/clock.h | 12 +++++++-----
 hw/core/clock.c    |  7 ++++++-
 2 files changed, 13 insertions(+), 6 deletions(-)
include/hw/clock.h +7 -5
index 468fed0996..d85af45c96 100644
@@ -127,17 +127,19 @@ void clock_set_source(Clock *clk, Clock *src);
  * @value: the clock's value, 0 means unclocked
  *
  * Set the local cached period value of @clk to @value.
+ *
+ * @return: true if the clock is changed.
  */
-void clock_set(Clock *clk, uint64_t value);
+bool clock_set(Clock *clk, uint64_t value);
 
-static inline void clock_set_hz(Clock *clk, unsigned hz)
+static inline bool clock_set_hz(Clock *clk, unsigned hz)
 {
-    clock_set(clk, CLOCK_PERIOD_FROM_HZ(hz));
+    return clock_set(clk, CLOCK_PERIOD_FROM_HZ(hz));
 }
 
-static inline void clock_set_ns(Clock *clk, unsigned ns)
+static inline bool clock_set_ns(Clock *clk, unsigned ns)
 {
-    clock_set(clk, CLOCK_PERIOD_FROM_NS(ns));
+    return clock_set(clk, CLOCK_PERIOD_FROM_NS(ns));
 }
 
 /**
hw/core/clock.c +6 -1
index 3c0daf7d4c..7066282f7b 100644
@@ -34,11 +34,16 @@ void clock_clear_callback(Clock *clk)
     clock_set_callback(clk, NULL, NULL);
 }
 
-void clock_set(Clock *clk, uint64_t period)
+bool clock_set(Clock *clk, uint64_t period)
 {
+    if (clk->period == period) {
+        return false;
+    }
     trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_NS(clk->period),
                     CLOCK_PERIOD_TO_NS(period));
     clk->period = period;
+
+    return true;
 }
 
 static void clock_propagate_period(Clock *clk, bool call_callbacks)
Signature · 1 line
2.21.3
#5 lore raw

PATCH 3/3 hw/clock: Only propagate clock changes if the clock is changed

In reply to Philippe Mathieu-Daudé

Avoid propagating the clock change when the clock does not change.

---
 include/hw/clock.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
include/hw/clock.h +3 -2
index d85af45c96..9ecd78b2c3 100644
@@ -165,8 +165,9 @@ void clock_propagate(Clock *clk);
  */
 static inline void clock_update(Clock *clk, uint64_t value)
 {
-    clock_set(clk, value);
-    clock_propagate(clk);
+    if (clock_set(clk, value)) {
+        clock_propagate(clk);
+    }
 }
 
 static inline void clock_update_hz(Clock *clk, unsigned hz)
Signature · 1 line
2.21.3
#7 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 5 lines · Philippe Mathieu-Daudé

Trivial patches for the clock API:
- remove unused code
- only propagate clock update when a clock change

Quoted 8 lines

Philippe Mathieu-Daudé (3):
hw/clock: Remove unused clock_init*() functions hw/clock: Let clock_set() return boolean value hw/clock: Only propagate clock changes if the clock is changed

 include/hw/clock.h | 30 ++++++++++--------------------
 hw/core/clock.c    |  7 ++++++-
 2 files changed, 16 insertions(+), 21 deletions(-)

Applied to target-arm.next, thanks.

-- PMM