From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15B3BC0650E for ; Wed, 3 Jul 2019 09:45:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E128921882 for ; Wed, 3 Jul 2019 09:45:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726936AbfGCJpl (ORCPT ); Wed, 3 Jul 2019 05:45:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41590 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725847AbfGCJpk (ORCPT ); Wed, 3 Jul 2019 05:45:40 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 95DA8B2DD4; Wed, 3 Jul 2019 09:45:40 +0000 (UTC) Received: from T460ec.redhat.com (ovpn-116-169.ams2.redhat.com [10.36.116.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A7B110A9827; Wed, 3 Jul 2019 09:45:38 +0000 (UTC) From: Eelco Chaudron To: netdev@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, andrii.nakryiko@gmail.com, magnus.karlsson@gmail.com Subject: [PATCH bpf-next v3] libbpf: add xsk_ring_prod__nb_free() function Date: Wed, 3 Jul 2019 11:45:28 +0200 Message-Id: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 03 Jul 2019 09:45:40 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When an AF_XDP application received X packets, it does not mean X frames can be stuffed into the producer ring. To make it easier for AF_XDP applications this API allows them to check how many frames can be added into the ring. Signed-off-by: Eelco Chaudron --- v2 -> v3 - Removed cache by pass option v1 -> v2 - Renamed xsk_ring_prod__free() to xsk_ring_prod__nb_free() - Add caching so it will only touch global state when needed tools/lib/bpf/xsk.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/xsk.h b/tools/lib/bpf/xsk.h index 82ea71a0f3ec..3411556e04d9 100644 --- a/tools/lib/bpf/xsk.h +++ b/tools/lib/bpf/xsk.h @@ -76,7 +76,7 @@ xsk_ring_cons__rx_desc(const struct xsk_ring_cons *rx, __u32 idx) return &descs[idx & rx->mask]; } -static inline __u32 xsk_prod_nb_free(struct xsk_ring_prod *r, __u32 nb) +static inline __u32 xsk_prod__nb_free(struct xsk_ring_prod *r, __u32 nb) { __u32 free_entries = r->cached_cons - r->cached_prod; @@ -110,7 +110,7 @@ static inline __u32 xsk_cons_nb_avail(struct xsk_ring_cons *r, __u32 nb) static inline size_t xsk_ring_prod__reserve(struct xsk_ring_prod *prod, size_t nb, __u32 *idx) { - if (xsk_prod_nb_free(prod, nb) < nb) + if (xsk_prod__nb_free(prod, nb) < nb) return 0; *idx = prod->cached_prod; -- 2.20.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36F28C0650E for ; Wed, 3 Jul 2019 12:52:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C707218A3 for ; Wed, 3 Jul 2019 12:52:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726598AbfGCMwj (ORCPT ); Wed, 3 Jul 2019 08:52:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45964 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725830AbfGCMwj (ORCPT ); Wed, 3 Jul 2019 08:52:39 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA2DC356E4; Wed, 3 Jul 2019 12:52:38 +0000 (UTC) Received: from T460ec.redhat.com (ovpn-116-169.ams2.redhat.com [10.36.116.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADD977BE6C; Wed, 3 Jul 2019 12:52:36 +0000 (UTC) From: Eelco Chaudron To: netdev@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, andrii.nakryiko@gmail.com, magnus.karlsson@gmail.com Subject: [PATCH bpf-next v3] libbpf: add xsk_ring_prod__nb_free() function Date: Wed, 3 Jul 2019 14:52:32 +0200 Message-Id: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 03 Jul 2019 12:52:38 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Message-ID: <20190703125232.a6yBh5F9lR8Aq8BcYl4PKNKbPvOxVWhhYI7Ue_Y6gZE@z> When an AF_XDP application received X packets, it does not mean X frames can be stuffed into the producer ring. To make it easier for AF_XDP applications this API allows them to check how many frames can be added into the ring. Signed-off-by: Eelco Chaudron --- v2 -> v3 - Removed cache by pass option v1 -> v2 - Renamed xsk_ring_prod__free() to xsk_ring_prod__nb_free() - Add caching so it will only touch global state when needed tools/lib/bpf/xsk.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/xsk.h b/tools/lib/bpf/xsk.h index 82ea71a0f3ec..3411556e04d9 100644 --- a/tools/lib/bpf/xsk.h +++ b/tools/lib/bpf/xsk.h @@ -76,7 +76,7 @@ xsk_ring_cons__rx_desc(const struct xsk_ring_cons *rx, __u32 idx) return &descs[idx & rx->mask]; } -static inline __u32 xsk_prod_nb_free(struct xsk_ring_prod *r, __u32 nb) +static inline __u32 xsk_prod__nb_free(struct xsk_ring_prod *r, __u32 nb) { __u32 free_entries = r->cached_cons - r->cached_prod; @@ -110,7 +110,7 @@ static inline __u32 xsk_cons_nb_avail(struct xsk_ring_cons *r, __u32 nb) static inline size_t xsk_ring_prod__reserve(struct xsk_ring_prod *prod, size_t nb, __u32 *idx) { - if (xsk_prod_nb_free(prod, nb) < nb) + if (xsk_prod__nb_free(prod, nb) < nb) return 0; *idx = prod->cached_prod; -- 2.20.1