ARM11 Translation Lookaside Buffer (TLB) usage?
Asked Answered
C

1

8

Is there a decent guide explaining how to use the TLB (Translation Lookaside Buffers) tables on an ARM1176JZF-S core?

Having looked over the technical documentation for the that ARM platform I still have no clue what a TLB is or what it looks like. As far as I understand, each TLB entry maps a virtual page to a physical page, allowing remapping and controlling memory permissions.

Apart from that, I have absolutely no clue on how to use them.

  • What structure does a TLB entry have? How do I create new entries?
  • How do I handle VM in context switches for user-space threads? How do I ensure that those threads can only access specific pages assigned to their parent processes (enforce memory protection)? Do I save the TLB state for each context?
  • Why are there two TLBs? What can I use the MicroTLB for if it can only have 10 entries? Surely, I need more than 10.
  • It says that one of the parts of the main TLB is "a fully-associative array of eight elements, that is lockable". What is that? Do I only get to have 8 entries for the Main TLB?

Thank you in advance. I'll be really glad if someone provides an explanation of what TLBs are. I'm currently working on a memory mapper for my kernel, and I've pretty much hit a dead end.

Colquitt answered 24/1, 2012 at 18:49 Comment(3)
Are you writing your own OS? If you're using an existing OS they will take care of these details for you. You may need to set up 1-2 TLB's by hand during boot but after that the OS kernel will take care of it.Bobbe
@Bobbe I'm porting an existing kernel (Darwin) to the ARM platform. The kernel relies on a set of HAL functions that abstract all the interactions with the platform (physical memory management, context switches, caches, exceptions etc.)Colquitt
A simple answer is the TLB is to an MMU page table as a cache is to memory; Ie. the TLB is an MMU cache. micro-TLB -> L1 cache, etc. Interestingly, the VIVT/PIPT etc behaviour of the cache will probably affect the operation of the TLB as described by ninjalj.Kirsti
A
17

The technical reference manual for ARM1176JZF-S appears to be DDI 0301. That document contains all the specific details for that specific ARM core.

I still have no clue what a TLB is or what it looks like. As far as I understand, each TLB entry maps a virtual page to a physical page, allowing remapping and controlling memory permissions.

A TLB is a cache of the page table. Some processors allow direct access to the TLB, while knowing nothing about page tables (e.g: MIPS), while others know about page tables, and internally use TLBs that the programmer mostly doesn't see (e.g: x86). In this case, the TLB is managed by hardware, and the system programmer only has to care to make the TTB (Translation Table Base) registers point to the page table, and invalidate the TLB in apropriate places.

What structure does a TLB entry have? How do I create new entries?

Done by hardware. On a TLB miss, the MMU walks the page table and fills the TLB from there.

How do I handle VM in context switches for user-space threads?

Some platforms have TLBs that simply map virtual addresses to physical addresses (e.g: x86). On these platforms, you have to do a full TLB flush on each context switch. Other platforms (MIPS, this specific ARM core) map (ASID, virtual address) pairs to physical addresses. An ASID is an Application-Specific Identifier, i.e: an identifier for a process. The MMU uses a register to know which ASID to use (I think it's the Context ID register in this case). Since there may be more processes than ASIDs, occasionally you may need to recycle an ASID (assigning it to a different process) and do a TLB flush (that's what the Invalidate TLB by ASID operation is for).

Why are there two TLBs? What can I use the MicroTLB for if it can only have 10 entries? Surely, I need more than 10.

This is exactly for the same reason you have small separate level-1 caches for instructions and data. Since they are caches, you don't need more than 10 (though having more could improve performance).

It says that one of the parts of the main TLB is "a fully-associative array of eight elements, that is lockable". What is that? Do I only get to have 8 entries for the Main TLB?

Some memory pages (e.g: some portions of the kernel) are accessed very often. It makes sense to lock them, so they don't get thrown off of the TLB. Also, on realtime systems, a TLB miss or a cache miss may introduce some unwanted unpredictability. So, there is an option to lock a number of TLB entries. The main TLB has more entries, but only those 8 are lockable.

Auricula answered 24/1, 2012 at 20:42 Comment(1)
Thanks for details what ARM <strike>ACID</strike> ASID is. Seems like like older domains and PID.Kirsti

© 2022 - 2024 — McMap. All rights reserved.