From 15aa2876d9c7181c58305430f726461a2f24cb00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Fri, 28 Aug 2020 10:02:44 +0100 Subject: hw/clock: Let clock_set() return boolean value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let clock_set() return a boolean value whether the clock has been updated or not. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-id: 20200806123858.30058-3-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/core/clock.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'hw/core') diff --git a/hw/core/clock.c b/hw/core/clock.c index 3c0daf7..7066282 100644 --- a/hw/core/clock.c +++ b/hw/core/clock.c @@ -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) -- cgit v1.1 From f129360ca15723e43a8c44d1a2f025c0df1270cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Fri, 28 Aug 2020 10:02:46 +0100 Subject: hw/qdev-clock: Uninline qdev_connect_clock_in() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to assert the device is not realized. To avoid overloading this header including "hw/qdev-core.h", uninline the function first. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis Message-id: 20200803105647.22223-4-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/core/qdev-clock.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'hw/core') diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c index 5cc1e82..f139b68 100644 --- a/hw/core/qdev-clock.c +++ b/hw/core/qdev-clock.c @@ -183,3 +183,8 @@ Clock *qdev_alias_clock(DeviceState *dev, const char *name, return ncl->clock; } + +void qdev_connect_clock_in(DeviceState *dev, const char *name, Clock *source) +{ + clock_set_source(qdev_get_clock_in(dev, name), source); +} -- cgit v1.1 From 739fa3255492f1c7541db1c7a9795fcf4b472c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Fri, 28 Aug 2020 10:02:46 +0100 Subject: hw/qdev-clock: Avoid calling qdev_connect_clock_in after DeviceRealize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clock canonical name is set in device_set_realized (see the block added to hw/core/qdev.c in commit 0e6934f264). If we connect a clock after the device is realized, this code is not executed. This is currently not a problem as this name is only used for trace events, however this disrupt tracing. Add a comment to document qdev_connect_clock_in() must be called before the device is realized, and assert this condition. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis Message-id: 20200803105647.22223-5-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/core/qdev-clock.c | 1 + 1 file changed, 1 insertion(+) (limited to 'hw/core') diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c index f139b68..47ecb5b 100644 --- a/hw/core/qdev-clock.c +++ b/hw/core/qdev-clock.c @@ -186,5 +186,6 @@ Clock *qdev_alias_clock(DeviceState *dev, const char *name, void qdev_connect_clock_in(DeviceState *dev, const char *name, Clock *source) { + assert(!dev->realized); clock_set_source(qdev_get_clock_in(dev, name), source); } -- cgit v1.1