migration: hold the lock only if it is really needed
authorXiao Guangrong <xiaoguangrong@tencent.com>
Tue, 21 Aug 2018 08:10:25 +0000 (16:10 +0800)
committerJuan Quintela <quintela@redhat.com>
Wed, 22 Aug 2018 10:36:18 +0000 (12:36 +0200)
Try to hold src_page_req_mutex only if the queue is not
empty

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Xiao Guangrong <xiaoguangrong@tencent.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
include/qemu/queue.h
migration/ram.c

index 59fd1203a1a323637fe16009c5b0a1f3cd7319a9..ac418efc43d8264f88aa18f01491983babde9a39 100644 (file)
@@ -341,6 +341,7 @@ struct {                                                                \
 /*
  * Simple queue access methods.
  */
+#define QSIMPLEQ_EMPTY_ATOMIC(head) (atomic_read(&((head)->sqh_first)) == NULL)
 #define QSIMPLEQ_EMPTY(head)        ((head)->sqh_first == NULL)
 #define QSIMPLEQ_FIRST(head)        ((head)->sqh_first)
 #define QSIMPLEQ_NEXT(elm, field)   ((elm)->field.sqe_next)
index 40013e68a1d051ed28cef515783a8a2cf86a9853..79c89425a34e2eb3daaaf964129fcb81a606dab5 100644 (file)
@@ -2033,6 +2033,10 @@ static RAMBlock *unqueue_page(RAMState *rs, ram_addr_t *offset)
 {
     RAMBlock *block = NULL;
 
+    if (QSIMPLEQ_EMPTY_ATOMIC(&rs->src_page_requests)) {
+        return NULL;
+    }
+
     qemu_mutex_lock(&rs->src_page_req_mutex);
     if (!QSIMPLEQ_EMPTY(&rs->src_page_requests)) {
         struct RAMSrcPageRequest *entry =