Commit 19e226e8 authored by Caleb Raitto's avatar Caleb Raitto Committed by David S. Miller

virtio: Make vp_set_vq_affinity() take a mask.

Make vp_set_vq_affinity() take a cpumask instead of taking a single CPU.

If there are fewer queues than cores, queue affinity should be able to
map to multiple cores.

Link: https://patchwork.ozlabs.org/patch/948149/Suggested-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarCaleb Raitto <caraitto@google.com>
Acked-by: default avatarGonglei <arei.gonglei@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 07624df1
...@@ -146,7 +146,7 @@ static void virtcrypto_clean_affinity(struct virtio_crypto *vi, long hcpu) ...@@ -146,7 +146,7 @@ static void virtcrypto_clean_affinity(struct virtio_crypto *vi, long hcpu)
if (vi->affinity_hint_set) { if (vi->affinity_hint_set) {
for (i = 0; i < vi->max_data_queues; i++) for (i = 0; i < vi->max_data_queues; i++)
virtqueue_set_affinity(vi->data_vq[i].vq, -1); virtqueue_set_affinity(vi->data_vq[i].vq, NULL);
vi->affinity_hint_set = false; vi->affinity_hint_set = false;
} }
...@@ -173,7 +173,7 @@ static void virtcrypto_set_affinity(struct virtio_crypto *vcrypto) ...@@ -173,7 +173,7 @@ static void virtcrypto_set_affinity(struct virtio_crypto *vcrypto)
* *
*/ */
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
virtqueue_set_affinity(vcrypto->data_vq[i].vq, cpu); virtqueue_set_affinity(vcrypto->data_vq[i].vq, cpumask_of(cpu));
if (++i >= vcrypto->max_data_queues) if (++i >= vcrypto->max_data_queues)
break; break;
} }
......
...@@ -1878,8 +1878,8 @@ static void virtnet_clean_affinity(struct virtnet_info *vi, long hcpu) ...@@ -1878,8 +1878,8 @@ static void virtnet_clean_affinity(struct virtnet_info *vi, long hcpu)
if (vi->affinity_hint_set) { if (vi->affinity_hint_set) {
for (i = 0; i < vi->max_queue_pairs; i++) { for (i = 0; i < vi->max_queue_pairs; i++) {
virtqueue_set_affinity(vi->rq[i].vq, -1); virtqueue_set_affinity(vi->rq[i].vq, NULL);
virtqueue_set_affinity(vi->sq[i].vq, -1); virtqueue_set_affinity(vi->sq[i].vq, NULL);
} }
vi->affinity_hint_set = false; vi->affinity_hint_set = false;
...@@ -1905,8 +1905,8 @@ static void virtnet_set_affinity(struct virtnet_info *vi) ...@@ -1905,8 +1905,8 @@ static void virtnet_set_affinity(struct virtnet_info *vi)
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
const unsigned long *mask = cpumask_bits(cpumask_of(cpu)); const unsigned long *mask = cpumask_bits(cpumask_of(cpu));
virtqueue_set_affinity(vi->rq[i].vq, cpu); virtqueue_set_affinity(vi->rq[i].vq, cpumask_of(cpu));
virtqueue_set_affinity(vi->sq[i].vq, cpu); virtqueue_set_affinity(vi->sq[i].vq, cpumask_of(cpu));
__netif_set_xps_queue(vi->dev, mask, i, false); __netif_set_xps_queue(vi->dev, mask, i, false);
i++; i++;
} }
......
...@@ -421,7 +421,7 @@ const char *vp_bus_name(struct virtio_device *vdev) ...@@ -421,7 +421,7 @@ const char *vp_bus_name(struct virtio_device *vdev)
* - OR over all affinities for shared MSI * - OR over all affinities for shared MSI
* - ignore the affinity request if we're using INTX * - ignore the affinity request if we're using INTX
*/ */
int vp_set_vq_affinity(struct virtqueue *vq, int cpu) int vp_set_vq_affinity(struct virtqueue *vq, const struct cpumask *cpu_mask)
{ {
struct virtio_device *vdev = vq->vdev; struct virtio_device *vdev = vq->vdev;
struct virtio_pci_device *vp_dev = to_vp_device(vdev); struct virtio_pci_device *vp_dev = to_vp_device(vdev);
...@@ -435,11 +435,10 @@ int vp_set_vq_affinity(struct virtqueue *vq, int cpu) ...@@ -435,11 +435,10 @@ int vp_set_vq_affinity(struct virtqueue *vq, int cpu)
if (vp_dev->msix_enabled) { if (vp_dev->msix_enabled) {
mask = vp_dev->msix_affinity_masks[info->msix_vector]; mask = vp_dev->msix_affinity_masks[info->msix_vector];
irq = pci_irq_vector(vp_dev->pci_dev, info->msix_vector); irq = pci_irq_vector(vp_dev->pci_dev, info->msix_vector);
if (cpu == -1) if (!cpu_mask)
irq_set_affinity_hint(irq, NULL); irq_set_affinity_hint(irq, NULL);
else { else {
cpumask_clear(mask); cpumask_copy(mask, cpu_mask);
cpumask_set_cpu(cpu, mask);
irq_set_affinity_hint(irq, mask); irq_set_affinity_hint(irq, mask);
} }
} }
......
...@@ -141,7 +141,7 @@ const char *vp_bus_name(struct virtio_device *vdev); ...@@ -141,7 +141,7 @@ const char *vp_bus_name(struct virtio_device *vdev);
* - OR over all affinities for shared MSI * - OR over all affinities for shared MSI
* - ignore the affinity request if we're using INTX * - ignore the affinity request if we're using INTX
*/ */
int vp_set_vq_affinity(struct virtqueue *vq, int cpu); int vp_set_vq_affinity(struct virtqueue *vq, const struct cpumask *cpu_mask);
const struct cpumask *vp_get_vq_affinity(struct virtio_device *vdev, int index); const struct cpumask *vp_get_vq_affinity(struct virtio_device *vdev, int index);
......
...@@ -79,7 +79,8 @@ struct virtio_config_ops { ...@@ -79,7 +79,8 @@ struct virtio_config_ops {
u64 (*get_features)(struct virtio_device *vdev); u64 (*get_features)(struct virtio_device *vdev);
int (*finalize_features)(struct virtio_device *vdev); int (*finalize_features)(struct virtio_device *vdev);
const char *(*bus_name)(struct virtio_device *vdev); const char *(*bus_name)(struct virtio_device *vdev);
int (*set_vq_affinity)(struct virtqueue *vq, int cpu); int (*set_vq_affinity)(struct virtqueue *vq,
const struct cpumask *cpu_mask);
const struct cpumask *(*get_vq_affinity)(struct virtio_device *vdev, const struct cpumask *(*get_vq_affinity)(struct virtio_device *vdev,
int index); int index);
}; };
...@@ -236,11 +237,11 @@ const char *virtio_bus_name(struct virtio_device *vdev) ...@@ -236,11 +237,11 @@ const char *virtio_bus_name(struct virtio_device *vdev)
* *
*/ */
static inline static inline
int virtqueue_set_affinity(struct virtqueue *vq, int cpu) int virtqueue_set_affinity(struct virtqueue *vq, const struct cpumask *cpu_mask)
{ {
struct virtio_device *vdev = vq->vdev; struct virtio_device *vdev = vq->vdev;
if (vdev->config->set_vq_affinity) if (vdev->config->set_vq_affinity)
return vdev->config->set_vq_affinity(vq, cpu); return vdev->config->set_vq_affinity(vq, cpu_mask);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment