xhci: Use Cached ring during endpoint ring allocation
Subsystems (2)
RFC PATCH 1/1 xhci: Use Cached ring during endpoint ring allocation
Currently during endpoint initialization, a new endpoint ring is alloacte using xhci_ring_alloc(), if this function fails to allocate ring a cached ring(if available) is assigned to endpoint ring.
This patch modifies the code that during endpoint initialization, if cached ring is available it is assigned to the endpoint ring. If cached rings are not available then xhci_ring_alloc() is called to allocate a new ring. Doing so will avoid unncessary memory allocations if cached ring is already available for use. This also fixes endpoint "Ring expansion failed" error which occurs due to insufficient memory during ring expansion.
--- drivers/usb/host/xhci-mem.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/usb/host/xhci-mem.c +8 -5
@@ -1514,19 +1514,22 @@ int xhci_endpoint_init(struct xhci_hcd *xhci, mult =0 ;/* Set up the endpoint ring */ - virt_dev->eps[ep_index].new_ring = -xhci_ring_alloc (xhci,2 ,1 , ring_type, max_packet, mem_flags); -if (!virt_dev->eps[ep_index].new_ring) { +if (virt_dev->num_rings_cached >0 ) {/* Attempt to use the ring cache */ -if (virt_dev->num_rings_cached ==0 ) -return -ENOMEM ; virt_dev->num_rings_cached--; virt_dev->eps[ep_index].new_ring = virt_dev->ring_cache[virt_dev->num_rings_cached]; virt_dev->ring_cache[virt_dev->num_rings_cached] =NULL ;xhci_reinit_cached_ring (xhci, virt_dev->eps[ep_index].new_ring,1 , ring_type); + }else { + virt_dev->eps[ep_index].new_ring = +xhci_ring_alloc (xhci,2 ,1 , ring_type, max_packet, + mem_flags); +if (!virt_dev->eps[ep_index].new_ring) +return -ENOMEM ; } + virt_dev->eps[ep_index].skip = false; ep_ring = virt_dev->eps[ep_index].new_ring;
Signature · 1 line
2.1.1
Quoted 11 lines · Anurag Kumar Vulisha
Currently during endpoint initialization, a new endpoint ring is alloacte using
xhci_ring_alloc(), if this function fails to allocate ring a cached ring(if available) is assigned to endpoint ring.
This patch modifies the code that during endpoint initialization, if cached ring is available it is assigned to the endpoint ring. If cached rings are not available thenxhci_ring_alloc()is called to allocate a new ring. Doing so will avoid unncessary memory allocations if cached ring is already available for use. This also fixes endpoint "Ring expansion failed" error which occurs due to insufficient memory during ring expansion.Signed-off-by Anurag Kumar Vulisha <[email protected]>
Thanks for bringing this to my attention.
Your approach certainly makes more sense than the current way.
I need to check history why this type of ring cache was created in the first place. It's possible that the whole ring cache is not really useful anymore
-Mathias