* [dpdk-dev] [PATCH] virtio: fix idx in used ring retrieved only once
@ 2016-06-15 18:30 Huawei Xie
2016-06-19 17:48 ` [dpdk-dev] [PATCH v2] " Huawei Xie
2016-06-20 6:27 ` [dpdk-dev] [PATCH] " Yuanhan Liu
0 siblings, 2 replies; 4+ messages in thread
From: Huawei Xie @ 2016-06-15 18:30 UTC (permalink / raw)
To: dev
Cc: yuanhan.liu, thomas.monjalon, mst, jianfeng.tan, stephen,
konstantin.ananyev, bruce.richardson, Huawei Xie
In the following loop:
while (vq->vq_used_cons_idx != vq->vq_ring.used->idx) {
...
}
There is no external function call or any explict memory barrier
in the loop, the re-read of used->idx would be optimized and would
only be retrieved once.
use of voaltile normally should be prohibited, and access_once
is Linux kernel's style to handle this issue; Once we have that
macro in DPDK, we could change to that style.
virtio_recv_mergable_pkts might have the same issue, so will be fixed.
Fixes: 823ad647950a ("virtio: support multiple queues")
Fixes: 13ce5e7eb94f ("virtio: mergeable buffers")
Signed-off-by: Huawei Xie <huawei.xie@intel.com>
---
drivers/net/virtio/virtio_ethdev.c | 4 ++--
drivers/net/virtio/virtio_ring.h | 2 +-
drivers/net/virtio/virtio_rxtx_simple.c | 3 +--
3 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index ea7a48e..6a51948 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -219,12 +219,12 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
virtqueue_notify(vq);
rte_rmb();
- while (vq->vq_used_cons_idx == vq->vq_ring.used->idx) {
+ while (VIRTQUEUE_NUSED(vq) == 0) {
rte_rmb();
usleep(100);
}
- while (vq->vq_used_cons_idx != vq->vq_ring.used->idx) {
+ while (VIRTQUEUE_NUSED(vq)) {
uint32_t idx, desc_idx, used_idx;
struct vring_used_elem *uep;
diff --git a/drivers/net/virtio/virtio_ring.h b/drivers/net/virtio/virtio_ring.h
index 447760a..fcecc16 100644
--- a/drivers/net/virtio/virtio_ring.h
+++ b/drivers/net/virtio/virtio_ring.h
@@ -79,7 +79,7 @@ struct vring_used_elem {
struct vring_used {
uint16_t flags;
- uint16_t idx;
+ volatile uint16_t idx;
struct vring_used_elem ring[0];
};
diff --git a/drivers/net/virtio/virtio_rxtx_simple.c b/drivers/net/virtio/virtio_rxtx_simple.c
index 7b50119..a0ef8d2 100644
--- a/drivers/net/virtio/virtio_rxtx_simple.c
+++ b/drivers/net/virtio/virtio_rxtx_simple.c
@@ -184,8 +184,7 @@ virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
if (unlikely(nb_pkts < RTE_VIRTIO_DESC_PER_LOOP))
return 0;
- nb_used = *(volatile uint16_t *)&vq->vq_ring.used->idx -
- vq->vq_used_cons_idx;
+ nb_used = vq->vq_ring.used->idx - vq->vq_used_cons_idx;
rte_compiler_barrier();
--
1.8.1.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* [dpdk-dev] [PATCH v2] virtio: fix idx in used ring retrieved only once
2016-06-15 18:30 [dpdk-dev] [PATCH] virtio: fix idx in used ring retrieved only once Huawei Xie
@ 2016-06-19 17:48 ` Huawei Xie
2016-06-20 11:46 ` Yuanhan Liu
2016-06-20 6:27 ` [dpdk-dev] [PATCH] " Yuanhan Liu
1 sibling, 1 reply; 4+ messages in thread
From: Huawei Xie @ 2016-06-19 17:48 UTC (permalink / raw)
To: dev
Cc: yuanhan.liu, thomas.monjalon, mst, jianfeng.tan, stephen,
konstantin.ananyev, bruce.richardson, Huawei Xie
In the following loop:
while (vq->vq_used_cons_idx != vq->vq_ring.used->idx) {
...
}
There is no external function call or any explict memory barrier
in the loop, the re-read of used->idx would be optimized and would
only be retrieved once.
use of voaltile normally should be prohibited, and access_once
is Linux kernel's style to handle this issue; Once we have that
macro in DPDK, we could change to that style.
virtio_recv_mergable_pkts might have the same issue, so will be fixed.
Fixes: 823ad647950a ("virtio: support multiple queues")
Fixes: 13ce5e7eb94f ("virtio: mergeable buffers")
Signed-off-by: Huawei Xie <huawei.xie@intel.com>
---
v2: use VIRTQUEUE_NUSED
---
drivers/net/virtio/virtio_ethdev.c | 4 ++--
drivers/net/virtio/virtio_ring.h | 2 +-
drivers/net/virtio/virtio_rxtx_simple.c | 3 +--
3 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index ea7a48e..6a51948 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -219,12 +219,12 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
virtqueue_notify(vq);
rte_rmb();
- while (vq->vq_used_cons_idx == vq->vq_ring.used->idx) {
+ while (VIRTQUEUE_NUSED(vq) == 0) {
rte_rmb();
usleep(100);
}
- while (vq->vq_used_cons_idx != vq->vq_ring.used->idx) {
+ while (VIRTQUEUE_NUSED(vq)) {
uint32_t idx, desc_idx, used_idx;
struct vring_used_elem *uep;
diff --git a/drivers/net/virtio/virtio_ring.h b/drivers/net/virtio/virtio_ring.h
index 447760a..fcecc16 100644
--- a/drivers/net/virtio/virtio_ring.h
+++ b/drivers/net/virtio/virtio_ring.h
@@ -79,7 +79,7 @@ struct vring_used_elem {
struct vring_used {
uint16_t flags;
- uint16_t idx;
+ volatile uint16_t idx;
struct vring_used_elem ring[0];
};
diff --git a/drivers/net/virtio/virtio_rxtx_simple.c b/drivers/net/virtio/virtio_rxtx_simple.c
index 7b50119..242ad90 100644
--- a/drivers/net/virtio/virtio_rxtx_simple.c
+++ b/drivers/net/virtio/virtio_rxtx_simple.c
@@ -184,8 +184,7 @@ virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
if (unlikely(nb_pkts < RTE_VIRTIO_DESC_PER_LOOP))
return 0;
- nb_used = *(volatile uint16_t *)&vq->vq_ring.used->idx -
- vq->vq_used_cons_idx;
+ nb_used = VIRTQUEUE_NUSED(vq);
rte_compiler_barrier();
--
1.8.1.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH] virtio: fix idx in used ring retrieved only once
2016-06-15 18:30 [dpdk-dev] [PATCH] virtio: fix idx in used ring retrieved only once Huawei Xie
2016-06-19 17:48 ` [dpdk-dev] [PATCH v2] " Huawei Xie
@ 2016-06-20 6:27 ` Yuanhan Liu
1 sibling, 0 replies; 4+ messages in thread
From: Yuanhan Liu @ 2016-06-20 6:27 UTC (permalink / raw)
To: Huawei Xie
Cc: dev, yuanhan.liu, thomas.monjalon, mst, jianfeng.tan, stephen,
konstantin.ananyev, bruce.richardson
On Thu, Jun 16, 2016 at 02:30:37AM +0800, Huawei Xie wrote:
> - while (vq->vq_used_cons_idx != vq->vq_ring.used->idx) {
> + while (VIRTQUEUE_NUSED(vq)) {
> uint32_t idx, desc_idx, used_idx;
> struct vring_used_elem *uep;
>
> diff --git a/drivers/net/virtio/virtio_ring.h b/drivers/net/virtio/virtio_ring.h
> index 447760a..fcecc16 100644
> --- a/drivers/net/virtio/virtio_ring.h
> +++ b/drivers/net/virtio/virtio_ring.h
> @@ -79,7 +79,7 @@ struct vring_used_elem {
>
> struct vring_used {
> uint16_t flags;
> - uint16_t idx;
> + volatile uint16_t idx;
> struct vring_used_elem ring[0];
> };
>
> diff --git a/drivers/net/virtio/virtio_rxtx_simple.c b/drivers/net/virtio/virtio_rxtx_simple.c
> index 7b50119..a0ef8d2 100644
> --- a/drivers/net/virtio/virtio_rxtx_simple.c
> +++ b/drivers/net/virtio/virtio_rxtx_simple.c
> @@ -184,8 +184,7 @@ virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
> if (unlikely(nb_pkts < RTE_VIRTIO_DESC_PER_LOOP))
> return 0;
>
> - nb_used = *(volatile uint16_t *)&vq->vq_ring.used->idx -
> - vq->vq_used_cons_idx;
> + nb_used = vq->vq_ring.used->idx - vq->vq_used_cons_idx;
How about replacing it with VIRTQUEUE_NUSED here?
--yliu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH v2] virtio: fix idx in used ring retrieved only once
2016-06-19 17:48 ` [dpdk-dev] [PATCH v2] " Huawei Xie
@ 2016-06-20 11:46 ` Yuanhan Liu
0 siblings, 0 replies; 4+ messages in thread
From: Yuanhan Liu @ 2016-06-20 11:46 UTC (permalink / raw)
To: Huawei Xie
Cc: dev, yuanhan.liu, thomas.monjalon, mst, jianfeng.tan, stephen,
konstantin.ananyev, bruce.richardson
On Mon, Jun 20, 2016 at 01:48:52AM +0800, Huawei Xie wrote:
> In the following loop:
> while (vq->vq_used_cons_idx != vq->vq_ring.used->idx) {
> ...
> }
> There is no external function call or any explict memory barrier
> in the loop, the re-read of used->idx would be optimized and would
> only be retrieved once.
>
> use of voaltile normally should be prohibited, and access_once
> is Linux kernel's style to handle this issue; Once we have that
> macro in DPDK, we could change to that style.
>
> virtio_recv_mergable_pkts might have the same issue, so will be fixed.
>
> Fixes: 823ad647950a ("virtio: support multiple queues")
> Fixes: 13ce5e7eb94f ("virtio: mergeable buffers")
>
> Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Applied to dpdk-next-virtio.
Thanks.
--yliu
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-06-20 11:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-15 18:30 [dpdk-dev] [PATCH] virtio: fix idx in used ring retrieved only once Huawei Xie
2016-06-19 17:48 ` [dpdk-dev] [PATCH v2] " Huawei Xie
2016-06-20 11:46 ` Yuanhan Liu
2016-06-20 6:27 ` [dpdk-dev] [PATCH] " Yuanhan Liu
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).