[PATCH 2/2] drm/i915/kvmgt: Add mdev atrr nr_cache_entries

Zhenyu Wang zhenyuw at linux.intel.com
Tue Feb 6 03:27:30 UTC 2018


On 2018.02.06 10:50:21 +0800, changbin.du at intel.com wrote:
> From: Changbin Du <changbin.du at intel.com>
> 
> This patch add a new mdev atrr nr_cache_entries. This will show the number
> of entry in dma cache.
> 
> $ cat /sys/bus/pci/devices/0000:00:02.0/<uuid>//intel_vgpu/nr_cache_entries
> 10101
>

Please move this to debugfs instead of normal mdev sysfs which is used as
interface to handle normal operation but not for debugging info.

> Signed-off-by: Changbin Du <changbin.du at intel.com>
> ---
>  drivers/gpu/drm/i915/gvt/gvt.h   |  1 +
>  drivers/gpu/drm/i915/gvt/kvmgt.c | 20 ++++++++++++++++++++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
> index 45209da..910f2a3 100644
> --- a/drivers/gpu/drm/i915/gvt/gvt.h
> +++ b/drivers/gpu/drm/i915/gvt/gvt.h
> @@ -210,6 +210,7 @@ struct intel_vgpu {
>  		 */
>  		struct rb_root gfn_cache;
>  		struct rb_root dma_addr_cache;
> +		unsigned long nr_cache_entries;
>  		struct mutex cache_lock;
>  
>  		struct notifier_block iommu_notifier;
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index e3629de..b527fa7 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -225,6 +225,8 @@ static void __gvt_cache_add(struct intel_vgpu *vgpu, gfn_t gfn,
>  	}
>  	rb_link_node(&new->dma_addr_node, parent, link);
>  	rb_insert_color(&new->dma_addr_node, &vgpu->vdev.dma_addr_cache);
> +
> +	vgpu->vdev.nr_cache_entries++;
>  }
>  
>  static void __gvt_cache_remove_entry(struct intel_vgpu *vgpu,
> @@ -233,6 +235,7 @@ static void __gvt_cache_remove_entry(struct intel_vgpu *vgpu,
>  	rb_erase(&entry->gfn_node, &vgpu->vdev.gfn_cache);
>  	rb_erase(&entry->dma_addr_node, &vgpu->vdev.dma_addr_cache);
>  	kfree(entry);
> +	vgpu->vdev.nr_cache_entries--;
>  }
>  
>  static void gvt_cache_destroy(struct intel_vgpu *vgpu)
> @@ -258,6 +261,7 @@ static void gvt_cache_init(struct intel_vgpu *vgpu)
>  {
>  	vgpu->vdev.gfn_cache = RB_ROOT;
>  	vgpu->vdev.dma_addr_cache = RB_ROOT;
> +	vgpu->vdev.nr_cache_entries = 0;
>  	mutex_init(&vgpu->vdev.cache_lock);
>  }
>  
> @@ -1276,12 +1280,28 @@ hw_id_show(struct device *dev, struct device_attribute *attr,
>  	return sprintf(buf, "\n");
>  }
>  
> +static ssize_t
> +nr_cache_entries_show(struct device *dev, struct device_attribute *attr,
> +	   char *buf)
> +{
> +	struct mdev_device *mdev = mdev_from_dev(dev);
> +	struct intel_vgpu *vgpu;
> +
> +	if (mdev) {
> +		vgpu = (struct intel_vgpu *)mdev_get_drvdata(mdev);
> +		return sprintf(buf, "%lu\n", vgpu->vdev.nr_cache_entries);
> +	}
> +	return sprintf(buf, "\n");
> +}
> +
>  static DEVICE_ATTR_RO(vgpu_id);
>  static DEVICE_ATTR_RO(hw_id);
> +static DEVICE_ATTR_RO(nr_cache_entries);
>  
>  static struct attribute *intel_vgpu_attrs[] = {
>  	&dev_attr_vgpu_id.attr,
>  	&dev_attr_hw_id.attr,
> +	&dev_attr_nr_cache_entries.attr,
>  	NULL
>  };
>  
> -- 
> 2.7.4
> 
> _______________________________________________
> intel-gvt-dev mailing list
> intel-gvt-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev

-- 
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/intel-gvt-dev/attachments/20180206/b904c0bb/attachment.sig>


More information about the intel-gvt-dev mailing list