Mutex ============== .. 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 : mutex.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_mutex_1: .. tab-set:: .. tab-item:: Version Info =============================== ======================================= # Version =============================== ======================================= Freebsd 14.1.0 =============================== ======================================= .. _FreebsdDeviceDriver_basic_fdd_mutex_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 use mutex in kernel module ? .. _FreebsdDeviceDriver_basic_fdd_mutex_3: .. tab-set:: .. tab-item:: mutex.c .. literalinclude:: mutex/mutex.c :language: c :linenos: .. _FreebsdDeviceDriver_basic_fdd_mutex_4: .. tab-set:: .. tab-item:: Makefile .. literalinclude:: mutex/Makefile :language: c :linenos: .. _FreebsdDeviceDriver_basic_fdd_mutex_5: .. tab-set:: .. tab-item:: Compile Program .. code-block:: c :linenos: :emphasize-lines: 1, 5, 9, 12 $ pwd basic_device_drivers/mutex $ ls mutex.c Makefile $ make $ ls .depend.mutex.o export_syms machine mutex.o opt_global.h Makefile i386 mutex.c mutex_module.ko x86 .. _FreebsdDeviceDriver_basic_fdd_mutex_6: .. tab-set:: .. tab-item:: Load the module * Load the module using kldload .. code-block:: c :linenos: :emphasize-lines: 1 $ kldload -v ./mutex_module.ko Loaded ./mutex_module.ko, id=8 .. _FreebsdDeviceDriver_basic_fdd_mutex_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 mutex_module.ko .. _FreebsdDeviceDriver_basic_fdd_mutex_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 Count = 0 Count = 1 .. _FreebsdDeviceDriver_basic_fdd_mutex_9: .. tab-set:: .. tab-item:: Unload the module * Unload the module using kldunload .. code-block:: c :linenos: :emphasize-lines: 1 $ kldunload -v ./mutex_module.ko Unloading mutex_module.ko, id=8 .. _FreebsdDeviceDriver_basic_fdd_mutex_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_mutex_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 Count = 0 Count = 1 Module unloaded