Order of the Butterfly
Posts: 301 from 2003/2/24
From: Genesi
Quote:
And Linux, which is older, does require cache coherency? Or is it the way current Linux drivers are coded?
It doesn't require it but it uses some fairly freakish techniques to manage it. Remember a lot of SoCs share IP cores between themselves so drivers that work on one chip also work with slight modifications on another. Adapting an existing solution to work without cache coherency messes up perfectly good drivers even in the best case, littering little snippets of cache management code where relevant.
At worst case the drivers don't perform well, and they have to be reworked so as to stress caches less, or manage data more effectively.
Or they need
whole new API entries to deal with it.
The way Linux manages non-coherency of peripherals is to map out a section of memory to do DMA to (which is mapped not coherent so the CPU does not attempt to load it into the cache). The important thing to remember is that you can't really turn off the internal CPU cache, as small as it may be on the MPC5121e at 32 kilobytes, it would absolutely destroy CPU performance. And running code requires the instruction cache. So as long as the CPU is just running code and it is acting on data, the system is in fact cache coherent. You just can't interact with a peripheral in that coherent memory.
So, it marks this block of memory, say 32MB at some high location, to use as a bounce buffer. This way, you can do DMA in and out of this 32MB by allocating memory out of it, doing your transfer (which will not be stomped on by a cache flush), and then when you need the data, copying it out to another place which is accessed only by the CPU, so you get the benefit of the instruction and data caches.
You can also do DMA to other parts of memory by specifically flushing caches at certain points but this is more complicated by far especially with things like kernel preemption. It *is* a lot faster though.
Both techniques mean you can't run the same kernel on these two different chips - support for coherent or non-coherent systems is a compile time option. This sort of defeats the object of a lot of things and means basically no Linux distribution on the planet would touch the chip without significant investment or interest, as they would have to duplicate yet another kernel tree, maintain another set of configs, and ship new installers.
In the end the amount of work to get it done is really not worth the hassle when you can pick a chip with a working coherency model and have the magic work behind the scenes and use everything you already used.
Matt Sealey, Genesi USA, Inc.
Developer Relations
Product Development Analyst