From patchwork Tue May 6 12:59:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Batuzov X-Patchwork-Id: 346170 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 29B641402D4 for ; Tue, 6 May 2014 23:01:02 +1000 (EST) Received: from localhost ([::1]:35138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhezU-00028n-5w for incoming@patchwork.ozlabs.org; Tue, 06 May 2014 09:01:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wheys-0001bq-DF for qemu-devel@nongnu.org; Tue, 06 May 2014 09:00:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wheyk-00040V-S1 for qemu-devel@nongnu.org; Tue, 06 May 2014 09:00:22 -0400 Received: from smtp.ispras.ru ([83.149.199.79]:41518) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wheyk-0003xD-LA for qemu-devel@nongnu.org; Tue, 06 May 2014 09:00:14 -0400 Received: from bulbul.intra.ispras.ru (unknown [83.149.199.91]) by smtp.ispras.ru (Postfix) with ESMTP id 71194224AA; Tue, 6 May 2014 17:00:05 +0400 (MSK) From: Kirill Batuzov To: qemu-devel@nongnu.org Date: Tue, 6 May 2014 16:59:53 +0400 Message-Id: <1399381193-2662-1-git-send-email-batuzovk@ispras.ru> X-Mailer: git-send-email 1.7.10.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 83.149.199.79 Cc: Paolo Bonzini , Stefan Hajnoczi , Anthony Liguori , Alex Bligh , Kirill Batuzov Subject: [Qemu-devel] [PATCH] vl.c: remove init_clocks call from main X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. Signed-off-by: Kirill Batuzov Reviewed-By: Alex Bligh --- 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. diff --git a/qemu-timer.c b/qemu-timer.c index e15ce47..335a0e5 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -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; diff --git a/vl.c b/vl.c index 9975e5a..a903776 100644 --- a/vl.c +++ b/vl.c @@ -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);