On Fri, 20 Nov 2026 at 20:49, Thomas Zimmermann <[email protected]> wrote:
>
> Hi
>
> Am 19.11.26 um 17:38 schrieb Jie Feng:
> > On Fri, 20 Nov 2026 at 00:30, Thomas Zimmermann <[email protected]> wrote:
> >> Move the code for allocating an URB into a separate helper function. Use
> >> the helper for initializing the URB cache.
> >>
> >> Signed-off-by: Thomas Zimmermann <[email protected]>
> >> ---
> >> drivers/gpu/drm/udl/udl_main.c | 74 +++++++++++++++++++++-------------
> >> 1 file changed, 47 insertions(+), 27 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/udl/udl_main.c
> >> b/drivers/gpu/drm/udl/udl_main.c
> >> index 67da676f0f94..a799d7710a7b 100644
> >> --- a/drivers/gpu/drm/udl/udl_main.c
> >> +++ b/drivers/gpu/drm/udl/udl_main.c
> >> @@ -163,6 +163,47 @@ static void udl_urb_completion(struct urb *urb)
> >> udl_put_urb(urb);
> >> }
> >>
> >> +static struct urb *udl_alloc_bulk_urb(struct udl_device *udl, size_t size)
> >> +{
> >> + struct usb_device *udev = udl_to_usb_device(udl);
> >> + struct urb_node *unode;
> >> + struct urb *urb;
> >> + char *buf;
> >> + int ret;
> >> +
> >> + urb = usb_alloc_urb(0, GFP_KERNEL);
> >> + if (!urb)
> >> + return ERR_PTR(-ENOMEM);
> >> +
> >> + unode = kzalloc_obj(struct urb_node);
> >> + if (!unode) {
> >> + ret = -ENOMEM;
> >> + goto err_usb_free_urb;
> >> + }
> >> + unode->dev = udl;
> >> + unode->urb = urb;
> >> +
> >> + buf = usb_alloc_coherent(udev, size, GFP_KERNEL,
> >> &urb->transfer_dma);
> > usb_alloc_coherent might map uncached memory on platforms such as ARM.
> > This might be slow for moving large amounts of frame data.
> > Would using kmalloc/usb_alloc_noncoherent be better?
>
> It's worth a try, but i cannot say for sure. The advantage of _coherent
> is that is makes DMA easy. And we don't read from these buffers from the
> CPU, so caching them might not help much for performance. In any case,
> it's a separate patch series.
If I'm not wrong, uncached memory also means that the CPU sends each memory
write as a separate transaction, so it does not wait a while to flush
the entire cache line
at once unlike normal/write-combined memory. Therefore it still makes sense to
use cacheable memory for the write path.
I agree that it should be a separate patch series.
Most of the uses of these USB display adapters should be on x86, where
there isn't
a performance impact, but given that ARM laptops has been rising in popularity,
I think looking into this might be a good idea.
> Best regards
> Thomas
>
> >> + if (!buf) {
> >> + ret = -ENOBUFS;
> >> + goto err_kfree;
> >> + }
> >> + unode->alloc_size = size;
> >> +
> >> + /* urb->transfer_buffer_length set to actual before submit */
> >> + usb_fill_bulk_urb(urb, udev, usb_sndbulkpipe(udev, 1), buf,
> >> unode->alloc_size,
> >> + udl_urb_completion, unode);
> >> + urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
> >> +
> >> + return urb;
> >> +
> >> +err_kfree:
> >> + kfree(unode);
> >> +err_usb_free_urb:
> >> + usb_free_urb(urb);
> >> + return ERR_PTR(ret);
> >> +}
> >> +
> >> static void udl_free_urb_list(struct udl_device *udl)
> >> {
> >> struct urb_node *unode;
> >> @@ -191,11 +232,7 @@ static void udl_free_urb_list(struct udl_device *udl)
> >>
> >> static int udl_alloc_urb_list(struct udl_device *udl, int count, size_t
> >> size)
> >> {
> >> - struct urb *urb;
> >> - struct urb_node *unode;
> >> - char *buf;
> >> size_t wanted_size = count * size;
> >> - struct usb_device *udev = udl_to_usb_device(udl);
> >>
> >> spin_lock_init(&udl->urbs.lock);
> >> INIT_LIST_HEAD(&udl->urbs.list);
> >> @@ -205,36 +242,19 @@ static int udl_alloc_urb_list(struct udl_device
> >> *udl, int count, size_t size)
> >>
> >> retry:
> >> while (udl->urbs.count * size < wanted_size) {
> >> - unode = kzalloc_obj(struct urb_node);
> >> - if (!unode)
> >> - break;
> >> - unode->dev = udl;
> >> + struct urb *urb;
> >> + struct urb_node *unode;
> >>
> >> - urb = usb_alloc_urb(0, GFP_KERNEL);
> >> - if (!urb) {
> >> - kfree(unode);
> >> - break;
> >> - }
> >> - unode->urb = urb;
> >> - unode->alloc_size = size;
> >> -
> >> - buf = usb_alloc_coherent(udev, unode->alloc_size,
> >> GFP_KERNEL,
> >> - &urb->transfer_dma);
> >> - if (!buf) {
> >> - kfree(unode);
> >> - usb_free_urb(urb);
> >> - if (size > PAGE_SIZE) {
> >> + urb = udl_alloc_bulk_urb(udl, size);
> >> + if (IS_ERR(urb)) {
> >> + if (PTR_ERR(urb) == -ENOBUFS && size > PAGE_SIZE) {
> >> size /= 2;
> >> udl_free_urb_list(udl);
> >> goto retry;
> >> }
> >> break;
> >> }
> >> -
> >> - /* urb->transfer_buffer_length set to actual before submit
> >> */
> >> - usb_fill_bulk_urb(urb, udev, usb_sndbulkpipe(udev, 1),
> >> - buf, size, udl_urb_completion, unode);
> >> - urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
> >> + unode = urb->context;
> >>
> >> list_add_tail(&unode->entry, &udl->urbs.list);
> >>
> >> --
> >> 2.56.0
> >>
> >>
> > Best regards,
> > Jie Feng
>
> --
> --
> Thomas Zimmermann
> Graphics Driver Developer
> SUSE Software Solutions Germany GmbH
> Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
> GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)
>
>
Best regards,
Jie Feng