Workqueue attempt, but fails to insmod, already loaded??

This commit is contained in:
Ciro Santilli
2017-05-14 09:34:27 +01:00
parent 8d20f8ce30
commit 67f669487e
3 changed files with 38 additions and 1 deletions

View File

@@ -38,3 +38,4 @@ See also: <https://superuser.com/questions/351387/how-to-stop-kernel-messages-fr
1. [hello2](kernel_module/hello2.c)
1. [debugfs](kernel_module/debugfs.c)
1. [fops](kernel_module/fops.c)
1. [workqueue](kernel_module/workqueue.c)

View File

@@ -1,4 +1,4 @@
obj-m += debugfs.o fops.o hello.o hello2.o
obj-m += $(addsuffix .o, $(notdir $(basename $(wildcard $(BR2_EXTERNAL_KERNEL_MODULE_PATH)/*.c))))
ccflags-y := -Wno-declaration-after-statement -std=gnu99
.PHONY: all clean

View File

@@ -0,0 +1,36 @@
/*
Usage:
insmod /workqueue.ko
# dmesg => worker
rmmod workqueue
Creates a separate thread. So init_module can return, but some work will still get done.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/workqueue.h>
MODULE_LICENSE("GPL");
static struct workqueue_struct *queue;
static void worker_func(struct work_struct *work)
{
printk(KERN_INFO "worker\n");
}
int init_module(void)
{
DECLARE_WORK(work, worker_func);
queue = create_singlethread_workqueue("myworkqueue");
queue_work(queue, &work);
return 0;
}
void cleanup_module(void)
{
destroy_workqueue(queue);
}