Periodic Tasklet ================ .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Topics in this section, * :ref:`Version Info ` * :ref:`Learnings in this section ` * :ref:`Explanation of tasklet APIs ` * :ref:`tasklet_init ` * :ref:`tasklet_schedule ` * :ref:`tasklet_hi_schedule ` * :ref:`tasklet_kill ` * :ref:`Explanation of miscellaneous APIs ` * :ref:`Module parameter APIs ` * :ref:`Driver entry point APIs ` * :ref:`Example 1: Scheduling the periodic tasklet using tasklet_schedule ` * :ref:`List of headers ` * :ref:`Module Macros ` * :ref:`Initialize the tasklet dynamically ` * :ref:`Tasklet Handler Function ` * :ref:`Tasklet Start Function ` * :ref:`Task Init Function ` * :ref:`Tasklet Stop Function ` * :ref:`Task Exit Function ` * :ref:`Driver entry points ` * :ref:`See the full program below ` * :ref:`Makefile ` * :ref:`Compile and load the module ` * :ref:`Example 2: Scheduling the periodic tasklet using tasklet_hi_schedule ` * :ref:`List of headers ` * :ref:`Module Macros ` * :ref:`Initialize the tasklet dynamically ` * :ref:`Tasklet Handler Function ` * :ref:`Tasklet Start Function ` * :ref:`Task Init Function ` * :ref:`Tasklet Stop Function ` * :ref:`Task Exit Function ` * :ref:`Driver entry points ` * :ref:`See the full program below ` * :ref:`Makefile ` * :ref:`Compile and load the module ` * :ref:`Example 3: Scheduling the periodic tasklet using both tasklet_schedule and tasklet_hi_schedule ` * :ref:`List of headers ` * :ref:`Module Macros ` * :ref:`Initialize the tasklet dynamically ` * :ref:`Tasklet Handler Function ` * :ref:`Tasklet Start Function ` * :ref:`Task Init Function ` * :ref:`Tasklet Stop Function ` * :ref:`Task Exit Function ` * :ref:`Driver entry points ` * :ref:`See the full program below ` * :ref:`Makefile ` * :ref:`Compile and load the module ` .. _p1_taskletperiodic_0: .. tab-set:: .. tab-item:: Version Info =============================== ======================================= # Version =============================== ======================================= Ubuntu Ubuntu 22.10 Kernel 6.8.0 =============================== ======================================= .. _p1_taskletperiodic_1: .. tab-set:: .. tab-item:: Learnings in this section * In this program, you are going to learn .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow * How to create tasklet ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow * What are the different ways to create tasklet ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow * How to schedule the tasklet periodically ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow * How to schedule high priority tasklet periodically ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow * How to kill the tasklet ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow * How to use tasklet APIs ? * `tasklet_init `_ * `tasklet_schedule `_ * `tasklet_hi_schedule `_ * `tasklet_kill `_ .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow * How to use below APIs ? * `MODULE_LICENSE `_ * `MODULE_DESCRIPTION `_ * `MODULE_AUTHOR `_ * `module_init `_ * `module_exit `_ .. _p1_taskletperiodic_2: .. tab-set:: .. tab-item:: Explanation of tasklet APIs .. _p1_taskletperiodic_3: .. tab-set:: .. tab-item:: tasklet_init * Here is the function prototype of the API: `tasklet_init `_ .. code-block:: c #include 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, .. code-block:: c tasklet_init(my_tasklet, tasklet_handler, 10); .. _p1_taskletperiodic_4: .. tab-set:: .. tab-item:: tasklet_schedule * Here is the function prototype of the API: `tasklet_schedule `_ .. code-block:: c #include static inline void tasklet_schedule(struct tasklet_struct *t); * Here is an example of how to use the API, .. code-block:: c tasklet_schedule(my_tasklet); .. _p1_taskletperiodic_48: .. tab-set:: .. tab-item:: tasklet_hi_schedule * Here is the function prototype of the API: `tasklet_hi_schedule `_ .. code-block:: c #include static inline void tasklet_hi_schedule(struct tasklet_struct *t); * Here is an example of how to use the API, .. code-block:: c tasklet_hi_schedule(my_tasklet2); .. _p1_taskletperiodic_5: .. tab-set:: .. tab-item:: tasklet_kill * Here is the function prototype of the API: `tasklet_kill `_ .. code-block:: c #include extern void tasklet_kill(struct tasklet_struct *t); * Here is an example of how to use the API, .. code-block:: c tasklet_kill(my_tasklet); .. _p1_taskletperiodic_6: .. tab-set:: .. tab-item:: Explanation of miscellaneous APIs .. _p1_taskletperiodic_7: .. tab-set:: .. tab-item:: Module parameter APIs * Here is the prototype of module paramter APIs .. code-block:: c #include #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, .. code-block:: c MODULE_LICENSE("GPL"); MODULE_AUTHOR("usr"); MODULE_DESCRIPTION("Tasklet"); .. _p1_taskletperiodic_8: .. tab-set:: .. tab-item:: Driver entry point API's * Here is the prototype of the Driver entry point API's .. code-block:: c #include #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 .. code-block:: c module_init(task_init); module_exit(task_exit); .. _p1_taskletperiodic_9: .. tab-set:: .. tab-item:: Example 1: Scheduling the periodic tasklet using tasklet_schedule. * In this example let's see how to schedule the tasklet and execute it. .. _p1_taskletperiodic_10: .. tab-set:: .. tab-item:: List of headers * Include the follow header files(.h) to refer the API being used for the execution. .. code-block:: c #include #include #include #include #include .. _p1_taskletperiodic_11: .. tab-set:: .. tab-item:: Module macros * Add the following module macros to display information about the license, author and description about the module. .. code-block:: c MODULE_LICENSE("GPL"); MODULE_AUTHOR("usr"); MODULE_DESCRIPTION("Tasklet"); .. _p1_taskletperiodic_12: .. tab-set:: .. tab-item:: Initialize the tasklet dynamically. * Initialize the tasklet which we are going to create and use in this example .. code-block:: c tasklet_init(my_tasklet, tasklet_handler, 10); .. _p1_taskletperiodic_13: .. tab-set:: .. tab-item:: Tasklet Handler Function * This function executes once the tasklet is scheduled using tasklet_schedule. .. code-block:: c void tasklet_handler(unsigned long data) { pr_info("Executing tasklet handler function with data : %ld\n", data); tasklet_schedule(my_tasklet); } .. _p1_taskletperiodic_14: .. tab-set:: .. tab-item:: Tasklet Start Function * This function schedules a tasklet. .. code-block:: c 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); } .. _p1_taskletperiodic_15: .. tab-set:: .. tab-item:: Task Init Function * This function calls tasklet_start function, will be executed once the module is loaded into the linux kernel. .. code-block:: c static int __init task_init(void) { pr_info("driver loaded\n"); tasklet_start(); return 0; } .. _p1_taskletperiodic_16: .. tab-set:: .. tab-item:: Tasklet Stop Function * This function kills tasklet and stops it's execution. .. code-block:: c void tasklet_stop(void) { tasklet_kill(my_tasklet); if (my_tasklet != NULL) kfree(my_tasklet); } .. _p1_taskletperiodic_17: .. tab-set:: .. tab-item:: Task Exit Function * This function calls tasklet_stop function, will be executed once the module is removed from the linux kernel .. code-block:: c static void __exit task_exit(void) { tasklet_stop(); pr_info("driver unloaded!\n"); } .. _p1_taskletperiodic_18: .. tab-set:: .. tab-item:: Driver entry points * Add the driver entry points which will be executed once the module is inserted or removed from the kernel. .. code-block:: c module_init(task_init); module_exit(task_exit); .. _p1_taskletperiodic_19: .. tab-set:: .. tab-item:: See the full program below .. tab-set:: .. tab-item:: tasklet.c .. literalinclude:: periodic_tasklet/tc1/tasklet.c :language: c :linenos: .. _p1_taskletperiodic_20: .. tab-set:: .. tab-item:: Makefile .. literalinclude:: periodic_tasklet/tc1/Makefile :language: c :linenos: .. _p1_taskletperiodic_21: .. tab-set:: .. tab-item:: Compile and load the module * Run make to compile the kernel source and generate the .ko image. .. code-block:: shell $ 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. .. code-block:: shell $ 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. .. code-block:: shell $ 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. .. code-block:: shell $ sudo insmod ./tasklet.ko * check if the module is loaded or not using lsmod command. .. code-block:: shell $ 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. .. code-block:: shell $ 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. .. code-block:: shell $ 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. .. code-block:: shell $ lsmod | grep tasklet * Check for kernel messages from exit function using dmesg command. .. code-block:: shell $ sudo dmesg [534946.455200] driver unloaded .. _p1_taskletperiodic_22: .. tab-set:: .. tab-item:: Example 2: Scheduling the periodic tasklet using tasklet_hi_schedule. * In this example let’s see how to schedule the tasklet and execute it. .. _p1_taskletperiodic_23: .. tab-set:: .. tab-item:: List of headers * Include the follow header files(.h) to refer the API being used for the execution. .. code-block:: c #include #include #include #include #include .. _p1_taskletperiodic_24: .. tab-set:: .. tab-item:: Module macros * Add the following module macros to display information about the license, author and description about the module. .. code-block:: c MODULE_LICENSE("GPL"); MODULE_AUTHOR("usr"); MODULE_DESCRIPTION("Tasklet"); .. _p1_taskletperiodic_25: .. tab-set:: .. tab-item:: Initialize the tasklet dynamically. * Initialize the tasklet which we are going to create and use in this example .. code-block:: c tasklet_init(my_tasklet, tasklet_handler, 10); .. _p1_taskletperiodic_26: .. tab-set:: .. tab-item:: Tasklet Handler Function * This function executes once the tasklet is scheduled using tasklet_hi_schedule. .. code-block:: c void tasklet_handler(unsigned long data) { pr_info("Executing tasklet handler function with data : %ld\n", data); tasklet_hi_schedule(my_tasklet); } .. _p1_taskletperiodic_27: .. tab-set:: .. tab-item:: Tasklet Start Function * This function schedules a tasklet. .. code-block:: c 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); } .. _p1_taskletperiodic_28: .. tab-set:: .. tab-item:: Task Init Function * This function calls tasklet_start function, will be executed once the module is loaded into the linux kernel. .. code-block:: c static int __init task_init(void) { pr_info("driver loaded\n"); tasklet_start(); return 0; } .. _p1_taskletperiodic_29: .. tab-set:: .. tab-item:: Tasklet Stop Function * This function kills tasklet and stops it's execution. .. code-block:: c void tasklet_stop(void) { tasklet_kill(my_tasklet); if (my_tasklet != NULL) kfree(my_tasklet); } .. _p1_taskletperiodic_30: .. tab-set:: .. tab-item:: Task Exit Function * This function calls tasklet_stop function, will be executed once the module is removed from the linux kernel .. code-block:: c static void __exit task_exit(void) { tasklet_stop(); pr_info("driver unloaded!\n"); } .. _p1_taskletperiodic_31: .. tab-set:: .. tab-item:: Driver entry points * Add the driver entry points which will be executed once the module is inserted or removed from the kernel. .. code-block:: c module_init(task_init); module_exit(task_exit); .. _p1_taskletperiodic_32: .. tab-set:: .. tab-item:: See the full program below .. tab-set:: .. tab-item:: tasklet.c .. literalinclude:: periodic_tasklet/tc2/tasklet.c :language: c :linenos: .. _p1_taskletperiodic_33: .. tab-set:: .. tab-item:: Makefile .. literalinclude:: periodic_tasklet/tc2/Makefile :language: c :linenos: .. _p1_taskletperiodic_34: .. tab-set:: .. tab-item:: Compile and load the module * Run make to compile the kernel source and generate the .ko image. .. code-block:: shell $ 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. .. code-block:: shell $ 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. .. code-block:: shell $ 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. .. code-block:: shell $ sudo insmod ./tasklet.ko * check if the module is loaded or not using lsmod command. .. code-block:: shell $ 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. .. code-block:: shell $ 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. .. code-block:: shell $ 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. .. code-block:: shell $ lsmod | grep tasklet * Check for kernel messages from exit function using dmesg command. .. code-block:: shell $ sudo dmesg [534946.455200] driver unloaded .. _p1_taskletperiodic_35: .. tab-set:: .. tab-item:: Example 3: Scheduling the periodic tasklet using both tasklet_schedule and tasklet_hi_schedule * In this example let’s see how to schedule the tasklet and execute it. .. _p1_taskletperiodic_36: .. tab-set:: .. tab-item:: List of headers * Include the follow header files(.h) to refer the API being used for the execution. .. code-block:: c #include #include #include #include #include .. _p1_taskletperiodic_37: .. tab-set:: .. tab-item:: Module macros * Add the following module macros to display information about the license, author and description about the module. .. code-block:: c MODULE_LICENSE("GPL"); MODULE_AUTHOR("usr"); MODULE_DESCRIPTION("Tasklet"); .. _p1_taskletperiodic_38: .. tab-set:: .. tab-item:: Initialize the tasklet dynamically. * Initialize the tasklet which we are going to create and use in this example. .. code-block:: c tasklet_init(my_tasklet1, tasklet_handler1, 10); tasklet_init(my_tasklet2, tasklet_handler2, 20); .. _p1_taskletperiodic_39: .. tab-set:: .. tab-item:: Tasklet Handler Function * This function executes once the tasklet is scheduled using tasklet_schedule. * It will stop it's execution once the tasklet_stop() is called. .. code-block:: c 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. .. code-block:: c void tasklet_handler2(unsigned long data) { pr_info("Executing the tasklet handler 2 function with data : %ld\n", data); tasklet_hi_schedule(my_tasklet2); } .. _p1_taskletperiodic_40: .. tab-set:: .. tab-item:: Tasklet Start Function * 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. .. code-block:: c 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); } .. _p1_taskletperiodic_41: .. tab-set:: .. tab-item:: Task Init Function * 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. .. code-block:: c static int __init task_init(void) { pr_info("driver loaded\n"); tasklet_start(); return 0; } .. _p1_taskletperiodic_42: .. tab-set:: .. tab-item:: Tasklet Stop Function * This function kills my_tasklet1, my_tasklet2 and stops it's execution. .. code-block:: c 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); } .. _p1_taskletperiodic_43: .. tab-set:: .. tab-item:: Task Exit Function * This function calls tasklet_stop function, will be executed once the module is removed from the linux kernel .. code-block:: c static void __exit task_exit(void) { tasklet_stop(); pr_info("driver unloaded!\n"); } .. _p1_taskletperiodic_44: .. tab-set:: .. tab-item:: Driver entry points * Add the driver entry points which will be executed once the module is inserted or removed from the kernel. .. code-block:: c module_init(task_init); module_exit(task_exit); .. _p1_taskletperiodic_45: .. tab-set:: .. tab-item:: See the full program below .. tab-set:: .. tab-item:: tasklet.c .. literalinclude:: periodic_tasklet/tc3/tasklet.c :language: c :linenos: .. _p1_taskletperiodic_46: .. tab-set:: .. tab-item:: Makefile .. literalinclude:: periodic_tasklet/tc3/Makefile :language: c :linenos: .. _p1_taskletperiodic_47: .. tab-set:: .. tab-item:: Compile and load the module * Run make to compile the kernel source and generate the .ko image. .. code-block:: shell $ 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. .. code-block:: shell $ 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. .. code-block:: shell $ 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. .. code-block:: shell $ sudo insmod ./tasklet.ko * check if the module is loaded or not using lsmod command. .. code-block:: shell $ 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. .. code-block:: shell $ 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. .. code-block:: shell $ 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. .. code-block:: shell $ lsmod | grep tasklet * Check for kernel messages from exit function using dmesg command. .. code-block:: shell $ sudo dmesg [534946.455200] driver unloaded