目录
container_of()
用于获取某指针所属的结构体。
Linked Lists
Linked List是基于双向链表的。后续内容基于下列数据结构。
创建和初始化Linked List
仅介绍动态方法。
创建一个list节点
添加
stack式Linked List
Queue式Linked List
删除一个list节点
遍历Linked List
acar充当遍历时的迭代器,carlist为指向Linked List的头节点,list为struct car结构体内list_head结构体类型的成员名(与该API内调用了container_of()宏有关)。
Kernel Sleeping Mechanism
static DECLARE_WAIT_QUEUE_HEAD(my_wq); //静态声明了一个wait_queue
INIT_WORK(&wrk, work_handler); //为work_struct注册一个回调函数
schedule_work(&wrk); //开始调度该work_struct,执行work_handeler
//阻塞等待my_wq,直到my_wq内一进程已调用wake_up_interruptible()和condition != 0(同时满足)
wait_event_interruptible(my_wq, condition != 0);
Delay and timer management
High resolution timers(HRTs)
Delays and sleep in the kernel
Atomic context
Nonatomic context
Kernel locking mechanism
Mutex
Spinlock
Spinlock VS mutextes
Work deferring mechannism
Tasklets
例子代码更正:
DECLARE_TASKLET(my_tasklet, tasklet_work, (unsigned long)tasklet_data);
static void __exit my_exit(void)
{
//***
}
Work queues
Kernel-global workqueue - the shared queue
Dedicated work queue
Predefined workqueue
Kernel interruption mechanism
Registering an interrupt handler
Interrupt handler and lock
总结:若要处理共享数据,用户空间的代码使用spin_lock_irqsave(),中断处理函数使用spin_lock()即可。若共享数据被多个不同中断处理函数使用,使用spin_lock_irqsave()
Threaded IRQs
Invoking user-space application from the kernel