All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vfio/migration: Improve to read/write full migration region per chunk
@ 2021-11-11  9:50 Yishai Hadas
  2021-11-22  7:40 ` Yishai Hadas
  2021-11-25 16:33 ` Cornelia Huck
  0 siblings, 2 replies; 4+ messages in thread
From: Yishai Hadas @ 2021-11-11  9:50 UTC (permalink / raw)
  To: alex.williamson; +Cc: jgg, qemu-devel, kwankhede, cohuck, yishaih, maorg

Upon reading/writing the migration data there is no real reason to limit
the read/write system call from the file to be 8 bytes.

In addition, there is no reason to depend on the file offset alignment.
The offset is just some logical value which depends also on the region
index and has nothing to do with the amount of data that can be
accessed.

Move to read/write the full region size per chunk, this reduces
dramatically the number of the systems calls that are needed and improve
performance.

Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
---
 hw/vfio/migration.c | 36 ++----------------------------------
 1 file changed, 2 insertions(+), 34 deletions(-)

diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index ff6b45de6b5..b5f310bb831 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -62,40 +62,8 @@ static inline int vfio_mig_access(VFIODevice *vbasedev, void *val, int count,
     return 0;
 }
 
-static int vfio_mig_rw(VFIODevice *vbasedev, __u8 *buf, size_t count,
-                       off_t off, bool iswrite)
-{
-    int ret, done = 0;
-    __u8 *tbuf = buf;
-
-    while (count) {
-        int bytes = 0;
-
-        if (count >= 8 && !(off % 8)) {
-            bytes = 8;
-        } else if (count >= 4 && !(off % 4)) {
-            bytes = 4;
-        } else if (count >= 2 && !(off % 2)) {
-            bytes = 2;
-        } else {
-            bytes = 1;
-        }
-
-        ret = vfio_mig_access(vbasedev, tbuf, bytes, off, iswrite);
-        if (ret) {
-            return ret;
-        }
-
-        count -= bytes;
-        done += bytes;
-        off += bytes;
-        tbuf += bytes;
-    }
-    return done;
-}
-
-#define vfio_mig_read(f, v, c, o)       vfio_mig_rw(f, (__u8 *)v, c, o, false)
-#define vfio_mig_write(f, v, c, o)      vfio_mig_rw(f, (__u8 *)v, c, o, true)
+#define vfio_mig_read(f, v, c, o)       vfio_mig_access(f, (__u8 *)v, c, o, false)
+#define vfio_mig_write(f, v, c, o)      vfio_mig_access(f, (__u8 *)v, c, o, true)
 
 #define VFIO_MIG_STRUCT_OFFSET(f)       \
                                  offsetof(struct vfio_device_migration_info, f)
-- 
2.18.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] vfio/migration: Improve to read/write full migration region per chunk
  2021-11-11  9:50 [PATCH] vfio/migration: Improve to read/write full migration region per chunk Yishai Hadas
@ 2021-11-22  7:40 ` Yishai Hadas
  2021-11-22 13:38   ` Alex Williamson
  2021-11-25 16:33 ` Cornelia Huck
  1 sibling, 1 reply; 4+ messages in thread
From: Yishai Hadas @ 2021-11-22  7:40 UTC (permalink / raw)
  To: alex.williamson, Dr. David Alan Gilbert
  Cc: jgg, qemu-devel, kwankhede, cohuck, maorg, cjia

Gentle ping for review, CCing more people who may be involved.

Thanks,
Yishai

On 11/11/2021 11:50 AM, Yishai Hadas wrote:
> Upon reading/writing the migration data there is no real reason to limit
> the read/write system call from the file to be 8 bytes.
>
> In addition, there is no reason to depend on the file offset alignment.
> The offset is just some logical value which depends also on the region
> index and has nothing to do with the amount of data that can be
> accessed.
>
> Move to read/write the full region size per chunk, this reduces
> dramatically the number of the systems calls that are needed and improve
> performance.
>
> Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
> ---
>   hw/vfio/migration.c | 36 ++----------------------------------
>   1 file changed, 2 insertions(+), 34 deletions(-)
>
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index ff6b45de6b5..b5f310bb831 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -62,40 +62,8 @@ static inline int vfio_mig_access(VFIODevice *vbasedev, void *val, int count,
>       return 0;
>   }
>   
> -static int vfio_mig_rw(VFIODevice *vbasedev, __u8 *buf, size_t count,
> -                       off_t off, bool iswrite)
> -{
> -    int ret, done = 0;
> -    __u8 *tbuf = buf;
> -
> -    while (count) {
> -        int bytes = 0;
> -
> -        if (count >= 8 && !(off % 8)) {
> -            bytes = 8;
> -        } else if (count >= 4 && !(off % 4)) {
> -            bytes = 4;
> -        } else if (count >= 2 && !(off % 2)) {
> -            bytes = 2;
> -        } else {
> -            bytes = 1;
> -        }
> -
> -        ret = vfio_mig_access(vbasedev, tbuf, bytes, off, iswrite);
> -        if (ret) {
> -            return ret;
> -        }
> -
> -        count -= bytes;
> -        done += bytes;
> -        off += bytes;
> -        tbuf += bytes;
> -    }
> -    return done;
> -}
> -
> -#define vfio_mig_read(f, v, c, o)       vfio_mig_rw(f, (__u8 *)v, c, o, false)
> -#define vfio_mig_write(f, v, c, o)      vfio_mig_rw(f, (__u8 *)v, c, o, true)
> +#define vfio_mig_read(f, v, c, o)       vfio_mig_access(f, (__u8 *)v, c, o, false)
> +#define vfio_mig_write(f, v, c, o)      vfio_mig_access(f, (__u8 *)v, c, o, true)
>   
>   #define VFIO_MIG_STRUCT_OFFSET(f)       \
>                                    offsetof(struct vfio_device_migration_info, f)




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] vfio/migration: Improve to read/write full migration region per chunk
  2021-11-22  7:40 ` Yishai Hadas
@ 2021-11-22 13:38   ` Alex Williamson
  0 siblings, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2021-11-22 13:38 UTC (permalink / raw)
  To: Yishai Hadas
  Cc: cjia, cohuck, Dr. David Alan Gilbert, qemu-devel, kwankhede, jgg, maorg

On Mon, 22 Nov 2021 09:40:56 +0200
Yishai Hadas <yishaih@nvidia.com> wrote:

> Gentle ping for review, CCing more people who may be involved.

I'll wait for comments from others, but since we're already in the 6.2
freeze and vfio migration is still experimental (and I'm on PTO this
week), I expect this to be queued when the next development window
opens.  Thanks,

Alex


> On 11/11/2021 11:50 AM, Yishai Hadas wrote:
> > Upon reading/writing the migration data there is no real reason to limit
> > the read/write system call from the file to be 8 bytes.
> >
> > In addition, there is no reason to depend on the file offset alignment.
> > The offset is just some logical value which depends also on the region
> > index and has nothing to do with the amount of data that can be
> > accessed.
> >
> > Move to read/write the full region size per chunk, this reduces
> > dramatically the number of the systems calls that are needed and improve
> > performance.
> >
> > Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
> > ---
> >   hw/vfio/migration.c | 36 ++----------------------------------
> >   1 file changed, 2 insertions(+), 34 deletions(-)
> >
> > diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> > index ff6b45de6b5..b5f310bb831 100644
> > --- a/hw/vfio/migration.c
> > +++ b/hw/vfio/migration.c
> > @@ -62,40 +62,8 @@ static inline int vfio_mig_access(VFIODevice *vbasedev, void *val, int count,
> >       return 0;
> >   }
> >   
> > -static int vfio_mig_rw(VFIODevice *vbasedev, __u8 *buf, size_t count,
> > -                       off_t off, bool iswrite)
> > -{
> > -    int ret, done = 0;
> > -    __u8 *tbuf = buf;
> > -
> > -    while (count) {
> > -        int bytes = 0;
> > -
> > -        if (count >= 8 && !(off % 8)) {
> > -            bytes = 8;
> > -        } else if (count >= 4 && !(off % 4)) {
> > -            bytes = 4;
> > -        } else if (count >= 2 && !(off % 2)) {
> > -            bytes = 2;
> > -        } else {
> > -            bytes = 1;
> > -        }
> > -
> > -        ret = vfio_mig_access(vbasedev, tbuf, bytes, off, iswrite);
> > -        if (ret) {
> > -            return ret;
> > -        }
> > -
> > -        count -= bytes;
> > -        done += bytes;
> > -        off += bytes;
> > -        tbuf += bytes;
> > -    }
> > -    return done;
> > -}
> > -
> > -#define vfio_mig_read(f, v, c, o)       vfio_mig_rw(f, (__u8 *)v, c, o, false)
> > -#define vfio_mig_write(f, v, c, o)      vfio_mig_rw(f, (__u8 *)v, c, o, true)
> > +#define vfio_mig_read(f, v, c, o)       vfio_mig_access(f, (__u8 *)v, c, o, false)
> > +#define vfio_mig_write(f, v, c, o)      vfio_mig_access(f, (__u8 *)v, c, o, true)
> >   
> >   #define VFIO_MIG_STRUCT_OFFSET(f)       \
> >                                    offsetof(struct vfio_device_migration_info, f)  
> 
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] vfio/migration: Improve to read/write full migration region per chunk
  2021-11-11  9:50 [PATCH] vfio/migration: Improve to read/write full migration region per chunk Yishai Hadas
  2021-11-22  7:40 ` Yishai Hadas
@ 2021-11-25 16:33 ` Cornelia Huck
  1 sibling, 0 replies; 4+ messages in thread
From: Cornelia Huck @ 2021-11-25 16:33 UTC (permalink / raw)
  To: Yishai Hadas, alex.williamson; +Cc: kwankhede, yishaih, maorg, qemu-devel, jgg

On Thu, Nov 11 2021, Yishai Hadas <yishaih@nvidia.com> wrote:

> Upon reading/writing the migration data there is no real reason to limit
> the read/write system call from the file to be 8 bytes.
>
> In addition, there is no reason to depend on the file offset alignment.
> The offset is just some logical value which depends also on the region
> index and has nothing to do with the amount of data that can be
> accessed.
>
> Move to read/write the full region size per chunk, this reduces
> dramatically the number of the systems calls that are needed and improve
> performance.
>
> Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
> ---
>  hw/vfio/migration.c | 36 ++----------------------------------
>  1 file changed, 2 insertions(+), 34 deletions(-)
>
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index ff6b45de6b5..b5f310bb831 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -62,40 +62,8 @@ static inline int vfio_mig_access(VFIODevice *vbasedev, void *val, int count,
>      return 0;
>  }
>  
> -static int vfio_mig_rw(VFIODevice *vbasedev, __u8 *buf, size_t count,
> -                       off_t off, bool iswrite)
> -{
> -    int ret, done = 0;
> -    __u8 *tbuf = buf;
> -
> -    while (count) {
> -        int bytes = 0;
> -
> -        if (count >= 8 && !(off % 8)) {
> -            bytes = 8;
> -        } else if (count >= 4 && !(off % 4)) {
> -            bytes = 4;
> -        } else if (count >= 2 && !(off % 2)) {
> -            bytes = 2;
> -        } else {
> -            bytes = 1;
> -        }
> -
> -        ret = vfio_mig_access(vbasedev, tbuf, bytes, off, iswrite);
> -        if (ret) {
> -            return ret;
> -        }
> -
> -        count -= bytes;
> -        done += bytes;
> -        off += bytes;
> -        tbuf += bytes;
> -    }
> -    return done;
> -}
> -
> -#define vfio_mig_read(f, v, c, o)       vfio_mig_rw(f, (__u8 *)v, c, o, false)
> -#define vfio_mig_write(f, v, c, o)      vfio_mig_rw(f, (__u8 *)v, c, o, true)
> +#define vfio_mig_read(f, v, c, o)       vfio_mig_access(f, (__u8 *)v, c, o, false)
> +#define vfio_mig_write(f, v, c, o)      vfio_mig_access(f, (__u8 *)v, c, o, true)
>  
>  #define VFIO_MIG_STRUCT_OFFSET(f)       \
>                                   offsetof(struct vfio_device_migration_info, f)

I've been looking at this patch and it doesn't look wrong to me in any
obvious way. The question is: why had it been done like that in the
first place?

I dug through the old mailing list discussions, and it seems it had been
introduced in v26, but I don't see any explanation for that. Kirti, do
you remember why you added this?



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-25 16:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-11  9:50 [PATCH] vfio/migration: Improve to read/write full migration region per chunk Yishai Hadas
2021-11-22  7:40 ` Yishai Hadas
2021-11-22 13:38   ` Alex Williamson
2021-11-25 16:33 ` Cornelia Huck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.