[PATCH][net-next][v2] virtio_net: s/raw_smp_processor_id/smp_processor_id/ in virtnet_xdp_get_sq

Subsystems: networking drivers, the rest, virtio net driver

STALE1789d

2 messages, 2 authors, 2021-09-13 · open the first message on its own page

[PATCH][net-next][v2] virtio_net: s/raw_smp_processor_id/smp_processor_id/ in virtnet_xdp_get_sq

From: Li RongQing <hidden>
Date: 2021-09-09 07:49:37

virtnet_xdp_get_sq() is called in non-preemptible context, so
it's safe to call the function smp_processor_id(), and keep
smp_processor_id(), and remove the calling of raw_smp_processor_id(),
this way we'll get a warning if this is ever called in a preemptible
context in the future

Signed-off-by: Li RongQing <redacted>
---
diff with v1: change log based on Michael S. Tsirkin's suggestion

 drivers/net/virtio_net.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 2e42210..2a7b368 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -528,19 +528,20 @@ static int __virtnet_xdp_xmit_one(struct virtnet_info *vi,
  * functions to perfectly solve these three problems at the same time.
  */
 #define virtnet_xdp_get_sq(vi) ({                                       \
+	int cpu = smp_processor_id();                                   \
 	struct netdev_queue *txq;                                       \
 	typeof(vi) v = (vi);                                            \
 	unsigned int qp;                                                \
 									\
 	if (v->curr_queue_pairs > nr_cpu_ids) {                         \
 		qp = v->curr_queue_pairs - v->xdp_queue_pairs;          \
-		qp += smp_processor_id();                               \
+		qp += cpu;                                              \
 		txq = netdev_get_tx_queue(v->dev, qp);                  \
 		__netif_tx_acquire(txq);                                \
 	} else {                                                        \
-		qp = smp_processor_id() % v->curr_queue_pairs;          \
+		qp = cpu % v->curr_queue_pairs;                         \
 		txq = netdev_get_tx_queue(v->dev, qp);                  \
-		__netif_tx_lock(txq, raw_smp_processor_id());           \
+		__netif_tx_lock(txq, cpu);                              \
 	}                                                               \
 	v->sq + qp;                                                     \
 })
-- 
1.7.1

Re: [PATCH][net-next][v2] virtio_net: s/raw_smp_processor_id/smp_processor_id/ in virtnet_xdp_get_sq

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-09-13 22:10:56

On Thu, Sep 09, 2021 at 03:49:31PM +0800, Li RongQing wrote:
virtnet_xdp_get_sq() is called in non-preemptible context, so
it's safe to call the function smp_processor_id(), and keep
smp_processor_id(), and remove the calling of raw_smp_processor_id(),
this way we'll get a warning if this is ever called in a preemptible
context in the future

Signed-off-by: Li RongQing <redacted>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
quoted hunk
---
diff with v1: change log based on Michael S. Tsirkin's suggestion

 drivers/net/virtio_net.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 2e42210..2a7b368 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -528,19 +528,20 @@ static int __virtnet_xdp_xmit_one(struct virtnet_info *vi,
  * functions to perfectly solve these three problems at the same time.
  */
 #define virtnet_xdp_get_sq(vi) ({                                       \
+	int cpu = smp_processor_id();                                   \
 	struct netdev_queue *txq;                                       \
 	typeof(vi) v = (vi);                                            \
 	unsigned int qp;                                                \
 									\
 	if (v->curr_queue_pairs > nr_cpu_ids) {                         \
 		qp = v->curr_queue_pairs - v->xdp_queue_pairs;          \
-		qp += smp_processor_id();                               \
+		qp += cpu;                                              \
 		txq = netdev_get_tx_queue(v->dev, qp);                  \
 		__netif_tx_acquire(txq);                                \
 	} else {                                                        \
-		qp = smp_processor_id() % v->curr_queue_pairs;          \
+		qp = cpu % v->curr_queue_pairs;                         \
 		txq = netdev_get_tx_queue(v->dev, qp);                  \
-		__netif_tx_lock(txq, raw_smp_processor_id());           \
+		__netif_tx_lock(txq, cpu);                              \
 	}                                                               \
 	v->sq + qp;                                                     \
 })
-- 
1.7.1

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help