Kthread ============== .. 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:`Complete program : kthread.c ` * :ref:`Makefile ` * :ref:`Compile Program ` * :ref:`Load the module ` * :ref:`Check if the module is loaded successfully ` * :ref:`Check what happened on module load ` * :ref:`Unload the module ` * :ref:`Check if the module is unloaded successfully ` * :ref:`Check what happened on module unload ` .. _FreebsdDeviceDriver_basic_fdd_kthread_1: .. tab-set:: .. tab-item:: Version Info =============================== ======================================= # Version =============================== ======================================= Freebsd 14.1.0 =============================== ======================================= .. _FreebsdDeviceDriver_basic_fdd_kthread_2: .. 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 the kernel thread ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow * How to stop the kernel thread ? .. _FreebsdDeviceDriver_basic_fdd_kthread_3: .. tab-set:: .. tab-item:: kthread.c .. literalinclude:: kthread/kthread.c :language: c :linenos: .. _FreebsdDeviceDriver_basic_fdd_kthread_4: .. tab-set:: .. tab-item:: Makefile .. literalinclude:: kthread/Makefile :language: c :linenos: .. _FreebsdDeviceDriver_basic_fdd_kthread_5: .. tab-set:: .. tab-item:: Compile Program * Run make command to compile .. code-block:: c :linenos: :emphasize-lines: 1, 5, 9, 12 $ pwd basic_device_drivers/kthread $ ls kthread.c Makefile $ make $ ls .depend.kthread.o export_syms kthread.c kthread_module.ko opt_global.h Makefile i386 kthread.o machine x86 .. _FreebsdDeviceDriver_basic_fdd_kthread_6: .. tab-set:: .. tab-item:: Load the module * Load the module using kldload .. code-block:: c :linenos: :emphasize-lines: 1 $ kldload -v ./kthread_module.ko Loaded ./kthread_module.ko, id=8 .. _FreebsdDeviceDriver_basic_fdd_kthread_7: .. tab-set:: .. tab-item:: Check if the module is loaded successfully * Run kldstat command to check the loaded modules .. code-block:: c :linenos: :emphasize-lines: 1, 10 $ kldstat Id Refs Address Size Name 1 29 0xffffffff80200000 1f6c698 kernel 2 1 0xffffffff8216d000 7850 cryptodev.ko 3 1 0xffffffff82176000 772c70 zfs.ko 4 1 0xffffffff83218000 3220 intpm.ko 5 1 0xffffffff8321c000 2178 smbus.ko 6 1 0xffffffff8321f000 3360 uhid.ko 7 1 0xffffffff83223000 3360 wmt.ko 8 1 0xffffffff83227000 209c kthread_module.ko .. _FreebsdDeviceDriver_basic_fdd_kthread_8: .. tab-set:: .. tab-item:: Check what happened on module load * Run dmesg command to check the kernel logs .. code-block:: c :linenos: :emphasize-lines: 1 $ dmesg Module loaded Kthread is running Kthread is running Kthread is running Kthread is running Kthread is running .. _FreebsdDeviceDriver_basic_fdd_kthread_9: .. tab-set:: .. tab-item:: Unload the module * Unload the module using kldunload .. code-block:: c :linenos: :emphasize-lines: 1 $ kldunload -v ./kthread_module.ko Unloading kthread_module.ko, id=8 .. _FreebsdDeviceDriver_basic_fdd_kthread_10: .. tab-set:: .. tab-item:: Check if the module is unloaded successfully * Run kldstat command to check the loaded modules .. code-block:: c :linenos: :emphasize-lines: 1 $ kldstat Id Refs Address Size Name 1 27 0xffffffff80200000 1f6c698 kernel 2 1 0xffffffff8216d000 7850 cryptodev.ko 3 1 0xffffffff82176000 772c70 zfs.ko 4 1 0xffffffff83218000 3220 intpm.ko 5 1 0xffffffff8321c000 2178 smbus.ko 6 1 0xffffffff8321f000 3360 uhid.ko 7 1 0xffffffff83223000 3360 wmt.ko .. _FreebsdDeviceDriver_basic_fdd_kthread_11: .. tab-set:: .. tab-item:: Check what happened on module unload * Run dmesg command to check the kernel logs .. code-block:: c :linenos: :emphasize-lines: 1 $ dmesg Module unloaded