[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1431617634.27831.60.camel@edumazet-glaptop2.roam.corp.google.com>
Date: Thu, 14 May 2015 08:33:54 -0700
From: Eric Dumazet <eric.dumazet@...il.com>
To: Willem de Bruijn <willemb@...gle.com>
Cc: netdev@...r.kernel.org, davem@...emloft.net
Subject: Re: [PATCH net-next] packet: fix warnings in rollover lock
contention
On Thu, 2015-05-14 at 10:42 -0400, Willem de Bruijn wrote:
> From: Willem de Bruijn <willemb@...gle.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@...gle.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.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists