From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ycu4i-0004q0-9v for qemu-devel@nongnu.org; Tue, 31 Mar 2015 07:11:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ycu4c-0005eW-4s for qemu-devel@nongnu.org; Tue, 31 Mar 2015 07:11:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37247) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ycu4b-0005eK-NB for qemu-devel@nongnu.org; Tue, 31 Mar 2015 07:11:10 -0400 Message-ID: <551A80C2.1060501@redhat.com> Date: Tue, 31 Mar 2015 13:10:58 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1424883128-9841-1-git-send-email-dgilbert@redhat.com> <1424883128-9841-18-git-send-email-dgilbert@redhat.com> <5516CC19.7080004@redhat.com> <20150330174646.GI2474@work-vm> <5519A2BE.1010201@redhat.com> <20150331110520.GA7687@work-vm> In-Reply-To: <20150331110520.GA7687@work-vm> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v5 17/45] Add wrappers and handlers for sending/receiving the postcopy-ram migration messages. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert" Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, quintela@redhat.com, qemu-devel@nongnu.org, amit.shah@redhat.com, yanghy@cn.fujitsu.com, david@gibson.dropbear.id.au On 31/03/2015 13:05, Dr. David Alan Gilbert wrote: > * Paolo Bonzini (pbonzini@redhat.com) wrote: >> >> >> On 30/03/2015 19:46, Dr. David Alan Gilbert wrote: >>>>>>> +PostcopyState postcopy_state_get(MigrationIncomingState *mis) >>>>>>> +{ >>>>>>> + return atomic_fetch_add(&mis->postcopy_state, 0); >>>>>>> +} >>>>>>> + >>>>>>> +/* Set the state and return the old state */ >>>>>>> +PostcopyState postcopy_state_set(MigrationIncomingState *mis, >>>>>>> + PostcopyState new_state) >>>>>>> +{ >>>>>>> + return atomic_xchg(&mis->postcopy_state, new_state); >>>>>>> +} >>>>> >>>>> Which are the (multiple) threads are calling these functions? >>> The main thread receiving the migration and the postcopy ram_listen_thread >>> receiving the RAM pages. >>> It's not actually racy between multiple threads updating it, >>> it's sequenced so that the main thread initialises it and then >>> hands over to the listen thread that takes it over from that point. >> >> I would use atomic_mb_read/atomic_mb_set here. > > The benefit of the atomic_xchg is that I get the old value back so > that I can sanity check I was in the state I thought I should have > been. Ok, you can still pair atomic_xchg with atomic_mb_read, it's a bit cheaper. Paolo