All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Willem de Bruijn <willemb@google.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net
Subject: Re: [PATCH net-next] packet: fix warnings in rollover lock contention
Date: Thu, 14 May 2015 08:33:54 -0700	[thread overview]
Message-ID: <1431617634.27831.60.camel@edumazet-glaptop2.roam.corp.google.com> (raw)
In-Reply-To: <1431614560-8866-1-git-send-email-willemb@google.com>

On Thu, 2015-05-14 at 10:42 -0400, Willem de Bruijn wrote:
> From: Willem de Bruijn <willemb@google.com>
> 
> Avoid two xchg calls whose return values were unused, causing this
> warning on some architectures:
> 
>     warning: value computed is not used [-Wunused-value]
>     #define xchg(ptr,x) ((__typeof__(*(ptr)))\
>         __xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
>                        ^
>     net/packet/af_packet.c:1314:3: note: in expansion of macro 'xchg'
>     xchg(&po->pressure, !has_room);
> 
> The relevant variable is a hint to avoid lock contention. It is
> allowed to be imprecise (race).
> 
> Still, when rewriting this, also convert to use explicit atomic ops
> and remove a race by switching to atomic_cmpxchg. A rerun of the
> experiment from the original patch did not show this to cause
> significant cache line contention. Another non-atomic conditional
> clear remains in packet_poll, and is safe.
> 
> Fixes: 2ccdbaa6d55b ("packet: rollover lock contention avoidance")
> 
> Signed-off-by: Willem de Bruijn <willemb@google.com>
> ---
>  net/packet/af_packet.c | 12 ++++++------
>  net/packet/internal.h  |  2 +-
>  2 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 31d5856..ac1a589 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -1310,8 +1310,7 @@ static int packet_rcv_has_room(struct packet_sock *po, struct sk_buff *skb)
>  	}
>  
>  	has_room = ret == ROOM_NORMAL;
> -	if (po->pressure == has_room)
> -		xchg(&po->pressure, !has_room);
> +	if (atomic_cmpxchg(&po->pressure, has_room, !has_room)) {}
>  

This makes no sense to me.

I thought you wanted to avoid dirtying the cache line.

No atomic op can help the race here.

  reply	other threads:[~2015-05-14 15:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-14 14:42 [PATCH net-next] packet: fix warnings in rollover lock contention Willem de Bruijn
2015-05-14 15:33 ` Eric Dumazet [this message]
2015-05-14 15:53   ` Willem de Bruijn
2015-05-14 16:24     ` Eric Dumazet
2015-05-14 16:59       ` David Miller
2015-05-14 18:35         ` Willem de Bruijn
2015-05-14 18:46           ` David Miller
2015-05-14 18:59             ` Willem de Bruijn

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=1431617634.27831.60.camel@edumazet-glaptop2.roam.corp.google.com \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=willemb@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.