mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
Move poll, ktrhead and kthreads docs to README
This commit is contained in:
@@ -20,11 +20,8 @@
|
||||
... link:dep2.c[]
|
||||
. Pseudo filesystems
|
||||
.. link:mmap.c[]
|
||||
.. link:poll.c[]
|
||||
. Asynchronous
|
||||
.. link:irq.c[]
|
||||
.. link:kthread.c[]
|
||||
.. link:kthreads.c[]
|
||||
.. link:schedule.c[]
|
||||
.. link:sleep.c[]
|
||||
.. link:timer.c[]
|
||||
|
||||
@@ -1,13 +1,4 @@
|
||||
/*
|
||||
Kernel threads are managed exactly like userland threads.
|
||||
|
||||
They also have a backing task_struct, and are scheduled with the same mechanism.
|
||||
|
||||
See also:
|
||||
|
||||
- http://stackoverflow.com/questions/10177641/proper-way-of-handling-threads-in-kernel
|
||||
- http://stackoverflow.com/questions/4084708/how-to-wait-for-a-linux-kernel-thread-kthreadto-exit
|
||||
*/
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#kthread */
|
||||
|
||||
#include <linux/delay.h> /* usleep_range */
|
||||
#include <linux/kernel.h>
|
||||
@@ -18,9 +9,9 @@ static struct task_struct *kthread;
|
||||
|
||||
static int work_func(void *data)
|
||||
{
|
||||
int i = 0;
|
||||
u32 i = 0;
|
||||
while (!kthread_should_stop()) {
|
||||
pr_info("%d\n", i);
|
||||
pr_info("%u\n", i);
|
||||
usleep_range(1000000, 1000001);
|
||||
i++;
|
||||
if (i == 10)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
/*
|
||||
2 kthreads!!! Will they interleave??? Yup.
|
||||
*/
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#kthreads */
|
||||
|
||||
#include <linux/delay.h> /* usleep_range */
|
||||
#include <linux/kernel.h>
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
/*
|
||||
/poll.sh
|
||||
|
||||
Outcome: user echoes jiffies every second.
|
||||
|
||||
https://stackoverflow.com/questions/30035776/how-to-add-poll-function-to-the-kernel-module-code/44645336#44645336
|
||||
*/
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#poll */
|
||||
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/delay.h> /* usleep_range */
|
||||
@@ -40,11 +34,10 @@ static ssize_t read(struct file *filp, char __user *buf, size_t len, loff_t *off
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
If you return 0 here, then the kernel will sleep until an event happens in the queue.
|
||||
|
||||
This gets called again every time an event happens in the wait queue.
|
||||
*/
|
||||
/* If you return 0 here, then the kernel will sleep until an event happens in the queue.
|
||||
*
|
||||
* This gets called again every time an event happens in the wait queue.
|
||||
*/
|
||||
unsigned int poll(struct file *filp, struct poll_table_struct *wait)
|
||||
{
|
||||
poll_wait(filp, &waitqueue, wait);
|
||||
|
||||
Reference in New Issue
Block a user