net: ipa: don't use lists for transaction state
cover net: ipa: don't use lists for transaction state
This is the last series of patches to convert the IPA code so integer IDs are used rather than lists to track the state of transactions.
A first series of patches added ID fields to track the state of transactions:
https://lore.kernel.org/netdev/[email protected]
The second series started transitioning code to use these IDs rather than lists to manage state:
https://lore.kernel.org/netdev/[email protected]
This final series finishes the transition, to always use IDs instead of the lists to manage transaction state. As a result, the list fields, links, and a spinlock to protect updates are no longer needed, so they are removed. This permits a few other improvements to be implemented.
-Alex
Alex Elder (5):
net: ipa: always use transaction IDs instead of lists
net: ipa: kill the allocated transaction list
net: ipa: kill all other transaction lists
net: ipa: update channel in gsi_channel_trans_complete()
net: ipa: don't have gsi_channel_update() return a value
drivers/net/ipa/gsi.c | 11 +-- drivers/net/ipa/gsi.h | 7 -- drivers/net/ipa/gsi_private.h | 22 ++---- drivers/net/ipa/gsi_trans.c | 136 ++++++---------------------------- drivers/net/ipa/gsi_trans.h | 3 - 5 files changed, 35 insertions(+), 144 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/5 net: ipa: always use transaction IDs instead of lists
In gsi_channel_trans_complete(), use the completed and pending IDs to determine whether there are any transactions in completed state.
Similarly, in gsi_channel_trans_cancel_pending(), use the pending and committed IDs to mark pending transactions cancelled. Rearrange the logic a bit there for a simpler result.
This removes the only user of list_last_entry_or_null(), so get rid of that macro.
Remove the temporary warnings added by the previous commit.
--- drivers/net/ipa/gsi_private.h | 14 --------- drivers/net/ipa/gsi_trans.c | 58 ++++++++++------------------------- 2 files changed, 16 insertions(+), 56 deletions(-)
drivers/net/ipa/gsi_private.h +0 -14
@@ -16,20 +16,6 @@ struct gsi_channel;#define GSI_RING_ELEMENT_SIZE 16/* bytes; must be a power of 2 */ -/** -* list_last_entry_or_null - get the last element from a list -* @ptr: the list head to take the element from. -* @type: the type of the struct this is embedded in. -* @member: the name of the list_head within the struct. -* -* Note that if the list is empty, it returns NULL. -*/ -#define list_last_entry_or_null (ptr, type, member) ({ \ - struct list_head *head__ = (ptr); \ - struct list_head *pos__ = READ_ONCE(head__->prev); \ - pos__ != head__ ? list_entry(pos__, type, member) : NULL; \ -}) -/** * gsi_trans_move_complete() - Mark a GSI transaction completed * @trans: Transaction to commit
drivers/net/ipa/gsi_trans.c +16 -42
85 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 2/5 net: ipa: kill the allocated transaction list
In reply to Alex ElderThe only place the trans_info->alloc list is used is when initializing it, when adding a transaction to it when allocation finishes, and when moving a transaction from that list to the committed list.
We can just skip putting a transaction on the allocated list, and add it (rather than move it) to the committed list when it is committed.
On additional caveat is that an allocated transaction that's committed without any TREs added will be immediately freed. Because we aren't adding allocated transactions to a list any more, the list links need to be initialized to ensure they're valid at the time list_del() is called for the transaction.
Then we can safely eliminate the allocated transaction list.
--- drivers/net/ipa/gsi.h | 1 - drivers/net/ipa/gsi_trans.c | 12 +++--------- 2 files changed, 3 insertions(+), 10 deletions(-)
drivers/net/ipa/gsi.h +0 -1
@@ -96,7 +96,6 @@ struct gsi_trans_info {struct gsi_trans_pool cmd_pool;/* command payload DMA pool */ spinlock_t spinlock;/* protects updates to the lists */ -struct list_head alloc;/* allocated, not committed */ struct list_head committed;/* committed, awaiting doorbell */ struct list_head pending;/* pending, awaiting completion */ struct list_head complete;/* completed, awaiting poll */
drivers/net/ipa/gsi_trans.c +3 -9
@@ -246,7 +246,7 @@ struct gsi_trans *gsi_channel_trans_complete(struct gsi_channel *channel)return &trans_info->trans[trans_id %= channel->tre_count]; } -/* Move a transaction from the allocated list to the committed list */ +/* Move a transaction from allocated to committed state */ static void gsi_trans_move_committed (struct gsi_trans *trans) {struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id];
@@ -254,7 +254,7 @@ static void gsi_trans_move_committed(struct gsi_trans *trans)spin_lock_bh (&trans_info->spinlock); -list_move_tail (&trans->links, &trans_info->committed); +list_add_tail (&trans->links, &trans_info->committed);spin_unlock_bh (&trans_info->spinlock);
@@ -383,6 +383,7 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id,memset (trans,0 ,sizeof (*trans));/* Initialize non-zero fields in the transaction */ +INIT_LIST_HEAD (&trans->links); trans->gsi = gsi; trans->channel_id = channel_id; trans->rsvd_count = tre_count;
@@ -398,12 +399,6 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id,/* This free transaction will now be allocated */ trans_info->free_id++; -spin_lock_bh (&trans_info->spinlock); - -list_add_tail (&trans->links, &trans_info->alloc); - -spin_unlock_bh (&trans_info->spinlock); -return trans; }
@@ -821,7 +816,6 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id) goto err_map_free;spin_lock_init (&trans_info->spinlock); -INIT_LIST_HEAD (&trans_info->alloc);INIT_LIST_HEAD (&trans_info->committed);INIT_LIST_HEAD (&trans_info->pending);INIT_LIST_HEAD (&trans_info->complete);
Signature · 1 line
2.34.1
PATCH 3/5 net: ipa: kill all other transaction lists
In reply to Alex ElderNone of the transaction lists are actually needed any more, because transaction IDs (which have been shown to be equivalent) are used instead. So we can remove all of them, as well as the spinlock that protects updates to them.
Not requiring a lock simplifies gsi_trans_free() as well; we only need to check the reference count once to decide whether we've hit the last reference.
This makes the links field in the gsi_trans structure unused, so get rid of that as well.
--- drivers/net/ipa/gsi.h | 6 ---- drivers/net/ipa/gsi_trans.c | 71 ++++--------------------------------- drivers/net/ipa/gsi_trans.h | 3 -- 3 files changed, 6 insertions(+), 74 deletions(-)
drivers/net/ipa/gsi.h +0 -6
@@ -94,12 +94,6 @@ struct gsi_trans_info {struct gsi_trans_pool sg_pool;/* scatterlist pool */ struct gsi_trans_pool cmd_pool;/* command payload DMA pool */ - -spinlock_t spinlock;/* protects updates to the lists */ -struct list_head committed;/* committed, awaiting doorbell */ -struct list_head pending;/* pending, awaiting completion */ -struct list_head complete;/* completed, awaiting poll */ -struct list_head polled;/* returned by gsi_channel_poll_one() */ };/* Hardware values signifying the state of a channel */
drivers/net/ipa/gsi_trans.c +6 -65
148 lines not on this page · raw message
drivers/net/ipa/gsi_trans.h +0 -3
@@ -29,7 +29,6 @@ struct gsi_trans_pool;* struct gsi_trans - a GSI transaction * * Most fields in this structure for internal use by the transaction core code: -* @links: Links for channel transaction lists by state * @gsi: GSI pointer * @channel_id: Channel number transaction is associated with * @cancelled: If set by the core code, transaction was cancelled
@@ -50,8 +49,6 @@ struct gsi_trans_pool;* received. */ struct gsi_trans { -struct list_head links;/* gsi_channel lists */ -struct gsi *gsi;u8 channel_id;
Signature · 1 line
2.34.1
PATCH 4/5 net: ipa: update channel in gsi_channel_trans_complete()
In reply to Alex ElderHave gsi_channel_trans_complete() update the known state from hardware rather than doing so in gsi_channel_poll_one().
--- drivers/net/ipa/gsi.c | 5 +---- drivers/net/ipa/gsi_private.h | 8 ++++++++ drivers/net/ipa/gsi_trans.c | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-)
drivers/net/ipa/gsi.c +1 -4
@@ -1475,7 +1475,7 @@ void gsi_channel_doorbell(struct gsi_channel *channel) }/* Consult hardware, move any newly completed transactions to completed list */ -static struct gsi_trans *gsi_channel_update (struct gsi_channel *channel) +struct gsi_trans *gsi_channel_update (struct gsi_channel *channel) {u32 evt_ring_id = channel->evt_ring_id;struct gsi *gsi = channel->gsi;
@@ -1529,9 +1529,6 @@ static struct gsi_trans *gsi_channel_poll_one(struct gsi_channel *channel)/* Get the first transaction from the completed list */ trans =gsi_channel_trans_complete (channel); -if (!trans)/* List is empty; see if there's more to do */ - trans =gsi_channel_update (channel); -if (trans)gsi_trans_move_polled (trans);
drivers/net/ipa/gsi_private.h +8 -0
@@ -94,6 +94,14 @@ void gsi_channel_trans_exit(struct gsi_channel *channel);*/ void gsi_channel_doorbell (struct gsi_channel *channel); +/* gsi_channel_update() - Update knowledge of channel hardware state +* @channel: Channel whose doorbell should be rung +* +* Consult hardware, move any newly completed transactions to a +* channel's completed list +*/ +struct gsi_trans *gsi_channel_update (struct gsi_channel *channel); +/** * gsi_ring_virt() - Return virtual address for a ring entry * @ring: Ring whose address is to be translated
drivers/net/ipa/gsi_trans.c +1 -1
@@ -241,7 +241,7 @@ struct gsi_trans *gsi_channel_trans_complete(struct gsi_channel *channel)u16 trans_id = trans_info->completed_id;if (trans_id == trans_info->pending_id) -return NULL ; +return gsi_channel_update (channel);return &trans_info->trans[trans_id %= channel->tre_count]; }
Signature · 1 line
2.34.1
PATCH 5/5 net: ipa: don't have gsi_channel_update() return a value
In reply to Alex ElderIf it finds no completed transactions, gsi_channel_trans_complete() calls gsi_channel_update() to check hardware. If new transactions have completed, gsi_channel_update() records that, then calls gsi_channel_trans_complete() to return the first of those found. This recursion won't go any further, but can be avoided if we have gsi_channel_update() only be responsible for updating state after accessing hardware.
Change gsi_channel_update() so it simply checks for and handles new completions, without returning a value. If it needs to call that function, have gsi_channel_trans_complete() determine whether there are new transactions available after the update.
--- drivers/net/ipa/gsi.c | 8 +++----- drivers/net/ipa/gsi_private.h | 6 +++--- drivers/net/ipa/gsi_trans.c | 7 +++++-- 3 files changed, 11 insertions(+), 10 deletions(-)
drivers/net/ipa/gsi.c +3 -5
@@ -1475,7 +1475,7 @@ void gsi_channel_doorbell(struct gsi_channel *channel) }/* Consult hardware, move any newly completed transactions to completed list */ -struct gsi_trans *gsi_channel_update (struct gsi_channel *channel) +void gsi_channel_update (struct gsi_channel *channel) {u32 evt_ring_id = channel->evt_ring_id;struct gsi *gsi = channel->gsi;
@@ -1494,12 +1494,12 @@ struct gsi_trans *gsi_channel_update(struct gsi_channel *channel) offset =GSI_EV_CH_E_CNTXT_4_OFFSET (evt_ring_id); index =gsi_ring_index (ring,ioread32 (gsi->virt + offset));if (index == ring->index % ring->count) -return NULL ; +return ;/* Get the transaction for the latest completed event. */ trans =gsi_event_trans (gsi,gsi_ring_virt (ring, index -1 ));if (!trans) -return NULL ; +return ;/* For RX channels, update each completed transaction with the number * of bytes that were actually received. For TX channels, report
@@ -1507,8 +1507,6 @@ struct gsi_trans *gsi_channel_update(struct gsi_channel *channel)* up the network stack. */ gsi_evt_ring_update (gsi, evt_ring_id, index); - -return gsi_channel_trans_complete (channel); }/**
drivers/net/ipa/gsi_private.h +3 -3
@@ -95,12 +95,12 @@ void gsi_channel_trans_exit(struct gsi_channel *channel);void gsi_channel_doorbell (struct gsi_channel *channel);/* gsi_channel_update() - Update knowledge of channel hardware state -* @channel: Channel whose doorbell should be rung +* @channel: Channel to be updated * * Consult hardware, move any newly completed transactions to a -* channel's completed list +* channel's completed list. */ -struct gsi_trans *gsi_channel_update (struct gsi_channel *channel); +void gsi_channel_update (struct gsi_channel *channel);/** * gsi_ring_virt() - Return virtual address for a ring entry
drivers/net/ipa/gsi_trans.c +5 -2
@@ -240,8 +240,11 @@ struct gsi_trans *gsi_channel_trans_complete(struct gsi_channel *channel)struct gsi_trans_info *trans_info = &channel->trans_info;u16 trans_id = trans_info->completed_id; -if (trans_id == trans_info->pending_id) -return gsi_channel_update (channel); +if (trans_id == trans_info->pending_id) { +gsi_channel_update (channel); +if (trans_id == trans_info->pending_id) +return NULL ; + }return &trans_info->trans[trans_id %= channel->tre_count]; }
Signature · 1 line
2.34.1
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 4 lines · On Tue, 6 Sep 2022 12:19:37 -0500 you wrote:
This is the last series of patches to convert the IPA code so integer IDs are used rather than lists to track the state of transactions.
Quoted 8 lines
A first series of patches added ID fields to track the state of transactions:
https://lore.kernel.org/netdev/[email protected]
The second series started transitioning code to use these IDs rather than lists to manage state:
https://lore.kernel.org/netdev/[email protected][...]
Here is the summary with links:
- [net-next,1/5] net: ipa: always use transaction IDs instead of lists (no matching commit)
- [net-next,2/5] net: ipa: kill the allocated transaction list
https://git.kernel.org/netdev/net-next/c/11902b41f2fa - [net-next,3/5] net: ipa: kill all other transaction lists https://git.kernel.org/netdev/net-next/c/d338ae28d8a8 - [net-next,4/5] net: ipa: update channel in gsi_channel_trans_complete() https://git.kernel.org/netdev/net-next/c/e0e3406c60d7 - [net-next,5/5] net: ipa: don't have gsi_channel_update() return a value https://git.kernel.org/netdev/net-next/c/019e37eaef97
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html