All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] xhci: Use Cached ring during endpoint ring allocation
@ 2017-02-22 15:05 Anurag Kumar Vulisha
  2017-02-23 16:15 ` Mathias Nyman
  0 siblings, 1 reply; 2+ messages in thread
From: Anurag Kumar Vulisha @ 2017-02-22 15:05 UTC (permalink / raw)
  To: mathias.nyman, gregkh
  Cc: linux-usb, linux-kernel, anirudh, punnaia, 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 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.

Signed-off-by: Anurag Kumar Vulisha <anuragku@xilinx.com>
---
 drivers/usb/host/xhci-mem.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 8414ed2..587b6c6 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -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;
 
-- 
2.1.1

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

* Re: [RFC PATCH] xhci: Use Cached ring during endpoint ring allocation
  2017-02-22 15:05 [RFC PATCH] xhci: Use Cached ring during endpoint ring allocation Anurag Kumar Vulisha
@ 2017-02-23 16:15 ` Mathias Nyman
  0 siblings, 0 replies; 2+ messages in thread
From: Mathias Nyman @ 2017-02-23 16:15 UTC (permalink / raw)
  To: Anurag Kumar Vulisha, mathias.nyman, gregkh
  Cc: linux-usb, linux-kernel, anirudh, punnaia, Anurag Kumar Vulisha

On 22.02.2017 17:05, Anurag Kumar Vulisha wrote:
> 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.
>
> Signed-off-by: Anurag Kumar Vulisha <anuragku@xilinx.com>

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  

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

end of thread, other threads:[~2017-02-23 16:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-22 15:05 [RFC PATCH] xhci: Use Cached ring during endpoint ring allocation Anurag Kumar Vulisha
2017-02-23 16:15 ` Mathias Nyman

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.