On Mon, Dec 19, 2022 at 1:16 PM Yongji Xie <xieyongji@xxxxxxxxxxxxx> wrote: > > On Fri, Dec 16, 2022 at 1:35 PM Jason Wang <jasowang@xxxxxxxxxx> wrote: > > > > On Mon, Dec 5, 2022 at 5:03 PM Xie Yongji <xieyongji@xxxxxxxxxxxxx> wrote: > > > > > > Add sysfs interface for each vduse virtqueue to > > > show the affinity and effective affinity for irq > > > callback. > > > > > > And we can also use this interface to change the > > > effective affinity which must be a subset of the > > > irq callback affinity mask for the virtqueue. This > > > might be useful for performance tuning when the irq > > > callback affinity mask contains more than one CPU. > > > > > > Signed-off-by: Xie Yongji <xieyongji@xxxxxxxxxxxxx> > > > --- > > > drivers/vdpa/vdpa_user/vduse_dev.c | 148 ++++++++++++++++++++++++++--- > > > 1 file changed, 137 insertions(+), 11 deletions(-) > > > > > > diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c > > > index 6507a78abc9d..c65f84100e30 100644 > > > --- a/drivers/vdpa/vdpa_user/vduse_dev.c > > > +++ b/drivers/vdpa/vdpa_user/vduse_dev.c > > > @@ -61,6 +61,7 @@ struct vduse_virtqueue { > > > int irq_effective_cpu; > > > struct cpumask irq_affinity; > > > spinlock_t irq_affinity_lock; > > > + struct kobject kobj; > > > }; > > > > > > struct vduse_dev; > > > @@ -1419,6 +1420,120 @@ static const struct file_operations vduse_dev_fops = { > > > .llseek = noop_llseek, > > > }; > > > > > > +static ssize_t irq_cb_affinity_show(struct vduse_virtqueue *vq, char *buf) > > > +{ > > > + return sprintf(buf, "%*pb\n", cpumask_pr_args(&vq->irq_affinity)); > > > +} > > > + > > > +static ssize_t irq_cb_effective_affinity_show(struct vduse_virtqueue *vq, > > > + char *buf) > > > +{ > > > + struct cpumask all_mask = CPU_MASK_ALL; > > > + const struct cpumask *mask = &all_mask; > > > + > > > + if (vq->irq_effective_cpu != -1) > > > + mask = get_cpu_mask(vq->irq_effective_cpu); > > > > Shouldn't this be vq->irq_affinity? > > > > This sysfs interface is provided for effective irq affinity rather > than irq affinity. We created another read-only sysfs interface for > irq affinity. > > > > + > > > + return sprintf(buf, "%*pb\n", cpumask_pr_args(mask)); > > > +} > > > + > > > +static ssize_t irq_cb_effective_affinity_store(struct vduse_virtqueue *vq, > > > + const char *buf, size_t count) > > > +{ > > > + cpumask_var_t new_value; > > > + int ret; > > > + > > > + if (!zalloc_cpumask_var(&new_value, GFP_KERNEL)) > > > + return -ENOMEM; > > > + > > > + ret = cpumask_parse(buf, new_value); > > > + if (ret) > > > + goto free_mask; > > > + > > > + ret = -EINVAL; > > > + if (!cpumask_intersects(new_value, &vq->irq_affinity)) > > > + goto free_mask; > > > + > > > + spin_lock(&vq->irq_affinity_lock); > > > + > > > + if (vq->irq_effective_cpu != -1) > > > + per_cpu(vduse_allocated_irq, vq->irq_effective_cpu) -= 1; > > > + > > > + vq->irq_effective_cpu = cpumask_first(new_value); > > > > Does this mean except for the first cpu, the rest of the mask is unused? > > > > Yes, but the user should always specify a mask that only contains one > CPU to make it work as expected. This doesn't seem to be the way that the IRQ affinity{hint} exported via /sys work. Any reason for doing this? (E.g we may have the require to limit the IRQ/callback to a NUMA node instead of a specific cpu) Thanks > This sysfs interface is used to > specify the effective irq affinity rather than irq affinity. > > Thanks, > Yongji > _______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linuxfoundation.org/mailman/listinfo/virtualization