Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2978321pxb; Mon, 16 Nov 2020 02:25:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJyUBhlCvFqURd/1tq9PII9sxP0AFLFFyoE5VQy5Tsw3QCcXxObMMmhiY8WCCP2LfoGnvIdL X-Received: by 2002:aa7:c597:: with SMTP id g23mr14820479edq.184.1605522325338; Mon, 16 Nov 2020 02:25:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605522325; cv=none; d=google.com; s=arc-20160816; b=IwxyEpZdkCsMrw12MI1K0ysVC+144NegTysNnceiBJT51x+C+u9ca76bKjWKeQtdi8 8bMvPymJLOT6JvWRpyjEURUygTxQ8yqloCu8ETehfygB2Vj//vmx3A4tNRyPD/tX6PIX 2Mmy7ni5oPD1p7inYEizi9Yx2bcbRoFB8dNLqrPwRcVDL86vpspFpDh1bpkgPktrAmyD CWbArHkZvEdMhvYELxRx6md8H21WqM7aDMsFsWQyCDL6QDBKH7odh4Rm493UNrkoo1IM RxnZgtdy+SorVSSv8iyTvY7/Jr80Qddb3Mdgm4EIJqTlde+UJUoklQbFnB7AF1TPvDP5 5Xng== 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:references :in-reply-to:mime-version:dkim-signature; bh=EpCdx6ixp9LFmw2piU2X13qWUIfYcG+nteeMAXbXg44=; b=Q+gRqZ368FQIxfoQFQE9W3dmC3AuizUH5QKVdBLQ3Yn6BxW9lnodIy2Sne/wNDi7DQ 7NYxu5/Otw0LNkJaCU0tKJKm6xe7OzBhfXAGNwWY136WIMsFOhIX82VE+Z8HW4Ifahty QawPJWipJsI1WgZtFC9X0/STqooMPTT/DDjT02LwR8y56kHZnDq0EodVIhULWQIYEBGD qw4FWrKYQv4BEiPFUIDpyG6JiXT+U4YYEPQAEMYwsVGuv8PqG4Cb52ifPalD5DRkooLL +sQUwTCJRIPvkZ7wd4nWVxJARXLPLyIpxYByi54BaySzqFCXs0dZhxBKZD7K5w9uNJ3g xWiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-powerpc-org.20150623.gappssmtp.com header.s=20150623 header.b=NGEJmjcq; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z41si12572080ede.375.2020.11.16.02.25.02; Mon, 16 Nov 2020 02:25:25 -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=@linux-powerpc-org.20150623.gappssmtp.com header.s=20150623 header.b=NGEJmjcq; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729134AbgKPKVG (ORCPT + 99 others); Mon, 16 Nov 2020 05:21:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728696AbgKPKVF (ORCPT ); Mon, 16 Nov 2020 05:21:05 -0500 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B7B0C0613D1 for ; Mon, 16 Nov 2020 02:21:05 -0800 (PST) Received: by mail-ej1-x644.google.com with SMTP id o9so23640122ejg.1 for ; Mon, 16 Nov 2020 02:21:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-powerpc-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=EpCdx6ixp9LFmw2piU2X13qWUIfYcG+nteeMAXbXg44=; b=NGEJmjcq260iw2P9sz5e2pCivewtZBnLTJib7zah8UlG7oP0vy4YcXL88dltH/Gc2K 5RTIFjxmScyk7J0oAqrZ3kdmEZHfOQg/k1O4+yvDzsyZHm7SCVN3Wgx0JyH4nCIFQWvd pcHOIeFx00U3JHZGEvQkun83UjkCECyGsX2FQCmeUeLuTX7Ir7GqbCT67ekse3aQ6k7c mgFwdaiwM1XzA95q6YkLov+zVHoGMe6X2azInEPkyZ/ldh7cnjCqUAxFjBOD+JQ52zcE N/LEXqKKA/SjvxGx8QZhH6qBUuA2PtBWNdk8FKa6oIWWTKa76LHeTOxWJ5FpeYVfSMk4 xd/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=EpCdx6ixp9LFmw2piU2X13qWUIfYcG+nteeMAXbXg44=; b=oX776PuLQhOZav31k13b32rbZJ6gHHdNACdTnvqHLdp/R/zChgBiUenmQRaAGXSsRx IBVOn3yEwHYKVHz6c7i1CInYpeSQ3Hrx6vuBvma/u0pPcqJE/p+8e3Ek+nIvPgWpJuBI K/sq90XQx7TuiEflbgAoWurlHfAchXE3w1TR44bDBZ0jvsM+g4QQJRJ2x0nPn8cpm9f1 ZfYYTibV8Cm5mNzRBWosCUL/LOW3Rt6UTiym3vK6yxfOLZnDMUOEHrcYL5OioxzDBzJZ c3CpeJVG4OWUOq36Kt5TA5PtzJDSInRtuYu8NWs5Ss02huHUqfK+mC3svW7mBUl0utwK 9YFQ== X-Gm-Message-State: AOAM530TJr+Wptg3ft666ozLvcXQA5EU/ruKaEyWp6UTwMr5JPAGVXTq oI7t4GZi1HPakWpDVt/TzwO4eYGYNsZ0w+CmuxX+EQ== X-Received: by 2002:a17:906:f8c5:: with SMTP id lh5mr14545185ejb.77.1605522064018; Mon, 16 Nov 2020 02:21:04 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a54:380d:0:0:0:0:0 with HTTP; Mon, 16 Nov 2020 02:21:03 -0800 (PST) X-Originating-IP: [5.35.10.61] In-Reply-To: References: <5fb245b1.1c69fb81.e2685.976dSMTPIN_ADDED_MISSING@mx.google.com> From: Denis Kirjanov Date: Mon, 16 Nov 2020 13:21:03 +0300 Message-ID: Subject: Re: [PATCH] xsk: add cq event To: Xuan Zhuo Cc: netdev@vger.kernel.org, =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/16/20, Denis Kirjanov wrote: > On 11/16/20, Xuan Zhuo wrote: >> On Mon, 16 Nov 2020 12:13:21 +0300, Denis Kirjanov >> >> wrote: >>> On 11/16/20, Xuan Zhuo wrote: >>> > When we write all cq items to tx, we have to wait for a new event >>> > based >>> > on poll to indicate that it is writable. But the current writability >>> > is >>> > triggered based on whether tx is full or not, and In fact, when tx is >>> > dissatisfied, the user of cq's item may not necessarily get it, >>> > because >>> > it >>> > may still be occupied by the network card. In this case, we need to >>> > know >>> > when cq is available, so this patch adds a socket option, When the >>> > user >>> > configures this option using setsockopt, when cq is available, a >>> > readable event is generated for all xsk bound to this umem. >>> > >>> > I can't find a better description of this event, >>> > I think it can also be 'readable', although it is indeed different >>> > from >>> > the 'readable' of the new data. But the overhead of xsk checking >>> > whether >>> > cq or rx is readable is small. >>> > >>> > Signed-off-by: Xuan Zhuo >>> > --- >>> > include/net/xdp_sock.h | 1 + >>> > include/uapi/linux/if_xdp.h | 1 + >>> > net/xdp/xsk.c | 28 ++++++++++++++++++++++++++++ >>> > 3 files changed, 30 insertions(+) >>> > >>> > diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h >>> > index 1a9559c..faf5b1a 100644 >>> > --- a/include/net/xdp_sock.h >>> > +++ b/include/net/xdp_sock.h >>> > @@ -49,6 +49,7 @@ struct xdp_sock { >>> > struct xsk_buff_pool *pool; >>> > u16 queue_id; >>> > bool zc; >>> > + bool cq_event; >>> > enum { >>> > XSK_READY = 0, >>> > XSK_BOUND, >>> > diff --git a/include/uapi/linux/if_xdp.h b/include/uapi/linux/if_xdp.h >>> > index a78a809..2dba3cb 100644 >>> > --- a/include/uapi/linux/if_xdp.h >>> > +++ b/include/uapi/linux/if_xdp.h >>> > @@ -63,6 +63,7 @@ struct xdp_mmap_offsets { >>> > #define XDP_UMEM_COMPLETION_RING 6 >>> > #define XDP_STATISTICS 7 >>> > #define XDP_OPTIONS 8 >>> > +#define XDP_CQ_EVENT 9 >>> > >>> > struct xdp_umem_reg { >>> > __u64 addr; /* Start of packet data area */ >>> > diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c >>> > index cfbec39..0c53403 100644 >>> > --- a/net/xdp/xsk.c >>> > +++ b/net/xdp/xsk.c >>> > @@ -285,7 +285,16 @@ void __xsk_map_flush(void) >>> > >>> > void xsk_tx_completed(struct xsk_buff_pool *pool, u32 nb_entries) >>> > { >>> > + struct xdp_sock *xs; >>> > + >>> > xskq_prod_submit_n(pool->cq, nb_entries); >>> > + >>> > + rcu_read_lock(); >>> > + list_for_each_entry_rcu(xs, &pool->xsk_tx_list, tx_list) { >>> > + if (xs->cq_event) >>> > + sock_def_readable(&xs->sk); >>> > + } >>> > + rcu_read_unlock(); >>> > } >>> > EXPORT_SYMBOL(xsk_tx_completed); >>> > >>> > @@ -495,6 +504,9 @@ static __poll_t xsk_poll(struct file *file, struct >>> > socket *sock, >>> > __xsk_sendmsg(sk); >>> > } >>> > >>> > + if (xs->cq_event && pool->cq && !xskq_prod_is_empty(pool->cq)) >>> > + mask |= EPOLLIN | EPOLLRDNORM; >>> > + >>> > if (xs->rx && !xskq_prod_is_empty(xs->rx)) >>> > mask |= EPOLLIN | EPOLLRDNORM; >>> > if (xs->tx && !xskq_cons_is_full(xs->tx)) >>> > @@ -882,6 +894,22 @@ static int xsk_setsockopt(struct socket *sock, >>> > int >>> > level, int optname, >>> > mutex_unlock(&xs->mutex); >>> > return err; >>> > } >>> > + case XDP_CQ_EVENT: >>> > + { >>> > + int cq_event; >>> > + >>> > + if (optlen < sizeof(cq_event)) >>> > + return -EINVAL; >>> > + if (copy_from_sockptr(&cq_event, optval, sizeof(cq_event))) >>> > + return -EFAULT; >>> > + >>> > + if (cq_event) >>> > + xs->cq_event = true; >>> > + else >>> > + xs->cq_event = false; >>> >>> It's false by default, isn't it? >> >> I add cq_event inside "xdp_sock", that is got by sk_alloc, this call >> sk_prot_alloc by __GFP_ZERO. So I think it is false. > > Right, I meant that what's the point to set it explicitly to 'false'? Nevermind, It's okay. > >> >> Thanks. >> >>> >>> > + >>> > + return 0; >>> > + } >>> > default: >>> > break; >>> > } >>> > -- >>> > 1.8.3.1 >>> > >>> > >> >