drm/i915/gvt: declare the vgpu active flag as atomic_t

Submitted by Weinan Li on Feb. 28, 2019, 8:19 a.m.

Details

Message ID 1551341988-1410-1-git-send-email-weinan.z.li@intel.com
State New
Headers show
Series "drm/i915/gvt: declare the vgpu active flag as atomic_t" ( rev: 1 ) in Intel GVT devel

Not browsing as part of any series.

Commit Message

Weinan Li Feb. 28, 2019, 8:19 a.m.
It's not necessary to protect the vgpu active flag with lock, atomic
access could meet the requirement.

Signed-off-by: Weinan Li <weinan.z.li@intel.com>
---
 drivers/gpu/drm/i915/gvt/debugfs.c   |  4 ++--
 drivers/gpu/drm/i915/gvt/dmabuf.c    |  3 ++-
 drivers/gpu/drm/i915/gvt/gvt.h       |  4 ++--
 drivers/gpu/drm/i915/gvt/scheduler.c |  2 +-
 drivers/gpu/drm/i915/gvt/vgpu.c      | 10 ++++------
 5 files changed, 11 insertions(+), 12 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/i915/gvt/debugfs.c b/drivers/gpu/drm/i915/gvt/debugfs.c
index 2ec89bc..5c8cec7 100644
--- a/drivers/gpu/drm/i915/gvt/debugfs.c
+++ b/drivers/gpu/drm/i915/gvt/debugfs.c
@@ -203,8 +203,8 @@  int intel_gvt_debugfs_add_vgpu(struct intel_vgpu *vgpu)
 	if (!vgpu->debugfs)
 		return -ENOMEM;
 
-	ent = debugfs_create_bool("active", 0444, vgpu->debugfs,
-				  &vgpu->active);
+	ent = debugfs_create_atomic_t("active", 0444, vgpu->debugfs,
+				      &vgpu->active);
 	if (!ent)
 		return -ENOMEM;
 
diff --git a/drivers/gpu/drm/i915/gvt/dmabuf.c b/drivers/gpu/drm/i915/gvt/dmabuf.c
index 3e7e2b8..c3916cb 100644
--- a/drivers/gpu/drm/i915/gvt/dmabuf.c
+++ b/drivers/gpu/drm/i915/gvt/dmabuf.c
@@ -89,7 +89,8 @@  static void dmabuf_gem_object_free(struct kref *kref)
 	struct list_head *pos;
 	struct intel_vgpu_dmabuf_obj *dmabuf_obj;
 
-	if (vgpu && vgpu->active && !list_empty(&vgpu->dmabuf_obj_list_head)) {
+	if (vgpu && atomic_read(&vgpu->active) &&
+	    !list_empty(&vgpu->dmabuf_obj_list_head)) {
 		list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
 			dmabuf_obj = container_of(pos,
 					struct intel_vgpu_dmabuf_obj, list);
diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
index ef710e2..8d88a77 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.h
+++ b/drivers/gpu/drm/i915/gvt/gvt.h
@@ -171,7 +171,7 @@  struct intel_vgpu {
 	struct mutex vgpu_lock;
 	int id;
 	unsigned long handle; /* vGPU handle used by hypervisor MPT modules */
-	bool active;
+	atomic_t active;
 	bool pv_notified;
 	bool failsafe;
 	unsigned int resetting_eng;
@@ -454,7 +454,7 @@  void intel_vgpu_write_fence(struct intel_vgpu *vgpu,
 
 #define for_each_active_vgpu(gvt, vgpu, id) \
 	idr_for_each_entry((&(gvt)->vgpu_idr), (vgpu), (id)) \
-		for_each_if(vgpu->active)
+		for_each_if(atomic_read(&vgpu->active))
 
 static inline void intel_vgpu_write_pci_bar(struct intel_vgpu *vgpu,
 					    u32 offset, u32 val, bool low)
diff --git a/drivers/gpu/drm/i915/gvt/scheduler.c b/drivers/gpu/drm/i915/gvt/scheduler.c
index 2bcb701..617cc42 100644
--- a/drivers/gpu/drm/i915/gvt/scheduler.c
+++ b/drivers/gpu/drm/i915/gvt/scheduler.c
@@ -739,7 +739,7 @@  static struct intel_vgpu_workload *pick_next_workload(
 		goto out;
 	}
 
-	if (!scheduler->current_vgpu->active ||
+	if (!atomic_read(&scheduler->current_vgpu->active) ||
 	    list_empty(workload_q_head(scheduler->current_vgpu, ring_id)))
 		goto out;
 
diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c
index 720e2b1..d55a714 100644
--- a/drivers/gpu/drm/i915/gvt/vgpu.c
+++ b/drivers/gpu/drm/i915/gvt/vgpu.c
@@ -212,9 +212,7 @@  static void intel_gvt_update_vgpu_types(struct intel_gvt *gvt)
  */
 void intel_gvt_activate_vgpu(struct intel_vgpu *vgpu)
 {
-	mutex_lock(&vgpu->gvt->lock);
-	vgpu->active = true;
-	mutex_unlock(&vgpu->gvt->lock);
+	atomic_set(&vgpu->active, true);
 }
 
 /**
@@ -229,7 +227,7 @@  void intel_gvt_deactivate_vgpu(struct intel_vgpu *vgpu)
 {
 	mutex_lock(&vgpu->vgpu_lock);
 
-	vgpu->active = false;
+	atomic_set(&vgpu->active, false);
 
 	if (atomic_read(&vgpu->submission.running_workload_num)) {
 		mutex_unlock(&vgpu->vgpu_lock);
@@ -274,7 +272,7 @@  void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu)
 
 	mutex_lock(&vgpu->vgpu_lock);
 
-	WARN(vgpu->active, "vGPU is still active!\n");
+	WARN(atomic_read(&vgpu->active), "vGPU is still active!\n");
 
 	intel_gvt_debugfs_remove_vgpu(vgpu);
 	intel_vgpu_clean_sched_policy(vgpu);
@@ -331,7 +329,7 @@  struct intel_vgpu *intel_gvt_create_idle_vgpu(struct intel_gvt *gvt)
 	if (ret)
 		goto out_free_vgpu;
 
-	vgpu->active = false;
+	atomic_set(&vgpu->active, false);
 
 	return vgpu;
 

Comments