The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
tlb.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file tlb.h
5 * @brief TLB shootdown: a change to the page tables reaches the TLB of
6 * every core that can hold the old entry.
7 *
8 * the paging functions flush the TLB of the core that makes the change.
9 * the other cores can still hold the old entry: those that have the user
10 * space loaded (its cpu_mask), or every core for the kernel half. the
11 * caller of a shootdown sends those cores an IPI and waits until each has
12 * flushed. only then may it free the frames that the old entries pointed
13 * to. one request is out at a time, as in Linux's old i386 flush_tlb_others.
14 *
15 * a core that spins on a spinlock with interrupts off does a pending flush
16 * while it waits (tlb_poll), so a caller that holds a lock while it waits
17 * for the other cores cannot deadlock with a core that waits for that lock.
18 */
19
20#include "common/stdint.h"
21#include "kernel/cpu/cpu.h"
22
23struct user_space;
24
25/**
26 * set up the shootdown. call once on the boot core, before the other cores
27 * start.
28 */
29void tlb_init(void);
30
31/**
32 * flush [start, end) of a user space on the other cores that have it
33 * loaded, and wait until they have flushed. call it after the change to
34 * the page tables and before the frames are freed. any context; interrupts
35 * can be on or off.
36 * @param space the user space whose page tables changed.
37 * @param start the first address, page-aligned.
38 * @param end the address after the range.
39 */
40void tlb_shootdown_user(struct user_space *space, uintptr_t start, uintptr_t end);
41
42/**
43 * flush [start, end) of the kernel half on all the other cores, and wait
44 * until they have flushed. as tlb_shootdown_user().
45 * @param start the first address, page-aligned.
46 * @param end the address after the range.
47 */
49
50/**
51 * do the flush that another core asks of this core, if there is one. the
52 * IPI handler calls it. call it with interrupts off.
53 */
54void tlb_do_pending(void);
55
56/**
57 * tlb_do_pending(), but only one load when nothing is asked. for wait loops
58 * that run with interrupts off (spin_lock).
59 */
60static inline void tlb_poll(void)
61{
62 if (cpu_ready && cpu_current()->tlb_flush_pending)
63 {
65 }
66}
bool cpu_ready
true once cpu_init_boot() has run, so cpu_current() is valid
Definition cpu.c:15
the data of each core (per-CPU data).
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:19
the user half of an address space: the page tables, the areas (vma.h) and the program break.
Definition user_space.h:16
void tlb_init(void)
set up the shootdown.
Definition tlb.c:24
void tlb_shootdown_kernel(uintptr_t start, uintptr_t end)
flush [start, end) of the kernel half on all the other cores, and wait until they have flushed.
Definition tlb.c:93
void tlb_shootdown_user(user_space_t *space, uintptr_t start, uintptr_t end)
flush [start, end) of a user space on the other cores that have it loaded, and wait until they have f...
Definition tlb.c:85
void tlb_do_pending(void)
do the flush that another core asks of this core, if there is one.
Definition tlb.c:98