Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] usbip: Implement map_urb_for_dma function for vhci to skip dma mapping
@ 2019-06-18 14:28 Suwan Kim
  2019-06-18 15:30 ` Alan Stern
  0 siblings, 1 reply; 3+ messages in thread
From: Suwan Kim @ 2019-06-18 14:28 UTC (permalink / raw)
  To: shuah, valentina.manea.m, gregkh; +Cc: linux-usb, linux-kernel, Suwan Kim

vhci doesn’t do dma for remote device. Actually, the real dma
operation is done by network card driver. So, vhci doesn’t use and
need dma address of transfer buffer of urb.

But hcd provides dma mapping function by defualt in usb_hcd_submit_urb()
and it causes unnecessary dma mapping which will be done again at
NIC driver and it wastes CPU cycles. So, implement map_urb_for_dma
function for vhci in order to skip the dma mapping procedure.

Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
---
 drivers/usb/usbip/vhci_hcd.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index 667d9c0ec905..9df4d9e36788 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -1287,6 +1287,13 @@ static int vhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
 	return 0;
 }
 
+static int vhci_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
+			    gfp_t mem_flags)
+{
+	dev_dbg(hcd->self.controller, "vhci does not map urb for dma\n");
+	return 0;
+}
+
 static const struct hc_driver vhci_hc_driver = {
 	.description	= driver_name,
 	.product_desc	= driver_desc,
@@ -1302,6 +1309,7 @@ static const struct hc_driver vhci_hc_driver = {
 	.urb_dequeue	= vhci_urb_dequeue,
 
 	.get_frame_number = vhci_get_frame_number,
+	.map_urb_for_dma = vhci_map_urb_for_dma,
 
 	.hub_status_data = vhci_hub_status,
 	.hub_control    = vhci_hub_control,
-- 
2.20.1


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

* Re: [PATCH] usbip: Implement map_urb_for_dma function for vhci to skip dma mapping
  2019-06-18 14:28 [PATCH] usbip: Implement map_urb_for_dma function for vhci to skip dma mapping Suwan Kim
@ 2019-06-18 15:30 ` Alan Stern
  2019-06-19  8:16   ` Suwan Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Stern @ 2019-06-18 15:30 UTC (permalink / raw)
  To: Suwan Kim; +Cc: shuah, valentina.manea.m, gregkh, linux-usb, linux-kernel

On Tue, 18 Jun 2019, Suwan Kim wrote:

> vhci doesn’t do dma for remote device. Actually, the real dma
> operation is done by network card driver. So, vhci doesn’t use and
> need dma address of transfer buffer of urb.
> 
> But hcd provides dma mapping function by defualt in usb_hcd_submit_urb()
> and it causes unnecessary dma mapping which will be done again at
> NIC driver and it wastes CPU cycles. So, implement map_urb_for_dma
> function for vhci in order to skip the dma mapping procedure.
> 
> Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
> ---
>  drivers/usb/usbip/vhci_hcd.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
> index 667d9c0ec905..9df4d9e36788 100644
> --- a/drivers/usb/usbip/vhci_hcd.c
> +++ b/drivers/usb/usbip/vhci_hcd.c
> @@ -1287,6 +1287,13 @@ static int vhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
>  	return 0;
>  }
>  
> +static int vhci_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
> +			    gfp_t mem_flags)
> +{
> +	dev_dbg(hcd->self.controller, "vhci does not map urb for dma\n");
> +	return 0;
> +}
> +
>  static const struct hc_driver vhci_hc_driver = {
>  	.description	= driver_name,
>  	.product_desc	= driver_desc,
> @@ -1302,6 +1309,7 @@ static const struct hc_driver vhci_hc_driver = {
>  	.urb_dequeue	= vhci_urb_dequeue,
>  
>  	.get_frame_number = vhci_get_frame_number,
> +	.map_urb_for_dma = vhci_map_urb_for_dma,
>  
>  	.hub_status_data = vhci_hub_status,
>  	.hub_control    = vhci_hub_control,

If the goal is to avoid wasting CPU cycles, you probably should have a 
vhci_unmap_urb_for_dma routine as well.

Alan Stern


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

* Re: [PATCH] usbip: Implement map_urb_for_dma function for vhci to skip dma mapping
  2019-06-18 15:30 ` Alan Stern
@ 2019-06-19  8:16   ` Suwan Kim
  0 siblings, 0 replies; 3+ messages in thread
From: Suwan Kim @ 2019-06-19  8:16 UTC (permalink / raw)
  To: Alan Stern; +Cc: shuah, valentina.manea.m, gregkh, linux-usb, linux-kernel

On Tue, Jun 18, 2019 at 11:30:34AM -0400, Alan Stern wrote:
> On Tue, 18 Jun 2019, Suwan Kim wrote:
> 
> > vhci doesn’t do dma for remote device. Actually, the real dma
> > operation is done by network card driver. So, vhci doesn’t use and
> > need dma address of transfer buffer of urb.
> > 
> > But hcd provides dma mapping function by defualt in usb_hcd_submit_urb()
> > and it causes unnecessary dma mapping which will be done again at
> > NIC driver and it wastes CPU cycles. So, implement map_urb_for_dma
> > function for vhci in order to skip the dma mapping procedure.
> > 
> > Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
> > ---
> >  drivers/usb/usbip/vhci_hcd.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
> > index 667d9c0ec905..9df4d9e36788 100644
> > --- a/drivers/usb/usbip/vhci_hcd.c
> > +++ b/drivers/usb/usbip/vhci_hcd.c
> > @@ -1287,6 +1287,13 @@ static int vhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
> >  	return 0;
> >  }
> >  
> > +static int vhci_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
> > +			    gfp_t mem_flags)
> > +{
> > +	dev_dbg(hcd->self.controller, "vhci does not map urb for dma\n");
> > +	return 0;
> > +}
> > +
> >  static const struct hc_driver vhci_hc_driver = {
> >  	.description	= driver_name,
> >  	.product_desc	= driver_desc,
> > @@ -1302,6 +1309,7 @@ static const struct hc_driver vhci_hc_driver = {
> >  	.urb_dequeue	= vhci_urb_dequeue,
> >  
> >  	.get_frame_number = vhci_get_frame_number,
> > +	.map_urb_for_dma = vhci_map_urb_for_dma,
> >  
> >  	.hub_status_data = vhci_hub_status,
> >  	.hub_control    = vhci_hub_control,
> 
> If the goal is to avoid wasting CPU cycles, you probably should have a 
> vhci_unmap_urb_for_dma routine as well.

I missed that. Thank you for pointing it out.
I will send v2 including unmap function.

Regards

Suwan Kim

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-18 14:28 [PATCH] usbip: Implement map_urb_for_dma function for vhci to skip dma mapping Suwan Kim
2019-06-18 15:30 ` Alan Stern
2019-06-19  8:16   ` Suwan Kim

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org linux-usb@archiver.kernel.org
	public-inbox-index linux-usb


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/ public-inbox