netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] tun: replace get_cpu_ptr with this_cpu_ptr when bh disabled
@ 2018-12-11  2:43 Prashant Bhole
  2018-12-11  3:31 ` Michael S. Tsirkin
  2018-12-14 21:33 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Prashant Bhole @ 2018-12-11  2:43 UTC (permalink / raw)
  To: David S . Miller
  Cc: Prashant Bhole, Jason Wang, Michael S . Tsirkin, netdev,
	Toshiaki Makita

tun_xdp_one() runs with local bh disabled. So there is no need to
disable preemption by calling get_cpu_ptr while updating stats. This
patch replaces the use of get_cpu_ptr() with this_cpu_ptr() as a
micro-optimization. Also removes related put_cpu_ptr call.

Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
---
v1 -> v2: Added comment to explain why this change is safe

 drivers/net/tun.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 6760b86547df..cb90859d0433 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -2494,12 +2494,14 @@ static int tun_xdp_one(struct tun_struct *tun,
 	skb_record_rx_queue(skb, tfile->queue_index);
 	netif_receive_skb(skb);
 
-	stats = get_cpu_ptr(tun->pcpu_stats);
+	/* No need for get_cpu_ptr() here since this function is
+	 * always called with bh disabled
+	 */
+	stats = this_cpu_ptr(tun->pcpu_stats);
 	u64_stats_update_begin(&stats->syncp);
 	stats->rx_packets++;
 	stats->rx_bytes += skb->len;
 	u64_stats_update_end(&stats->syncp);
-	put_cpu_ptr(stats);
 
 	if (rxhash)
 		tun_flow_update(tun, rxhash, tfile);
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v2] tun: replace get_cpu_ptr with this_cpu_ptr when bh disabled
  2018-12-11  2:43 [PATCH net-next v2] tun: replace get_cpu_ptr with this_cpu_ptr when bh disabled Prashant Bhole
@ 2018-12-11  3:31 ` Michael S. Tsirkin
  2018-12-14 21:33 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2018-12-11  3:31 UTC (permalink / raw)
  To: Prashant Bhole; +Cc: David S . Miller, Jason Wang, netdev, Toshiaki Makita

On Tue, Dec 11, 2018 at 11:43:07AM +0900, Prashant Bhole wrote:
> tun_xdp_one() runs with local bh disabled. So there is no need to
> disable preemption by calling get_cpu_ptr while updating stats. This
> patch replaces the use of get_cpu_ptr() with this_cpu_ptr() as a
> micro-optimization. Also removes related put_cpu_ptr call.
> 
> Acked-by: Jason Wang <jasowang@redhat.com>
> Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
> v1 -> v2: Added comment to explain why this change is safe
> 
>  drivers/net/tun.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 6760b86547df..cb90859d0433 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -2494,12 +2494,14 @@ static int tun_xdp_one(struct tun_struct *tun,
>  	skb_record_rx_queue(skb, tfile->queue_index);
>  	netif_receive_skb(skb);
>  
> -	stats = get_cpu_ptr(tun->pcpu_stats);
> +	/* No need for get_cpu_ptr() here since this function is
> +	 * always called with bh disabled
> +	 */
> +	stats = this_cpu_ptr(tun->pcpu_stats);
>  	u64_stats_update_begin(&stats->syncp);
>  	stats->rx_packets++;
>  	stats->rx_bytes += skb->len;
>  	u64_stats_update_end(&stats->syncp);
> -	put_cpu_ptr(stats);
>  
>  	if (rxhash)
>  		tun_flow_update(tun, rxhash, tfile);
> -- 
> 2.17.2
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v2] tun: replace get_cpu_ptr with this_cpu_ptr when bh disabled
  2018-12-11  2:43 [PATCH net-next v2] tun: replace get_cpu_ptr with this_cpu_ptr when bh disabled Prashant Bhole
  2018-12-11  3:31 ` Michael S. Tsirkin
@ 2018-12-14 21:33 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2018-12-14 21:33 UTC (permalink / raw)
  To: bhole_prashant_q7; +Cc: jasowang, mst, netdev, makita.toshiaki

From: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
Date: Tue, 11 Dec 2018 11:43:07 +0900

> tun_xdp_one() runs with local bh disabled. So there is no need to
> disable preemption by calling get_cpu_ptr while updating stats. This
> patch replaces the use of get_cpu_ptr() with this_cpu_ptr() as a
> micro-optimization. Also removes related put_cpu_ptr call.
> 
> Acked-by: Jason Wang <jasowang@redhat.com>
> Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
> ---
> v1 -> v2: Added comment to explain why this change is safe

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-14 21:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-11  2:43 [PATCH net-next v2] tun: replace get_cpu_ptr with this_cpu_ptr when bh disabled Prashant Bhole
2018-12-11  3:31 ` Michael S. Tsirkin
2018-12-14 21:33 ` David Miller

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).