Skip to main content

Module tlb

Module tlb 

Source
Expand description

TLB (Translation Lookaside Buffer) shootdown for SMP.

When a page table entry is modified on one CPU, all other CPUs that might have cached that entry in their TLB must be notified to invalidate it.

This implementation uses a per-CPU mailbox system inspired by Asterinas :

  1. Each CPU has its own queue of pending TLB operations.
  2. The initiator pushes an operation into each target’s queue.
  3. The initiator sends a TLB shootdown IPI to all targets.
  4. The targets process their own queue and set an ACK flag.
  5. The initiator waits for all ACK flags to become true.

This avoids global lock contention and race conditions on global counters.

StructsΒ§

TlbOp πŸ”’
A single TLB operation.
TlbQueue πŸ”’
Per-CPU queue of pending TLB operations.

EnumsΒ§

TlbShootdownKind πŸ”’
Type of TLB shootdown operation.

ConstantsΒ§

TLB_RANGE_THRESHOLD_PAGES
Page-count threshold above which a ranged shootdown falls back to a full CR3 reload (shootdown_all) rather than issuing one invlpg per page.

StaticsΒ§

TLB_ACKS πŸ”’
Global array of per-CPU acknowledgement flags.
TLB_QUEUES πŸ”’
Global array of per-CPU TLB queues.

FunctionsΒ§

collect_tlb_targets πŸ”’
Collect target APIC IDs into a pre-allocated buffer.
current_cpu_index πŸ”’
Current CPU index.
dispatch_op πŸ”’
Internal helper to dispatch an operation to target CPUs.
flush_tlb_all πŸ”’ ⚠
Flush all TLB entries by reloading CR3 (local CPU only).
init
Initialize TLB shootdown system.
invlpg πŸ”’ ⚠
Invalidate a single TLB entry (local CPU only).
local_page
Invalidate a single page on the current CPU only.
local_range
Invalidate a range on the current CPU only.
send_tlb_ipi πŸ”’
Send TLB IPI.
shootdown_all
Flush all TLB entries on all CPUs.
shootdown_page
Invalidate a single page on all CPUs.
shootdown_range
Invalidate a range of pages on all CPUs.
tlb_shootdown_ipi_handler
IPI handler for TLB shootdown (called on receiving CPU).
wait_for_acks πŸ”’
Wait for ACKs from specific APIC IDs.