Re: [PATCH 2/3] vdpa_sim_blk: limit the number of request handled per batch
On Tue, Jun 28, 2022 at 6:01 AM Jason Wang wrote: > > On Thu, Jun 23, 2022 at 4:58 PM Stefano Garzarella > wrote: > > > > On Thu, Jun 23, 2022 at 11:50:22AM +0800, Jason Wang wrote: > > >On Wed, Jun 22, 2022 at 12:09 AM Stefano Garzarella > > >wrote: > > >> > > >> Limit the number of requests (4 per queue as for vdpa_sim_net) handled > > >> in a batch to prevent the worker from using the CPU for too long. > > >> > > >> Suggested-by: Eugenio Pérez > > >> Signed-off-by: Stefano Garzarella > > >> --- > > >> drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 15 ++- > > >> 1 file changed, 14 insertions(+), 1 deletion(-) > > >> > > >> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > > >> b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > > >> index a83a5c76f620..ac86478845b6 100644 > > >> --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > > >> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > > >> @@ -197,6 +197,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim > > >> *vdpasim, > > >> static void vdpasim_blk_work(struct work_struct *work) > > >> { > > >> struct vdpasim *vdpasim = container_of(work, struct vdpasim, > > >> work); > > >> + bool reschedule = false; > > >> int i; > > >> > > >> spin_lock(&vdpasim->lock); > > >> @@ -206,11 +207,15 @@ static void vdpasim_blk_work(struct work_struct > > >> *work) > > >> > > >> for (i = 0; i < VDPASIM_BLK_VQ_NUM; i++) { > > >> struct vdpasim_virtqueue *vq = &vdpasim->vqs[i]; > > >> + bool vq_work = true; > > >> + int reqs = 0; > > >> > > >> if (!vq->ready) > > >> continue; > > >> > > >> - while (vdpasim_blk_handle_req(vdpasim, vq)) { > > >> + while (vq_work) { > > >> + vq_work = vdpasim_blk_handle_req(vdpasim, vq); > > >> + > > > > > >Is it better to check and exit the loop early here? > > > > Maybe, but I'm not sure. > > > > In vdpa_sim_net we call vringh_complete_iotlb() and send notification > > also in the error path, > > Looks not? > > read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->in_iov, &ctrl, > sizeof(ctrl)); > if (read != sizeof(ctrl)) > break; > > We break the loop. I was looking at vdpasim_net_work(), but I was confused since it handles 2 queues. I'll break the loop as it was before. Thanks, Stefano ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 2/3] vdpa_sim_blk: limit the number of request handled per batch
On Thu, Jun 23, 2022 at 4:58 PM Stefano Garzarella wrote: > > On Thu, Jun 23, 2022 at 11:50:22AM +0800, Jason Wang wrote: > >On Wed, Jun 22, 2022 at 12:09 AM Stefano Garzarella > >wrote: > >> > >> Limit the number of requests (4 per queue as for vdpa_sim_net) handled > >> in a batch to prevent the worker from using the CPU for too long. > >> > >> Suggested-by: Eugenio Pérez > >> Signed-off-by: Stefano Garzarella > >> --- > >> drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 15 ++- > >> 1 file changed, 14 insertions(+), 1 deletion(-) > >> > >> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > >> b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > >> index a83a5c76f620..ac86478845b6 100644 > >> --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > >> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > >> @@ -197,6 +197,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim > >> *vdpasim, > >> static void vdpasim_blk_work(struct work_struct *work) > >> { > >> struct vdpasim *vdpasim = container_of(work, struct vdpasim, work); > >> + bool reschedule = false; > >> int i; > >> > >> spin_lock(&vdpasim->lock); > >> @@ -206,11 +207,15 @@ static void vdpasim_blk_work(struct work_struct > >> *work) > >> > >> for (i = 0; i < VDPASIM_BLK_VQ_NUM; i++) { > >> struct vdpasim_virtqueue *vq = &vdpasim->vqs[i]; > >> + bool vq_work = true; > >> + int reqs = 0; > >> > >> if (!vq->ready) > >> continue; > >> > >> - while (vdpasim_blk_handle_req(vdpasim, vq)) { > >> + while (vq_work) { > >> + vq_work = vdpasim_blk_handle_req(vdpasim, vq); > >> + > > > >Is it better to check and exit the loop early here? > > Maybe, but I'm not sure. > > In vdpa_sim_net we call vringh_complete_iotlb() and send notification > also in the error path, Looks not? read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->in_iov, &ctrl, sizeof(ctrl)); if (read != sizeof(ctrl)) break; We break the loop. Thanks > so I thought was better to send notification > also when vdpasim_blk_handle_req() return false, since we will update > the used.idx. > > However, I don't think it's a common path, so if you think it's better > to exit the loop early, I can do it. > > Thanks, > Stefano > ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 2/3] vdpa_sim_blk: limit the number of request handled per batch
On Thu, Jun 23, 2022 at 11:50:22AM +0800, Jason Wang wrote: On Wed, Jun 22, 2022 at 12:09 AM Stefano Garzarella wrote: Limit the number of requests (4 per queue as for vdpa_sim_net) handled in a batch to prevent the worker from using the CPU for too long. Suggested-by: Eugenio Pérez Signed-off-by: Stefano Garzarella --- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 15 ++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c index a83a5c76f620..ac86478845b6 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c @@ -197,6 +197,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpasim, static void vdpasim_blk_work(struct work_struct *work) { struct vdpasim *vdpasim = container_of(work, struct vdpasim, work); + bool reschedule = false; int i; spin_lock(&vdpasim->lock); @@ -206,11 +207,15 @@ static void vdpasim_blk_work(struct work_struct *work) for (i = 0; i < VDPASIM_BLK_VQ_NUM; i++) { struct vdpasim_virtqueue *vq = &vdpasim->vqs[i]; + bool vq_work = true; + int reqs = 0; if (!vq->ready) continue; - while (vdpasim_blk_handle_req(vdpasim, vq)) { + while (vq_work) { + vq_work = vdpasim_blk_handle_req(vdpasim, vq); + Is it better to check and exit the loop early here? Maybe, but I'm not sure. In vdpa_sim_net we call vringh_complete_iotlb() and send notification also in the error path, so I thought was better to send notification also when vdpasim_blk_handle_req() return false, since we will update the used.idx. However, I don't think it's a common path, so if you think it's better to exit the loop early, I can do it. Thanks, Stefano ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 2/3] vdpa_sim_blk: limit the number of request handled per batch
On Wed, Jun 22, 2022 at 12:09 AM Stefano Garzarella wrote: > > Limit the number of requests (4 per queue as for vdpa_sim_net) handled > in a batch to prevent the worker from using the CPU for too long. > > Suggested-by: Eugenio Pérez > Signed-off-by: Stefano Garzarella > --- > drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 15 ++- > 1 file changed, 14 insertions(+), 1 deletion(-) > > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > index a83a5c76f620..ac86478845b6 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > @@ -197,6 +197,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim > *vdpasim, > static void vdpasim_blk_work(struct work_struct *work) > { > struct vdpasim *vdpasim = container_of(work, struct vdpasim, work); > + bool reschedule = false; > int i; > > spin_lock(&vdpasim->lock); > @@ -206,11 +207,15 @@ static void vdpasim_blk_work(struct work_struct *work) > > for (i = 0; i < VDPASIM_BLK_VQ_NUM; i++) { > struct vdpasim_virtqueue *vq = &vdpasim->vqs[i]; > + bool vq_work = true; > + int reqs = 0; > > if (!vq->ready) > continue; > > - while (vdpasim_blk_handle_req(vdpasim, vq)) { > + while (vq_work) { > + vq_work = vdpasim_blk_handle_req(vdpasim, vq); > + Is it better to check and exit the loop early here? Thanks > /* Make sure used is visible before rasing the > interrupt. */ > smp_wmb(); > > @@ -218,10 +223,18 @@ static void vdpasim_blk_work(struct work_struct *work) > if (vringh_need_notify_iotlb(&vq->vring) > 0) > vringh_notify(&vq->vring); > local_bh_enable(); > + > + if (++reqs > 4) { > + vq_work = false; > + reschedule = true; > + } > } > } > out: > spin_unlock(&vdpasim->lock); > + > + if (reschedule) > + schedule_work(&vdpasim->work); > } > > static void vdpasim_blk_get_config(struct vdpasim *vdpasim, void *config) > -- > 2.36.1 > ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization