media_specific_debugging_guide.rst 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ============================================
  3. Debugging and tracing in the media subsystem
  4. ============================================
  5. This document serves as a starting point and lookup for debugging device
  6. drivers in the media subsystem and to debug these drivers from userspace.
  7. .. contents::
  8. :depth: 3
  9. General debugging advice
  10. ------------------------
  11. For general advice see the :doc:`general advice document
  12. </process/debugging/index>`.
  13. The following sections show you some of the available tools.
  14. dev_debug module parameter
  15. --------------------------
  16. Every video device provides a ``dev_debug`` parameter, which allows to get
  17. further insights into the IOCTLs in the background.::
  18. # cat /sys/class/video4linux/video3/name
  19. rkvdec
  20. # echo 0xff > /sys/class/video4linux/video3/dev_debug
  21. # dmesg -wH
  22. [...] videodev: v4l2_open: video3: open (0)
  23. [ +0.000036] video3: VIDIOC_QUERYCAP: driver=rkvdec, card=rkvdec,
  24. bus=platform:rkvdec, version=0x00060900, capabilities=0x84204000,
  25. device_caps=0x04204000
  26. For the full documentation see :ref:`driver-api/media/v4l2-dev:video device
  27. debugging`
  28. dev_dbg() / v4l2_dbg()
  29. ----------------------
  30. Two debug print statements, which are specific for devices and for the v4l2
  31. subsystem, avoid adding these to your final submission unless they have
  32. long-term value for investigations.
  33. For a general overview please see the
  34. :ref:`process/debugging/driver_development_debugging_guide:printk() & friends`
  35. guide.
  36. - Difference between both?
  37. - v4l2_dbg() utilizes v4l2_printk() under the hood, which further uses
  38. printk() directly, thus it cannot be targeted by dynamic debug
  39. - dev_dbg() can be targeted by dynamic debug
  40. - v4l2_dbg() has a more specific prefix format for the media subsystem, while
  41. dev_dbg only highlights the driver name and the location of the log
  42. Dynamic debug
  43. -------------
  44. A method to trim down the debug output to your needs.
  45. For general advice see the
  46. :ref:`process/debugging/userspace_debugging_guide:dynamic debug` guide.
  47. Here is one example, that enables all available pr_debug()'s within the file::
  48. $ alias ddcmd='echo $* > /proc/dynamic_debug/control'
  49. $ ddcmd '-p; file v4l2-h264.c +p'
  50. $ grep =p /proc/dynamic_debug/control
  51. drivers/media/v4l2-core/v4l2-h264.c:372 [v4l2_h264]print_ref_list_b =p
  52. "ref_pic_list_b%u (cur_poc %u%c) %s"
  53. drivers/media/v4l2-core/v4l2-h264.c:333 [v4l2_h264]print_ref_list_p =p
  54. "ref_pic_list_p (cur_poc %u%c) %s\n"
  55. Ftrace
  56. ------
  57. An internal kernel tracer that can trace static predefined events, function
  58. calls, etc. Very useful for debugging problems without changing the kernel and
  59. understanding the behavior of subsystems.
  60. For general advice see the
  61. :ref:`process/debugging/userspace_debugging_guide:ftrace` guide.
  62. DebugFS
  63. -------
  64. This tool allows you to dump or modify internal values of your driver to files
  65. in a custom filesystem.
  66. For general advice see the
  67. :ref:`process/debugging/driver_development_debugging_guide:debugfs` guide.
  68. Perf & alternatives
  69. -------------------
  70. Tools to measure the various stats on a running system to diagnose issues.
  71. For general advice see the
  72. :ref:`process/debugging/userspace_debugging_guide:perf & alternatives` guide.
  73. Example for media devices:
  74. Gather statistics data for a decoding job: (This example is on a RK3399 SoC
  75. with the rkvdec codec driver using the `fluster test suite
  76. <https://github.com/fluendo/fluster>`__)::
  77. perf stat -d python3 fluster.py run -d GStreamer-H.264-V4L2SL-Gst1.0 -ts
  78. JVT-AVC_V1 -tv AUD_MW_E -j1
  79. ...
  80. Performance counter stats for 'python3 fluster.py run -d
  81. GStreamer-H.264-V4L2SL-Gst1.0 -ts JVT-AVC_V1 -tv AUD_MW_E -j1 -v':
  82. 7794.23 msec task-clock:u # 0.697 CPUs utilized
  83. 0 context-switches:u # 0.000 /sec
  84. 0 cpu-migrations:u # 0.000 /sec
  85. 11901 page-faults:u # 1.527 K/sec
  86. 882671556 cycles:u # 0.113 GHz (95.79%)
  87. 711708695 instructions:u # 0.81 insn per cycle (95.79%)
  88. 10581935 branches:u # 1.358 M/sec (15.13%)
  89. 6871144 branch-misses:u # 64.93% of all branches (95.79%)
  90. 281716547 L1-dcache-loads:u # 36.144 M/sec (95.79%)
  91. 9019581 L1-dcache-load-misses:u # 3.20% of all L1-dcache accesses (95.79%)
  92. <not supported> LLC-loads:u
  93. <not supported> LLC-load-misses:u
  94. 11.180830431 seconds time elapsed
  95. 1.502318000 seconds user
  96. 6.377221000 seconds sys
  97. The availability of events and metrics depends on the system you are running.
  98. Error checking & panic analysis
  99. -------------------------------
  100. Various Kernel configuration options to enhance error detection of the Linux
  101. Kernel with the cost of lowering performance.
  102. For general advice see the
  103. :ref:`process/debugging/driver_development_debugging_guide:kasan, ubsan,
  104. lockdep and other error checkers` guide.
  105. Driver verification with v4l2-compliance
  106. ----------------------------------------
  107. To verify, that a driver adheres to the v4l2 API, the tool v4l2-compliance is
  108. used, which is part of the `v4l_utils
  109. <https://git.linuxtv.org/v4l-utils.git>`__, a suite of userspace tools to work
  110. with the media subsystem.
  111. To see the detailed media topology (and check it) use::
  112. v4l2-compliance -M /dev/mediaX --verbose
  113. You can also run a full compliance check for all devices referenced in the
  114. media topology with::
  115. v4l2-compliance -m /dev/mediaX
  116. Debugging problems with receiving video
  117. ---------------------------------------
  118. Implementing vidioc_log_status in the driver: this can log the current status
  119. to the kernel log. It's called by v4l2-ctl --log-status. Very useful for
  120. debugging problems with receiving video (TV/S-Video/HDMI/etc) since the video
  121. signal is external (so unpredictable). Less useful with camera sensor inputs
  122. since you have control over what the camera sensor does.
  123. Usually you can just assign the default::
  124. .vidioc_log_status = v4l2_ctrl_log_status,
  125. But you can also create your own callback, to create a custom status log.
  126. You can find an example in the cobalt driver
  127. (`drivers/media/pci/cobalt/cobalt-v4l2.c <https://elixir.bootlin.com/linux/v6.11.6/source/drivers/media/pci/cobalt/cobalt-v4l2.c#L567>`__).
  128. **Copyright** ©2024 : Collabora