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