首先内核要使能两个配置才可以使用。一般内核都是打开的。
CONFIG_DEBUG_FS=y
CONFIG_DYNAMIC_DEBUG=y
当编译选项CONFIG_DYNAMIC_DEBUG打开的时候,在编译阶段,kernel会把所有使用dev_dbg()的信息记录在一个table中,这些信息我们可以从/sys/kernel/debug/dynamic_debug/control解析出来:
[root@localhost ~]# cat /sys/kernel/debug/dynamic_debug/control | grep infiniband
drivers/infiniband/core/uverbs_cmd.c:730 [ib_uverbs]ib_uverbs_reg_mr =_ "ODP support not available\012"
drivers/infiniband/core/umem_odp.c:458 [ib_uverbs]ib_umem_odp_map_dma_and_lock =_ "ib_umem_odp_map_dma_single_page failed with error %d\012"
drivers/infiniband/core/umem_odp.c:449 [ib_uverbs]ib_umem_odp_map_dma_and_lock =_ "%s: un-expected hmm_order %d, page_shift %d\012"
drivers/infiniband/core/verbs.c:2071 [ib_core]ib_reg_user_mr =_ "ODP support not available\012"
drivers/infiniband/core/cache.c:626 [ib_core]_ib_cache_gid_del =p "%s: can't delete gid %pI6 error=%d\012"
drivers/infiniband/core/cache.c:391 [ib_core]del_gid =p "%s port=%d index=%d gid %pI6\012"
drivers/infiniband/core/cache.c:328 [ib_core]store_gid_entry =p "%s port=%d index=%d gid %pI6\012"
drivers/infiniband/core/cache.c:244 [ib_core]free_gid_entry_locked =p "%s port=%d index=%d gid %pI6\012"
drivers/infiniband/core/mad.c:366 [ib_core]ib_register_mad_agent =_ "%s: QP %d not supported\012"
drivers/infiniband/core/mad.c:356 [ib_core]ib_register_mad_agent =_ "%s: Invalid port %d\012"
drivers/infiniband/core/mad.c:340 [ib_core]ib_register_mad_agent =_ "%s: Invalid GS QP type: class 0x%x\012"
drivers/infiniband/core/mad.c:330 [ib_core]ib_register_mad_agent =_ "%s: Invalid SM QP type: class 0x%x\012"
drivers/infiniband/core/mad.c:317 [ib_core]ib_register_mad_agent =_ "%s: RMPP version for non-RMPP class 0x%x\012"
drivers/infiniband/core/mad.c:308 [ib_core]ib_register_mad_agent =_ "%s: No OUI specified for class 0x%x\012"
drivers/infiniband/core/mad.c:297 [ib_core]ib_register_mad_agent =_ "%s: Invalid Mgmt Class 0\012"
drivers/infiniband/core/mad.c:287 [ib_core]ib_register_mad_agent =_ "%s: Invalid Mgmt Class 0x%x\012"
drivers/infiniband/core/mad.c:275 [ib_core]ib_register_mad_agent =_ "%s: no recv_handler\012"
drivers/infiniband/core/mad.c:270 [ib_core]ib_register_mad_agent =_ "%s: invalid Class Version %u\012"
drivers/infiniband/core/mad.c:260 [ib_core]ib_register_mad_agent =_ "%s: invalid RMPP Version %u\012"
drivers/infiniband/core/mad.c:253 [ib_core]ib_register_mad_agent =_ "%s: invalid QP Type %d\012"
drivers/infiniband/core/ib_core_uverbs.c:328 [ib_core]rdma_user_mmap_entry_insert_range =_ "mmap: pgoff[%#lx] npages[%#x] inserted\012"
drivers/infiniband/core/ib_core_uverbs.c:196 [ib_core]rdma_user_mmap_entry_free =_ "mmap: pgoff[%#lx] npages[%#zx] removed\012"
drivers/infiniband/core/ib_core_uverbs.c:141 [ib_core]rdma_user_mmap_entry_get_pgoff =_ "mmap: pgoff[%#lx] npages[%#zx] returned\012"
比如我们想打开rdma设备gid管理的相关日志。
打开整个文件的dev_dbg使用file关键字:
echo -n "file drivers/infiniband/core/cache.c +p" > /mnt/debug/dynamic_debug/control
打开一个函数的dev_dbg开关,使用func关键字:
echo -n "func del_gid -p" > /sys/kernel/debug/dynamic_debug/control
关闭日志,则使用-p:
echo -n "file drivers/infiniband/core/cache.c -p" > /mnt/debug/dynamic_debug/control
在/sys/kernel/debug/dynamic_debug/control的输出中,我们上面的操作都会体现出来。如果函数后面是“=p”,则说明开关打开。如果是“=_”,则说明开关关闭。
使能开关后,日志必须通过dmesg查看,前面会带有设备名称作为前缀:
与printk不同的是printk会打印到串口输出,但dev_dbg不会。