All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/6] net: ipa: simplify completion statistics
@ 2022-06-13 17:17 Alex Elder
  2022-06-13 17:17 ` [PATCH net-next 1/6] net: ipa: use "tre_ring" for all TRE ring local variables Alex Elder
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Alex Elder @ 2022-06-13 17:17 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni
  Cc: mka, evgreen, bjorn.andersson, quic_cpratapa, quic_avuyyuru,
	quic_jponduru, quic_subashab, elder, netdev, linux-arm-msm,
	linux-kernel

The first patch in this series makes the name used for variables
representing a TRE ring be consistent everywhere.  The second
renames two structure fields to better represent their purpose.

The last four rework a little code that manages some tranaction and
byte transfer statistics maintained mainly for TX endpoints.  For
the most part this series is refactoring.  The last one also
includes the first step toward no longer assuming an event ring is
dedicated to a single channel.

					-Alex

Alex Elder (6):
  net: ipa: use "tre_ring" for all TRE ring local variables
  net: ipa: rename two transaction fields
  net: ipa: introduce gsi_trans_tx_committed()
  net: ipa: simplify TX completion statistics
  net: ipa: stop counting total RX bytes and transactions
  net: ipa: rework gsi_channel_tx_update()

 drivers/net/ipa/gsi.c         | 77 +++++++++++++++++------------------
 drivers/net/ipa/gsi.h         |  2 +-
 drivers/net/ipa/gsi_private.h |  9 ++++
 drivers/net/ipa/gsi_trans.c   | 68 +++++++++++++++----------------
 drivers/net/ipa/gsi_trans.h   | 15 +++----
 5 files changed, 87 insertions(+), 84 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH net-next 1/6] net: ipa: use "tre_ring" for all TRE ring local variables
  2022-06-13 17:17 [PATCH net-next 0/6] net: ipa: simplify completion statistics Alex Elder
@ 2022-06-13 17:17 ` Alex Elder
  2022-06-13 17:17 ` [PATCH net-next 2/6] net: ipa: rename two transaction fields Alex Elder
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alex Elder @ 2022-06-13 17:17 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni
  Cc: mka, evgreen, bjorn.andersson, quic_cpratapa, quic_avuyyuru,
	quic_jponduru, quic_subashab, elder, netdev, linux-arm-msm,
	linux-kernel

All local variables that represent event rings are named "ring".

All but two functions that represent a channel's TRE ring with a
local variable use the name "tre_ring".  For consistency, use that
name in the two functions that don't fit the pattern.

Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/gsi_trans.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c
index 278e467c5430b..e3f3c736c7409 100644
--- a/drivers/net/ipa/gsi_trans.c
+++ b/drivers/net/ipa/gsi_trans.c
@@ -549,7 +549,7 @@ static void gsi_trans_tre_fill(struct gsi_tre *dest_tre, dma_addr_t addr,
 static void __gsi_trans_commit(struct gsi_trans *trans, bool ring_db)
 {
 	struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id];
-	struct gsi_ring *ring = &channel->tre_ring;
+	struct gsi_ring *tre_ring = &channel->tre_ring;
 	enum ipa_cmd_opcode opcode = IPA_CMD_NONE;
 	bool bei = channel->toward_ipa;
 	struct gsi_tre *dest_tre;
@@ -567,8 +567,8 @@ static void __gsi_trans_commit(struct gsi_trans *trans, bool ring_db)
 	 * transfer request, whose opcode is IPA_CMD_NONE.
 	 */
 	cmd_opcode = channel->command ? &trans->cmd_opcode[0] : NULL;
-	avail = ring->count - ring->index % ring->count;
-	dest_tre = gsi_ring_virt(ring, ring->index);
+	avail = tre_ring->count - tre_ring->index % tre_ring->count;
+	dest_tre = gsi_ring_virt(tre_ring, tre_ring->index);
 	for_each_sg(trans->sgl, sg, trans->used, i) {
 		bool last_tre = i == trans->used - 1;
 		dma_addr_t addr = sg_dma_address(sg);
@@ -576,14 +576,14 @@ static void __gsi_trans_commit(struct gsi_trans *trans, bool ring_db)
 
 		byte_count += len;
 		if (!avail--)
-			dest_tre = gsi_ring_virt(ring, 0);
+			dest_tre = gsi_ring_virt(tre_ring, 0);
 		if (cmd_opcode)
 			opcode = *cmd_opcode++;
 
 		gsi_trans_tre_fill(dest_tre, addr, len, last_tre, bei, opcode);
 		dest_tre++;
 	}
-	ring->index += trans->used;
+	tre_ring->index += trans->used;
 
 	if (channel->toward_ipa) {
 		/* We record TX bytes when they are sent */
@@ -595,7 +595,7 @@ static void __gsi_trans_commit(struct gsi_trans *trans, bool ring_db)
 	}
 
 	/* Associate the last TRE with the transaction */
-	gsi_channel_trans_map(channel, ring->index - 1, trans);
+	gsi_channel_trans_map(channel, tre_ring->index - 1, trans);
 
 	gsi_trans_move_pending(trans);
 
@@ -675,7 +675,7 @@ void gsi_channel_trans_cancel_pending(struct gsi_channel *channel)
 int gsi_trans_read_byte(struct gsi *gsi, u32 channel_id, dma_addr_t addr)
 {
 	struct gsi_channel *channel = &gsi->channel[channel_id];
-	struct gsi_ring *ring = &channel->tre_ring;
+	struct gsi_ring *tre_ring = &channel->tre_ring;
 	struct gsi_trans_info *trans_info;
 	struct gsi_tre *dest_tre;
 
@@ -687,10 +687,10 @@ int gsi_trans_read_byte(struct gsi *gsi, u32 channel_id, dma_addr_t addr)
 
 	/* Now fill the the reserved TRE and tell the hardware */
 
-	dest_tre = gsi_ring_virt(ring, ring->index);
+	dest_tre = gsi_ring_virt(tre_ring, tre_ring->index);
 	gsi_trans_tre_fill(dest_tre, addr, 1, true, false, IPA_CMD_NONE);
 
-	ring->index++;
+	tre_ring->index++;
 	gsi_channel_doorbell(channel);
 
 	return 0;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 2/6] net: ipa: rename two transaction fields
  2022-06-13 17:17 [PATCH net-next 0/6] net: ipa: simplify completion statistics Alex Elder
  2022-06-13 17:17 ` [PATCH net-next 1/6] net: ipa: use "tre_ring" for all TRE ring local variables Alex Elder
@ 2022-06-13 17:17 ` Alex Elder
  2022-06-13 17:17 ` [PATCH net-next 3/6] net: ipa: introduce gsi_trans_tx_committed() Alex Elder
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alex Elder @ 2022-06-13 17:17 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni
  Cc: mka, evgreen, bjorn.andersson, quic_cpratapa, quic_avuyyuru,
	quic_jponduru, quic_subashab, elder, netdev, linux-arm-msm,
	linux-kernel

There are two fields in a GSI transaction that keep track of TRE
counts.  The first represents the number of TREs reserved for the
transaction in the TRE ring; that's currently named "tre_count".
The second is the number of TREs that are actually *used* by the
transaction at the time it is committed.

Rename the "tre_count" field to be "rsvd_count", to make its meaning
a little more specific.  The "_count" is present in the name mainly
to avoid interpreting it as a reserved (not-to-be-used) field.  This
name also distinguishes it from the "tre_count" field associated
with a channel.

Rename the "used" field to be "used_count", to match the convention
used for reserved TREs.

Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/gsi_trans.c | 41 +++++++++++++++++++------------------
 drivers/net/ipa/gsi_trans.h |  8 ++++----
 2 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c
index e3f3c736c7409..986857eb39296 100644
--- a/drivers/net/ipa/gsi_trans.c
+++ b/drivers/net/ipa/gsi_trans.c
@@ -355,7 +355,7 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id,
 	trans = gsi_trans_pool_alloc(&trans_info->pool, 1);
 	trans->gsi = gsi;
 	trans->channel_id = channel_id;
-	trans->tre_count = tre_count;
+	trans->rsvd_count = tre_count;
 	init_completion(&trans->completion);
 
 	/* Allocate the scatterlist and (if requested) info entries. */
@@ -405,17 +405,17 @@ void gsi_trans_free(struct gsi_trans *trans)
 	/* Releasing the reserved TREs implicitly frees the sgl[] and
 	 * (if present) info[] arrays, plus the transaction itself.
 	 */
-	gsi_trans_tre_release(trans_info, trans->tre_count);
+	gsi_trans_tre_release(trans_info, trans->rsvd_count);
 }
 
 /* Add an immediate command to a transaction */
 void gsi_trans_cmd_add(struct gsi_trans *trans, void *buf, u32 size,
 		       dma_addr_t addr, enum ipa_cmd_opcode opcode)
 {
-	u32 which = trans->used++;
+	u32 which = trans->used_count++;
 	struct scatterlist *sg;
 
-	WARN_ON(which >= trans->tre_count);
+	WARN_ON(which >= trans->rsvd_count);
 
 	/* Commands are quite different from data transfer requests.
 	 * Their payloads come from a pool whose memory is allocated
@@ -446,9 +446,9 @@ int gsi_trans_page_add(struct gsi_trans *trans, struct page *page, u32 size,
 	struct scatterlist *sg = &trans->sgl[0];
 	int ret;
 
-	if (WARN_ON(trans->tre_count != 1))
+	if (WARN_ON(trans->rsvd_count != 1))
 		return -EINVAL;
-	if (WARN_ON(trans->used))
+	if (WARN_ON(trans->used_count))
 		return -EINVAL;
 
 	sg_set_page(sg, page, size, offset);
@@ -456,7 +456,7 @@ int gsi_trans_page_add(struct gsi_trans *trans, struct page *page, u32 size,
 	if (!ret)
 		return -ENOMEM;
 
-	trans->used++;	/* Transaction now owns the (DMA mapped) page */
+	trans->used_count++;	/* Transaction now owns the (DMA mapped) page */
 
 	return 0;
 }
@@ -465,25 +465,26 @@ int gsi_trans_page_add(struct gsi_trans *trans, struct page *page, u32 size,
 int gsi_trans_skb_add(struct gsi_trans *trans, struct sk_buff *skb)
 {
 	struct scatterlist *sg = &trans->sgl[0];
-	u32 used;
+	u32 used_count;
 	int ret;
 
-	if (WARN_ON(trans->tre_count != 1))
+	if (WARN_ON(trans->rsvd_count != 1))
 		return -EINVAL;
-	if (WARN_ON(trans->used))
+	if (WARN_ON(trans->used_count))
 		return -EINVAL;
 
 	/* skb->len will not be 0 (checked early) */
 	ret = skb_to_sgvec(skb, sg, 0, skb->len);
 	if (ret < 0)
 		return ret;
-	used = ret;
+	used_count = ret;
 
-	ret = dma_map_sg(trans->gsi->dev, sg, used, trans->direction);
+	ret = dma_map_sg(trans->gsi->dev, sg, used_count, trans->direction);
 	if (!ret)
 		return -ENOMEM;
 
-	trans->used += used;	/* Transaction now owns the (DMA mapped) skb */
+	/* Transaction now owns the (DMA mapped) skb */
+	trans->used_count += used_count;
 
 	return 0;
 }
@@ -559,7 +560,7 @@ static void __gsi_trans_commit(struct gsi_trans *trans, bool ring_db)
 	u32 avail;
 	u32 i;
 
-	WARN_ON(!trans->used);
+	WARN_ON(!trans->used_count);
 
 	/* Consume the entries.  If we cross the end of the ring while
 	 * filling them we'll switch to the beginning to finish.
@@ -569,8 +570,8 @@ static void __gsi_trans_commit(struct gsi_trans *trans, bool ring_db)
 	cmd_opcode = channel->command ? &trans->cmd_opcode[0] : NULL;
 	avail = tre_ring->count - tre_ring->index % tre_ring->count;
 	dest_tre = gsi_ring_virt(tre_ring, tre_ring->index);
-	for_each_sg(trans->sgl, sg, trans->used, i) {
-		bool last_tre = i == trans->used - 1;
+	for_each_sg(trans->sgl, sg, trans->used_count, i) {
+		bool last_tre = i == trans->used_count - 1;
 		dma_addr_t addr = sg_dma_address(sg);
 		u32 len = sg_dma_len(sg);
 
@@ -583,7 +584,7 @@ static void __gsi_trans_commit(struct gsi_trans *trans, bool ring_db)
 		gsi_trans_tre_fill(dest_tre, addr, len, last_tre, bei, opcode);
 		dest_tre++;
 	}
-	tre_ring->index += trans->used;
+	tre_ring->index += trans->used_count;
 
 	if (channel->toward_ipa) {
 		/* We record TX bytes when they are sent */
@@ -611,7 +612,7 @@ static void __gsi_trans_commit(struct gsi_trans *trans, bool ring_db)
 /* Commit a GSI transaction */
 void gsi_trans_commit(struct gsi_trans *trans, bool ring_db)
 {
-	if (trans->used)
+	if (trans->used_count)
 		__gsi_trans_commit(trans, ring_db);
 	else
 		gsi_trans_free(trans);
@@ -620,7 +621,7 @@ void gsi_trans_commit(struct gsi_trans *trans, bool ring_db)
 /* Commit a GSI transaction and wait for it to complete */
 void gsi_trans_commit_wait(struct gsi_trans *trans)
 {
-	if (!trans->used)
+	if (!trans->used_count)
 		goto out_trans_free;
 
 	refcount_inc(&trans->refcount);
@@ -638,7 +639,7 @@ void gsi_trans_complete(struct gsi_trans *trans)
 {
 	/* If the entire SGL was mapped when added, unmap it now */
 	if (trans->direction != DMA_NONE)
-		dma_unmap_sg(trans->gsi->dev, trans->sgl, trans->used,
+		dma_unmap_sg(trans->gsi->dev, trans->sgl, trans->used_count,
 			     trans->direction);
 
 	ipa_gsi_trans_complete(trans);
diff --git a/drivers/net/ipa/gsi_trans.h b/drivers/net/ipa/gsi_trans.h
index 020c3b32de1d7..b5f80250ca006 100644
--- a/drivers/net/ipa/gsi_trans.h
+++ b/drivers/net/ipa/gsi_trans.h
@@ -33,8 +33,8 @@ struct gsi_trans_pool;
  * @gsi:	GSI pointer
  * @channel_id: Channel number transaction is associated with
  * @cancelled:	If set by the core code, transaction was cancelled
- * @tre_count:	Number of TREs reserved for this transaction
- * @used:	Number of TREs *used* (could be less than tre_count)
+ * @rsvd_count:	Number of TREs reserved for this transaction
+ * @used_count:	Number of TREs *used* (could be less than rsvd_count)
  * @len:	Total # of transfer bytes represented in sgl[] (set by core)
  * @data:	Preserved but not touched by the core transaction code
  * @cmd_opcode:	Array of command opcodes (command channel only)
@@ -56,8 +56,8 @@ struct gsi_trans {
 
 	bool cancelled;			/* true if transaction was cancelled */
 
-	u8 tre_count;			/* # TREs requested */
-	u8 used;			/* # entries used in sgl[] */
+	u8 rsvd_count;			/* # TREs requested */
+	u8 used_count;			/* # entries used in sgl[] */
 	u32 len;			/* total # bytes across sgl[] */
 
 	union {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 3/6] net: ipa: introduce gsi_trans_tx_committed()
  2022-06-13 17:17 [PATCH net-next 0/6] net: ipa: simplify completion statistics Alex Elder
  2022-06-13 17:17 ` [PATCH net-next 1/6] net: ipa: use "tre_ring" for all TRE ring local variables Alex Elder
  2022-06-13 17:17 ` [PATCH net-next 2/6] net: ipa: rename two transaction fields Alex Elder
@ 2022-06-13 17:17 ` Alex Elder
  2022-06-13 17:17 ` [PATCH net-next 4/6] net: ipa: simplify TX completion statistics Alex Elder
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alex Elder @ 2022-06-13 17:17 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni
  Cc: mka, evgreen, bjorn.andersson, quic_cpratapa, quic_avuyyuru,
	quic_jponduru, quic_subashab, elder, netdev, linux-arm-msm,
	linux-kernel

Create a new function that encapsulates recording information needed
for TX channel statistics when a transaction is committed.

Record the accumulated length in the transaction before the call
(for both RX and TX), so it can be used when updating TX statistics.

Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/gsi.c         | 11 +++++++++++
 drivers/net/ipa/gsi_private.h |  9 +++++++++
 drivers/net/ipa/gsi_trans.c   | 11 +++--------
 drivers/net/ipa/gsi_trans.h   |  7 ++++---
 4 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c
index 5b446d2a07c8a..1091ac23567d5 100644
--- a/drivers/net/ipa/gsi.c
+++ b/drivers/net/ipa/gsi.c
@@ -991,6 +991,17 @@ void gsi_resume(struct gsi *gsi)
 	enable_irq(gsi->irq);
 }
 
+void gsi_trans_tx_committed(struct gsi_trans *trans)
+{
+	struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id];
+
+	trans->trans_count = channel->trans_count;
+	trans->byte_count = channel->byte_count;
+
+	channel->trans_count++;
+	channel->byte_count += trans->len;
+}
+
 void gsi_trans_tx_queued(struct gsi_trans *trans)
 {
 	u32 channel_id = trans->channel_id;
diff --git a/drivers/net/ipa/gsi_private.h b/drivers/net/ipa/gsi_private.h
index 56450a1899074..74cbc287fc715 100644
--- a/drivers/net/ipa/gsi_private.h
+++ b/drivers/net/ipa/gsi_private.h
@@ -104,6 +104,15 @@ void gsi_channel_doorbell(struct gsi_channel *channel);
  */
 void *gsi_ring_virt(struct gsi_ring *ring, u32 index);
 
+/**
+ * gsi_trans_tx_committed() - Record bytes committed for transmit
+ * @trans:	TX endpoint transaction being committed
+ *
+ * Report that a TX transaction has been committed.  It updates some
+ * statistics used to manage transmit rates.
+ */
+void gsi_trans_tx_committed(struct gsi_trans *trans);
+
 /**
  * gsi_trans_tx_queued() - Report a queued TX channel transaction
  * @trans:	Transaction being passed to hardware
diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c
index 986857eb39296..a110be72f70b6 100644
--- a/drivers/net/ipa/gsi_trans.c
+++ b/drivers/net/ipa/gsi_trans.c
@@ -586,14 +586,9 @@ static void __gsi_trans_commit(struct gsi_trans *trans, bool ring_db)
 	}
 	tre_ring->index += trans->used_count;
 
-	if (channel->toward_ipa) {
-		/* We record TX bytes when they are sent */
-		trans->len = byte_count;
-		trans->trans_count = channel->trans_count;
-		trans->byte_count = channel->byte_count;
-		channel->trans_count++;
-		channel->byte_count += byte_count;
-	}
+	trans->len = byte_count;
+	if (channel->toward_ipa)
+		gsi_trans_tx_committed(trans);
 
 	/* Associate the last TRE with the transaction */
 	gsi_channel_trans_map(channel, tre_ring->index - 1, trans);
diff --git a/drivers/net/ipa/gsi_trans.h b/drivers/net/ipa/gsi_trans.h
index b5f80250ca006..7084507830c21 100644
--- a/drivers/net/ipa/gsi_trans.h
+++ b/drivers/net/ipa/gsi_trans.h
@@ -35,7 +35,7 @@ struct gsi_trans_pool;
  * @cancelled:	If set by the core code, transaction was cancelled
  * @rsvd_count:	Number of TREs reserved for this transaction
  * @used_count:	Number of TREs *used* (could be less than rsvd_count)
- * @len:	Total # of transfer bytes represented in sgl[] (set by core)
+ * @len:	Number of bytes sent or received by the transaction
  * @data:	Preserved but not touched by the core transaction code
  * @cmd_opcode:	Array of command opcodes (command channel only)
  * @sgl:	An array of scatter/gather entries managed by core code
@@ -45,8 +45,9 @@ struct gsi_trans_pool;
  * @byte_count:	TX channel byte count recorded when transaction committed
  * @trans_count: Channel transaction count when committed (for BQL accounting)
  *
- * The size used for some fields in this structure were chosen to ensure
- * the full structure size is no larger than 128 bytes.
+ * The @len field is set when the transaction is committed.  For RX
+ * transactions it is updated later to reflect the actual number of bytes
+ * received.
  */
 struct gsi_trans {
 	struct list_head links;		/* gsi_channel lists */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 4/6] net: ipa: simplify TX completion statistics
  2022-06-13 17:17 [PATCH net-next 0/6] net: ipa: simplify completion statistics Alex Elder
                   ` (2 preceding siblings ...)
  2022-06-13 17:17 ` [PATCH net-next 3/6] net: ipa: introduce gsi_trans_tx_committed() Alex Elder
@ 2022-06-13 17:17 ` Alex Elder
  2022-06-13 17:17 ` [PATCH net-next 5/6] net: ipa: stop counting total RX bytes and transactions Alex Elder
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alex Elder @ 2022-06-13 17:17 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni
  Cc: mka, evgreen, bjorn.andersson, quic_cpratapa, quic_avuyyuru,
	quic_jponduru, quic_subashab, elder, netdev, linux-arm-msm,
	linux-kernel

When a TX request is issued, its channel's accumulated byte and
transaction counts are recorded.  This currently does *not* take
into account the transaction being committed.

Later, when the transaction completes, the number of bytes and
transactions that have completed since the transaction was committed
are reported to the network stack.  The transaction and its byte
count are accounted for at that time.

Instead, record the transaction and its bytes in the counts recorded
at commit time.  This avoids the need to do so when the transaction
completes, and provides a (small) simplification of that code.

Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/gsi.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c
index 1091ac23567d5..4f8187c543824 100644
--- a/drivers/net/ipa/gsi.c
+++ b/drivers/net/ipa/gsi.c
@@ -995,11 +995,11 @@ void gsi_trans_tx_committed(struct gsi_trans *trans)
 {
 	struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id];
 
-	trans->trans_count = channel->trans_count;
-	trans->byte_count = channel->byte_count;
-
 	channel->trans_count++;
 	channel->byte_count += trans->len;
+
+	trans->trans_count = channel->trans_count;
+	trans->byte_count = channel->byte_count;
 }
 
 void gsi_trans_tx_queued(struct gsi_trans *trans)
@@ -1047,13 +1047,11 @@ void gsi_trans_tx_queued(struct gsi_trans *trans)
 static void
 gsi_channel_tx_update(struct gsi_channel *channel, struct gsi_trans *trans)
 {
-	u64 byte_count = trans->byte_count + trans->len;
-	u64 trans_count = trans->trans_count + 1;
+	u64 trans_count = trans->trans_count - channel->compl_trans_count;
+	u64 byte_count = trans->byte_count - channel->compl_byte_count;
 
-	byte_count -= channel->compl_byte_count;
-	channel->compl_byte_count += byte_count;
-	trans_count -= channel->compl_trans_count;
 	channel->compl_trans_count += trans_count;
+	channel->compl_byte_count += byte_count;
 
 	ipa_gsi_channel_tx_completed(channel->gsi, gsi_channel_id(channel),
 				     trans_count, byte_count);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 5/6] net: ipa: stop counting total RX bytes and transactions
  2022-06-13 17:17 [PATCH net-next 0/6] net: ipa: simplify completion statistics Alex Elder
                   ` (3 preceding siblings ...)
  2022-06-13 17:17 ` [PATCH net-next 4/6] net: ipa: simplify TX completion statistics Alex Elder
@ 2022-06-13 17:17 ` Alex Elder
  2022-06-13 17:17 ` [PATCH net-next 6/6] net: ipa: rework gsi_channel_tx_update() Alex Elder
  2022-06-15  8:20 ` [PATCH net-next 0/6] net: ipa: simplify completion statistics patchwork-bot+netdevbpf
  6 siblings, 0 replies; 8+ messages in thread
From: Alex Elder @ 2022-06-13 17:17 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni
  Cc: mka, evgreen, bjorn.andersson, quic_cpratapa, quic_avuyyuru,
	quic_jponduru, quic_subashab, elder, netdev, linux-arm-msm,
	linux-kernel

In gsi_evt_ring_rx_update(), we update each transaction so its len
field reflects the actual number of bytes received.  In the process,
the total number of transactions and bytes processed on the channel
are summed, and added to a running total for the channel.

But we don't actually use those running totals for RX endpoints.
They're maintained for TX channels to support CoDel when they are
associated with a "real" network device.

So stop maintaining these totals for RX endpoints, and update the
comment where the fields are defined to make it clear they're only
valid for TX channels.

Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/gsi.c | 8 --------
 drivers/net/ipa/gsi.h | 2 +-
 2 files changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c
index 4f8187c543824..c2cafd9247a70 100644
--- a/drivers/net/ipa/gsi.c
+++ b/drivers/net/ipa/gsi.c
@@ -1374,8 +1374,6 @@ static void gsi_evt_ring_rx_update(struct gsi_evt_ring *evt_ring, u32 index)
 	struct gsi_event *event_done;
 	struct gsi_event *event;
 	struct gsi_trans *trans;
-	u32 trans_count = 0;
-	u32 byte_count = 0;
 	u32 event_avail;
 	u32 old_index;
 
@@ -1399,8 +1397,6 @@ static void gsi_evt_ring_rx_update(struct gsi_evt_ring *evt_ring, u32 index)
 	event_done = gsi_ring_virt(ring, index);
 	do {
 		trans->len = __le16_to_cpu(event->len);
-		byte_count += trans->len;
-		trans_count++;
 
 		/* Move on to the next event and transaction */
 		if (--event_avail)
@@ -1409,10 +1405,6 @@ static void gsi_evt_ring_rx_update(struct gsi_evt_ring *evt_ring, u32 index)
 			event = gsi_ring_virt(ring, 0);
 		trans = gsi_trans_pool_next(&trans_info->pool, trans);
 	} while (event != event_done);
-
-	/* We record RX bytes when they are received */
-	channel->byte_count += byte_count;
-	channel->trans_count += trans_count;
 }
 
 /* Initialize a ring, including allocating DMA memory for its entries */
diff --git a/drivers/net/ipa/gsi.h b/drivers/net/ipa/gsi.h
index 89dac7fc8c4cb..bad1a78a96ede 100644
--- a/drivers/net/ipa/gsi.h
+++ b/drivers/net/ipa/gsi.h
@@ -117,9 +117,9 @@ struct gsi_channel {
 	struct gsi_ring tre_ring;
 	u32 evt_ring_id;
 
+	/* The following counts are used only for TX endpoints */
 	u64 byte_count;			/* total # bytes transferred */
 	u64 trans_count;		/* total # transactions */
-	/* The following counts are used only for TX endpoints */
 	u64 queued_byte_count;		/* last reported queued byte count */
 	u64 queued_trans_count;		/* ...and queued trans count */
 	u64 compl_byte_count;		/* last reported completed byte count */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 6/6] net: ipa: rework gsi_channel_tx_update()
  2022-06-13 17:17 [PATCH net-next 0/6] net: ipa: simplify completion statistics Alex Elder
                   ` (4 preceding siblings ...)
  2022-06-13 17:17 ` [PATCH net-next 5/6] net: ipa: stop counting total RX bytes and transactions Alex Elder
@ 2022-06-13 17:17 ` Alex Elder
  2022-06-15  8:20 ` [PATCH net-next 0/6] net: ipa: simplify completion statistics patchwork-bot+netdevbpf
  6 siblings, 0 replies; 8+ messages in thread
From: Alex Elder @ 2022-06-13 17:17 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni
  Cc: mka, evgreen, bjorn.andersson, quic_cpratapa, quic_avuyyuru,
	quic_jponduru, quic_subashab, elder, netdev, linux-arm-msm,
	linux-kernel

Rename gsi_channel_tx_update() to be gsi_trans_tx_completed(), and
pass it just the transaction pointer, deriving the channel from the
transaction.  Update the comments above the function to provide a
more concise description of how statistics for TX endpoints are
maintained and used.

Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/gsi.c | 54 ++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 29 deletions(-)

diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c
index c2cafd9247a70..df8af1f00fc8b 100644
--- a/drivers/net/ipa/gsi.c
+++ b/drivers/net/ipa/gsi.c
@@ -1021,40 +1021,36 @@ void gsi_trans_tx_queued(struct gsi_trans *trans)
 }
 
 /**
- * gsi_channel_tx_update() - Report completed TX transfers
- * @channel:	Channel that has completed transmitting packets
- * @trans:	Last transation known to be complete
- *
- * Compute the number of transactions and bytes that have been transferred
- * over a TX channel since the given transaction was committed.  Report this
- * information to the network stack.
- *
- * At the time a transaction is committed, we record its channel's
- * committed transaction and byte counts *in the transaction*.
- * Completions are signaled by the hardware with an interrupt, and
- * we can determine the latest completed transaction at that time.
- *
- * The difference between the byte/transaction count recorded in
- * the transaction and the count last time we recorded a completion
- * tells us exactly how much data has been transferred between
- * completions.
- *
- * Calling this each time we learn of a newly-completed transaction
- * allows us to provide accurate information to the network stack
- * about how much work has been completed by the hardware at a given
- * point in time.
+ * gsi_trans_tx_completed() - Report completed TX transactions
+ * @trans:	TX channel transaction that has completed
+ *
+ * Report that a transaction on a TX channel has completed.  At the time a
+ * transaction is committed, we record *in the transaction* its channel's
+ * committed transaction and byte counts.  Transactions are completed in
+ * order, and the difference between the channel's byte/transaction count
+ * when the transaction was committed and when it completes tells us
+ * exactly how much data has been transferred while the transaction was
+ * pending.
+ *
+ * We report this information to the network stack, which uses it to manage
+ * the rate at which data is sent to hardware.
  */
-static void
-gsi_channel_tx_update(struct gsi_channel *channel, struct gsi_trans *trans)
+static void gsi_trans_tx_completed(struct gsi_trans *trans)
 {
-	u64 trans_count = trans->trans_count - channel->compl_trans_count;
-	u64 byte_count = trans->byte_count - channel->compl_byte_count;
+	u32 channel_id = trans->channel_id;
+	struct gsi *gsi = trans->gsi;
+	struct gsi_channel *channel;
+	u32 trans_count;
+	u32 byte_count;
+
+	channel = &gsi->channel[channel_id];
+	trans_count = trans->trans_count - channel->compl_trans_count;
+	byte_count = trans->byte_count - channel->compl_byte_count;
 
 	channel->compl_trans_count += trans_count;
 	channel->compl_byte_count += byte_count;
 
-	ipa_gsi_channel_tx_completed(channel->gsi, gsi_channel_id(channel),
-				     trans_count, byte_count);
+	ipa_gsi_channel_tx_completed(gsi, channel_id, trans_count, byte_count);
 }
 
 /* Channel control interrupt handler */
@@ -1504,7 +1500,7 @@ static struct gsi_trans *gsi_channel_update(struct gsi_channel *channel)
 	 * up the network stack.
 	 */
 	if (channel->toward_ipa)
-		gsi_channel_tx_update(channel, trans);
+		gsi_trans_tx_completed(trans);
 	else
 		gsi_evt_ring_rx_update(evt_ring, index);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 0/6] net: ipa: simplify completion statistics
  2022-06-13 17:17 [PATCH net-next 0/6] net: ipa: simplify completion statistics Alex Elder
                   ` (5 preceding siblings ...)
  2022-06-13 17:17 ` [PATCH net-next 6/6] net: ipa: rework gsi_channel_tx_update() Alex Elder
@ 2022-06-15  8:20 ` patchwork-bot+netdevbpf
  6 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-06-15  8:20 UTC (permalink / raw)
  To: Alex Elder
  Cc: davem, edumazet, kuba, pabeni, mka, evgreen, bjorn.andersson,
	quic_cpratapa, quic_avuyyuru, quic_jponduru, quic_subashab,
	elder, netdev, linux-arm-msm, linux-kernel

Hello:

This series was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Mon, 13 Jun 2022 12:17:53 -0500 you wrote:
> The first patch in this series makes the name used for variables
> representing a TRE ring be consistent everywhere.  The second
> renames two structure fields to better represent their purpose.
> 
> The last four rework a little code that manages some tranaction and
> byte transfer statistics maintained mainly for TX endpoints.  For
> the most part this series is refactoring.  The last one also
> includes the first step toward no longer assuming an event ring is
> dedicated to a single channel.
> 
> [...]

Here is the summary with links:
  - [net-next,1/6] net: ipa: use "tre_ring" for all TRE ring local variables
    https://git.kernel.org/netdev/net-next/c/2295947bdaa6
  - [net-next,2/6] net: ipa: rename two transaction fields
    https://git.kernel.org/netdev/net-next/c/3eeabea6c895
  - [net-next,3/6] net: ipa: introduce gsi_trans_tx_committed()
    https://git.kernel.org/netdev/net-next/c/4e0f28e9ee4b
  - [net-next,4/6] net: ipa: simplify TX completion statistics
    https://git.kernel.org/netdev/net-next/c/65d39497fab6
  - [net-next,5/6] net: ipa: stop counting total RX bytes and transactions
    https://git.kernel.org/netdev/net-next/c/dbad2fa71914
  - [net-next,6/6] net: ipa: rework gsi_channel_tx_update()
    (no matching commit)

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-06-15  8:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-13 17:17 [PATCH net-next 0/6] net: ipa: simplify completion statistics Alex Elder
2022-06-13 17:17 ` [PATCH net-next 1/6] net: ipa: use "tre_ring" for all TRE ring local variables Alex Elder
2022-06-13 17:17 ` [PATCH net-next 2/6] net: ipa: rename two transaction fields Alex Elder
2022-06-13 17:17 ` [PATCH net-next 3/6] net: ipa: introduce gsi_trans_tx_committed() Alex Elder
2022-06-13 17:17 ` [PATCH net-next 4/6] net: ipa: simplify TX completion statistics Alex Elder
2022-06-13 17:17 ` [PATCH net-next 5/6] net: ipa: stop counting total RX bytes and transactions Alex Elder
2022-06-13 17:17 ` [PATCH net-next 6/6] net: ipa: rework gsi_channel_tx_update() Alex Elder
2022-06-15  8:20 ` [PATCH net-next 0/6] net: ipa: simplify completion statistics patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.