delay attempt

This commit is contained in:
Ciro Santilli
2017-05-14 14:36:52 +01:00
parent 045ec40780
commit c82378c7de
3 changed files with 52 additions and 5 deletions

View File

@@ -17,9 +17,7 @@ QEMU opens up, and you can run:
Each module comes from a C file under `kernel_module/`. For module usage do:
head *.c
We use Buildroot's default kernel version, you can confirm it after build with:
head *. use Buildroot's default kernel version, you can confirm it after build with:
grep BR2_LINUX_KERNEL_VERSION buildroot/.config
@@ -46,3 +44,4 @@ When your kernel starts crashing, get the full trace with:
1. [fops](kernel_module/fops.c)
1. [workqueue](kernel_module/workqueue.c)
1. [panic](kernel_module/panic.c)
1. [delay](kernel_module/delay.c)

48
kernel_module/delay.c Normal file
View File

@@ -0,0 +1,48 @@
/*
Usage:
insmod /delay.ko
rmmod delay
dmesg prints an integer every second until rmmod.
Since insmod returns, this Illustrates how the work queues are asynchronous.
TODO: insmod not returning...
*/
#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/workqueue.h>
MODULE_LICENSE("GPL");
static struct workqueue_struct *queue;
static void work_func(struct work_struct *work)
{
int i = 0;
while (1) {
printk(KERN_INFO "%d\n", i);
usleep_range(1000000, 1000001);
i++;
if (i == 10)
i = 0;
}
}
DECLARE_WORK(work, work_func);
int init_module(void)
{
queue = create_workqueue("myworkqueue");
queue_work(queue, &work);
return 0;
}
void cleanup_module(void)
{
cancel_work_sync(&work);
destroy_workqueue(queue);
}

View File

@@ -1,9 +1,9 @@
/*
Usage:
insmod /workqueue.ko
insmod /workqueue_cheat.ko
# dmesg => worker
rmmod workqueue
rmmod workqueue_cheat
Creates a separate thread. So init_module can return, but some work will still get done.