interview prepare
Contents
links: https://github.com/torvalds/linux/commits/master?author=liuhangbin@gmail.com https://github.com/kernelslacker/trinity/commits/master?author=liuhangbin@gmail.com https://github.com/borkmann/lksctp-tools/commits/master?author=liuhangbin@gmail.com
pci_register_driver(&e100_driver) alloc_etherdev() // alloc dev memory register_netdev()
receive message:
- netif_rx_schedule -> napi_schedule -> netif_recive_skb
Send messag:
- dev_queue_xmit -> qdisc_run -> hard_start_xmit
- hard_start_xmit()
Diff NAPI/Net Poll
- NAPI: stop interrupt and start poll mode, increase performance for device which will receive huge of packages per seconds.
- Netpoll: let kernel send package with unintact network, e.g. netconsole
Locks
- spin lock: used for multi processors, and can only be hold by one kernel task, incase multi processor visit critical Section. should only be uses with little time. Not allowed sleep, can be used in interrupt context
- mutex: sleep lock, can only be used in Process Context, could not be used in interrupt context.
- RCU(Read-Copy Update): read much and write little, like route query
- rwlock
memory management:
- First 1M physical memory store BIOS info, linux start from 1M
- Segmentation
- Page: 4K/per page
- X86_64: 0-3G user space, 3-4G kernel space
- kernel space: 0-896M, lower memory, > 896M, High memory
- the last 128K for page mapping
malloc:
- malloc: for user space
- kmalloc: for kernel, but with consecutive memory, fast
- vmalloc: for kernel, but may not onsecutive, slow
block, char device
- char device only be called like stream.
- block device can be read from anyware.
show driver print info, module info, and interrupt info
- dmesg, lsmod, cat /proc/interrupt
copy_to_user/copy_from_user:
- check whether user space pointer is valid
- incase of do_page_fault
register char device
- cdev_init
- register_chrdev()
- mknod to create a device under /dev
DMA, interrupt
- DMA: no need cpu, copy date from kernel to device directly
- interrupt: need cpu, when have IRQ, cpu stop current job and deal with IRQ
Author Hangbin Liu
LastMod 2018-12-13 (1672b97)