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 :
- Each CPU has its own queue of pending TLB operations.
- The initiator pushes an operation into each targetβs queue.
- The initiator sends a TLB shootdown IPI to all targets.
- The targets process their own queue and set an ACK flag.
- The initiator waits for all ACK flags to become true.
This avoids global lock contention and race conditions on global counters.
StructsΒ§
EnumsΒ§
- TlbShootdown
Kind π - 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 oneinvlpgper 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.