vl.c: remove init_clocks call from main
PATCH 1/1 vl.c: remove init_clocks call from main
Clocks are initialized in qemu_init_main_loop. They are not needed before it. Initializing them twice is not only unnecessary but is harmful: it results in memory leak and potentially can lead to a situation where different parts of QEMU use different sets of timers.
To avoid it remove init_clocks call from main and add an assertion to qemu_clock_init that corresponding clock has not been initialized yet.
--- qemu-timer.c | 3 +++ vl.c | 1 - 2 files changed, 3 insertions(+), 1 deletion(-)
The init_clocks call was added to qemu_init_main_loop in commit 172061a0a0d98c974ea8d5ed715195237bc44225. init_clocks was made idempotent in prior commit 744ca8e3754e6808c6b5331d287adc533fca0ad3. Back then it was not possible to remove init_clocks call from main because rtc_clock variable was of type QEMUClock * and was used in option processing. So clocks needed to be initialized before command line options could be processed.
Commit 7bf8fbde449600926370f744b2b3d9cc819ca74f removed idempotence property from init_clocks. Commit 884f17c235095af99b92dd8cd10bb824a5b0f777 removed the need to call init_clocks from main, but did not remove the call.
qemu-timer.c +3 -0
@@ -126,6 +126,9 @@ static void qemu_clock_init(QEMUClockType type) {QEMUClock *clock =qemu_clock_ptr (type); +/* Assert that the clock of type TYPE has not been initialized yet. */ +assert (main_loop_tlg.tl[type] ==NULL ); + clock->type = type; clock->enabled = true; clock->last =INT64_MIN ;
vl.c +0 -1
@@ -2999,7 +2999,6 @@ int main(int argc, char **argv, char **envp)runstate_init (); -init_clocks (); rtc_clock =QEMU_CLOCK_HOST ;qemu_init_auxval (envp);
Signature · 1 line
1.7.10.4
Quoted 21 lines · Kirill Batuzov
Clocks are initialized in
qemu_init_main_loop. They are not needed before it. Initializing them twice is not only unnecessary but is harmful: it results in memory leak and potentially can lead to a situation where different parts of QEMU use different sets of timers.To avoid it remove
init_clockscall from main and add an assertion toqemu_clock_initthat corresponding clock has not been initialized yet.Signed-off-by Kirill Batuzov <[email protected]>---
qemu-timer.c | 3 +++ vl.c | 1 - 2 files changed, 3 insertions(+), 1 deletion(-)The
init_clockscall was added toqemu_init_main_loopin commit172061a0a0d98c974ea8d5ed715195237bc44225.init_clockswas made idempotent in prior commit744ca8e3754e6808c6b5331d287adc533fca0ad3. Back then it was not possible to removeinit_clockscall from main becausertc_clockvariable was of type QEMUClock * and was used in option processing. So clocks needed to be initialized before command line options could be processed.
Quoted 3 lines
Commit
7bf8fbde449600926370f744b2b3d9cc819ca74fremoved idempotence property frominit_clocks. Commit884f17c235095af99b92dd8cd10bb824a5b0f777removed the need to callinit_clocksfrom main, but did not remove the call.
So if I read this right, init_clocks() is now only done in vl.c.
I think this is problematic, as qemu-img (for instance) still uses the mainloop (it calls qemu_init_main_loop() from main), but does not use vl.c as far as I know.
Perhaps restoring the idempotence would be a better plan.
Signature · 1 line
Alex Bligh
Quoted 11 lines · Alex Bligh
Quoted 8 lines · Kirill Batuzov
Clocks are initialized in
qemu_init_main_loop. They are not needed before it. Initializing them twice is not only unnecessary but is harmful: it results in memory leak and potentially can lead to a situation where different parts of QEMU use different sets of timers.To avoid it remove
init_clockscall from main and add an assertion toqemu_clock_initthat corresponding clock has not been initialized yet.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Kirill Batuzov <[email protected]>---
qemu-timer.c | 3 +++ vl.c | 1 - 2 files changed, 3 insertions(+), 1 deletion(-)So if I read this right,
init_clocks()is now only done invl.c.
No, you're misreading it -- the commit message says "remove init_clocks call from main" and you can see from the diffstat it's removed from vl.c. It's now done only in qemu_clock_init().
thanks
-- PMM
Alex Bligh
Reviewed-byQuoted 6 lines · Peter Maydell
Quoted 2 lines
So if I read this right,
init_clocks()is now only done invl.c.No, you're misreading it -- the commit message says "remove
init_clockscall from main" and you can see from the diffstat it's removed fromvl.c. It's now done only inqemu_clock_init().
Indeed. I get to wear the dunce's cap for a bit. Apologies. Twice, actually, for not removing it from main() in the first place.
Signature · 1 line
Alex Bligh
Stefan Hajnoczi
AppliedQuoted 21 lines · Kirill Batuzov
Clocks are initialized in
qemu_init_main_loop. They are not needed before it. Initializing them twice is not only unnecessary but is harmful: it results in memory leak and potentially can lead to a situation where different parts of QEMU use different sets of timers.To avoid it remove
init_clockscall from main and add an assertion toqemu_clock_initthat corresponding clock has not been initialized yet.Signed-off-by Kirill Batuzov <[email protected]>--- qemu-timer.c | 3 +++ vl.c | 1 - 2 files changed, 3 insertions(+), 1 deletion(-)The
init_clockscall was added toqemu_init_main_loopin commit172061a0a0d98c974ea8d5ed715195237bc44225.init_clockswas made idempotent in prior commit744ca8e3754e6808c6b5331d287adc533fca0ad3. Back then it was not possible to removeinit_clockscall from main becausertc_clockvariable was of type QEMUClock * and was used in option processing. So clocks needed to be initialized before command line options could be processed.
Quoted 3 lines
Commit
7bf8fbde449600926370f744b2b3d9cc819ca74fremoved idempotence property frominit_clocks. Commit884f17c235095af99b92dd8cd10bb824a5b0f777removed the need to callinit_clocksfrom main, but did not remove the call.
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan