Click here to load reader
Upload
anne-nicolas
View
1.082
Download
1
Embed Size (px)
Citation preview
Porting Linux to a new processor architectureKernel Recipes 2015
Joël Porquet
September 30th, 2015
Background
Research engineer at LIP6 from 2013 to 2015
TSAREU-funded projectMassively parallel architectureShared and hardware-maintained coherent memory
cluster(n,n)
cluster(0,0)
MIPS32
L1 cache+ MMU
MemoryCache
MIPS32
L1 cache+ MMU
MIPS32
L1 cache+ MMU
MIPS32
L1 cache+ MMU
Local Crossbar
ExternalRAM
INT/timercontroller
DMAcontroller
Joël Porquet Kernel Recipes 2015 September 30th, 2015 2 / 14
Is a new port necessary?*
New board with already-supported processorNew processor within an existing, already supported processor familyNew processor architecture
$ mkdir arch/tsar
*https://lwn.net/Articles/597351/Joël Porquet Kernel Recipes 2015 September 30th, 2015 3 / 14
How to start?
Two-step process1 Minimal set of files that define a minimal set of symbols2 Gradual implementation of the boot functions
$ ls -l arch/tsar/configs/
tsar_defconfiginclude/
asm/uapi/asm/
kernel/vmlinux.lds.S
lib/mm/KconfigMakefile
Joël Porquet Kernel Recipes 2015 September 30th, 2015 4 / 14
The boot sequence
kernel_entry*start_kernel
setup_arch*trap_init*mm_init
mem_init*init_IRQ*time_init*rest_init
kernel_thread(kernel_init)kernel_thread(kthreadd)cpu_startup_entry
Joël Porquet Kernel Recipes 2015 September 30th, 2015 5 / 14
Early assembly boot code
kernel_entry()resets the processor to a default stateclears the bss segmentsaves the bootloader argument(s) (e.g. device tree)initializes the first page table
maps the kernel image
enables the virtual memory and jumps into the virtual address spacesets up the stack register (and optionally the current thread info register)jumps to start_kernel()
Joël Porquet Kernel Recipes 2015 September 30th, 2015 6 / 14
setup_arch()
Scans the flattened device tree, discovers the physical memory banks andregisters them into the memblock layerParses the early arguments (e.g. early_printk)Configures memblock and maps the low memoryMemory zones (ZONE_DMA, ZONE_NORMAL, ZONE_HIGHMEM)
PhysicalMemory
VirtualMemory
user space kernel space
DirectMapping vmalloc
0GiB 3GiB 4GiB
lowmem highmem
pkmap
Joël Porquet Kernel Recipes 2015 September 30th, 2015 7 / 14
trap_init()
Exception vectorThe exception vector acts as a dispatcher:
mfc0 k1, CP0_CAUSEandi k1, k1, 0x7clw k0, exception_handlers(k1)jr k0
Configures the processor to use this exception vectorInitializes exception_handlers with the sub-handlers (handle_int,handle_bp, etc.)
Joël Porquet Kernel Recipes 2015 September 30th, 2015 8 / 14
Trap infrastructure
ENTRY(handle_int)SAVE_ALLCLImove a0, spla ra, ret_from_intrj do_IRQ
ENDPROC(handle_int)
ENTRY(handle_bp)SAVE_ALLSTImove a0, spla ra, ret_from_exceptionj do_bp
ENDPROC(handle_bp)
/* CLI: switch to pure kernel mode and disable interruptions *//* STI: switch to pure kernel mode and enable interruptions */
do_* are C functions:
void do_bp(struct pt_regs *regs){
die_if_kernel("do_bp in kernel",regs);
force_sig(SIGTRAP, current);}
Joël Porquet Kernel Recipes 2015 September 30th, 2015 9 / 14
mem_init()
Releases the free memory from memblock to the buddy allocator (aka thepage allocator)
Memory: 257916k/262144k available (1412k kernel code, 4228k reserved,267k data, 84k bss, 169k init, 0k highmem)Virtual kernel memory layout:
vmalloc : 0xd0800000 - 0xfffff000 ( 759 MB)lowmem : 0xc0000000 - 0xd0000000 ( 256 MB)
.init : 0xc01a5000 - 0xc01ba000 ( 84 kB)
.data : 0xc01621f8 - 0xc01a4fe0 ( 267 kB)
.text : 0xc00010c0 - 0xc01621f8 (1412 kB)
Joël Porquet Kernel Recipes 2015 September 30th, 2015 10 / 14
init_IRQ()
Scans device tree and finds all the nodes identified as interrupt controllers.icu: xicu {
compatible = "soclib,vci_xicu";interrupt-controller;#interrupt-cells = <1>;reg = <0x0 0xf0000000 0x1000>;
};
→ First device driver!
Joël Porquet Kernel Recipes 2015 September 30th, 2015 11 / 14
time_init()
Parses clock provider nodesclocks {
freq: frequency@25MHz {#clock-cells = <0>;compatible = "fixed-clock";clock-frequency = <25000000>;
};};
Parses clocksource nodesClock-source device (monotonic counter)Clock-event device (counts periods of time and raises interrupts)
→ Second device driver!
Joël Porquet Kernel Recipes 2015 September 30th, 2015 12 / 14
To init
Process managementSetting up the stack for new threadsSwitching between threads (switch_to())
Page fault handlerCatching memory faults
System callsList of system callsEnhancement of the interrupt and exception handler
Signal managementExecution of the signal handlers
User-space memory accessSetting up the exception table
Joël Porquet Kernel Recipes 2015 September 30th, 2015 13 / 14
Conclusion
After the initial portPush it upstream if possibleKeep it up-to-dateEnhance it: SMP, NUMA, drivers, etc.
Bedtime readingSeries of articles on LWN.net
The basics: https://lwn.net/Articles/654783/The early code: https://lwn.net/Articles/656286/To the finish line: https://lwn.net/Articles/657939/
Joël Porquet Kernel Recipes 2015 September 30th, 2015 14 / 14