17_INIT_WORKLinux内核模块
环境
01_basicLinux内核模块_the kernel was built by-CSDN博客文章浏览阅读1k次,点赞3次,收藏3次。文章介绍了在Ubuntu22.04系统中,如何使用Makefile和C语言编写并编译一个简单的Linux内核模块,包括基本结构、初始化与退出函数,以及如何处理编译时的警告和加载模块到内核的过程。
https://blog.csdn.net/m0_37132481/article/details/136157384
效果
worker.c
# cat worker.c #include <linux/module.h> #include <linux/workqueue.h> #include <linux/delay.h>#define TAG "HELLO# "static struct work_struct adsp_ldr_work; static struct work_struct cdsp_ldr_work;static void adsp_load_fw(struct work_struct *adsp_ldr_work) {int i = 0;while(1){printk(TAG "%s called%d\n", __func__, i);msleep(1000);} }static void cdsp_load_fw(struct work_struct *adsp_ldr_work) {while(1){printk(TAG "%s called\n", __func__);msleep(1000);} }static int __init wq_init(void) {printk(TAG "wq_init\n");INIT_WORK(&adsp_ldr_work, adsp_load_fw);INIT_WORK(&cdsp_ldr_work, cdsp_load_fw);printk(TAG "start adsp\n");schedule_work(&adsp_ldr_work);printk(TAG "start cdsp\n");schedule_work(&cdsp_ldr_work);return 0; }static void __exit wq_exit(void) {printk(TAG "wq_exit\n"); }module_init(wq_init); module_exit(wq_exit);MODULE_LICENSE("GPL");