bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Magnus Karlsson <magnus.karlsson@intel.com>
To: magnus.karlsson@intel.com, bjorn.topel@intel.com, ast@kernel.org,
	daniel@iogearbox.net, netdev@vger.kernel.org,
	jonathan.lemon@gmail.com
Cc: bpf@vger.kernel.org, saeedm@mellanox.com,
	jeffrey.t.kirsher@intel.com, maciej.fijalkowski@intel.com,
	maciejromanfijalkowski@gmail.com
Subject: [PATCH bpf-next v2 02/12] xsk: simplify detection of empty and full rings
Date: Thu, 19 Dec 2019 13:39:21 +0100	[thread overview]
Message-ID: <1576759171-28550-3-git-send-email-magnus.karlsson@intel.com> (raw)
In-Reply-To: <1576759171-28550-1-git-send-email-magnus.karlsson@intel.com>

In order to set the correct return flags for poll, the xsk code has to
check if the Rx queue is empty and if the Tx queue is full. This code
was unnecessarily large and complex as it used the functions that are
used to update the local state from the global state (xskq_nb_free and
xskq_nb_avail). Since we are not doing this nor updating any data
dependent on this state, we can simplify the functions. Another
benefit from this is that we can also simplify the xskq_nb_free and
xskq_nb_avail functions in a later commit.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
---
 net/xdp/xsk_queue.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h
index a2f0ba6..b28f9da 100644
--- a/net/xdp/xsk_queue.h
+++ b/net/xdp/xsk_queue.h
@@ -362,12 +362,15 @@ static inline void xskq_produce_flush_desc(struct xsk_queue *q)
 
 static inline bool xskq_full_desc(struct xsk_queue *q)
 {
-	return xskq_nb_avail(q, q->nentries) == q->nentries;
+	/* No barriers needed since data is not accessed */
+	return READ_ONCE(q->ring->producer) - READ_ONCE(q->ring->consumer) ==
+		q->nentries;
 }
 
 static inline bool xskq_empty_desc(struct xsk_queue *q)
 {
-	return xskq_nb_free(q, q->prod_tail, q->nentries) == q->nentries;
+	/* No barriers needed since data is not accessed */
+	return READ_ONCE(q->ring->consumer) == READ_ONCE(q->ring->producer);
 }
 
 void xskq_set_umem(struct xsk_queue *q, u64 size, u64 chunk_mask);
-- 
2.7.4


  parent reply	other threads:[~2019-12-19 12:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-19 12:39 [PATCH bpf-next v2 00/12] xsk: clean up ring access functions Magnus Karlsson
2019-12-19 12:39 ` [PATCH bpf-next v2 01/12] xsk: eliminate the lazy update threshold Magnus Karlsson
2019-12-19 12:39 ` Magnus Karlsson [this message]
2019-12-19 12:39 ` [PATCH bpf-next v2 03/12] xsk: consolidate to one single cached producer pointer Magnus Karlsson
2019-12-19 12:39 ` [PATCH bpf-next v2 04/12] xsk: standardize naming of producer ring access functions Magnus Karlsson
2019-12-19 12:39 ` [PATCH bpf-next v2 05/12] xsk: eliminate the RX batch size Magnus Karlsson
2019-12-19 12:39 ` [PATCH bpf-next v2 06/12] xsk: simplify xskq_nb_avail and xskq_nb_free Magnus Karlsson
2019-12-19 12:39 ` [PATCH bpf-next v2 07/12] xsk: simplify the consumer ring access functions Magnus Karlsson
2019-12-19 12:39 ` [PATCH bpf-next v2 08/12] xsk: change names of validation functions Magnus Karlsson
2019-12-19 12:39 ` [PATCH bpf-next v2 09/12] xsk: ixgbe: i40e: ice: mlx5: xsk_umem_discard_addr to xsk_umem_release_addr Magnus Karlsson
2019-12-19 12:39 ` [PATCH bpf-next v2 10/12] xsk: remove unnecessary READ_ONCE of data Magnus Karlsson
2019-12-19 12:39 ` [PATCH bpf-next v2 11/12] xsk: add function naming comments and reorder functions Magnus Karlsson
2019-12-19 12:39 ` [PATCH bpf-next v2 12/12] xsk: use struct_size() helper Magnus Karlsson
2019-12-20 10:09 ` [PATCH bpf-next v2 00/12] xsk: clean up ring access functions Björn Töpel
2019-12-21  0:03   ` Alexei Starovoitov

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=1576759171-28550-3-git-send-email-magnus.karlsson@intel.com \
    --to=magnus.karlsson@intel.com \
    --cc=ast@kernel.org \
    --cc=bjorn.topel@intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=jonathan.lemon@gmail.com \
    --cc=maciej.fijalkowski@intel.com \
    --cc=maciejromanfijalkowski@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).