Timer : Periodic ========================= .. 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 : timer.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_timer_timer_periodic_1: .. tab-set:: .. tab-item:: Version Info =============================== ======================================= # Version =============================== ======================================= Freebsd 14.1.0 =============================== ======================================= .. _FreebsdDeviceDriver_basic_fdd_timer_timer_periodic_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 timer ? .. _FreebsdDeviceDriver_basic_fdd_timer_timer_periodic_3: .. tab-set:: .. tab-item:: timer.c .. literalinclude:: timer_periodic/timer.c :language: c :linenos: .. _FreebsdDeviceDriver_basic_fdd_timer_timer_periodic_4: .. tab-set:: .. tab-item:: Makefile .. literalinclude:: timer_periodic/Makefile :language: c :linenos: .. _FreebsdDeviceDriver_basic_fdd_timer_timer_periodic_5: .. tab-set:: .. tab-item:: Compile Program .. code-block:: c :linenos: :emphasize-lines: 1, 5, 9, 12 $ pwd basic_device_drivers/timer_periodic $ ls timer.c Makefile $ make $ ls .depend.timer.o export_syms machine timer.c timer_module.ko Makefile i386 opt_global.h timer.o x86 .. _FreebsdDeviceDriver_basic_fdd_timer_timer_periodic_6: .. tab-set:: .. tab-item:: Load the module * Load the module using kldload .. code-block:: c :linenos: :emphasize-lines: 1 $ kldload -v ./timer_module.ko Loaded ./timer_module.ko, id=8 .. _FreebsdDeviceDriver_basic_fdd_timer_timer_periodic_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 772c70 zfs.ko 3 1 0xffffffff828e1000 7850 cryptodev.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 20d4 timer_module.ko .. _FreebsdDeviceDriver_basic_fdd_timer_timer_periodic_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 Counter value = 1 Counter value = 2 Counter value = 3 Counter value = 4 .. _FreebsdDeviceDriver_basic_fdd_timer_timer_periodic_9: .. tab-set:: .. tab-item:: Unload the module * Unload the module using kldunload .. code-block:: c :linenos: :emphasize-lines: 1 $ kldunload -v ./timer_module.ko Unloading timer_module.ko, id=8 .. _FreebsdDeviceDriver_basic_fdd_timer_timer_periodic_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 772c70 zfs.ko 3 1 0xffffffff828e1000 7850 cryptodev.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_timer_timer_periodic_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 loaded Counter value = 1 Counter value = 2 Counter value = 3 Counter value = 4 Counter value = 5 Counter value = 6 Module unloaded