From patchwork Fri Apr 21 11:56:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 753355 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 3w8ZtZ646Jz9s4s for ; Fri, 21 Apr 2017 22:34:30 +1000 (AEST) Received: from localhost ([::1]:58999 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Xlc-0007zk-AQ for incoming@patchwork.ozlabs.org; Fri, 21 Apr 2017 08:34:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1XC3-0002Tp-0T for qemu-devel@nongnu.org; Fri, 21 Apr 2017 07:57:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1XBz-0007WC-2r for qemu-devel@nongnu.org; Fri, 21 Apr 2017 07:57:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39230) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1XBy-0007Vu-QH for qemu-devel@nongnu.org; Fri, 21 Apr 2017 07:57:39 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD3F5DF23C for ; Fri, 21 Apr 2017 11:57:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AD3F5DF23C Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AD3F5DF23C Received: from secure.com (ovpn-116-35.ams2.redhat.com [10.36.116.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABF4D89F64; Fri, 21 Apr 2017 11:57:35 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 21 Apr 2017 13:56:14 +0200 Message-Id: <20170421115646.15544-34-quintela@redhat.com> In-Reply-To: <20170421115646.15544-1-quintela@redhat.com> References: <20170421115646.15544-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 21 Apr 2017 11:57:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 33/65] ram: Move src_page_req* to RAMState 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: dgilbert@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This are the last postcopy fields still at MigrationState. Once there Move MigrationSrcPageRequest to ram.c and remove MigrationState parameters where appropiate. Signed-off-by: Juan Quintela Reviewed-by: Peter Xu --- include/migration/migration.h | 17 +----------- migration/migration.c | 5 +--- migration/ram.c | 61 +++++++++++++++++++++++++++---------------- 3 files changed, 40 insertions(+), 43 deletions(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index 0f75573..084d195 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -128,18 +128,6 @@ struct MigrationIncomingState { MigrationIncomingState *migration_incoming_get_current(void); void migration_incoming_state_destroy(void); -/* - * An outstanding page request, on the source, having been received - * and queued - */ -struct MigrationSrcPageRequest { - RAMBlock *rb; - hwaddr offset; - hwaddr len; - - QSIMPLEQ_ENTRY(MigrationSrcPageRequest) next_req; -}; - struct MigrationState { size_t bytes_xfer; @@ -186,9 +174,6 @@ struct MigrationState /* Flag set once the migration thread called bdrv_inactivate_all */ bool block_inactive; - /* Queue of outstanding page requests from the destination */ - QemuMutex src_page_req_mutex; - QSIMPLEQ_HEAD(src_page_requests, MigrationSrcPageRequest) src_page_requests; /* The semaphore is used to notify COLO thread that failover is finished */ QemuSemaphore colo_exit_sem; @@ -371,7 +356,7 @@ void savevm_skip_configuration(void); int global_state_store(void); void global_state_store_running(void); -void migration_page_queue_free(MigrationState *ms); +void migration_page_queue_free(void); int ram_save_queue_pages(MigrationState *ms, const char *rbname, ram_addr_t start, ram_addr_t len); uint64_t ram_pagesize_summary(void); diff --git a/migration/migration.c b/migration/migration.c index c1730a0..5918b21 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -109,7 +109,6 @@ MigrationState *migrate_get_current(void) }; if (!once) { - qemu_mutex_init(¤t_migration.src_page_req_mutex); current_migration.parameters.tls_creds = g_strdup(""); current_migration.parameters.tls_hostname = g_strdup(""); once = true; @@ -957,7 +956,7 @@ static void migrate_fd_cleanup(void *opaque) qemu_bh_delete(s->cleanup_bh); s->cleanup_bh = NULL; - migration_page_queue_free(s); + migration_page_queue_free(); if (s->to_dst_file) { trace_migrate_fd_cleanup(); @@ -1131,8 +1130,6 @@ MigrationState *migrate_init(const MigrationParams *params) migrate_set_state(&s->state, MIGRATION_STATUS_NONE, MIGRATION_STATUS_SETUP); - QSIMPLEQ_INIT(&s->src_page_requests); - s->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); return s; } diff --git a/migration/ram.c b/migration/ram.c index cec51b4..be26d0c 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -151,6 +151,18 @@ struct RAMBitmap { }; typedef struct RAMBitmap RAMBitmap; +/* + * An outstanding page request, on the source, having been received + * and queued + */ +struct RAMSrcPageRequest { + RAMBlock *rb; + hwaddr offset; + hwaddr len; + + QSIMPLEQ_ENTRY(RAMSrcPageRequest) next_req; +}; + /* State of RAM for migration */ struct RAMState { /* Last block that we have visited searching for dirty pages */ @@ -206,6 +218,9 @@ struct RAMState { RAMBitmap *ram_bitmap; /* The RAMBlock used in the last src_page_requests */ RAMBlock *last_req_rb; + /* Queue of outstanding page requests from the destination */ + QemuMutex src_page_req_mutex; + QSIMPLEQ_HEAD(src_page_requests, RAMSrcPageRequest) src_page_requests; }; typedef struct RAMState RAMState; @@ -1085,20 +1100,20 @@ static bool find_dirty_block(RAMState *rs, QEMUFile *f, PageSearchStatus *pss, * * Returns the block of the page (or NULL if none available) * - * @ms: current migration state + * @rs: current RAM state * @offset: used to return the offset within the RAMBlock * @ram_addr_abs: pointer into which to store the address of the dirty page * within the global ram_addr space */ -static RAMBlock *unqueue_page(MigrationState *ms, ram_addr_t *offset, +static RAMBlock *unqueue_page(RAMState *rs, ram_addr_t *offset, ram_addr_t *ram_addr_abs) { RAMBlock *block = NULL; - qemu_mutex_lock(&ms->src_page_req_mutex); - if (!QSIMPLEQ_EMPTY(&ms->src_page_requests)) { - struct MigrationSrcPageRequest *entry = - QSIMPLEQ_FIRST(&ms->src_page_requests); + qemu_mutex_lock(&rs->src_page_req_mutex); + if (!QSIMPLEQ_EMPTY(&rs->src_page_requests)) { + struct RAMSrcPageRequest *entry = + QSIMPLEQ_FIRST(&rs->src_page_requests); block = entry->rb; *offset = entry->offset; *ram_addr_abs = (entry->offset + entry->rb->offset) & @@ -1109,11 +1124,11 @@ static RAMBlock *unqueue_page(MigrationState *ms, ram_addr_t *offset, entry->offset += TARGET_PAGE_SIZE; } else { memory_region_unref(block->mr); - QSIMPLEQ_REMOVE_HEAD(&ms->src_page_requests, next_req); + QSIMPLEQ_REMOVE_HEAD(&rs->src_page_requests, next_req); g_free(entry); } } - qemu_mutex_unlock(&ms->src_page_req_mutex); + qemu_mutex_unlock(&rs->src_page_req_mutex); return block; } @@ -1126,13 +1141,11 @@ static RAMBlock *unqueue_page(MigrationState *ms, ram_addr_t *offset, * Returns if a queued page is found * * @rs: current RAM state - * @ms: current migration state * @pss: data about the state of the current dirty page scan * @ram_addr_abs: pointer into which to store the address of the dirty page * within the global ram_addr space */ -static bool get_queued_page(RAMState *rs, MigrationState *ms, - PageSearchStatus *pss, +static bool get_queued_page(RAMState *rs, PageSearchStatus *pss, ram_addr_t *ram_addr_abs) { RAMBlock *block; @@ -1140,7 +1153,7 @@ static bool get_queued_page(RAMState *rs, MigrationState *ms, bool dirty; do { - block = unqueue_page(ms, &offset, ram_addr_abs); + block = unqueue_page(rs, &offset, ram_addr_abs); /* * We're sending this page, and since it's postcopy nothing else * will dirty it, and we must make sure it doesn't get sent again @@ -1194,18 +1207,18 @@ static bool get_queued_page(RAMState *rs, MigrationState *ms, * It should be empty at the end anyway, but in error cases there may * be some left. in case that there is any page left, we drop it. * - * @ms: current migration state */ -void migration_page_queue_free(MigrationState *ms) +void migration_page_queue_free(void) { - struct MigrationSrcPageRequest *mspr, *next_mspr; + struct RAMSrcPageRequest *mspr, *next_mspr; + RAMState *rs = &ram_state; /* This queue generally should be empty - but in the case of a failed * migration might have some droppings in. */ rcu_read_lock(); - QSIMPLEQ_FOREACH_SAFE(mspr, &ms->src_page_requests, next_req, next_mspr) { + QSIMPLEQ_FOREACH_SAFE(mspr, &rs->src_page_requests, next_req, next_mspr) { memory_region_unref(mspr->rb->mr); - QSIMPLEQ_REMOVE_HEAD(&ms->src_page_requests, next_req); + QSIMPLEQ_REMOVE_HEAD(&rs->src_page_requests, next_req); g_free(mspr); } rcu_read_unlock(); @@ -1262,16 +1275,16 @@ int ram_save_queue_pages(MigrationState *ms, const char *rbname, goto err; } - struct MigrationSrcPageRequest *new_entry = - g_malloc0(sizeof(struct MigrationSrcPageRequest)); + struct RAMSrcPageRequest *new_entry = + g_malloc0(sizeof(struct RAMSrcPageRequest)); new_entry->rb = ramblock; new_entry->offset = start; new_entry->len = len; memory_region_ref(ramblock->mr); - qemu_mutex_lock(&ms->src_page_req_mutex); - QSIMPLEQ_INSERT_TAIL(&ms->src_page_requests, new_entry, next_req); - qemu_mutex_unlock(&ms->src_page_req_mutex); + qemu_mutex_lock(&rs->src_page_req_mutex); + QSIMPLEQ_INSERT_TAIL(&rs->src_page_requests, new_entry, next_req); + qemu_mutex_unlock(&rs->src_page_req_mutex); rcu_read_unlock(); return 0; @@ -1410,7 +1423,7 @@ static int ram_find_and_save_block(RAMState *rs, QEMUFile *f, bool last_stage) do { again = true; - found = get_queued_page(rs, ms, &pss, &dirty_ram_abs); + found = get_queued_page(rs, &pss, &dirty_ram_abs); if (!found) { /* priority queue empty, so just search for something dirty */ @@ -1970,6 +1983,8 @@ static int ram_state_init(RAMState *rs) memset(rs, 0, sizeof(*rs)); qemu_mutex_init(&rs->bitmap_mutex); + qemu_mutex_init(&rs->src_page_req_mutex); + QSIMPLEQ_INIT(&rs->src_page_requests); if (migrate_use_xbzrle()) { XBZRLE_cache_lock();