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;#endif}; 通...
struct work_struct{unsigned long pending;/* 这个工作正在等待处理吗?*/struct list_head entry;/* 连接所有工作的链表 */void(*func)(void*);/* 要执行的函数 */void*data;/* 传递给函数的参数 */void*wq_data;/* 内部使用 */struct timer_list timer;/* 延迟的工作队列所用到的定时器 */}; 这...
schedule_work(struct work_struct *work) schedule_work_on(int cpu, struct work_struct *work) 一个work可以被调度到系统的任意一个CPU,也可以被调度在指定的CPU,这就是以上两个API的区别。 取消一个work_struct cancel_work(struct work_struct *work); cancel_work_sync(struct work_struct *work); 取...
TP中断的处理,一般有种固定模式,两种实现方法,采用work_struct和work_struct workqueue_struct混合都可以处理。 (1)work_struct 定义报点函数 static struct work_struct msg21xx_wq; 1. static int touch_event_handler(void *unused) 1. probe中初始化 INIT_WORK( &msg21xx_wq, touch_event_handler ); 注...
schedule_work_on(int cpu, struct work_struct *work) 一个work可以被调度到系统的任意一个CPU,也可以被调度在指定的CPU,这就是以上两个API的区别。 取消一个work_struct cancel_work(struct work_struct *work); cancel_work_sync(struct work_struct *work); ...
使用work queue时,步骤如下: 1)构造一个work_struct实例,设置处理函数。 2)把work_struct放入工作队列,内核线程会运行work中的函数(func)。 使用work queue 创建work 静态创建 宏DECLARE_WORK用来定义一个work_struct结构体,需要指定它的处理函数。 宏DECLARE_DELAYED_WORK用来定义一个delayed_work结构体,也需要指定...
struct work_struct n=__WORK_INITIALIZER(n,f) 举例如下: staticvoiddo_poweroff(struct work_struct*dummy){kernel_power_off();}staticDECLARE_WORK(poweroff_work,do_poweroff); 即创建了一个全局静态变量:static work_struct poweroff_work,且被初始化了,其执行函数为do_poweroff。
static struct work_struct test_work; 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) ...
struct work_struct{atomic_long_t data;//低比特存放状态位,高比特存放worker_pool的ID或者pool_workqueue的指针struct list_head entry;//用于添加到其他队列上work_func_t func;//工作任务的处理函数,在内核线程中回调#ifdefCONFIG_LOCKDEPstruct lockdep_map lockdep_map;#endif}; ...
编写Linux驱动的时候对于work_struct的使用还是很普遍的,很早之前就在阅读驱动源码的时候就看到了它的踪影,根据其命名大概知道了它的具体作用,但是仍然不知所以,同时,伴随出现的还有delayed_work以及workqueue_struct,抱着知其然并知其所以然的态度,在这里归纳总结一下work_struct,以及如何在驱动中使用,因为工作队列相对...