Creating Tasklet : Static Method

#

Version

Ubuntu

Ubuntu 22.10

Kernel

6.8.0

  • In this program, you are going to learn

  • How to create tasklet in static method ?

  • What are the different ways to create tasklet ?

  • How to kill the tasklet ?

#include <linux/interrupt.h>

#define DECLARE_TASKLET(name, _callback)
  • Here is an example of how to use the API,

DECLARE_TASKLET(my_tasklet, (void *)tasklet_handler);
#include <linux/interrupt.h>

static inline void tasklet_schedule(struct tasklet_struct *t);
  • where

    • tasklet_schedule: Schedules the tasklet.

    • struct tasklet_struct * t : Parameter of type pointer to struct tasklet_struct, which represents the tasklet that is being scheduled for execution.

  • Here is an example of how to use the API,

tasklet_schedule(&my_tasklet);
#include <linux/interrupt.h>

extern void tasklet_kill(struct tasklet_struct *t);
  • where

    • tasklet_kill: kills tasklet.

    • struct tasklet_struct * t : Parameter of type pointer to struct tasklet_struct, representing the tasklet that is to be killed or stopped.

  • 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 create tasklet using DECLARE_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");
  • Declare and initialize the tasklet which we are going to create and use in this example

DECLARE_TASKLET(my_tasklet, (void *)tasklet_handler);
  • This function executes once the tasklet is scheduled using tasklet_schedule.

void tasklet_handler(struct tasklet_struct *t)
{
        int *ptr;
        ptr = (int *) t->data;

        pr_info("Executing tasklet handler function\n");
        pr_info("data addr : %x\n", (unsigned int)t->data);
        pr_info("*ptr addr : %x\n", (unsigned int)ptr);
        pr_info("*ptr value : %ld\n", (unsigned long)*ptr);
}
  • This function schedules a tasklet.

void tasklet_start(void)
{
        my_tasklet.data = (unsigned long)&a;
        pr_info("my_tasklet.data : %x\n", (unsigned int)my_tasklet.data);
        pr_info("&my_tasklet.data : %x\n", (unsigned int)&my_tasklet.data);
        pr_info("a value : %ld\n", (unsigned long)a);
        pr_info("a addr : %x\n", (unsigned int)&a);
        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);
        pr_info("tasklet killed\n");
}
  • 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 : Static Method : DECLARE_TASKLET */
 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
13void tasklet_handler(struct tasklet_struct *t);
14void tasklet_start(void);
15void tasklet_stop(void);
16
17/* Init the tasklet by static method */
18DECLARE_TASKLET(my_tasklet, (void *)tasklet_handler);
19
20int a = 10;
21
22/* tasklet_handler - it executes once the tasklet is scheduled using tasklet_schedule */
23void tasklet_handler(struct tasklet_struct *t)
24{
25	int *ptr;
26
27	ptr = (int *) t->data;
28
29	pr_info("Executing asklet handler function\n");
30	pr_info("data addr : %x\n", (unsigned int)t->data);
31	pr_info("*ptr addr : %x\n", (unsigned int)ptr);
32	pr_info("*ptr value : %ld\n", (unsigned long)*ptr);
33}
34
35/* tasklet_start - schedules a tasklet */
36void tasklet_start(void)
37{
38	my_tasklet.data = (unsigned long)&a;
39	pr_info("my_tasklet.data : %x\n", (unsigned int)my_tasklet.data);
40	pr_info("&my_tasklet.data : %x\n", (unsigned int)&my_tasklet.data);
41	pr_info("a value : %ld\n", (unsigned long)a);
42	pr_info("a addr : %x\n", (unsigned int)&a);
43	pr_info("Scheduling the tasklet\n");
44	tasklet_schedule(&my_tasklet);
45}
46
47/* task_init - calls tasklet_start function,
48 * will be executed once the module is loaded into the linux kernel
49 */
50static int __init task_init(void)
51{
52	pr_info("driver loaded\n");
53	tasklet_start();
54	return 0;
55}
56
57/* tasklet_stop - kills tasklet and stops it's execution */
58void tasklet_stop(void)
59{
60	tasklet_kill(&my_tasklet);
61	pr_info("tasklet killed\n");
62}
63
64/* task_exit - calls tasklet_stop function,
65 * will be executed once the module is removed from the linux kernel
66 */
67static void __exit task_exit(void)
68{
69	tasklet_stop();
70	pr_info("driver unloaded!\n");
71}
72
73module_init(task_init);
74module_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/test/Desktop/kernel_api/tasklet/create_static/tc1 modules
make[1]: Entering directory '/home/test/Desktop/kernel_api/linux-6.8'
  CC [M]  /home/test/Desktop/kernel_api/tasklet/create_static/tc1/tasklet.o
  MODPOST /home/test/Desktop/kernel_api/tasklet/create_static/tc1/Module.symvers
  CC [M]  /home/test/Desktop/kernel_api/tasklet/create_static/tc1/tasklet.mod.o
  LD [M]  /home/test/Desktop/kernel_api/tasklet/create_static/tc1/tasklet.ko
make[1]: Leaving directory '/home/test/Desktop/kernel_api/linux-6.8'
  • Check if the .ko is generated or not using ls command.

$ ls -l
total 376
-rw-rw-r-- 1 test test    206 Jun 21 12:17 Makefile
-rw-rw-r-- 1 test test     66 Jul 11 16:11 modules.order
-rw-rw-r-- 1 test test      0 Jul 11 16:11 Module.symvers
-rw-rw-r-- 1 test test   1548 Jul 11 16:07 tasklet.c
-rw-rw-r-- 1 test test 178256 Jul 11 16:11 tasklet.ko
-rw-rw-r-- 1 test test     66 Jul 11 16:11 tasklet.mod
-rw-rw-r-- 1 test test   1039 Jul 11 16:11 tasklet.mod.c
-rw-rw-r-- 1 test test 149152 Jul 11 16:11 tasklet.mod.o
-rw-rw-r-- 1 test test  30464 Jul 11 16:11 tasklet.o
  • Run modinfo command to get the information about the kernel module.

$ modinfo tasklet.ko
filename:       /home/test/Desktop/kernel_api/tasklet/create_static/tc1/tasklet.ko
description:    Tasklet
author:         usr
license:        GPL
srcversion:     A00B74CEDDF5019A762E676
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
[534397.572870] driver loaded
[534397.572877] Scheduling the tasklet
[534397.573501] Executing asklet handler function
[534397.573504] *ptr value : 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
[534515.467513] tasklet killed
[534515.467516] driver unloaded!
  • In this example let’s see how to create tasklet using DECLARE_TASKLET_OLD 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");
  • Declare and initialize the tasklet which we are going to create and use in this example

DECLARE_TASKLET_OLD(my_tasklet, (void *)my_tasklet_handler);
  • This function executes once the tasklet is scheduled using tasklet_schedule.

void my_tasklet_handler(unsigned long data)
{
        int *ptr;
        ptr = (int *) data;

        pr_info("Executing tasklet function\n");
        pr_info("*ptr : %ld\n", (unsigned long)*ptr);
}
  • This function schedules a tasklet.

void tasklet_start(void)
{
        my_tasklet.data = (unsigned long)&a;

        pr_info("my_tasklet.data : %x\n", (unsigned int)my_tasklet.data);
        pr_info("&my_tasklet.data : %x\n", &my_tasklet.data);
        pr_info("a value : %ld\n", a);
        pr_info("a addr : %x\n", &a);
        pr_info("Scheduling tasklet\n");
        tasklet_schedule(&my_tasklet);
        pr_info("tasklet scheduled\n");
}
  • 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);
}
  • This function calls tasklet_stop function, will be executed once the module is removed from the linux kernel

static void __exit task_exit(void)
{
        pr_info("driver unloaded\n");
        tasklet_stop();
}
  • 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 : Static Method : DECLARE_TASKLET_OLD */
 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("Linux_usr");
11MODULE_DESCRIPTION("Tasklet");
12
13void my_tasklet_handler(unsigned long data);
14void tasklet_start(void);
15void tasklet_stop(void);
16
17int a = 10;
18
19/* Init the tasklet by static method */
20DECLARE_TASKLET_OLD(my_tasklet, (void *)my_tasklet_handler);
21
22/* tasklet_handler - it executes once the tasklet is scheduled using tasklet_schedule */
23void my_tasklet_handler(unsigned long data)
24{
25	int *ptr;
26	ptr = (int *) data;
27
28	pr_info("Executing tasklet function\n");
29	pr_info("*ptr : %ld\n", (unsigned long)*ptr);
30}
31
32/* tasklet_start - schedules a tasklet */
33void tasklet_start(void)
34{
35	my_tasklet.data = (unsigned long)&a;
36
37	pr_info("my_tasklet.data : %x\n", (unsigned int)my_tasklet.data);
38	pr_info("&my_tasklet.data : %x\n", &my_tasklet.data);
39	pr_info("a value : %ld\n", a);
40	pr_info("a addr : %x\n", &a);
41	pr_info("Scheduling tasklet\n");
42	tasklet_schedule(&my_tasklet);
43	pr_info("tasklet scheduled\n");
44}
45
46/* task_init - calls tasklet_start function,
47 * will be executed once the module is loaded into the linux kernel
48 */
49static int __init task_init(void)
50{
51	pr_info("driver loaded\n");
52	tasklet_start();
53	return 0;
54}
55
56/* tasklet_stop - kills tasklet and stops it's execution */
57void tasklet_stop(void)
58{
59	tasklet_kill(&my_tasklet);
60}
61
62/* task_exit - calls tasklet_stop function,
63 * will be executed once the module is removed from the linux kernel
64 */
65static void __exit task_exit(void)
66{
67	pr_info("driver unloaded\n");
68	tasklet_stop();
69}
70
71module_init(task_init);
72module_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/test/Desktop/kernel_api/tasklet/create_static/tc2 modules
make[1]: Entering directory '/home/test/Desktop/kernel_api/linux-6.8'
  CC [M]  /home/test/Desktop/kernel_api/tasklet/create_static/tc2/tasklet.o
  MODPOST /home/test/Desktop/kernel_api/tasklet/create_static/tc2/Module.symvers
  CC [M]  /home/test/Desktop/kernel_api/tasklet/create_static/tc2/tasklet.mod.o
  LD [M]  /home/test/Desktop/kernel_api/tasklet/create_static/tc2/tasklet.ko
make[1]: Leaving directory '/home/test/Desktop/kernel_api/linux-6.8'
  • Check if the .ko is generated or not using ls command.

$ ls -l
total 376
-rw-rw-r-- 1 arun arun    206 Jun 21 12:17 Makefile
-rw-rw-r-- 1 arun arun     66 Jul 11 16:19 modules.order
-rw-rw-r-- 1 arun arun      0 Jul 11 16:19 Module.symvers
-rw-rw-r-- 1 arun arun   1541 Jul 11 16:19 tasklet.c
-rw-rw-r-- 1 arun arun 178192 Jul 11 16:19 tasklet.ko
-rw-rw-r-- 1 arun arun     66 Jul 11 16:19 tasklet.mod
-rw-rw-r-- 1 arun arun   1039 Jul 11 16:19 tasklet.mod.c
-rw-rw-r-- 1 arun arun 149152 Jul 11 16:19 tasklet.mod.o
-rw-rw-r-- 1 arun arun  30440 Jul 11 16:19 tasklet.o
  • Run modinfo command to get the information about the kernel module.

$ modinfo tasklet.ko
filename:       /home/arun/Desktop/kernel_api/tasklet/create_static/tc2/tasklet.ko
description:    Tasklet
author:         Linux_usr
license:        GPL
srcversion:     8D4858F7AB5C64157D5CF0D
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
[534724.012807] driver loaded
[534724.012811] Scheduling tasklet
[534724.012815] tasklet scheduled
[534724.012841] Executing tasklet function
[534724.012842] * ptr : 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
[534742.482383] driver unloaded
  • In this example let’s see how to create tasklet using DECLARE_TASKLET_DISABLED 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");
  • Declare and initialize the tasklet which we are going to create and use in this example.

  • The tasklet can be declared and set at a disabled state, which means that the tasklet can be scheduled, but will not run until the tasklet is specifically enabled. We need to use tasklet_enable to enable.

DECLARE_TASKLET_DISABLED(my_tasklet, (void *)my_tasklet_handler);
  • This function executes once the tasklet is scheduled using tasklet_schedule.

void my_tasklet_handler(struct tasklet_struct *t)
{
        int *ptr;
        ptr = (int *) t->data;

        pr_info("Executing asklet handler function\n");
        pr_info("data addr : %x\n", (unsigned int)t->data);
        pr_info("*ptr addr : %x\n", (unsigned int)ptr);
        pr_info("*ptr value : %ld\n", (unsigned long)*ptr);
}
  • This function schedules a tasklet, but will not run until the tasklet is specifically enabled.

void tasklet_start(void)
{
        my_tasklet.data = (unsigned long)&a;
        pr_info("my_tasklet.data : %x\n", (unsigned int)my_tasklet.data);
        pr_info("&my_tasklet.data : %x\n", (unsigned int)&my_tasklet.data);
        pr_info("a value : %ld\n", (unsigned long)a);
        pr_info("a addr : %x\n", (unsigned int)&a);
        pr_info("Enabling tasklet\n");
        tasklet_enable(&my_tasklet);
        pr_info("Tasklet enabled\n");
        pr_info("Scheduling tasklet\n");
        tasklet_schedule(&my_tasklet);
        pr_info("tasklet scheduled\n");
}
  • 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);
}
  • This function calls tasklet_stop function, will be executed once the module is removed from the linux kernel

static void __exit task_exit(void)
{
        pr_info("driver unloaded\n");
        tasklet_stop();
}
  • 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 : Static Method : DECLARE_TASKLET_DISABLED */
 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("Linux_usr");
11MODULE_DESCRIPTION("Tasklet");
12
13void my_tasklet_handler(struct tasklet_struct *t);
14void tasklet_start(void);
15void tasklet_stop(void);
16
17int a = 10;
18
19/* Init the tasklet by static method
20 * tasklet is declared and set at a disabled state
21 */
22DECLARE_TASKLET_DISABLED(my_tasklet, (void *)my_tasklet_handler);
23
24/* tasklet_handler - it executes once the tasklet is scheduled using tasklet_schedule */
25void my_tasklet_handler(struct tasklet_struct *t)
26{
27	int *ptr;
28	ptr = (int *) t->data;
29
30	pr_info("Executing asklet handler function\n");
31	pr_info("data addr : %x\n", (unsigned int)t->data);
32	pr_info("*ptr addr : %x\n", (unsigned int)ptr);
33	pr_info("*ptr value : %ld\n", (unsigned long)*ptr);
34}
35
36/* tasklet_start - schedules a tasklet
37 * it can be scheduled,
38 * but will not run until the tasklet is specifically enabled
39 */
40void tasklet_start(void)
41{
42	my_tasklet.data = (unsigned long)&a;
43	pr_info("my_tasklet.data : %x\n", (unsigned int)my_tasklet.data);
44	pr_info("&my_tasklet.data : %x\n", (unsigned int)&my_tasklet.data);
45	pr_info("a value : %ld\n", (unsigned long)a);
46	pr_info("a addr : %x\n", (unsigned int)&a);
47	pr_info("Enabling tasklet\n");
48	tasklet_enable(&my_tasklet);
49	pr_info("Tasklet enabled\n");
50	pr_info("Scheduling tasklet\n");
51	tasklet_schedule(&my_tasklet);
52	pr_info("tasklet scheduled\n");
53}
54
55/* task_init - calls tasklet_start function,
56 * will be executed once the module is loaded into the linux kernel
57 */
58static int __init task_init(void)
59{
60	pr_info("driver loaded\n");
61	tasklet_start();
62	return 0;
63}
64
65/* tasklet_stop - kills tasklet and stops it's execution */
66void tasklet_stop(void)
67{
68	tasklet_kill(&my_tasklet);
69}
70
71/* task_exit - calls tasklet_stop function,
72 * will be executed once the module is removed from the linux kernel
73 */
74static void __exit task_exit(void)
75{
76	pr_info("driver unloaded\n");
77	tasklet_stop();
78}
79
80module_init(task_init);
81module_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/create_static/tc3 modules
make[1]: Entering directory '/home/arun/Desktop/kernel_api/linux-6.8'
  CC [M]  /home/arun/Desktop/kernel_api/tasklet/create_static/tc3/tasklet.o
  MODPOST /home/arun/Desktop/kernel_api/tasklet/create_static/tc3/Module.symvers
  CC [M]  /home/arun/Desktop/kernel_api/tasklet/create_static/tc3/tasklet.mod.o
  LD [M]  /home/arun/Desktop/kernel_api/tasklet/create_static/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 376
-rw-rw-r-- 1 arun arun    206 Jun 21 12:12 Makefile
-rw-rw-r-- 1 arun arun     66 Jul 11 16:23 modules.order
-rw-rw-r-- 1 arun arun      0 Jul 11 16:23 Module.symvers
-rw-rw-r-- 1 arun arun   1810 Jul 11 16:23 tasklet.c
-rw-rw-r-- 1 arun arun 180128 Jul 11 16:23 tasklet.ko
-rw-rw-r-- 1 arun arun     66 Jul 11 16:23 tasklet.mod
-rw-rw-r-- 1 arun arun   1039 Jul 11 16:23 tasklet.mod.c
-rw-rw-r-- 1 arun arun 149152 Jul 11 16:23 tasklet.mod.o
-rw-rw-r-- 1 arun arun  32352 Jul 11 16:23 tasklet.o
  • Run modinfo command to get the information about the kernel module.

$ modinfo tasklet.ko
filename:       /home/arun/Desktop/kernel_api/tasklet/create_static/tc3/tasklet.ko
description:    Tasklet
author:         Linux_usr
license:        GPL
srcversion:     816E2EE14D9027FFBC8E642
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
[534914.651150] driver loaded
[534914.651160] Enabling tasklet
[534914.651162] Tasklet enabled
[534914.651164] Scheduling tasklet
[534914.651177] tasklet scheduled
[534914.651195] Executing asklet handler function
[534914.651197] * ptr value : 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