[PATCH v2] drm/i915/gvt: free workload in vgpu release
Zhang, Xiong Y
xiong.y.zhang at intel.com
Fri Aug 10 03:07:54 UTC 2018
> From: Hang Yuan <hang.yuan at linux.intel.com>
>
> Some workloads may be prepared in vgpu's queue but not be scheduled to
> run yet. If vgpu is released at this time, they will not be freed in workload
> complete callback and so need to be freed in vgpu release operation.
>
> Add new vgpu_release operation in gvt_ops to stop vgpu and release runtime
> resources. gvt_ops vgpu_deactivate operation will only stop vgpu.
>
> v2: add new gvt ops to clean vgpu running status (Xiong Zhang)
>
> Signed-off-by: Hang Yuan <hang.yuan at linux.intel.com>
[Zhang, Xiong Y] Reviewed-by: Xiong Zhang <xiong.y.zhang at intel.com>
thanks
> ---
> drivers/gpu/drm/i915/gvt/gvt.c | 1 +
> drivers/gpu/drm/i915/gvt/gvt.h | 4 +++-
> drivers/gpu/drm/i915/gvt/kvmgt.c | 2 +-
> drivers/gpu/drm/i915/gvt/scheduler.c | 7 ++++---
> drivers/gpu/drm/i915/gvt/scheduler.h | 3 +++
> drivers/gpu/drm/i915/gvt/vgpu.c | 22 ++++++++++++++++++++--
> 6 files changed, 32 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c
> index 3babc4e..46c8b72 100644
> --- a/drivers/gpu/drm/i915/gvt/gvt.c
> +++ b/drivers/gpu/drm/i915/gvt/gvt.c
> @@ -176,6 +176,7 @@ static const struct intel_gvt_ops intel_gvt_ops = {
> .emulate_mmio_write = intel_vgpu_emulate_mmio_write,
> .vgpu_create = intel_gvt_create_vgpu,
> .vgpu_destroy = intel_gvt_destroy_vgpu,
> + .vgpu_release = intel_gvt_release_vgpu,
> .vgpu_reset = intel_gvt_reset_vgpu,
> .vgpu_activate = intel_gvt_activate_vgpu,
> .vgpu_deactivate = intel_gvt_deactivate_vgpu, diff --git
> a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h index
> 9a96715..31f6cdb 100644
> --- a/drivers/gpu/drm/i915/gvt/gvt.h
> +++ b/drivers/gpu/drm/i915/gvt/gvt.h
> @@ -486,6 +486,7 @@ void intel_gvt_destroy_idle_vgpu(struct intel_vgpu
> *vgpu); struct intel_vgpu *intel_gvt_create_vgpu(struct intel_gvt *gvt,
> struct intel_vgpu_type *type);
> void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu);
> +void intel_gvt_release_vgpu(struct intel_vgpu *vgpu);
> void intel_gvt_reset_vgpu_locked(struct intel_vgpu *vgpu, bool dmlr,
> unsigned int engine_mask);
> void intel_gvt_reset_vgpu(struct intel_vgpu *vgpu); @@ -563,7 +564,8 @@
> struct intel_gvt_ops {
> unsigned int);
> struct intel_vgpu *(*vgpu_create)(struct intel_gvt *,
> struct intel_vgpu_type *);
> - void (*vgpu_destroy)(struct intel_vgpu *);
> + void (*vgpu_destroy)(struct intel_vgpu *vgpu);
> + void (*vgpu_release)(struct intel_vgpu *vgpu);
> void (*vgpu_reset)(struct intel_vgpu *);
> void (*vgpu_activate)(struct intel_vgpu *);
> void (*vgpu_deactivate)(struct intel_vgpu *); diff --git
> a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index ecc8f93..0578f48 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -666,7 +666,7 @@ static void __intel_vgpu_release(struct intel_vgpu
> *vgpu)
> if (atomic_cmpxchg(&vgpu->vdev.released, 0, 1))
> return;
>
> - intel_gvt_ops->vgpu_deactivate(vgpu);
> + intel_gvt_ops->vgpu_release(vgpu);
>
> ret = vfio_unregister_notifier(mdev_dev(vgpu->vdev.mdev),
> VFIO_IOMMU_NOTIFY,
> &vgpu->vdev.iommu_notifier);
> diff --git a/drivers/gpu/drm/i915/gvt/scheduler.c
> b/drivers/gpu/drm/i915/gvt/scheduler.c
> index 8087354..c143ff9 100644
> --- a/drivers/gpu/drm/i915/gvt/scheduler.c
> +++ b/drivers/gpu/drm/i915/gvt/scheduler.c
> @@ -786,7 +786,8 @@ static void update_guest_context(struct
> intel_vgpu_workload *workload)
> kunmap(page);
> }
>
> -static void clean_workloads(struct intel_vgpu *vgpu, unsigned long
> engine_mask)
> +void intel_vgpu_clean_workloads(struct intel_vgpu *vgpu,
> + unsigned long engine_mask)
> {
> struct intel_vgpu_submission *s = &vgpu->submission;
> struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv; @@ -881,7
> +882,7 @@ static void complete_current_workload(struct intel_gvt *gvt, int
> ring_id)
> * cleaned up during the resetting process later, so doing
> * the workload clean up here doesn't have any impact.
> **/
> - clean_workloads(vgpu, ENGINE_MASK(ring_id));
> + intel_vgpu_clean_workloads(vgpu, ENGINE_MASK(ring_id));
> }
>
> workload->complete(workload);
> @@ -1083,7 +1084,7 @@ void intel_vgpu_reset_submission(struct
> intel_vgpu *vgpu,
> if (!s->active)
> return;
>
> - clean_workloads(vgpu, engine_mask);
> + intel_vgpu_clean_workloads(vgpu, engine_mask);
> s->ops->reset(vgpu, engine_mask);
> }
>
> diff --git a/drivers/gpu/drm/i915/gvt/scheduler.h
> b/drivers/gpu/drm/i915/gvt/scheduler.h
> index 21eddab..ca5529d 100644
> --- a/drivers/gpu/drm/i915/gvt/scheduler.h
> +++ b/drivers/gpu/drm/i915/gvt/scheduler.h
> @@ -158,4 +158,7 @@ intel_vgpu_create_workload(struct intel_vgpu *vgpu,
> int ring_id,
>
> void intel_vgpu_destroy_workload(struct intel_vgpu_workload *workload);
>
> +void intel_vgpu_clean_workloads(struct intel_vgpu *vgpu,
> + unsigned long engine_mask);
> +
> #endif
> diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c
> b/drivers/gpu/drm/i915/gvt/vgpu.c index d6ffee3..30de683 100644
> --- a/drivers/gpu/drm/i915/gvt/vgpu.c
> +++ b/drivers/gpu/drm/i915/gvt/vgpu.c
> @@ -222,7 +222,7 @@ void intel_gvt_activate_vgpu(struct intel_vgpu
> *vgpu)
> * @vgpu: virtual GPU
> *
> * This function is called when user wants to deactivate a virtual GPU.
> - * All virtual GPU runtime information will be destroyed.
> + * The virtual GPU will be stopped.
> *
> */
> void intel_gvt_deactivate_vgpu(struct intel_vgpu *vgpu) @@ -238,12
> +238,30 @@ void intel_gvt_deactivate_vgpu(struct intel_vgpu *vgpu)
> }
>
> intel_vgpu_stop_schedule(vgpu);
> - intel_vgpu_dmabuf_cleanup(vgpu);
>
> mutex_unlock(&vgpu->vgpu_lock);
> }
>
> /**
> + * intel_gvt_release_vgpu - release a virtual GPU
> + * @vgpu: virtual GPU
> + *
> + * This function is called when user wants to release a virtual GPU.
> + * The virtual GPU will be stopped and all runtime information will be
> + * destroyed.
> + *
> + */
> +void intel_gvt_release_vgpu(struct intel_vgpu *vgpu) {
> + intel_gvt_deactivate_vgpu(vgpu);
> +
> + mutex_lock(&vgpu->vgpu_lock);
> + intel_vgpu_clean_workloads(vgpu, ALL_ENGINES);
> + intel_vgpu_dmabuf_cleanup(vgpu);
> + mutex_unlock(&vgpu->vgpu_lock);
> +}
> +
> +/**
> * intel_gvt_destroy_vgpu - destroy a virtual GPU
> * @vgpu: virtual GPU
> *
> --
> 2.7.4
>
> _______________________________________________
> intel-gvt-dev mailing list
> intel-gvt-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev
More information about the intel-gvt-dev
mailing list