2020-10-14 17:41:57

by Alan Stern

[permalink] [raw]
Subject: Re: [patch 03/12] USB: serial: keyspan_pda: Consolidate room query

On Wed, Oct 14, 2020 at 06:27:14PM +0200, Sebastian Andrzej Siewior wrote:
> On 2020-10-14 12:14:33 [-0400], Alan Stern wrote:
> > Instead, consider using the new usb_control_msg_recv() API. But it
> > might be better to allocate the buffer once and for all.
>
> This will still allocate and free buffer on each invocation. What about

Yes. That's why I suggesting doing a single buffer allocation at the
start and using it for each I/O transfer. (But I'm not familiar with
this code, and I don't know if there might be multiple transfers going
on concurrently.)

> moving the query_buf to the begin of the struct / align it?

No, thank won't work either. The key to the issue is that while some
memory is mapped for DMA, the CPU must not touch it or anything else in
the same cache line. If a field is a member of a data structure, the
CPU might very well access a neighboring member while this one is
mapped, thereby messing up the cache line.

Alan Stern


Subject: Re: [patch 03/12] USB: serial: keyspan_pda: Consolidate room query

On 2020-10-14 12:34:25 [-0400], Alan Stern wrote:
> On Wed, Oct 14, 2020 at 06:27:14PM +0200, Sebastian Andrzej Siewior wrote:
> > On 2020-10-14 12:14:33 [-0400], Alan Stern wrote:
> > > Instead, consider using the new usb_control_msg_recv() API. But it
> > > might be better to allocate the buffer once and for all.
> >
> > This will still allocate and free buffer on each invocation. What about
>
> Yes. That's why I suggesting doing a single buffer allocation at the
> start and using it for each I/O transfer. (But I'm not familiar with
> this code, and I don't know if there might be multiple transfers going
> on concurrently.)

There are no concurrent transfer. There is a bit used as a lock. The
first one does the transfer, the other wait.

> > moving the query_buf to the begin of the struct / align it?
>
> No, thank won't work either. The key to the issue is that while some
> memory is mapped for DMA, the CPU must not touch it or anything else in
> the same cache line. If a field is a member of a data structure, the
> CPU might very well access a neighboring member while this one is
> mapped, thereby messing up the cache line.

that is unfortunately true. Let me do the single buffer.

> Alan Stern

Sebastian