From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVVqd-00040r-OG for qemu-devel@nongnu.org; Tue, 10 Mar 2015 21:54:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVVqZ-0007Hp-MC for qemu-devel@nongnu.org; Tue, 10 Mar 2015 21:54:11 -0400 Received: from ozlabs.org ([103.22.144.67]:48552) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVVqZ-0007GK-2Z for qemu-devel@nongnu.org; Tue, 10 Mar 2015 21:54:07 -0400 Date: Wed, 11 Mar 2015 12:54:42 +1100 From: David Gibson Message-ID: <20150311015442.GM11973@voom.redhat.com> References: <1424883128-9841-1-git-send-email-dgilbert@redhat.com> <1424883128-9841-12-git-send-email-dgilbert@redhat.com> <20150310054725.GC11973@voom.redhat.com> <20150310143402.GB18865@work-vm> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="+nG9yj4eE4W6Oba0" Content-Disposition: inline In-Reply-To: <20150310143402.GB18865@work-vm> Subject: Re: [Qemu-devel] [PATCH v5 11/45] Return path: Send responses from destination to source 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, pbonzini@redhat.com, yanghy@cn.fujitsu.com --+nG9yj4eE4W6Oba0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 10, 2015 at 02:34:03PM +0000, Dr. David Alan Gilbert wrote: > * David Gibson (david@gibson.dropbear.id.au) wrote: > > On Wed, Feb 25, 2015 at 04:51:34PM +0000, Dr. David Alan Gilbert (git) = wrote: > > > From: "Dr. David Alan Gilbert" > > >=20 > > > Add migrate_send_rp_message to send a message from destination to sou= rce along the return path. > > > (It uses a mutex to let it be called from multiple threads) > > > Add migrate_send_rp_shut to send a 'shut' message to indicate > > > the destination is finished with the RP. > > > Add migrate_send_rp_ack to send a 'PONG' message in response to a PING > > > Use it in the CMD_PING handler > > >=20 > > > Signed-off-by: Dr. David Alan Gilbert > > > --- > > > include/migration/migration.h | 17 ++++++++++++++++ > > > migration/migration.c | 45 +++++++++++++++++++++++++++++++++= ++++++++++ > > > savevm.c | 2 +- > > > trace-events | 1 + > > > 4 files changed, 64 insertions(+), 1 deletion(-) > > >=20 > > > diff --git a/include/migration/migration.h b/include/migration/migrat= ion.h > > > index c514dd4..6775747 100644 > > > --- a/include/migration/migration.h > > > +++ b/include/migration/migration.h > > > @@ -41,6 +41,13 @@ struct MigrationParams { > > > bool shared; > > > }; > > > =20 > > > +/* Commands sent on the return path from destination to source*/ > > > +enum mig_rpcomm_cmd { > >=20 > > "command" doesn't seem like quite the right description for these rp > > messages. >=20 > Would you prefer 'message' ? Perhaps "message type" to distinguish from the the blob including both tag and data. > > > + MIG_RP_CMD_INVALID =3D 0, /* Must be 0 */ > > > + MIG_RP_CMD_SHUT, /* sibling will not send any more RP me= ssages */ > > > + MIG_RP_CMD_PONG, /* Response to a PING; data (seq: be32 = ) */ > > > +}; > > > + > > > typedef struct MigrationState MigrationState; > > > =20 > > > /* State for the incoming migration */ > > > @@ -48,6 +55,7 @@ struct MigrationIncomingState { > > > QEMUFile *file; > > > =20 > > > QEMUFile *return_path; > > > + QemuMutex rp_mutex; /* We send replies from multiple thr= eads */ > > > }; > > > =20 > > > MigrationIncomingState *migration_incoming_get_current(void); > > > @@ -169,6 +177,15 @@ int64_t migrate_xbzrle_cache_size(void); > > > =20 > > > int64_t xbzrle_cache_resize(int64_t new_size); > > > =20 > > > +/* Sending on the return path - generic and then for each message ty= pe */ > > > +void migrate_send_rp_message(MigrationIncomingState *mis, > > > + enum mig_rpcomm_cmd cmd, > > > + uint16_t len, uint8_t *data); > > > +void migrate_send_rp_shut(MigrationIncomingState *mis, > > > + uint32_t value); > > > +void migrate_send_rp_pong(MigrationIncomingState *mis, > > > + uint32_t value); > > > + > > > void ram_control_before_iterate(QEMUFile *f, uint64_t flags); > > > void ram_control_after_iterate(QEMUFile *f, uint64_t flags); > > > void ram_control_load_hook(QEMUFile *f, uint64_t flags); > > > diff --git a/migration/migration.c b/migration/migration.c > > > index a36ea65..80d234c 100644 > > > --- a/migration/migration.c > > > +++ b/migration/migration.c > > > @@ -78,6 +78,7 @@ MigrationIncomingState *migration_incoming_state_ne= w(QEMUFile* f) > > > { > > > mis_current =3D g_malloc0(sizeof(MigrationIncomingState)); > > > mis_current->file =3D f; > > > + qemu_mutex_init(&mis_current->rp_mutex); > > > =20 > > > return mis_current; > > > } > > > @@ -88,6 +89,50 @@ void migration_incoming_state_destroy(void) > > > mis_current =3D NULL; > > > } > > > =20 > > > +/* > > > + * Send a message on the return channel back to the source > > > + * of the migration. > > > + */ > > > +void migrate_send_rp_message(MigrationIncomingState *mis, > > > + enum mig_rpcomm_cmd cmd, > > > + uint16_t len, uint8_t *data) > >=20 > > Using (void *) for data would avoid casts in a bunch of the callers. >=20 > Fixed; thanks. >=20 > > > +{ > > > + trace_migrate_send_rp_message((int)cmd, len); > > > + qemu_mutex_lock(&mis->rp_mutex); > > > + qemu_put_be16(mis->return_path, (unsigned int)cmd); > > > + qemu_put_be16(mis->return_path, len); > > > + qemu_put_buffer(mis->return_path, data, len); > > > + qemu_fflush(mis->return_path); > > > + qemu_mutex_unlock(&mis->rp_mutex); > > > +} > > > + > > > +/* > > > + * Send a 'SHUT' message on the return channel with the given value > > > + * to indicate that we've finished with the RP. None-0 value indica= tes > > > + * error. > > > + */ > > > +void migrate_send_rp_shut(MigrationIncomingState *mis, > > > + uint32_t value) > > > +{ > > > + uint32_t buf; > > > + > > > + buf =3D cpu_to_be32(value); > > > + migrate_send_rp_message(mis, MIG_RP_CMD_SHUT, 4, (uint8_t *)&buf= ); > >=20 > > ^ sizeof(buf) > > would be safer >=20 > Done. >=20 > > > +} > > > + > > > +/* > > > + * Send a 'PONG' message on the return channel with the given value > > > + * (normally in response to a 'PING') > > > + */ > > > +void migrate_send_rp_pong(MigrationIncomingState *mis, > > > + uint32_t value) > > > +{ > > > + uint32_t buf; > > > + > > > + buf =3D cpu_to_be32(value); > > > + migrate_send_rp_message(mis, MIG_RP_CMD_PONG, 4, (uint8_t *)&buf= ); > >=20 > > It occurs to me that you could define PONG as returning the whole > > buffer that PING sends, instead of just 4-bytes. Might allow for some > > more testing of variable sized messages. >=20 > Yes; although it would complicate things a lot if I made it fully generic > because I'd have to worry about allocating a buffer etc and I'm not > making vast use of the 4 bytes I've already got. Couldn't migrate_send_rp_pong just take a buf pointer and length, then you can point that directly at the buffer in the ping message you've received. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --+nG9yj4eE4W6Oba0 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJU/6BiAAoJEGw4ysog2bOSwvgQAMiW3hTIBRfviQorhnyaw4QO UmmJxw1wkRNCBx9rBKGvvDcBdOEyxzNUOu+B22vIXnfmX4zGEGC5vmVEgFymw81b 9FVvVP1F8KnnGaCOHwX9OuuExK+FIU2toO6IaC7dfZGzqeVdsCFN/hkmy7AwcHva peR71czNcxGghF1T8EyGHpB7n/9aOdBb3mO0HmyrwRcKmojZFoo93hzGC09u5NGG nrRyG+raza+ClPlIttUoG9GLpcPtJ8zHQ8A0xDwUG2v28TmI/dSmKLe03J05LJfw bGaonWt8yub22L9ziBbgFeIrXTWoZsizK900AOgeAI84fiKhtCCR2HQkUXPFOh4L gJNTdqKri2juqz9OwwQWMZGaI1kJR0wpDXwe87Hcn0ehMfWVEBKXv72lmwlHz4V9 rmqfFskXNtxpJg68BndgDp819W/bLUrgPcXKIXOscl/2UW4eTWFiloL7aa6UA/Po AfzC7Nfyw42h/7snuFZ83VG+xHKBDBwEf2tm6cRbOa4eQ6uBdC/EowZR0hYSv9Gs cyEedx+oT1vxtHy344olk7BtuDaOVarTcKMalChEts5ZJ6Wt3sY3xn94LddXWyHl z3Z1iZt1qLXTx2dWa87v/8lHXfVB48qupuHfnXjkBQmv/aWSMC2DkaxDrRQQ1+u9 Nq7h45ZbyJCjcs+8UDD0 =fdOs -----END PGP SIGNATURE----- --+nG9yj4eE4W6Oba0--