In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
What is the dev_info, dev_dbg, dev_err and dynamic debugging in the Linux kernel? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
At present, in the kernel driver code, it is no longer recommended to directly use printk to add print information, but to use functions such as dev_info,dev_dbg,dev_err instead. Although the nature of these dev_xxx functions is printed using printk, compared to printk:
Support printing module information, dev information
Support dynamic debugging (dynamic debug) mode
The following is a brief description of the basic rules for the use of these dev_xxx functions, as well as the use of dynamic debugging.
Dev_info (): "notification class" information such as startup process or module loading process is usually notified only once, such as the probe function.
Dev_dbg (): generally used in common errors, such as-EINVAL,-ENOMEM and other errno occurrence, for debugging
Dev_err (): generally used in serious errors, especially where the user cannot get errno, or where it is not easy for programmers to guess what went wrong with the system.
Use method of dynamic debugging
Turn on the kernel dynamic debug switch, and make menuconfig selects CONFIG_DYNAMIC_DEBUG and CONFIG_DEBUG_FS
After Linux starts, mount the dbgfs using the command line
Mkdir / mnt/dbg mount-t debugfs none / mnt/dbg
Use the following ways to control how you want to output dev_dbg () information
1. Control all dev_dbg (), echo-n "file xxx.c + p" > / mnt/dbg/dynamic_debug/control of a file
two。 Control all dev_dbg (), echo-n "func xxx + p" > / mnt/dbg/dynamic_debug/control of a function
When you run the program, you can see the output information of the corresponding dev_dbg () using dmesg
When debugging is finished and you no longer want to output dev_dbg () information, use the following command to turn it off
1.echo-n "file xxx.c-p" > / mnt/dbg/dynamic_debug/control
2.echo-n "func xxx-p" > / mnt/dbg/dynamic_debug/control
For example, echo-n "file ca_dsc_core.c + p" > / mnt/dbg/dynamic_debug/control prints all the dev_dbg () information of ca_dsc_core.c echo-n "func ca_dsc_read + p" > / mnt/dbg/dynamic_debug/control prints all dev_dbg () information of ca_dsc_read () function and prints the basic principle of dynamic printing debugging.
When the compilation option CONFIG_DYNAMIC_DEBUG is turned on, during the compilation phase, kernel records all information using dev_dbg () in a table, which can be parsed from / mnt/dbg/dynamic_debug/control:
# cat / mnt/dbg/dynamic_debug/control... Drivers/alidrivers/modules/alidsc/ca_dsc_core.c:800 [alidsc] ca_dsc_probe_dt = _ "get dev-index error12" drivers/alidrivers/modules/alidsc/ca_dsc_core.c:789 [alidsc] ca_dsc_probe_dt = _ "get clk error12" drivers/alidrivers/modules/alidsc/ca_dsc_core.c:292 [alidsc] ca_dsc_read = p "read: session#%d read returned% d bytes12" drivers/alidrivers/modules/alidsc/ca _ dsc_core.c:234 [alidsc] ca_dsc_read = p "read: session#%d read request:% zd bytes12" drivers/alidrivers/modules/alidsc/ca_dsc_core.c:435 [alidsc] ca_dsc_vm_fault = _ "dsc_vm_fault: buffer#%d release% d bytes for session#%d12" drivers/alidrivers/modules/alidsc/ca_dsc_core.c:112 [alidsc] ca_dsc_open = _ "dsc_se: failed register se12" Drivers/alidrivers/modules/alidsc/ca_dsc_core.c:755 [alidsc] ca_dsc_splice_write = _ "splice_write: session#%d dsc_from_pipe% d bytes12" drivers/alidrivers/modules/alidsc/ca_dsc_core.c:729 [alidsc] ca_dsc_splice_write = _ "splice_write: session#%d count% zd bytes12" drivers/alidrivers/modules/alidsc/ca_dsc_core.c:619 [alidsc] ca_dsc_splice_read = _ "splice_read: session#%d ret% zd bytes12" drivers/alidrivers/modules/alidsc/ca_dsc_core.c:532 [alidsc] ca_dsc_splice_read = _ "splice_read: session#%d request% zd bytes12" drivers/alidrivers/modules/alidsc/ca_dsc_core.c:871 [alidsc] ca_dsc_probe = _ "Get DSC handler errorships 12" drivers/alidrivers/modules/alidsc/ca_dsc_core.c:820 [alidsc] ca_dsc_ Probe = _ "Failed to parse DT12" drivers/alidrivers/modules/alidsc/ca_dsc_core.c:923 [alidsc] ca_dsc_remove = _ "get clk error12" drivers/alidrivers/modules/alidsc/ca_dsc_core.c:396 [alidsc] ca_dsc_write = _ "write: session#%d ret% zd12" drivers/alidrivers/modules/alidsc/ca_dsc_core.c:325 [alidsc] ca_dsc_write = _ "write: session#%d count% zd12 "... Net/ipv4/ping.c:965 [ping] ping_rcv = _ "no socket, dropping12" net/ipv4/ping.c:960 [ping] ping_rcv = _ "rcv on socket% p12" net/ipv4/ping.c:953 [ping] ping_rcv = _ "ping_rcv (skb=%p,id=x) Seq=x) 12 "net/ipv4/ping.c:932 [ping] ping_queue_rcv_skb = _" ping_queue_rcv_skb-> failed12 "net/ipv4/ping.c:929 [ping] ping_queue_rcv_skb = _" ping_queue_rcv_skb (sk=%p,sk- > num=%d) Skb=%p) 12 "net/ipv4/ping.c:921 [ping] ping_recvmsg = _" ping_recvmsg->% D12 "net/ipv4/ping.c:840 [ping] ping_recvmsg = _" ping_recvmsg (sk=%p,sk- > num=%u) 12 "net/ipv4/ping.c:693 [ping] ping_v4_sendmsg = _" ping_v4_sendmsg (sk=%p) Sk- > num=%u) 12 "net/ipv4/ping.c:197 [ping] ping_lookup = _" found:% p: num=%d, daddr=%pI4, dif=%d12 "net/ipv4/ping.c:189 [ping] ping_lookup = _" iterate12 "net/ipv4/ping.c:176 [ping] ping_lookup = _" try to find: num=%d, daddr=%pI4 Dif =% D12 "net/ipv4/ping.c:505 [ping] ping_err = _" err on socket% p12 "net/ipv4/ping.c:502 [ping] ping_err = _" no socket, dropping12 "net/ipv4/ping.c:498 [ping] ping_err = _" ping_err (proto=0x%x,type=%d,code=%d,id=x,seq=x) 12 "net/ipv4/ping.c:304 [ping] ping_check_bind_addr = _" ping_check_bind_addr (sk=%p) Addr=%pI4,port=%d) 12 "net/ipv4/ping.c:445 [ping] ping_bind = _" ping_v4_bind->% D12 "net/ipv4/ping.c:423 [ping] ping_bind = _" after bind (): num =% d, dif =% d12 "net/ipv4/ping.c:286 [ping] ping_close = _" isk- > refcnt =% D12 "net/ipv4/ping.c:285 [ping] ping_close = _" ping_close (sk=%p Sk- > num=%u) 12 "net/ipv4/ping.c:153 [ping] ping_unhash = _" ping_unhash (isk=%p Isk- > num=%u) 12 "net/ipv4/ping.c:146 [ping] ping_hash = _" ping_hash (sk- > port=%u) 12 "net/ipv4/ping.c:67 [ping] ping_hashfn = _" hash (% d) =% D12 "net/ipv4/ping.c:130 [ping] ping_get_port = _" was not hashed12 "net/ipv4/ping.c:127 [ping] ping_get_port = _" found port/ident =% D12 "
Take one of them as an example:
Drivers/alidrivers/modules/alidsc/ca_dsc_core.c:800 [alidsc] ca_dsc_probe_dt = _ "get dev-index error12" will not print drivers/alidrivers/modules/alidsc/ca_dsc_core.c:800 [alidsc] ca_dsc_probe_dt = p "get dev-index error12" will print
So in the application layer, users can control the dynamic_debug/control file by using echo, and then control whether to print a certain dev_dbg () message!
Dev_dbg () is also useful for analyzing some kernel subsystems or driver processes, such as debug switches that enable net/ipv4/ping.c to observe how ping works.
Code analysis
From a code perspective, it is also easy to see the design of dev_dbg ():
After include/linux/device.h include/linux/dynamic_debug.h lib/dynamic_debug.c// enables CONFIG_DYNAMIC_DEBUG, it dynamically prints # if defined (CONFIG_DYNAMIC_DEBUG) # define dev_dbg (dev, format,...) based on control information. Do {dynamic_dev_dbg (dev, format, # # _ _ VA_ARGS__);} while (0) / / enable DEBUG, print the dev_dbg information of the entire kernel # elif defined (DEBUG) # define dev_dbg (dev, format, arg...) Dev_printk (KERN_DEBUG, dev, format, # # arg) / / does not enable, dev_dbg does not print anything # else # define dev_dbg (dev, format, arg...) ({if (0) dev_printk (KERN_DEBUG, dev, format, # # arg); 0;}) # endif
The following dynamic_dev_dbg () implementation clearly shows that printing is based on descriptor's flag bit _ DPRINTK_FLAGS_PRINT, which can be controlled by dbgfs.
# define dynamic_dev_dbg (dev, fmt,...) Do {DEFINE_DYNAMIC_DEBUG_METADATA (descriptor, fmt); if (unlikely (descriptor.flags & _ DPRINTK_FLAGS_PRINT)) _ dynamic_dev_dbg (& descriptor, dev, fmt, # # _ VA_ARGS__);} while (0) have you mastered the methods of dev_info, dev_dbg, dev_err and dynamic debugging in the Linux kernel after reading the above? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.