-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpmsg: Allow to send virtqueue_kick only when RX queue is empty #615
Conversation
@arnopo Hi, about your concerns:
The rpmsg virtio default implementation in OpenAMP use polling method to wait the tx buffer, so in this case, the real-time performance is not affected and the number of interrupts are reduced. But if we implemented the Is the default behavior more important?
As you said, this behavior indeed does not conform to the VIRTIO standard, the virtio standard says:
But actually, Linux does the same thing like this PR, please see: https://github.com/torvalds/linux/blob/master/drivers/rpmsg/virtio_rpmsg_bus.c#L778 static void rpmsg_recv_done(struct virtqueue *rvq)
{
struct virtproc_info *vrp = rvq->vdev->priv;
struct device *dev = &rvq->vdev->dev;
struct rpmsg_hdr *msg;
unsigned int len, msgs_received = 0;
int err;
msg = virtqueue_get_buf(rvq, &len);
if (!msg) {
dev_err(dev, "uhm, incoming signal, but no used buffer ?\n");
return;
}
while (msg) {
err = rpmsg_recv_single(vrp, dev, msg, len);
if (err)
break;
msgs_received++;
msg = virtqueue_get_buf(rvq, &len);
}
dev_dbg(dev, "Received %u messages\n", msgs_received);
/* tell the remote processor we added another available rx buffer */
if (msgs_received)
virtqueue_kick(vrp->rvq);
} |
Yes, it is, as it can affect existing projects. If we want to maintain the stability of the library, we have to take legacy into account.
rproc virtio/rpmsg virtio in Linux is probably not the best example in terms of virtio specification conformance. 😃 That said, your proposal is still valid in terms of optimization. However, I would be in favor of supporting both, even if it would add a new build configuration to test. @edmooring @tnmysh, any opinions on that? |
Yes, kick only one time when we need add serveral buffers to the virtqueue is a very easy way to optimize the performance and I found more virtio drivers' implementations in linux do this thing: virtio_net: https://github.com/torvalds/linux/blob/master/drivers/net/virtio_net.c#L3053 @arnopo So what's your plan about this? If it's OK, you could give us some advices so that we can continue this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @arnopo at least in part. If we do support this, it should be in addition to the current approach, and it should not be the default. Current users of the library will be surprised if the default behavior changes.
This might be an optimization for performance in some applications, but it might also be a pessimization (the opposite of optimization) for others because it could affect latency.
Concerning the implementation, one way to do it could be to define an RPMSG_VIRTIO_ENABLED macro similar to VIRTIO_ENABLED and a VQ_RX_EMPTY_NOTIFY build config. Then, use if (RPMSG_VIRTIO_ENABLED(VQ_RX_EMPTY_NOTIFY)) to define the behavior. if (RPMSG_VIRTIO_ENABLED(VQ_RX_EMPTY_NOTIFY))
/* only notify when no more Message in queue */
else
/* notify for each buffer released */ |
@arnopo @edmooring Thanks for the reply and we will update this PR based on your suggestions @arnopo. |
@arnopo rpmsg_virtio.c already have use VIRTIO_ENABLED,so can we use VIRTIO_ENABLED directly? |
86902e1
to
2bb1932
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implementation seems LGTM, few typos to fix.
Please also fix commit message, here is a proposal:
rpmsg: Allow to send virtqueue_kick only when RX queue is empty
Add VQ_RX_EMPTY_NOTIFY config to define the behavior. If
VQ_RX_EMPTY_NOTIFY is disabled, notify the other side each
time a buffer is released. If VQ_RX_EMPTY_NOTIFY is enabled,
only send one notification when the RX queue is empty to
improve performance.
Add VQ_RX_EMPTY_NOTIFY config to define the behavior. If VQ_RX_EMPTY_NOTIFY is disabled, notify the other side each time a buffer is released. If VQ_RX_EMPTY_NOTIFY is enabled, only send one notification when the RX queue is empty to improve performance. Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
Thanks for pointing out the grammatical error, done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to go.
Add VQ_RX_EMPTY_NOTIFY config to define the behavior. If VQ_RX_EMPTY_NOTIFY is disabled, notify the other side each time a buffer is released. If VQ_RX_EMPTY_NOTIFY is enabled, only send one notification when the RX queue is empty to improve performance.