From patchwork Thu May 5 07:32:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Liang Z" X-Patchwork-Id: 618866 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3r0n2L255Yz9ssM for ; Thu, 5 May 2016 17:43:06 +1000 (AEST) Received: from localhost ([::1]:52225 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayDw5-0002q2-6G for incoming@patchwork.ozlabs.org; Thu, 05 May 2016 03:43:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58395) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayDr7-00019m-GR for qemu-devel@nongnu.org; Thu, 05 May 2016 03:37:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayDqv-0001M6-LC for qemu-devel@nongnu.org; Thu, 05 May 2016 03:37:48 -0400 Received: from mga14.intel.com ([192.55.52.115]:61079) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayDqv-0001Am-GK for qemu-devel@nongnu.org; Thu, 05 May 2016 03:37:41 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP; 05 May 2016 00:37:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,581,1455004800"; d="scan'208";a="799336552" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.27]) by orsmga003.jf.intel.com with ESMTP; 05 May 2016 00:37:08 -0700 From: Liang Li To: qemu-devel@nongnu.org Date: Thu, 5 May 2016 15:32:59 +0800 Message-Id: <1462433579-13691-10-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462433579-13691-1-git-send-email-liang.z.li@intel.com> References: <1462433579-13691-1-git-send-email-liang.z.li@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.115 Subject: [Qemu-devel] [PATCH v2 9/9] migration: code clean up X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amit.shah@redhat.com, Liang Li , dgilbert@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Use 'QemuMutex comp_done_lock' and 'QemuCond comp_done_cond' instead of 'QemuMutex *comp_done_lock' and 'QemuCond comp_done_cond'. To keep consistent with 'QemuMutex decomp_done_lock' and 'QemuCond comp_done_cond'. Signed-off-by: Liang Li --- migration/ram.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 51de958..5076862 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -278,8 +278,8 @@ static QemuThread *compress_threads; * one of the compression threads has finished the compression. * comp_done_lock is used to co-work with comp_done_cond. */ -static QemuMutex *comp_done_lock; -static QemuCond *comp_done_cond; +static QemuMutex comp_done_lock; +static QemuCond comp_done_cond; /* The empty QEMUFileOps will be used by file in CompressParam */ static const QEMUFileOps empty_ops = { }; @@ -308,10 +308,10 @@ static void *do_data_compress(void *opaque) do_compress_ram_page(param->file, block, offset); - qemu_mutex_lock(comp_done_lock); + qemu_mutex_lock(&comp_done_lock); param->done = true; - qemu_cond_signal(comp_done_cond); - qemu_mutex_unlock(comp_done_lock); + qemu_cond_signal(&comp_done_cond); + qemu_mutex_unlock(&comp_done_lock); qemu_mutex_lock(¶m->mutex); } else { @@ -351,16 +351,12 @@ void migrate_compress_threads_join(void) qemu_mutex_destroy(&comp_param[i].mutex); qemu_cond_destroy(&comp_param[i].cond); } - qemu_mutex_destroy(comp_done_lock); - qemu_cond_destroy(comp_done_cond); + qemu_mutex_destroy(&comp_done_lock); + qemu_cond_destroy(&comp_done_cond); g_free(compress_threads); g_free(comp_param); - g_free(comp_done_cond); - g_free(comp_done_lock); compress_threads = NULL; comp_param = NULL; - comp_done_cond = NULL; - comp_done_lock = NULL; } void migrate_compress_threads_create(void) @@ -374,10 +370,8 @@ void migrate_compress_threads_create(void) thread_count = migrate_compress_threads(); compress_threads = g_new0(QemuThread, thread_count); comp_param = g_new0(CompressParam, thread_count); - comp_done_cond = g_new0(QemuCond, 1); - comp_done_lock = g_new0(QemuMutex, 1); - qemu_cond_init(comp_done_cond); - qemu_mutex_init(comp_done_lock); + qemu_cond_init(&comp_done_cond); + qemu_mutex_init(&comp_done_lock); for (i = 0; i < thread_count; i++) { /* com_param[i].file is just used as a dummy buffer to save data, set * it's ops to empty. @@ -840,13 +834,13 @@ static void flush_compressed_data(QEMUFile *f) } thread_count = migrate_compress_threads(); - qemu_mutex_lock(comp_done_lock); + qemu_mutex_lock(&comp_done_lock); for (idx = 0; idx < thread_count; idx++) { while (!comp_param[idx].done) { - qemu_cond_wait(comp_done_cond, comp_done_lock); + qemu_cond_wait(&comp_done_cond, &comp_done_lock); } } - qemu_mutex_unlock(comp_done_lock); + qemu_mutex_unlock(&comp_done_lock); for (idx = 0; idx < thread_count; idx++) { qemu_mutex_lock(&comp_param[idx].mutex); @@ -872,7 +866,7 @@ static int compress_page_with_multi_thread(QEMUFile *f, RAMBlock *block, int idx, thread_count, bytes_xmit = -1, pages = -1; thread_count = migrate_compress_threads(); - qemu_mutex_lock(comp_done_lock); + qemu_mutex_lock(&comp_done_lock); while (true) { for (idx = 0; idx < thread_count; idx++) { if (comp_param[idx].done) { @@ -891,10 +885,10 @@ static int compress_page_with_multi_thread(QEMUFile *f, RAMBlock *block, if (pages > 0) { break; } else { - qemu_cond_wait(comp_done_cond, comp_done_lock); + qemu_cond_wait(&comp_done_cond, &comp_done_lock); } } - qemu_mutex_unlock(comp_done_lock); + qemu_mutex_unlock(&comp_done_lock); return pages; }