Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1162461pxu; Fri, 27 Nov 2020 00:54:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGZBERXV+SBB44eXvelKpO0sPwQ51kKssSoyrkA0jXYZAP9pkrAYviYhN8rcN5aUgp5B5k X-Received: by 2002:a17:906:ecad:: with SMTP id qh13mr1173609ejb.443.1606467252981; Fri, 27 Nov 2020 00:54:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606467252; cv=none; d=google.com; s=arc-20160816; b=UPDHzARGRgrrKhtWLsGriQtptWh1cJQLGlDX1Wjbh+E3qKZfysvI7BQwTFBPzYe8Hx a79id2WQOVLt7Rcmt5IDcBQlYgcxIflARdAhFH9N9V2usAkLKBgq3o1FH4GjH/BIs5i7 FIevwNbf07CHlwOa5h9FjuOtyllRIiCufMurhNL5uJlUJQ4TireRzDfdsf/G1j+N7tgZ NV9Vwvs5QGrrUjafqwSEr8PN9lQrHsy8x0QslTTUpptD72dsQTy9ADxTaS5n3daBspmp j3NzOmCs3IuPNtCtMa3JZbFFdh+24hDktkhK40H7XbEmrm0cF65LqZxyJkSpWr+UP31Y Hvcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Gc7eWnisDSwnflspZV/ylxsl1sx9kw3MIByDGHLLb8w=; b=0oSRvAjSlbDgl97fHrI/Ywuok7tPzhTE3xEeeg/QWV1U3CJXj9yWBmSZXqSTf3Ds10 eDE/tP5xT9Y+h61d/3Sp4og1VRQ7VCEl/8tqlpdPAGGt5r6hXK41CwcpmVajl69GZbMl zGVW7ZGuibDeKPHltAxsIRg+Rozh0E4bvjSD1QLqhaAU+8denPsu9kQACqHBqdh8qmMK kMmpwroWyIS3tfH0L127V0Wn2KwBraI/y7C2V9DYDWIaP81+bXyEjQUEPjRiMkdLBo8Q mhUBHvlFQAu7KF9hYhxoSDG/lmYhA5CM8RJqEKX/IT9DvP6Nc/hiLD/sp/LuSLTd/3fP rZ7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qhn8gpAo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j18si4650126ejs.70.2020.11.27.00.53.50; Fri, 27 Nov 2020 00:54:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qhn8gpAo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727514AbgK0IXI (ORCPT + 99 others); Fri, 27 Nov 2020 03:23:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725980AbgK0IXB (ORCPT ); Fri, 27 Nov 2020 03:23:01 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DFD3C0613D1; Fri, 27 Nov 2020 00:23:01 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id w4so3732464pgg.13; Fri, 27 Nov 2020 00:23:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Gc7eWnisDSwnflspZV/ylxsl1sx9kw3MIByDGHLLb8w=; b=qhn8gpAomZ7r9dr1lS3P0cP4zSZT5JoJ4JRDBQpT94LsCTD0o8Qa4w0ppXdZiY3bIA zHFhKJov7HDaBjiq40XUIGo8jQKGxhAn3lPSy+8/x/nlj7qt68S0cpnIEhmGcb0+YC8d sXv3/uODwwWWT5BLEjoaklobwNBgJtS7HVlt+YsgK+SsI16+MY/k/QAY+/CCep/wWf88 gbF5TUVwh4+AijS4nkf1dxd5Y58QUdGKv1bPMGAFDN0QCk7ir1U6aWTjIAAZUpm4Gy5l xprNDTh+guiF96qAVTHUUkK+r4v5CfX5hXA8hrBx/sZG+zMG9CF6I3VAZX7BTEbOL9ov yScw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Gc7eWnisDSwnflspZV/ylxsl1sx9kw3MIByDGHLLb8w=; b=NgY7QIdjNnh4URjPeohgBUL1KjVoep/C6wjc5rF6HocaFwTbNQtwy/jyW0UD5nn8mw EmR02As3w7n4Kh7E3QcFO1yZ/cPj2HzbDSpI9CIh7X5Df4/sFanwtmtOBG4Sc1BBimJn fs/HAS59R4daAO5/eFo1eReINekxRMDSntOvIcjAoEanXSST0P6GM7zwopbJqWgXwUpQ lCp1K9orv8RCZMXEOtCcRdAJqIbOQAhjjMl6o8A2cRMbU4TwzxrX6rr55Mpbjjwq+qTz 93VWt1060m45eRCz9Pu/7DBvhguz/ICCMdAn+b5m+LXYK+PKaep6+kHuQk4azZjjWBMw OmuQ== X-Gm-Message-State: AOAM533Nv5xLSyVkfbSHFFNC/kzXis5ZnBEeYgVwXgJSo3u0jKIACi94 I7m5bLJ0Z7GDAm6m3z58EliZy9cYryAWWj2g5yU= X-Received: by 2002:a17:90a:eb90:: with SMTP id o16mr8306990pjy.204.1606465380670; Fri, 27 Nov 2020 00:23:00 -0800 (PST) MIME-Version: 1.0 References: <4fd58d473f4548dc6e9e24ea9876c802d5d584b4.1606285978.git.xuanzhuo@linux.alibaba.com> In-Reply-To: <4fd58d473f4548dc6e9e24ea9876c802d5d584b4.1606285978.git.xuanzhuo@linux.alibaba.com> From: Magnus Karlsson Date: Fri, 27 Nov 2020 09:22:49 +0100 Message-ID: Subject: Re: [PATCH bpf v2 2/2] xsk: change the tx writeable condition To: Xuan Zhuo Cc: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , KP Singh , "open list:XDP SOCKETS (AF_XDP)" , "open list:XDP SOCKETS (AF_XDP)" , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 25, 2020 at 7:49 AM Xuan Zhuo wrote: > > Modify the tx writeable condition from the queue is not full to the > number of present tx queues is less than the half of the total number > of queues. Because the tx queue not full is a very short time, this will > cause a large number of EPOLLOUT events, and cause a large number of > process wake up. > > Signed-off-by: Xuan Zhuo Thank you Xuan! Acked-by: Magnus Karlsson > --- > net/xdp/xsk.c | 16 +++++++++++++--- > net/xdp/xsk_queue.h | 6 ++++++ > 2 files changed, 19 insertions(+), 3 deletions(-) > > diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c > index 0df8651..22e35e9 100644 > --- a/net/xdp/xsk.c > +++ b/net/xdp/xsk.c > @@ -211,6 +211,14 @@ static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len, > return 0; > } > > +static bool xsk_tx_writeable(struct xdp_sock *xs) > +{ > + if (xskq_cons_present_entries(xs->tx) > xs->tx->nentries / 2) > + return false; > + > + return true; > +} > + > static bool xsk_is_bound(struct xdp_sock *xs) > { > if (READ_ONCE(xs->state) == XSK_BOUND) { > @@ -296,7 +304,8 @@ void xsk_tx_release(struct xsk_buff_pool *pool) > rcu_read_lock(); > list_for_each_entry_rcu(xs, &pool->xsk_tx_list, tx_list) { > __xskq_cons_release(xs->tx); > - xs->sk.sk_write_space(&xs->sk); > + if (xsk_tx_writeable(xs)) > + xs->sk.sk_write_space(&xs->sk); > } > rcu_read_unlock(); > } > @@ -499,7 +508,8 @@ static int xsk_generic_xmit(struct sock *sk) > > out: > if (sent_frame) > - sk->sk_write_space(sk); > + if (xsk_tx_writeable(xs)) > + sk->sk_write_space(sk); > > mutex_unlock(&xs->mutex); > return err; > @@ -556,7 +566,7 @@ static __poll_t xsk_poll(struct file *file, struct socket *sock, > > if (xs->rx && !xskq_prod_is_empty(xs->rx)) > mask |= EPOLLIN | EPOLLRDNORM; > - if (xs->tx && !xskq_cons_is_full(xs->tx)) > + if (xs->tx && xsk_tx_writeable(xs)) > mask |= EPOLLOUT | EPOLLWRNORM; > > return mask; > diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h > index b936c46..b655004 100644 > --- a/net/xdp/xsk_queue.h > +++ b/net/xdp/xsk_queue.h > @@ -307,6 +307,12 @@ static inline bool xskq_cons_is_full(struct xsk_queue *q) > q->nentries; > } > > +static inline __u64 xskq_cons_present_entries(struct xsk_queue *q) > +{ > + /* No barriers needed since data is not accessed */ > + return READ_ONCE(q->ring->producer) - READ_ONCE(q->ring->consumer); > +} > + > /* Functions for producers */ > > static inline u32 xskq_prod_nb_free(struct xsk_queue *q, u32 max) > -- > 1.8.3.1 >