i'm working on an accademic project and i have to understand the usage of linux's workqueue. For this reason i've developed a small module that simply schedule the execution of a work on a custom workqueue after 1000 jiffies. However, when the timeout expires, the system is blocked, i need to restart the VM and i can't collect any info for debug.
These are the portions of the code i'm using:
static void enqueue_message(struct work_struct *work){
printk("%s: Step 2\n", MODULE_NAME);
return;
}
int init_module(void){
struct workqueue_struct *workqueue;
struct delayed_work deferred_write;
workqueue = alloc_workqueue("pending_writes",WQ_MEM_RECLAIM, 0);
INIT_DELAYED_WORK(&deferred_write, enqueue_message);
queue_delayed_work(workqueue, &deferred_write, 1000);
printk("%s: Step 1\n", MODULE_NAME);
return 0;
}
If i quickly (before timer expiration) ask for 'dmesg' on shell, i can read 'the Step 1' print but then i can't use the system. I know probably there is a beginner bug in the code but i can't individuate it. Thanks everybody for the help.
Like many other functions in the Linux kernel,
queue_delayed_work
expects its argument to exist until the work will be triggered.However, you pass the function a local variable (
deferred_write
) - which has been destroyed wheninit_module
function returns.Use global variable instead.