Re: [RFC] avoid indirect calls for DMA direct mappings
From: Christoph Hellwig
Date: Thu Dec 06 2018 - 13:43:34 EST
On Thu, Dec 06, 2018 at 10:28:22AM -0800, Linus Torvalds wrote:
> which is counterproductive because it checks for the fast case *after*
> you've done a load (and a check) that is entirely pointless for the
> fast case.
>
> Put another way, you made the fast case unnecessarily slow.
>
> If this fast case matters (and the whole point of the series is that
> it *does* matter), then you should make sure that
>
> (a) the dma_is_direct() function/macro uses "likely()" for the test
I'm a little worried about that. Yes, for the common case it is
likely. But if you run a setup where you say always have an iommu
it is not, in fact it is never called in that case, but we only know
that at runtime.
> (b) the code is organized like this instead:
>
> + if (dma_is_direct(ops))
> + dma_direct_unmap_page(dev, addr, size, dir, attrs);
> + else if (ops->unmap_page)
> + ops->unmap_page(dev, addr, size, dir, attrs);
>
> because now you avoid that unnecessary conditional for the common
> case, and you hopefully never even access the pointer (because you
> know what's behind it: the direct ops cases that you're
> short-circuiting).
Agreed on that, I've fixed it up now (current patch attached below).
> In fact, as a further micro-optimization it might be a good idea to
> just specify that the dma_is_direct() ops is a special pointer
> (perhaps even just say that "NULL means it's direct"), because that
> then makes the fast-case test much simpler (avoids a whole nasty
> constant load, and testing for NULL in particular is often much
> better).
So I wanted to do the NULL case, and it would be much nicer. But the
arm folks went to great length to make sure they don't have a default
set of dma ops and require it to be explicitly set on every device
to catch cases where people don't set things up properly and I didn't
want to piss them off.. But maybe I should just go for it and see who
screams, as the benefit is pretty obvious.
---