Message ID | 20200211235635.488-4-gurchetansingh@chromium.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | *** Delay enqueuing context create command *** | expand |
Hi, > --- a/drivers/gpu/drm/virtio/virtgpu_kms.c > +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c > @@ -270,7 +270,9 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file) > return id; > } > > + > vfpriv->ctx_id = id; checkpatch warning here: -:52: CHECK:LINE_SPACING: Please don't use multiple blank lines #52: FILE: drivers/gpu/drm/virtio/virtgpu_kms.c:276: cheers, Gerd
On Tue, Feb 11, 2020 at 3:56 PM Gurchetan Singh <gurchetansingh@chromium.org> wrote: > > We only want create a new virglrenderer context after the first > 3D ioctl. > > Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org> > --- > drivers/gpu/drm/virtio/virtgpu_drv.h | 1 + > drivers/gpu/drm/virtio/virtgpu_ioctl.c | 5 +++++ > drivers/gpu/drm/virtio/virtgpu_kms.c | 2 ++ > 3 files changed, 8 insertions(+) > > diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h > index edaa7b8224a8..93ce69c0d9be 100644 > --- a/drivers/gpu/drm/virtio/virtgpu_drv.h > +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h > @@ -209,6 +209,7 @@ struct virtio_gpu_device { > > struct virtio_gpu_fpriv { > uint32_t ctx_id; > + atomic_t context_initiated; > }; > /* virtio_ioctl.c */ > diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c > index f1afabaa3a08..858ee153fb18 100644 > --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c > +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c > @@ -44,9 +44,14 @@ void virtio_gpu_create_context(struct drm_device *dev, > if (!vgdev->has_virgl_3d) > return; > > + if (atomic_read(&vfpriv->context_initiated)) > + return; > + > get_task_comm(dbgname, current); > virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id, > strlen(dbgname), dbgname); > + > + atomic_inc(&vfpriv->context_initiated); > } This needs to be protected with a lock. ctx_id can probably be generated here as well. > > static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data, > diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c > index e1e1c0821a35..64fe5fcbedfd 100644 > --- a/drivers/gpu/drm/virtio/virtgpu_kms.c > +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c > @@ -270,7 +270,9 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file) > return id; > } > > + > vfpriv->ctx_id = id; > + atomic_set(&vfpriv->context_initiated, 0); > file->driver_priv = vfpriv; > virtio_gpu_create_context(dev, file); > > -- > 2.25.0.225.g125e21ebc7-goog >
On Wed, Feb 12, 2020 at 10:50 AM Chia-I Wu <olvaffe@gmail.com> wrote: > > On Tue, Feb 11, 2020 at 3:56 PM Gurchetan Singh > <gurchetansingh@chromium.org> wrote: > > > > We only want create a new virglrenderer context after the first > > 3D ioctl. > > > > Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org> > > --- > > drivers/gpu/drm/virtio/virtgpu_drv.h | 1 + > > drivers/gpu/drm/virtio/virtgpu_ioctl.c | 5 +++++ > > drivers/gpu/drm/virtio/virtgpu_kms.c | 2 ++ > > 3 files changed, 8 insertions(+) > > > > diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h > > index edaa7b8224a8..93ce69c0d9be 100644 > > --- a/drivers/gpu/drm/virtio/virtgpu_drv.h > > +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h > > @@ -209,6 +209,7 @@ struct virtio_gpu_device { > > > > struct virtio_gpu_fpriv { > > uint32_t ctx_id; > > + atomic_t context_initiated; > > }; > > /* virtio_ioctl.c */ > > diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c > > index f1afabaa3a08..858ee153fb18 100644 > > --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c > > +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c > > @@ -44,9 +44,14 @@ void virtio_gpu_create_context(struct drm_device *dev, > > if (!vgdev->has_virgl_3d) > > return; > > > > + if (atomic_read(&vfpriv->context_initiated)) > > + return; > > + > > get_task_comm(dbgname, current); > > virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id, > > strlen(dbgname), dbgname); > > + > > + atomic_inc(&vfpriv->context_initiated); > > } > This needs to be protected with a lock. What do you think about atomic_add_unless(&vfpriv->context_initiated, 1, 1)? > ctx_id can probably be > generated here as well. If we generate the context id in virtio_gpu_create_context, we'll have to add error checking in all of the ioctl call-sites (since ida_alloc may fail). int virtio_gpu_create_context(..) ret = virtio_gpu_create_context(dev, file); if (ret) return -EINVAL vs. void virtio_gpu_create_context(..) virtio_gpu_create_context(..) Any strong opinions here? > > > > > static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data, > > diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c > > index e1e1c0821a35..64fe5fcbedfd 100644 > > --- a/drivers/gpu/drm/virtio/virtgpu_kms.c > > +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c > > @@ -270,7 +270,9 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file) > > return id; > > } > > > > + > > vfpriv->ctx_id = id; > > + atomic_set(&vfpriv->context_initiated, 0); > > file->driver_priv = vfpriv; > > virtio_gpu_create_context(dev, file); > > > > -- > > 2.25.0.225.g125e21ebc7-goog > >
On Wed, Feb 12, 2020 at 5:54 PM Gurchetan Singh <gurchetansingh@chromium.org> wrote: > > On Wed, Feb 12, 2020 at 10:50 AM Chia-I Wu <olvaffe@gmail.com> wrote: > > > > On Tue, Feb 11, 2020 at 3:56 PM Gurchetan Singh > > <gurchetansingh@chromium.org> wrote: > > > > > > We only want create a new virglrenderer context after the first > > > 3D ioctl. > > > > > > Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org> > > > --- > > > drivers/gpu/drm/virtio/virtgpu_drv.h | 1 + > > > drivers/gpu/drm/virtio/virtgpu_ioctl.c | 5 +++++ > > > drivers/gpu/drm/virtio/virtgpu_kms.c | 2 ++ > > > 3 files changed, 8 insertions(+) > > > > > > diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h > > > index edaa7b8224a8..93ce69c0d9be 100644 > > > --- a/drivers/gpu/drm/virtio/virtgpu_drv.h > > > +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h > > > @@ -209,6 +209,7 @@ struct virtio_gpu_device { > > > > > > struct virtio_gpu_fpriv { > > > uint32_t ctx_id; > > > + atomic_t context_initiated; > > > }; > > > /* virtio_ioctl.c */ > > > diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c > > > index f1afabaa3a08..858ee153fb18 100644 > > > --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c > > > +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c > > > @@ -44,9 +44,14 @@ void virtio_gpu_create_context(struct drm_device *dev, > > > if (!vgdev->has_virgl_3d) > > > return; > > > > > > + if (atomic_read(&vfpriv->context_initiated)) > > > + return; > > > + > > > get_task_comm(dbgname, current); > > > virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id, > > > strlen(dbgname), dbgname); > > > + > > > + atomic_inc(&vfpriv->context_initiated); > > > } > > This needs to be protected with a lock. > > What do you think about atomic_add_unless(&vfpriv->context_initiated, 1, 1)? Does that prevent virtio_gpu_cmd_context_create from being called more than once when two threads call this function at the same time? > > > ctx_id can probably be > > generated here as well. > > If we generate the context id in virtio_gpu_create_context, we'll have > to add error checking in all of the ioctl call-sites (since ida_alloc > may fail). > > int virtio_gpu_create_context(..) > ret = virtio_gpu_create_context(dev, file); > if (ret) > return -EINVAL > > vs. > > void virtio_gpu_create_context(..) > virtio_gpu_create_context(..) > > Any strong opinions here? Yeah, the current way should be better... unless we decide to make virtio_gpu_cmd_context_create synchronous and check for errors. > > > > > > > > > static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data, > > > diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c > > > index e1e1c0821a35..64fe5fcbedfd 100644 > > > --- a/drivers/gpu/drm/virtio/virtgpu_kms.c > > > +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c > > > @@ -270,7 +270,9 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file) > > > return id; > > > } > > > > > > + > > > vfpriv->ctx_id = id; > > > + atomic_set(&vfpriv->context_initiated, 0); > > > file->driver_priv = vfpriv; > > > virtio_gpu_create_context(dev, file); > > > > > > -- > > > 2.25.0.225.g125e21ebc7-goog > > >
diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index edaa7b8224a8..93ce69c0d9be 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -209,6 +209,7 @@ struct virtio_gpu_device { struct virtio_gpu_fpriv { uint32_t ctx_id; + atomic_t context_initiated; }; /* virtio_ioctl.c */ diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index f1afabaa3a08..858ee153fb18 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -44,9 +44,14 @@ void virtio_gpu_create_context(struct drm_device *dev, if (!vgdev->has_virgl_3d) return; + if (atomic_read(&vfpriv->context_initiated)) + return; + get_task_comm(dbgname, current); virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id, strlen(dbgname), dbgname); + + atomic_inc(&vfpriv->context_initiated); } static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data, diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c index e1e1c0821a35..64fe5fcbedfd 100644 --- a/drivers/gpu/drm/virtio/virtgpu_kms.c +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c @@ -270,7 +270,9 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file) return id; } + vfpriv->ctx_id = id; + atomic_set(&vfpriv->context_initiated, 0); file->driver_priv = vfpriv; virtio_gpu_create_context(dev, file);
We only want create a new virglrenderer context after the first 3D ioctl. Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org> --- drivers/gpu/drm/virtio/virtgpu_drv.h | 1 + drivers/gpu/drm/virtio/virtgpu_ioctl.c | 5 +++++ drivers/gpu/drm/virtio/virtgpu_kms.c | 2 ++ 3 files changed, 8 insertions(+)