From: Xiang Xiao <xiaoxiang781216@gmail.com>
To: ohad@wizery.com, bjorn.andersson@linaro.org,
wendy.liang@xilinx.com, arnaud.pouliquen@st.com,
linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Xiang Xiao <xiaoxiang@xiaomi.com>
Subject: [PATCH 1/3] rpmsg: virtio_rpmsg_bus: allow the different vring size for send/recv
Date: Thu, 31 Jan 2019 23:41:18 +0800 [thread overview]
Message-ID: <1548949280-31794-2-git-send-email-xiaoxiang@xiaomi.com> (raw)
In-Reply-To: <1548949280-31794-1-git-send-email-xiaoxiang@xiaomi.com>
it's useful if the communication throughput is different from each side
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
---
drivers/rpmsg/virtio_rpmsg_bus.c | 47 ++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 23 deletions(-)
diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 664f957..fb0d2eb 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -36,8 +36,9 @@
* @svq: tx virtqueue
* @rbufs: kernel address of rx buffers
* @sbufs: kernel address of tx buffers
- * @num_bufs: total number of buffers for rx and tx
- * @buf_size: size of one rx or tx buffer
+ * @num_rbufs: total number of buffers for rx
+ * @num_sbufs: total number of buffers for tx
+ * @buf_size: size of one rx or tx buffer
* @last_sbuf: index of last tx buffer used
* @bufs_dma: dma base addr of the buffers
* @tx_lock: protects svq, sbufs and sleepers, to allow concurrent senders.
@@ -57,7 +58,8 @@ struct virtproc_info {
struct virtio_device *vdev;
struct virtqueue *rvq, *svq;
void *rbufs, *sbufs;
- unsigned int num_bufs;
+ unsigned int num_rbufs;
+ unsigned int num_sbufs;
unsigned int buf_size;
int last_sbuf;
dma_addr_t bufs_dma;
@@ -136,7 +138,7 @@ struct virtio_rpmsg_channel {
/*
* We're allocating buffers of 512 bytes each for communications. The
* number of buffers will be computed from the number of buffers supported
- * by the vring, upto a maximum of 512 buffers (256 in each direction).
+ * by the vring, up to a maximum of 256 in each direction.
*
* Each buffer will have 16 bytes for the msg header and 496 bytes for
* the payload.
@@ -151,7 +153,7 @@ struct virtio_rpmsg_channel {
* can change this without changing anything in the firmware of the remote
* processor.
*/
-#define MAX_RPMSG_NUM_BUFS (512)
+#define MAX_RPMSG_NUM_BUFS (256)
#define MAX_RPMSG_BUF_SIZE (512)
/*
@@ -446,11 +448,8 @@ static void *get_a_tx_buf(struct virtproc_info *vrp)
/* support multiple concurrent senders */
mutex_lock(&vrp->tx_lock);
- /*
- * either pick the next unused tx buffer
- * (half of our buffers are used for sending messages)
- */
- if (vrp->last_sbuf < vrp->num_bufs / 2)
+ /* either pick the next unused tx buffer */
+ if (vrp->last_sbuf < vrp->num_sbufs)
ret = vrp->sbufs + vrp->buf_size * vrp->last_sbuf++;
/* or recycle a used one */
else
@@ -897,19 +896,20 @@ static int rpmsg_probe(struct virtio_device *vdev)
vrp->rvq = vqs[0];
vrp->svq = vqs[1];
- /* we expect symmetric tx/rx vrings */
- WARN_ON(virtqueue_get_vring_size(vrp->rvq) !=
- virtqueue_get_vring_size(vrp->svq));
-
/* we need less buffers if vrings are small */
- if (virtqueue_get_vring_size(vrp->rvq) < MAX_RPMSG_NUM_BUFS / 2)
- vrp->num_bufs = virtqueue_get_vring_size(vrp->rvq) * 2;
+ if (virtqueue_get_vring_size(vrp->rvq) < MAX_RPMSG_NUM_BUFS)
+ vrp->num_rbufs = virtqueue_get_vring_size(vrp->rvq);
+ else
+ vrp->num_rbufs = MAX_RPMSG_NUM_BUFS;
+
+ if (virtqueue_get_vring_size(vrp->svq) < MAX_RPMSG_NUM_BUFS)
+ vrp->num_sbufs = virtqueue_get_vring_size(vrp->svq);
else
- vrp->num_bufs = MAX_RPMSG_NUM_BUFS;
+ vrp->num_sbufs = MAX_RPMSG_NUM_BUFS;
vrp->buf_size = MAX_RPMSG_BUF_SIZE;
- total_buf_space = vrp->num_bufs * vrp->buf_size;
+ total_buf_space = (vrp->num_rbufs + vrp->num_sbufs) * vrp->buf_size;
/* allocate coherent memory for the buffers */
bufs_va = dma_alloc_coherent(vdev->dev.parent->parent,
@@ -923,14 +923,14 @@ static int rpmsg_probe(struct virtio_device *vdev)
dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n",
bufs_va, &vrp->bufs_dma);
- /* half of the buffers is dedicated for RX */
+ /* first part of the buffers is dedicated for RX */
vrp->rbufs = bufs_va;
- /* and half is dedicated for TX */
- vrp->sbufs = bufs_va + total_buf_space / 2;
+ /* and second part is dedicated for TX */
+ vrp->sbufs = bufs_va + vrp->num_rbufs * vrp->buf_size;
/* set up the receive buffers */
- for (i = 0; i < vrp->num_bufs / 2; i++) {
+ for (i = 0; i < vrp->num_rbufs; i++) {
struct scatterlist sg;
void *cpu_addr = vrp->rbufs + i * vrp->buf_size;
@@ -999,7 +999,8 @@ static int rpmsg_remove_device(struct device *dev, void *data)
static void rpmsg_remove(struct virtio_device *vdev)
{
struct virtproc_info *vrp = vdev->priv;
- size_t total_buf_space = vrp->num_bufs * vrp->buf_size;
+ unsigned int num_bufs = vrp->num_rbufs + vrp->num_sbufs;
+ size_t total_buf_space = num_bufs * vrp->buf_size;
int ret;
vdev->config->reset(vdev);
--
2.7.4
next prev parent reply other threads:[~2019-01-31 15:42 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-31 15:41 [PATCH 0/3] Enhance virtio rpmsg bus driver buffer allocation Xiang Xiao
2019-01-31 15:41 ` Xiang Xiao [this message]
2019-05-09 11:47 ` [PATCH 1/3] rpmsg: virtio_rpmsg_bus: allow the different vring size for send/recv Arnaud Pouliquen
2019-01-31 15:41 ` [PATCH 2/3] rpmsg: virtio_rpmsg_bus: allocate rx/tx buffer separately Xiang Xiao
2019-05-09 12:02 ` Arnaud Pouliquen
2019-05-09 12:37 ` xiang xiao
2019-01-31 15:41 ` [PATCH 3/3] rpmsg: virtio_rpmsg_bus: get buffer size from config space Xiang Xiao
2019-05-09 12:36 ` Arnaud Pouliquen
2019-05-09 13:00 ` xiang xiao
2019-06-04 14:25 ` Arnaud Pouliquen
2019-06-05 2:40 ` xiang xiao
2019-06-05 8:02 ` Arnaud Pouliquen
2019-06-05 8:36 ` xiang xiao
2019-06-05 4:34 ` [PATCH 0/3] Enhance virtio rpmsg bus driver buffer allocation Bjorn Andersson
2019-06-05 7:33 ` Arnaud Pouliquen
2019-06-05 8:35 ` xiang xiao
2019-07-01 6:13 ` Bjorn Andersson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1548949280-31794-2-git-send-email-xiaoxiang@xiaomi.com \
--to=xiaoxiang781216@gmail.com \
--cc=arnaud.pouliquen@st.com \
--cc=bjorn.andersson@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=ohad@wizery.com \
--cc=wendy.liang@xilinx.com \
--cc=xiaoxiang@xiaomi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).