[v3,02/11] vdpa: Add set/get_vq_affinity callbacks in vdpa_config_ops

Message ID 20230228094110.37-3-xieyongji@bytedance.com
State New
Headers
Series VDUSE: Improve performance |

Commit Message

Yongji Xie Feb. 28, 2023, 9:41 a.m. UTC
  This introduces set/get_vq_affinity callbacks in
vdpa_config_ops to support interrupt affinity
management for vdpa device drivers.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Acked-by: Jason Wang <jasowang@redhat.com>
---
 drivers/virtio/virtio_vdpa.c | 28 ++++++++++++++++++++++++++++
 include/linux/vdpa.h         | 13 +++++++++++++
 2 files changed, 41 insertions(+)
  

Comments

Jason Wang March 16, 2023, 3:27 a.m. UTC | #1
在 2023/2/28 17:41, Xie Yongji 写道:
> This introduces set/get_vq_affinity callbacks in
> vdpa_config_ops to support interrupt affinity
> management for vdpa device drivers.
>
> Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
> Acked-by: Jason Wang <jasowang@redhat.com>
> ---
>   drivers/virtio/virtio_vdpa.c | 28 ++++++++++++++++++++++++++++
>   include/linux/vdpa.h         | 13 +++++++++++++
>   2 files changed, 41 insertions(+)
>
> diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
> index d7f5af62ddaa..f72696b4c1c2 100644
> --- a/drivers/virtio/virtio_vdpa.c
> +++ b/drivers/virtio/virtio_vdpa.c
> @@ -337,6 +337,32 @@ static const char *virtio_vdpa_bus_name(struct virtio_device *vdev)
>   	return dev_name(&vdpa->dev);
>   }
>   
> +static int virtio_vdpa_set_vq_affinity(struct virtqueue *vq,
> +				       const struct cpumask *cpu_mask)
> +{
> +	struct virtio_vdpa_device *vd_dev = to_virtio_vdpa_device(vq->vdev);
> +	struct vdpa_device *vdpa = vd_dev->vdpa;
> +	const struct vdpa_config_ops *ops = vdpa->config;
> +	unsigned int index = vq->index;
> +
> +	if (ops->set_vq_affinity)
> +		return ops->set_vq_affinity(vdpa, index, cpu_mask);
> +
> +	return 0;
> +}
> +
> +static const struct cpumask *
> +virtio_vdpa_get_vq_affinity(struct virtio_device *vdev, int index)
> +{
> +	struct vdpa_device *vdpa = vd_get_vdpa(vdev);
> +	const struct vdpa_config_ops *ops = vdpa->config;
> +
> +	if (ops->get_vq_affinity)
> +		return ops->get_vq_affinity(vdpa, index);
> +
> +	return NULL;
> +}
> +
>   static const struct virtio_config_ops virtio_vdpa_config_ops = {
>   	.get		= virtio_vdpa_get,
>   	.set		= virtio_vdpa_set,
> @@ -349,6 +375,8 @@ static const struct virtio_config_ops virtio_vdpa_config_ops = {
>   	.get_features	= virtio_vdpa_get_features,
>   	.finalize_features = virtio_vdpa_finalize_features,
>   	.bus_name	= virtio_vdpa_bus_name,
> +	.set_vq_affinity = virtio_vdpa_set_vq_affinity,
> +	.get_vq_affinity = virtio_vdpa_get_vq_affinity,
>   };
>   
>   static void virtio_vdpa_release_dev(struct device *_d)
> diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
> index 43f59ef10cc9..d61f369f9cd6 100644
> --- a/include/linux/vdpa.h
> +++ b/include/linux/vdpa.h
> @@ -250,6 +250,15 @@ struct vdpa_map_file {
>    *				@vdev: vdpa device
>    *				Returns the iova range supported by
>    *				the device.
> + * @set_vq_affinity:		Set the irq affinity of virtqueue (optional)


Nit: it's better not mention IRQ here because the virtqueue notification 
is not necessarily backed on IRQ.

Thanks


> + *				@vdev: vdpa device
> + *				@idx: virtqueue index
> + *				@cpu_mask: irq affinity mask
> + *				Returns integer: success (0) or error (< 0)
> + * @get_vq_affinity:		Get the irq affinity of virtqueue (optional)
> + *				@vdev: vdpa device
> + *				@idx: virtqueue index
> + *				Returns the irq affinity mask
>    * @set_group_asid:		Set address space identifier for a
>    *				virtqueue group (optional)
>    *				@vdev: vdpa device
> @@ -340,6 +349,10 @@ struct vdpa_config_ops {
>   			   const void *buf, unsigned int len);
>   	u32 (*get_generation)(struct vdpa_device *vdev);
>   	struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev);
> +	int (*set_vq_affinity)(struct vdpa_device *vdev, u16 idx,
> +			       const struct cpumask *cpu_mask);
> +	const struct cpumask *(*get_vq_affinity)(struct vdpa_device *vdev,
> +						 u16 idx);
>   
>   	/* DMA ops */
>   	int (*set_map)(struct vdpa_device *vdev, unsigned int asid,
  
Yongji Xie March 17, 2023, 7:10 a.m. UTC | #2
On Thu, Mar 16, 2023 at 11:27 AM Jason Wang <jasowang@redhat.com> wrote:
>
>
> 在 2023/2/28 17:41, Xie Yongji 写道:
> > This introduces set/get_vq_affinity callbacks in
> > vdpa_config_ops to support interrupt affinity
> > management for vdpa device drivers.
> >
> > Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
> > Acked-by: Jason Wang <jasowang@redhat.com>
> > ---
> >   drivers/virtio/virtio_vdpa.c | 28 ++++++++++++++++++++++++++++
> >   include/linux/vdpa.h         | 13 +++++++++++++
> >   2 files changed, 41 insertions(+)
> >
> > diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
> > index d7f5af62ddaa..f72696b4c1c2 100644
> > --- a/drivers/virtio/virtio_vdpa.c
> > +++ b/drivers/virtio/virtio_vdpa.c
> > @@ -337,6 +337,32 @@ static const char *virtio_vdpa_bus_name(struct virtio_device *vdev)
> >       return dev_name(&vdpa->dev);
> >   }
> >
> > +static int virtio_vdpa_set_vq_affinity(struct virtqueue *vq,
> > +                                    const struct cpumask *cpu_mask)
> > +{
> > +     struct virtio_vdpa_device *vd_dev = to_virtio_vdpa_device(vq->vdev);
> > +     struct vdpa_device *vdpa = vd_dev->vdpa;
> > +     const struct vdpa_config_ops *ops = vdpa->config;
> > +     unsigned int index = vq->index;
> > +
> > +     if (ops->set_vq_affinity)
> > +             return ops->set_vq_affinity(vdpa, index, cpu_mask);
> > +
> > +     return 0;
> > +}
> > +
> > +static const struct cpumask *
> > +virtio_vdpa_get_vq_affinity(struct virtio_device *vdev, int index)
> > +{
> > +     struct vdpa_device *vdpa = vd_get_vdpa(vdev);
> > +     const struct vdpa_config_ops *ops = vdpa->config;
> > +
> > +     if (ops->get_vq_affinity)
> > +             return ops->get_vq_affinity(vdpa, index);
> > +
> > +     return NULL;
> > +}
> > +
> >   static const struct virtio_config_ops virtio_vdpa_config_ops = {
> >       .get            = virtio_vdpa_get,
> >       .set            = virtio_vdpa_set,
> > @@ -349,6 +375,8 @@ static const struct virtio_config_ops virtio_vdpa_config_ops = {
> >       .get_features   = virtio_vdpa_get_features,
> >       .finalize_features = virtio_vdpa_finalize_features,
> >       .bus_name       = virtio_vdpa_bus_name,
> > +     .set_vq_affinity = virtio_vdpa_set_vq_affinity,
> > +     .get_vq_affinity = virtio_vdpa_get_vq_affinity,
> >   };
> >
> >   static void virtio_vdpa_release_dev(struct device *_d)
> > diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
> > index 43f59ef10cc9..d61f369f9cd6 100644
> > --- a/include/linux/vdpa.h
> > +++ b/include/linux/vdpa.h
> > @@ -250,6 +250,15 @@ struct vdpa_map_file {
> >    *                          @vdev: vdpa device
> >    *                          Returns the iova range supported by
> >    *                          the device.
> > + * @set_vq_affinity:         Set the irq affinity of virtqueue (optional)
>
>
> Nit: it's better not mention IRQ here because the virtqueue notification
> is not necessarily backed on IRQ.
>

OK.

Thanks,
Yongji
  

Patch

diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
index d7f5af62ddaa..f72696b4c1c2 100644
--- a/drivers/virtio/virtio_vdpa.c
+++ b/drivers/virtio/virtio_vdpa.c
@@ -337,6 +337,32 @@  static const char *virtio_vdpa_bus_name(struct virtio_device *vdev)
 	return dev_name(&vdpa->dev);
 }
 
+static int virtio_vdpa_set_vq_affinity(struct virtqueue *vq,
+				       const struct cpumask *cpu_mask)
+{
+	struct virtio_vdpa_device *vd_dev = to_virtio_vdpa_device(vq->vdev);
+	struct vdpa_device *vdpa = vd_dev->vdpa;
+	const struct vdpa_config_ops *ops = vdpa->config;
+	unsigned int index = vq->index;
+
+	if (ops->set_vq_affinity)
+		return ops->set_vq_affinity(vdpa, index, cpu_mask);
+
+	return 0;
+}
+
+static const struct cpumask *
+virtio_vdpa_get_vq_affinity(struct virtio_device *vdev, int index)
+{
+	struct vdpa_device *vdpa = vd_get_vdpa(vdev);
+	const struct vdpa_config_ops *ops = vdpa->config;
+
+	if (ops->get_vq_affinity)
+		return ops->get_vq_affinity(vdpa, index);
+
+	return NULL;
+}
+
 static const struct virtio_config_ops virtio_vdpa_config_ops = {
 	.get		= virtio_vdpa_get,
 	.set		= virtio_vdpa_set,
@@ -349,6 +375,8 @@  static const struct virtio_config_ops virtio_vdpa_config_ops = {
 	.get_features	= virtio_vdpa_get_features,
 	.finalize_features = virtio_vdpa_finalize_features,
 	.bus_name	= virtio_vdpa_bus_name,
+	.set_vq_affinity = virtio_vdpa_set_vq_affinity,
+	.get_vq_affinity = virtio_vdpa_get_vq_affinity,
 };
 
 static void virtio_vdpa_release_dev(struct device *_d)
diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
index 43f59ef10cc9..d61f369f9cd6 100644
--- a/include/linux/vdpa.h
+++ b/include/linux/vdpa.h
@@ -250,6 +250,15 @@  struct vdpa_map_file {
  *				@vdev: vdpa device
  *				Returns the iova range supported by
  *				the device.
+ * @set_vq_affinity:		Set the irq affinity of virtqueue (optional)
+ *				@vdev: vdpa device
+ *				@idx: virtqueue index
+ *				@cpu_mask: irq affinity mask
+ *				Returns integer: success (0) or error (< 0)
+ * @get_vq_affinity:		Get the irq affinity of virtqueue (optional)
+ *				@vdev: vdpa device
+ *				@idx: virtqueue index
+ *				Returns the irq affinity mask
  * @set_group_asid:		Set address space identifier for a
  *				virtqueue group (optional)
  *				@vdev: vdpa device
@@ -340,6 +349,10 @@  struct vdpa_config_ops {
 			   const void *buf, unsigned int len);
 	u32 (*get_generation)(struct vdpa_device *vdev);
 	struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev);
+	int (*set_vq_affinity)(struct vdpa_device *vdev, u16 idx,
+			       const struct cpumask *cpu_mask);
+	const struct cpumask *(*get_vq_affinity)(struct vdpa_device *vdev,
+						 u16 idx);
 
 	/* DMA ops */
 	int (*set_map)(struct vdpa_device *vdev, unsigned int asid,