Periodic Tasklet
# |
Version |
---|---|
Ubuntu |
Ubuntu 22.10 |
Kernel |
6.8.0 |
In this program, you are going to learn
How to create tasklet ?
What are the different ways to create tasklet ?
How to schedule the tasklet periodically ?
How to schedule high priority tasklet periodically ?
How to kill the tasklet ?
How to use tasklet APIs ?
How to use below APIs ?
Here is the function prototype of the API: tasklet_init
#include <linux/interrupt.h>
extern void tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long), unsigned long data);
Here is an example of how to use the API,
tasklet_init(my_tasklet, tasklet_handler, 10);
Here is the function prototype of the API: tasklet_schedule
#include <linux/interrupt.h>
static inline void tasklet_schedule(struct tasklet_struct *t);
Here is an example of how to use the API,
tasklet_schedule(my_tasklet);
Here is the function prototype of the API: tasklet_hi_schedule
#include <linux/interrupt.h>
static inline void tasklet_hi_schedule(struct tasklet_struct *t);
Here is an example of how to use the API,
tasklet_hi_schedule(my_tasklet2);
Here is the function prototype of the API: tasklet_kill
#include <linux/interrupt.h>
extern void tasklet_kill(struct tasklet_struct *t);
Here is an example of how to use the API,
tasklet_kill(my_tasklet);
Here is the prototype of module paramter APIs
#include <linux/module.h>
#define MODULE_LICENSE(_license) MODULE_FILE MODULE_INFO(license, _license)
#define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
where
MODULE_LICENSE: tells the kernel what license is used by our module.
MODULE_AUTHOR: denotes the author of this kernel module.
MODULE_DESCRIPTION: gives a basic idea about what the kernel module does.
These information can be found when modinfo command is used which lists out all these above mentioned information.
Here is the example of how to use the Module parameter APIs,
MODULE_LICENSE("GPL");
MODULE_AUTHOR("usr");
MODULE_DESCRIPTION("Tasklet");
Here is the prototype of the Driver entry point API’s
#include <linux/module.h>
#define module_init(x) __initcall(x);
#define module_exit(x) __exitcall(x);
where
module_init: driver initialization entry point which will be called at module insertion time.
module_exit: driver exit entry point which will be called during the removal of module.
- x:
function to be run at module insertion for module_init function.
function to be run when driver is removed for module_exit function.
Here is an example of how to use the driver entry point API’s
module_init(task_init);
module_exit(task_exit);
In this example let’s see how to schedule the tasklet and execute it.
Include the follow header files(.h) to refer the API being used for the execution.
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
Add the following module macros to display information about the license, author and description about the module.
MODULE_LICENSE("GPL");
MODULE_AUTHOR("usr");
MODULE_DESCRIPTION("Tasklet");
Initialize the tasklet which we are going to create and use in this example
tasklet_init(my_tasklet, tasklet_handler, 10);
This function executes once the tasklet is scheduled using tasklet_schedule.
void tasklet_handler(unsigned long data)
{
pr_info("Executing tasklet handler function with data : %ld\n", data);
tasklet_schedule(my_tasklet);
}
This function schedules a tasklet.
void tasklet_start(void)
{
my_tasklet = kmalloc(sizeof(struct tasklet_struct), GFP_KERNEL);
if (my_tasklet == NULL)
pr_info("Cannot allocate memory\n");
tasklet_init(my_tasklet, tasklet_handler, 10);
pr_info("Scheduling the tasklet\n");
tasklet_schedule(my_tasklet);
}
This function calls tasklet_start function, will be executed once the module is loaded into the linux kernel.
static int __init task_init(void)
{
pr_info("driver loaded\n");
tasklet_start();
return 0;
}
This function kills tasklet and stops it’s execution.
void tasklet_stop(void)
{
tasklet_kill(my_tasklet);
if (my_tasklet != NULL)
kfree(my_tasklet);
}
This function calls tasklet_stop function, will be executed once the module is removed from the linux kernel
static void __exit task_exit(void)
{
tasklet_stop();
pr_info("driver unloaded!\n");
}
Add the driver entry points which will be executed once the module is inserted or removed from the kernel.
module_init(task_init);
module_exit(task_exit);
1/* Creating a tasklet : Periodic Tasklet : tasklet_schedule */
2
3#include <linux/init.h>
4#include <linux/kernel.h>
5#include <linux/module.h>
6#include <linux/fs.h>
7#include <linux/interrupt.h>
8
9MODULE_LICENSE("GPL");
10MODULE_AUTHOR("usr");
11MODULE_DESCRIPTION("Tasklet");
12
13struct tasklet_struct *my_tasklet;
14void tasklet_handler(unsigned long data);
15void tasklet_start(void);
16void tasklet_stop(void);
17
18/* tasklet_handler - it executes once the tasklet is scheduled using tasklet_schedule
19 * will stop it's execution once the tasklet_stop() is called
20 */
21void tasklet_handler(unsigned long data)
22{
23 pr_info("Executing tasklet handler function with data : %ld\n", data);
24 tasklet_schedule(my_tasklet);
25}
26
27/* tasklet_start - initializes the tasklet dynamically using tasklet_init
28 * schedules a tasklet using tasklet_schedule
29 */
30void tasklet_start(void)
31{
32 my_tasklet = kmalloc(sizeof(struct tasklet_struct), GFP_KERNEL);
33 if (my_tasklet == NULL)
34 pr_info("Cannot allocate memory\n");
35 tasklet_init(my_tasklet, tasklet_handler, 10);
36 pr_info("Scheduling the tasklet\n");
37 tasklet_schedule(my_tasklet);
38}
39
40/* task_init - calls tasklet_start function,
41 * will be executed once the module is loaded into the linux kernel
42 */
43static int __init task_init(void)
44{
45 pr_info("driver loaded\n");
46 tasklet_start();
47 return 0;
48}
49
50/* tasklet_stop - kills tasklet and stops it's execution */
51void tasklet_stop(void)
52{
53 tasklet_kill(my_tasklet);
54 if (my_tasklet != NULL)
55 kfree(my_tasklet);
56}
57
58/* task_exit - calls tasklet_stop function,
59 * will be executed once the module is removed from the linux kernel
60 */
61static void __exit task_exit(void)
62{
63 tasklet_stop();
64 pr_info("driver unloaded!\n");
65}
66
67module_init(task_init);
68module_exit(task_exit);
1obj-m += tasklet.o
2
3all:
4 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
5 sudo ../../checkpatch.pl --no-tree -f tasklet.c
6
7clean:
8 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Run make to compile the kernel source and generate the .ko image.
$ make
make -C /lib/modules/6.8.0/build M=/home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc1 modules
make[1]: Entering directory '/home/arun/Desktop/kernel_api/linux-6.8'
CC [M] /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc1/tasklet.o
MODPOST /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc1/Module.symvers
CC [M] /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc1/tasklet.mod.o
LD [M] /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc1/tasklet.ko
make[1]: Leaving directory '/home/arun/Desktop/kernel_api/linux-6.8'
Check if the .ko is generated or not using ls command.
$ ls -l
total 384
-rw-rw-r-- 1 arun arun 206 Jun 24 18:26 Makefile
-rw-rw-r-- 1 arun arun 69 Jul 11 18:10 modules.order
-rw-rw-r-- 1 arun arun 0 Jul 11 18:10 Module.symvers
-rw-rw-r-- 1 arun arun 1730 Jun 24 19:09 tasklet.c
-rw-rw-r-- 1 arun arun 181472 Jul 11 18:10 tasklet.ko
-rw-rw-r-- 1 arun arun 69 Jul 11 18:10 tasklet.mod
-rw-rw-r-- 1 arun arun 1166 Jul 11 18:10 tasklet.mod.c
-rw-rw-r-- 1 arun arun 149416 Jul 11 18:10 tasklet.mod.o
-rw-rw-r-- 1 arun arun 33472 Jul 11 18:10 tasklet.o
Run modinfo command to get the information about the kernel module.
$ modinfo tasklet.ko
filename: /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc1/tasklet.ko
description: Tasklet
author: usr
license: GPL
srcversion: 7AE1624A61A2F412B6F3758
depends:
retpoline: Y
name: tasklet
vermagic: 6.8.0 SMP preempt mod_unload modversions
insert the module using insmod command.
$ sudo insmod ./tasklet.ko
check if the module is loaded or not using lsmod command.
$ lsmod | grep tasklet
tasklet 12288 0
check for the kernel messages from init function and thread function once the module is loaded and thread is created.
$ sudo dmesg
[541865.377689] driver loaded
[541865.377692] Scheduling the tasklet
[541865.377697] Executing tasklet handler function with data : 10
[541946.624936] Executing tasklet handler function with data : 10
[541946.624936] Executing tasklet handler function with data : 10
[541946.624937] Executing tasklet handler function with data : 10
[541946.624937] Executing tasklet handler function with data : 10
[541946.624938] Executing tasklet handler function with data : 10
[541946.624939] Executing tasklet handler function with data : 10
[541946.624939] Executing tasklet handler function with data : 10
remove the module from kernel using rmmod command.
$ sudo rmmod tasklet
check if the module is still loaded after removing the kernel module using lsmod if it is not displayed in lsmod output it is verified that the module is removed successfully.
$ lsmod | grep tasklet
Check for kernel messages from exit function using dmesg command.
$ sudo dmesg
[534946.455200] driver unloaded
In this example let’s see how to schedule the tasklet and execute it.
Include the follow header files(.h) to refer the API being used for the execution.
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
Add the following module macros to display information about the license, author and description about the module.
MODULE_LICENSE("GPL");
MODULE_AUTHOR("usr");
MODULE_DESCRIPTION("Tasklet");
Initialize the tasklet which we are going to create and use in this example
tasklet_init(my_tasklet, tasklet_handler, 10);
This function executes once the tasklet is scheduled using tasklet_hi_schedule.
void tasklet_handler(unsigned long data)
{
pr_info("Executing tasklet handler function with data : %ld\n", data);
tasklet_hi_schedule(my_tasklet);
}
This function schedules a tasklet.
void tasklet_start(void)
{
my_tasklet = kmalloc(sizeof(struct tasklet_struct), GFP_KERNEL);
if (my_tasklet == NULL)
pr_info("Cannot allocate memory\n");
tasklet_init(my_tasklet, tasklet_handler, 10);
pr_info("Scheduling the high priority tasklet\n");
tasklet_hi_schedule(my_tasklet);
}
This function calls tasklet_start function, will be executed once the module is loaded into the linux kernel.
static int __init task_init(void)
{
pr_info("driver loaded\n");
tasklet_start();
return 0;
}
This function kills tasklet and stops it’s execution.
void tasklet_stop(void)
{
tasklet_kill(my_tasklet);
if (my_tasklet != NULL)
kfree(my_tasklet);
}
This function calls tasklet_stop function, will be executed once the module is removed from the linux kernel
static void __exit task_exit(void)
{
tasklet_stop();
pr_info("driver unloaded!\n");
}
Add the driver entry points which will be executed once the module is inserted or removed from the kernel.
module_init(task_init);
module_exit(task_exit);
1/* Creating a tasklet : Periodic Tasklet : tasklet_schedule */
2
3#include <linux/init.h>
4#include <linux/kernel.h>
5#include <linux/module.h>
6#include <linux/fs.h>
7#include <linux/interrupt.h>
8
9MODULE_LICENSE("GPL");
10MODULE_AUTHOR("usr");
11MODULE_DESCRIPTION("Tasklet");
12
13struct tasklet_struct *my_tasklet;
14void tasklet_handler(unsigned long data);
15void tasklet_start(void);
16void tasklet_stop(void);
17
18/* tasklet_handler - it executes once the high priority tasklet is scheduled using tasklet_hi_schedule
19 * will stop it's execution once the tasklet_stop() is called
20 */
21void tasklet_handler(unsigned long data)
22{
23 pr_info("Executing tasklet handler function with data : %ld\n", data);
24 tasklet_hi_schedule(my_tasklet);
25}
26
27/* tasklet_start - initializes the tasklet dynamically using tasklet_init
28 * schedules a high priority tasklet using tasklet_hi_schedule
29 */
30void tasklet_start(void)
31{
32 my_tasklet = kmalloc(sizeof(struct tasklet_struct), GFP_KERNEL);
33 if (my_tasklet == NULL)
34 pr_info("Cannot allocate memory\n");
35 tasklet_init(my_tasklet, tasklet_handler, 10);
36
37 pr_info("Scheduling the high priority tasklet\n");
38 tasklet_hi_schedule(my_tasklet);
39}
40
41/* task_init - calls tasklet_start function,
42 * will be executed once the module is loaded into the linux kernel
43 */
44static int __init task_init(void)
45{
46 pr_info("driver loaded\n");
47 tasklet_start();
48 return 0;
49}
50
51/* tasklet_stop - kills tasklet and stops it's execution */
52void tasklet_stop(void)
53{
54 tasklet_kill(my_tasklet);
55 if (my_tasklet != NULL)
56 kfree(my_tasklet);
57}
58
59/* task_exit - calls tasklet_stop function,
60 * will be executed once the module is removed from the linux kernel
61 */
62static void __exit task_exit(void)
63{
64 tasklet_stop();
65 pr_info("driver unloaded!\n");
66}
67
68module_init(task_init);
69module_exit(task_exit);
1obj-m += tasklet.o
2
3all:
4 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
5 sudo ../../checkpatch.pl --no-tree -f tasklet.c
6
7clean:
8 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Run make to compile the kernel source and generate the .ko image.
$ make
make -C /lib/modules/6.8.0/build M=/home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc2 modules
make[1]: Entering directory '/home/arun/Desktop/kernel_api/linux-6.8'
CC [M] /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc2/tasklet.o
MODPOST /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc2/Module.symvers
CC [M] /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc2/tasklet.mod.o
LD [M] /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc2/tasklet.ko
make[1]: Leaving directory '/home/arun/Desktop/kernel_api/linux-6.8'
Check if the .ko is generated or not using ls command.
$ ls -l
total 384
-rw-rw-r-- 1 arun arun 206 Jun 24 18:51 Makefile
-rw-rw-r-- 1 arun arun 69 Jul 11 18:22 modules.order
-rw-rw-r-- 1 arun arun 0 Jul 11 18:22 Module.symvers
-rw-rw-r-- 1 arun arun 1785 Jun 24 19:07 tasklet.c
-rw-rw-r-- 1 arun arun 181552 Jul 11 18:22 tasklet.ko
-rw-rw-r-- 1 arun arun 69 Jul 11 18:22 tasklet.mod
-rw-rw-r-- 1 arun arun 1169 Jul 11 18:22 tasklet.mod.c
-rw-rw-r-- 1 arun arun 149416 Jul 11 18:22 tasklet.mod.o
-rw-rw-r-- 1 arun arun 33496 Jul 11 18:22 tasklet.o
Run modinfo command to get the information about the kernel module.
$ modinfo tasklet.ko
filename: /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc2/tasklet.ko
description: Tasklet
author: usr
license: GPL
srcversion: BF70BBE5EEE4BDE0E05A756
depends:
retpoline: Y
name: tasklet
vermagic: 6.8.0 SMP preempt mod_unload modversions
insert the module using insmod command.
$ sudo insmod ./tasklet.ko
check if the module is loaded or not using lsmod command.
$ lsmod | grep tasklet
tasklet 12288 0
check for the kernel messages from init function and thread function once the module is loaded and thread is created.
$ sudo dmesg
[542554.714827] driver loaded
[542554.714828] Scheduling the tasklet
[542554.714829] Executing tasklet handler function with data : 10
[542554.714829] Executing tasklet handler function with data : 10
[542554.714830] Executing tasklet handler function with data : 10
[542554.714831] Executing tasklet handler function with data : 10
[542554.714832] Executing tasklet handler function with data : 10
[542554.714833] Executing tasklet handler function with data : 10
[542554.714834] Executing tasklet handler function with data : 10
[542554.714835] Executing tasklet handler function with data : 10
remove the module from kernel using rmmod command.
$ sudo rmmod tasklet
check if the module is still loaded after removing the kernel module using lsmod if it is not displayed in lsmod output it is verified that the module is removed successfully.
$ lsmod | grep tasklet
Check for kernel messages from exit function using dmesg command.
$ sudo dmesg
[534946.455200] driver unloaded
In this example let’s see how to schedule the tasklet and execute it.
Include the follow header files(.h) to refer the API being used for the execution.
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
Add the following module macros to display information about the license, author and description about the module.
MODULE_LICENSE("GPL");
MODULE_AUTHOR("usr");
MODULE_DESCRIPTION("Tasklet");
Initialize the tasklet which we are going to create and use in this example.
tasklet_init(my_tasklet1, tasklet_handler1, 10);
tasklet_init(my_tasklet2, tasklet_handler2, 20);
This function executes once the tasklet is scheduled using tasklet_schedule.
It will stop it’s execution once the tasklet_stop() is called.
void tasklet_handler1(unsigned long data)
{
pr_info("Executing the tasklet handler 1 function with data : %ld\n", data);
tasklet_schedule(my_tasklet1);
}
This function executes once the tasklet is scheduled using tasklet_hi_schedule.
It will stop it’s execution once the tasklet_stop() is called.
void tasklet_handler2(unsigned long data)
{
pr_info("Executing the tasklet handler 2 function with data : %ld\n", data);
tasklet_hi_schedule(my_tasklet2);
}
Initializes the my_tasklet1 and my_tasklet2 dynamically using tasklet_init.
Schedules a my_tasklet1 using tasklet_schedule.
Schedules a my_tasklet2 using tasklet_hi_schedule.
void tasklet_start(void)
{
my_tasklet1 = kmalloc(sizeof(struct tasklet_struct), GFP_KERNEL);
if (my_tasklet1 == NULL)
pr_info("Cannot allocate memory\n");
my_tasklet2 = kmalloc(sizeof(struct tasklet_struct), GFP_KERNEL);
if (my_tasklet2 == NULL)
pr_info("Cannot allocate memory\n");
tasklet_init(my_tasklet1, tasklet_handler1, 10);
tasklet_init(my_tasklet2, tasklet_handler2, 20);
pr_info("Scheduling the high priority tasklet\n");
tasklet_schedule(my_tasklet1);
tasklet_hi_schedule(my_tasklet2);
}
This function calls tasklet_start function, will be executed once the module is loaded into the linux kernel.
kills my_tasklet1 and my_tasklet2 using tasklet_kill, stops it’s execution.
static int __init task_init(void)
{
pr_info("driver loaded\n");
tasklet_start();
return 0;
}
This function kills my_tasklet1, my_tasklet2 and stops it’s execution.
void tasklet_stop(void)
{
tasklet_kill(my_tasklet1);
tasklet_kill(my_tasklet2);
if (my_tasklet1 != NULL)
kfree(my_tasklet1);
if (my_tasklet2 != NULL)
kfree(my_tasklet2);
}
This function calls tasklet_stop function, will be executed once the module is removed from the linux kernel
static void __exit task_exit(void)
{
tasklet_stop();
pr_info("driver unloaded!\n");
}
Add the driver entry points which will be executed once the module is inserted or removed from the kernel.
module_init(task_init);
module_exit(task_exit);
1/* Creating a tasklet : Periodic Tasklet : tasklet_schedule */
2
3#include <linux/init.h>
4#include <linux/kernel.h>
5#include <linux/module.h>
6#include <linux/fs.h>
7#include <linux/interrupt.h>
8
9MODULE_LICENSE("GPL");
10MODULE_AUTHOR("usr");
11MODULE_DESCRIPTION("Tasklet");
12
13struct tasklet_struct *my_tasklet1;
14struct tasklet_struct *my_tasklet2;
15
16void tasklet_handler1(unsigned long data);
17void tasklet_handler2(unsigned long data);
18void tasklet_start(void);
19void tasklet_stop(void);
20
21/* tasklet_handler1 - it executes once the tasklet is scheduled using tasklet_schedule
22 * will stop it's execution once the tasklet_stop() is called
23 */
24void tasklet_handler1(unsigned long data)
25{
26 pr_info("Executing the tasklet handler 1 function with data : %ld\n", data);
27 tasklet_schedule(my_tasklet1);
28}
29
30/* tasklet_handler2 - it executes once the high priority tasklet is scheduled using tasklet_hi_schedule
31 * will stop it's execution once the tasklet_stop() is called
32 */
33void tasklet_handler2(unsigned long data)
34{
35 pr_info("Executing the tasklet handler 2 function with data : %ld\n", data);
36 tasklet_hi_schedule(my_tasklet2);
37}
38
39/* tasklet_start - initializes the my_tasklet1 dynamically using tasklet_init
40 * initializes the my_tasklet2 dynamically using tasklet_init
41 * schedules a my_tasklet1 using tasklet_schedule
42 * schedules a my_tasklet2 using tasklet_hi_schedule
43 */
44void tasklet_start(void)
45{
46 my_tasklet1 = kmalloc(sizeof(struct tasklet_struct), GFP_KERNEL);
47 if (my_tasklet1 == NULL)
48 pr_info("Cannot allocate memory\n");
49
50 my_tasklet2 = kmalloc(sizeof(struct tasklet_struct), GFP_KERNEL);
51 if (my_tasklet2 == NULL)
52 pr_info("Cannot allocate memory\n");
53
54 tasklet_init(my_tasklet1, tasklet_handler1, 10);
55 tasklet_init(my_tasklet2, tasklet_handler2, 20);
56
57 pr_info("Scheduling the high priority tasklet\n");
58 tasklet_schedule(my_tasklet1);
59 tasklet_hi_schedule(my_tasklet2);
60}
61
62/* task_init - calls tasklet_start function,
63 * will be executed once the module is loaded into the linux kernel
64 */
65static int __init task_init(void)
66{
67 pr_info("driver loaded\n");
68 tasklet_start();
69 return 0;
70}
71
72/* tasklet_stop - kills my_tasklet1, my_tasklet2 using tasklet_kill
73 * stops it's execution
74 */
75void tasklet_stop(void)
76{
77 tasklet_kill(my_tasklet1);
78 tasklet_kill(my_tasklet2);
79
80 if (my_tasklet1 != NULL)
81 kfree(my_tasklet1);
82 if (my_tasklet2 != NULL)
83 kfree(my_tasklet2);
84}
85
86/* task_exit - calls tasklet_stop function,
87 * will be executed once the module is removed from the linux kernel
88 */
89static void __exit task_exit(void)
90{
91 tasklet_stop();
92 pr_info("driver unloaded!\n");
93}
94
95module_init(task_init);
96module_exit(task_exit);
1obj-m += tasklet.o
2
3all:
4 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
5 sudo ../../checkpatch.pl --no-tree -f tasklet.c
6
7clean:
8 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Run make to compile the kernel source and generate the .ko image.
$ make
make -C /lib/modules/6.8.0/build M=/home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc3 modules
make[1]: Entering directory '/home/arun/Desktop/kernel_api/linux-6.8'
CC [M] /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc3/tasklet.o
MODPOST /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc3/Module.symvers
CC [M] /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc3/tasklet.mod.o
LD [M] /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc3/tasklet.ko
make[1]: Leaving directory '/home/arun/Desktop/kernel_api/linux-6.8'
Check if the .ko is generated or not using ls command.
$ ls -l
total 392
-rw-rw-r-- 1 arun arun 206 Jun 24 19:11 Makefile
-rw-rw-r-- 1 arun arun 69 Jul 11 19:09 modules.order
-rw-rw-r-- 1 arun arun 0 Jul 11 19:09 Module.symvers
-rw-rw-r-- 1 arun arun 2629 Jun 24 19:40 tasklet.c
-rw-rw-r-- 1 arun arun 186384 Jul 11 19:09 tasklet.ko
-rw-rw-r-- 1 arun arun 69 Jul 11 19:09 tasklet.mod
-rw-rw-r-- 1 arun arun 1208 Jul 11 19:09 tasklet.mod.c
-rw-rw-r-- 1 arun arun 149480 Jul 11 19:09 tasklet.mod.o
-rw-rw-r-- 1 arun arun 38280 Jul 11 19:09 tasklet.o
Run modinfo command to get the information about the kernel module.
$ modinfo tasklet.ko
filename: /home/arun/Desktop/kernel_api/tasklet/periodic_tasklet/tc3/tasklet.ko
description: Tasklet
author: usr
license: GPL
srcversion: 39319B4610DAD038CF1C336
depends:
retpoline: Y
name: tasklet
vermagic: 6.8.0 SMP preempt mod_unload modversions
insert the module using insmod command.
$ sudo insmod ./tasklet.ko
check if the module is loaded or not using lsmod command.
$ lsmod | grep tasklet
tasklet 12288 0
check for the kernel messages from init function and thread function once the module is loaded and thread is created.
$ sudo dmesg
[541865.377689] driver loaded
[541865.377692] Scheduling the tasklet
[541865.377697] Executing tasklet handler function with data : 10
[541946.624936] Executing tasklet handler function with data : 10
[541946.624936] Executing tasklet handler function with data : 10
[541946.624937] Executing tasklet handler function with data : 10
[541946.624937] Executing tasklet handler function with data : 10
[541946.624938] Executing tasklet handler function with data : 10
[541946.624939] Executing tasklet handler function with data : 10
[541946.624939] Executing tasklet handler function with data : 10
remove the module from kernel using rmmod command.
$ sudo rmmod tasklet
check if the module is still loaded after removing the kernel module using lsmod if it is not displayed in lsmod output it is verified that the module is removed successfully.
$ lsmod | grep tasklet
Check for kernel messages from exit function using dmesg command.
$ sudo dmesg
[534946.455200] driver unloaded