[lowrisc-dev] Re: [sw-dev] Is a de facto standard memory map helpful or harmful?

Arnd Bergmann arnd at arndb.de
Wed Jul 13 15:55:16 BST 2016


On Wednesday, July 13, 2016 3:03:59 PM CEST Alex Bradbury wrote:
> On 13 July 2016 at 14:38, Arnd Bergmann <arnd at arndb.de> wrote:
> > The main problem for operating systems is to have the kernel run at
> > a nonconstant physical address. On ARM Linux, we work around this by
> > patching every call to phys_to_virt() and virt_to_phys() at early
> > boot time as soon as we have detected the start of RAM.
> >
> > This works fine for the most part, but there are a couple of downsides:
> >
> > (snip)
> 
> Thanks for sharing your experience here Arnd - I'm glad someone with
> considerable kernel experience has chimed in. Would having a CSR
> (RISC-V control register) that contains the base physical address be
> an effective solution to avoid the need for function patching?

The patching is done purely for performance reasons, the implementation
of virt_to_phys() is expected to be a single instruction adding an
immediate value on ARM rather than loading a global 32-bit variable and
adding that.

This means using a CSR only helps if that makes it substantially faster
than reading from cached memory.

I'm actually not convinced that there is much need for the patching
to start with, the most common operations that need the translation
(page table updates, DMA setup, task switching, ...) are not in the
extreme hot path, and it may have been done just to ensure that there
could not be a performance regression at the point when we started
allowing a single kernel binary to run on variable RAM addresses.

Then again, all other architectures seem to use a constant value,
so maybe the runtime overhead is bigger than I think.

	Arnd



More information about the lowrisc-dev mailing list