work_struct work_struct的数据结构如下,暂时我们还无法关注其原理,只关注如何去开启一个work #include<linux/include/workqueue.h>typedefvoid(*work_func_t)(structwork_struct *work);structwork_struct{atomic_long_tdata;structlist_headentry;work_func_tfunc;#ifdefCONFIG_LOCKDEPstructlockdep_maplockdep_map;#...
flush_workqueue(struct workqueue_struct *_wq) 四、工作队列demo(使用系统自带的工作队列) 以下驱动demo,特意使用了schedule_work_on的API,证明一个work是可以指定CPU运行的,通过写/dev/work_queue设备节点,触发调度work,在work回调里执行计算密集型任务,即可观察指定的CPU的使用率,最后卸载模块的时候,特意使用了带s...
flush_workqueue(struct workqueue_struct *_wq) 四、工作队列demo(使用系统自带的工作队列) 以下驱动demo,特意使用了schedule_work_on的API,证明一个work是可以指定CPU运行的,通过写/dev/work_queue设备节点,触发调度work,在work回调里执行计算密集型任务,即可观察指定的CPU的使用率,最后卸载模块的时候,特意使用了带s...
中断handler中通过调用到work_struct work结合queue_struct来调用报点函数 static void tpd_eint_handler(void) { queue_work(mtk_tpd_wq, &work); } 1. 2. 3. 4. 在模块exit函数中,注销workqueue_struct destroy_workqueue(mtk_tpd_wq); 1. ===定时处理delayed_work=== delayed_work是在work_struct的基...
struct work_struct用来描述work,初始化一个work并添加到工作队列后,将会将其传递到合适的内核线程来进行处理,它是用于调度的最小单位。 关键字段描述如下: struct work_struct { atomic_long_t data; //低比特存放状态位,高比特存放worker_pool的ID或者pool_workqueue的指针 ...
编写Linux驱动的时候对于work_struct的使用还是很普遍的,很早之前就在阅读驱动源码的时候就看到了它的踪影,根据其命名大概知道了它的具体作用,但是仍然不知所以,同时,伴随出现的还有delayed_work以及workqueue_struct,抱着知其然并知其所以然的态度,在这里归纳总结一下work_struct,以及如何在驱动中使用,因为工作队列相对...
工作队列(workqueue_struct) structworkqueue_struct {structlist_head pwqs;/*WR: all pwqs of this wq*/structlist_head list;/*PL: list of all workqueues*/structmutex mutex;/*protects this wq*/intwork_color;/*WQ: current work color*/intflush_color;/*WQ: current flush color*/atomic_t nr...
static struct delayed_work test_delayed_work; static void test_func(struct work_struct *work) { printk("%s, %d, %ld\n", __func__, __LINE__, jiffies); } static void test_delayed_func(struct work_struct *work) { printk("%s, %d, %ld\n", __func__, __LINE__, jiffies); ...
DECLARE_WORK(name,void(*func)(void*),void*data); 这样就会静态地创建一个名为name,待执行函数为func,参数为data的work_struct结构。 同样,也可以在运行时通过指针创建一个工作: 代码语言:javascript 代码运行次数:0 复制 Cloud Studio代码运行 INIT_WORK(struct work_struct*work,woid(*func)(void*),void*...
struct work_struct {atomic_long_t data;struct list_head entry;work_func_t func; // 指向处理函数#ifdef CONFIG_LOCKDEPstruct lockdep_map lockdep_map;#endif}; 1. 2. 3. 4. 5. 6. 7. 8. 在内核中,工作队列中的所有工作项,是通过链表串在一起的,并且等待着操作系统中的某个线程挨个取出来处理...