I think the recent discussions on linaro-mm-sig and the BoF last week
at ELC have been quite productive, and at least my understanding
of the missing pieces has improved quite a bit. This is a list of
things that I think need to be done in the kernel. Please complain
if any of these still seem controversial:
1. Fix the arm version of dma_alloc_coherent. It's in use today and
is broken on modern CPUs because it results in both cached and
uncached mappings. Rebecca suggested different approaches how to
get there.
2. Implement dma_alloc_noncoherent on ARM. Marek pointed out
that this is needed, and it currently is not implemented, with
an outdated comment explaining why it used to not be possible
to do it.
3. Convert ARM to use asm-generic/dma-mapping-common.h. We need
both IOMMU and direct mapped DMA on some machines.
4. Implement an architecture independent version of dma_map_ops
based on the iommu.h API. As Joerg mentioned, this has been
missing for some time, and it would be better to do it once
than for each IOMMU separately. This is probably a lot of work.
5. Find a way to define per-device IOMMUs, if that is not actually
possible already. We had conflicting statements for this.
6. Implement iommu_ops for each of the ARM platforms that has
an IOMMU. Needs some modifications for MSM and a rewrite for
OMAP. Implementation for Samsung is under work.
7. Extend the dma_map_ops to have a way for mapping a buffer
from dma_alloc_{non,}coherent into user space. We have not
discussed that yet, but after thinking this for some time, I
believe this would be the right approach to map buffers into
user space from code that doesn't care about the underlying
hardware.
After all these are in place, building anything on top of
dma_alloc_{non,}coherent should be much easier. The question
of passing buffers between V4L and DRM is still completely
unsolved as far as I can tell, but that discussion might become
more focused if we can agree on the above points and assume
that it will be done.
I expect that I will have to update the list above as people
point out mistakes in my assumptions.
Arnd
On Wednesday 27 April 2011 23:31:06 Benjamin Herrenschmidt wrote:
> On Thu, 2011-04-21 at 21:29 +0200, Arnd Bergmann wrote:
> > 7. Extend the dma_map_ops to have a way for mapping a buffer
> >
> > from dma_alloc_{non,}coherent into user space. We have not
> > discussed that yet, but after thinking this for some time, I
> > believe this would be the right approach to map buffers into
> > user space from code that doesn't care about the underlying
> > hardware.
>
> Yes. There is a dma_mmap_coherent() call that's not part of the "Real"
> API but is implemented by some archs and used by Alsa (I added support
> for it on powerpc recently).
>
> Maybe that should go into the dma ops.
>
> The question remains, if we ever want to do more complex demand-paged
> operations, should we also expose a lower level set of functions to get
> struct page out of a dma_alloc_coherent() allocation and to get the
> pgprot for the user dma mapping ?
>
> > After all these are in place, building anything on top of
> > dma_alloc_{non,}coherent should be much easier. The question
> > of passing buffers between V4L and DRM is still completely
> > unsolved as far as I can tell, but that discussion might become
> > more focused if we can agree on the above points and assume
> > that it will be done.
>
> My gut feeling is that it should be done by having V4L use DRM buffers
> in the first place...
V4L2 needs to capture data to a wide variety of memory locations (system
memory when you just want to process the data using the CPU, frame buffer
memory, contiguous buffers that will be passed to a DSP for video encoding,
GPU textures, ...). To allow those use cases (and more) the V4L2 API provides
two ways to handle data buffers: applications can request the driver to
allocate memory internally, and them mmap() the buffers to userspace, or pass
arbitrary memory pointers (and sizes) to the driver to be used as video
capture buffers.
In the first case drivers will allocate memory depending on their
requirements. This could mean vmalloc_user() for USB drivers that use memcpy()
in the kernel, vmalloc() for hardware that support SG-lists or IOMMUs,
dma_alloc_coherent() for drivers that need contiguous memory, ...
In the second case the driver will verify that the memory it receives from the
application matches its requirements (regarding contiguousness for instance)
and will then use that memory.
I think we could target the second case only if we want to share buffers
between V4L and DRM, as V4L2 (unlike DRM) is already pretty good at using
buffers it didn't allocate itself. The current API will need to be extended to
pass an opaque buffer handle instead of a memory address, as we want to avoid
requiring a userspace mapping for the buffer when not necessary. That's the
whole point of the initial memory management discussion.
We will of course need to make sure that the DRM buffers fullfil the V4L2
needs.
> > I expect that I will have to update the list above as people
> > point out mistakes in my assumptions.
--
Regards,
Laurent Pinchart
Hey all,
While we are working out requirements, I was hoping to get some more
information about another related issue that keeps coming up on mailing
lists and in discussions.
ARM has stated that if you have the same physical memory mapped with two
different sets of attribute bits you get undefined behavior. I think it's
going to be a requirement that some of the memory allocated via the unified
memory manager is mapped uncached. However, because all of memory is mapped
cached into the unity map at boot, we already have two mappings with
different attributes. I want to understand the mechanism of the problem,
because none of the solutions I can come up with are particularly nice. I'd
also like to know exactly which architectures are affected, since the fix
may be costly in performance, memory or both. Can someone at ARM explain to
me why this causes a problem. I have a theory, but it's mostly a guess. I
especially want to understand if it's still a problem if we never access the
memory via the mapping in the unity map. I know speculative prefetching is
part of the issue, so I assume older architectures without that feature
don't exhibit this behaviour
If we really need all mappings of physical memory to have the same cache
attribute bits, I see three workarounds:
1- set aside memory at boot that never gets mapped by the kernel. The
unified memory manager can then ensure there's only one mapping at a time.
Obvious drawbacks here are that you have to statically partition your system
into memory you want accessible to the unified memory manager and memory you
don't. This may not be that big a deal, since most current solutions, pmem,
cmem, et al basically do this. I can say that on Android devices running on
a high resolution display (720p and above) we're easily talking about
needing 256M of memory or more to dedicate to this.
2- use highmem pages only for the unified memory manager. Highmem pages
only get mapped on demand.
This has some performance costs when the kernel allocates other metadata in
highmem. Most embedded systems still don't have enough memory to need
highmem, though I'm guessing that'll follow the current trend and shift in
the next couple of years.
3- fix up the unity mapping so the attribute bits match those desired by the
unified memory manger. This could be done by removing pages from the unity
map. It's complicated by the fact that the unity map makes use of large
pages, sections and supersections to reduce tlb pressure. I don't think
this is impossible if we restrict the set of contexts from which it can
happen, but I'm imagining that we will also need to maintain some kind of
pool of memory we've moved from cached to uncached since the process is
likely to be expensive. Quite likely we will have to iterate
over processes and update all their top level page tables.
These all have drawbacks, so I'd like to really understand the problem
before pursuing them. Can the linaro folks find someone who can explain the
problem in more detail?
Thanks,
Rebecca
Hi all,
For those that are interested in or required to attend additional
sessions at the larger LDS or UDS events, at the request of the folks
managing the scheduling, I've created blueprints, one for each day, to
track the sessions. The reason for this is that the autoscheduler
will attempt to honor people's "essential" participation, so if you
are marked "essential" for both the mini-summit and another track
session, there is increased likelihood that you will not have a
conflict. I have limited editorial say in the scheduling, so if there
are critical conflicts, I can try to help resolve them.
I've put the links to the blueprints under "registration" in the
mini-summit event on https://wiki.linaro.org/Events, but for
convenience, here they are:
https://blueprints.edge.launchpad.net/linaro-graphics-wg/+spec/linaro-graph…https://blueprints.edge.launchpad.net/linaro-graphics-wg/+spec/linaro-graph…https://blueprints.edge.launchpad.net/linaro-graphics-wg/+spec/linaro-graph…
I'm still tracking the agenda on the Linaro wiki, but will be moving
the day's agenda to each blueprint as the event approaches.
cheers,
Jesse
Hi all,
The good news is that largely everything is as I announced previously.
The tracks have been cleaned up a bit, so the memory management
mini-summit is now driven out of the Linaro Graphics track, but the
room (Ond) and schedule (M-W afternoons) is still the same. All the
info you need on the schedule is here:
http://summit.ubuntu.com/uds-o/
The room is supposed to have a projector, be mic'd for live audio and
have an IRC channel. Those participating remotely will be interested
in the details around the audio and IRC access here:
http://uds.ubuntu.com/participate/remote/
A link for the mini-summit event found here:
https://wiki.linaro.org/Events
goes to the (work in progress) agenda and there is a registration link
as well. Please let me know if I've missed any components that need
representation, if there are some on there that you feel don't need
it, or if there are additional items you'd like to see on the agenda.
I have 2 requests of the people that will participate in person:
1) Please "register" to indicate you'll be there in person (or even if
you plan on participating remotely). There are a few reasons for
this, but the critical one is to make sure we have a big enough room.
2) Sign-up to represent a component, at least in the overview
sessions. This is important for sane discussion afterwards.
If you don't or can't get write access to the Linaro wiki, just send
me email directly and I'll do it by proxy. Also, if you have material
that you will "show" people (slides, etc.), please send it to the list
ahead of time for the benefit of those participating remotely.
Finally, the "project page" for this effort is here on the Linaro
wiki:
https://wiki.linaro.org/OfficeofCTO/MemoryManagement
Thanks again to everyone for their contributions.
cheers,
Jesse
During the MM BoF at ELC, it seemed to me that one of the things that scared
most ARM vendors away from GEM in the first place is that was perceived to be
too closely married to the rest of DRM (especially KMS).
I know that some might argue that isn't necessarily true and we can go back
and forth on that point, but I think it is still valuable to ask this question:
How feasible is it to break out the GEM portion of DRM (essentially drm_gem.c)
and put it into its own subsystem or library component for use by a DRM or
a non DRM component. What parts would a non DRM component be missing to use
GEM effectively (authentication comes to mind)?
Jordan
Hi all,
I'll be rolling out the details around the Budapest mini-summit as I
get them, so there will be more to follow. You can check out the
overall schedule here:
http://summit.ubuntu.com/uds-o/
As of right now, viewing by track, the mini-summit is listed in the
"other" track, though, this may change over the next few days.
Viewing the schedule by day, we are right after lunch through the end
of the day on Monday-Wednesday (there are plenaries scheduled for
immediately after lunch, but unless there are strong objections, I'd
argue for going straight into the summit). And finally, by room, we
are in "Ond". For those that will be participating remotely, I don't
yet have the details on how to tune in to the audio channel, but the
IRC channel will be named for the room we're in; I expect to have the
rest of those details later this week or early next. I'll also be
creating a blueprint on Launchpad to hold our outline, agenda, notes,
minutes, etc. (last cycle we used "gobby" to take notes live, but
there were stability issues with the server, so we'll see how that
goes). Based upon the discussion from ELC, I would expect much of the
first day to be component/subsystem overview; I really think that will
be critical to finalizing sane requirements. These discussions do not
have to wait until Budapest. If there are questions you would like to
see answered, send them along. Also, if folks that are attending in
person could let me know directly, it would be good to get an updated
headcount of who is coming to make sure I don't need to argue for a
bigger room.
cheers,
Jesse