tracepoints.rst 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. ===================
  2. Tracepoints in ALSA
  3. ===================
  4. 2017/07/02
  5. Takasahi Sakamoto
  6. Tracepoints in ALSA PCM core
  7. ============================
  8. ALSA PCM core registers ``snd_pcm`` subsystem to kernel tracepoint system.
  9. This subsystem includes two categories of tracepoints; for state of PCM buffer
  10. and for processing of PCM hardware parameters. These tracepoints are available
  11. when corresponding kernel configurations are enabled. When ``CONFIG_SND_DEBUG``
  12. is enabled, the latter tracepoints are available. When additional
  13. ``SND_PCM_XRUN_DEBUG`` is enabled too, the former trace points are enabled.
  14. Tracepoints for state of PCM buffer
  15. ------------------------------------
  16. This category includes four tracepoints; ``hwptr``, ``applptr``, ``xrun`` and
  17. ``hw_ptr_error``.
  18. Tracepoints for processing of PCM hardware parameters
  19. -----------------------------------------------------
  20. This category includes two tracepoints; ``hw_mask_param`` and
  21. ``hw_interval_param``.
  22. In a design of ALSA PCM core, data transmission is abstracted as PCM substream.
  23. Applications manage PCM substream to maintain data transmission for PCM frames.
  24. Before starting the data transmission, applications need to configure PCM
  25. substream. In this procedure, PCM hardware parameters are decided by
  26. interaction between applications and ALSA PCM core. Once decided, runtime of
  27. the PCM substream keeps the parameters.
  28. The parameters are described in struct snd_pcm_hw_params. This
  29. structure includes several types of parameters. Applications set preferable
  30. value to these parameters, then execute ioctl(2) with SNDRV_PCM_IOCTL_HW_REFINE
  31. or SNDRV_PCM_IOCTL_HW_PARAMS. The former is used just for refining available
  32. set of parameters. The latter is used for an actual decision of the parameters.
  33. The struct snd_pcm_hw_params structure has below members:
  34. ``flags``
  35. Configurable. ALSA PCM core and some drivers handle this flag to select
  36. convenient parameters or change their behaviour.
  37. ``masks``
  38. Configurable. This type of parameter is described in
  39. struct snd_mask and represent mask values. As of PCM protocol
  40. v2.0.13, three types are defined.
  41. - SNDRV_PCM_HW_PARAM_ACCESS
  42. - SNDRV_PCM_HW_PARAM_FORMAT
  43. - SNDRV_PCM_HW_PARAM_SUBFORMAT
  44. ``intervals``
  45. Configurable. This type of parameter is described in
  46. struct snd_interval and represent values with a range. As of
  47. PCM protocol v2.0.13, twelve types are defined.
  48. - SNDRV_PCM_HW_PARAM_SAMPLE_BITS
  49. - SNDRV_PCM_HW_PARAM_FRAME_BITS
  50. - SNDRV_PCM_HW_PARAM_CHANNELS
  51. - SNDRV_PCM_HW_PARAM_RATE
  52. - SNDRV_PCM_HW_PARAM_PERIOD_TIME
  53. - SNDRV_PCM_HW_PARAM_PERIOD_SIZE
  54. - SNDRV_PCM_HW_PARAM_PERIOD_BYTES
  55. - SNDRV_PCM_HW_PARAM_PERIODS
  56. - SNDRV_PCM_HW_PARAM_BUFFER_TIME
  57. - SNDRV_PCM_HW_PARAM_BUFFER_SIZE
  58. - SNDRV_PCM_HW_PARAM_BUFFER_BYTES
  59. - SNDRV_PCM_HW_PARAM_TICK_TIME
  60. ``rmask``
  61. Configurable. This is evaluated at ioctl(2) with
  62. SNDRV_PCM_IOCTL_HW_REFINE only. Applications can select which
  63. mask/interval parameter can be changed by ALSA PCM core. For
  64. SNDRV_PCM_IOCTL_HW_PARAMS, this mask is ignored and all of parameters
  65. are going to be changed.
  66. ``cmask``
  67. Read-only. After returning from ioctl(2), buffer in user space for
  68. struct snd_pcm_hw_params includes result of each operation.
  69. This mask represents which mask/interval parameter is actually changed.
  70. ``info``
  71. Read-only. This represents hardware/driver capabilities as bit flags
  72. with SNDRV_PCM_INFO_XXX. Typically, applications execute ioctl(2) with
  73. SNDRV_PCM_IOCTL_HW_REFINE to retrieve this flag, then decide candidates
  74. of parameters and execute ioctl(2) with SNDRV_PCM_IOCTL_HW_PARAMS to
  75. configure PCM substream.
  76. ``msbits``
  77. Read-only. This value represents available bit width in MSB side of
  78. a PCM sample. When a parameter of SNDRV_PCM_HW_PARAM_SAMPLE_BITS was
  79. decided as a fixed number, this value is also calculated according to
  80. it. Else, zero. But this behaviour depends on implementations in driver
  81. side.
  82. ``rate_num``
  83. Read-only. This value represents numerator of sampling rate in fraction
  84. notation. Basically, when a parameter of SNDRV_PCM_HW_PARAM_RATE was
  85. decided as a single value, this value is also calculated according to
  86. it. Else, zero. But this behaviour depends on implementations in driver
  87. side.
  88. ``rate_den``
  89. Read-only. This value represents denominator of sampling rate in
  90. fraction notation. Basically, when a parameter of
  91. SNDRV_PCM_HW_PARAM_RATE was decided as a single value, this value is
  92. also calculated according to it. Else, zero. But this behaviour depends
  93. on implementations in driver side.
  94. ``fifo_size``
  95. Read-only. This value represents the size of FIFO in serial sound
  96. interface of hardware. Basically, each driver can assigns a proper
  97. value to this parameter but some drivers intentionally set zero with
  98. a care of hardware design or data transmission protocol.
  99. ALSA PCM core handles buffer of struct snd_pcm_hw_params when
  100. applications execute ioctl(2) with SNDRV_PCM_HW_REFINE or SNDRV_PCM_HW_PARAMS.
  101. Parameters in the buffer are changed according to
  102. struct snd_pcm_hardware and rules of constraints in the runtime. The
  103. structure describes capabilities of handled hardware. The rules describes
  104. dependencies on which a parameter is decided according to several parameters.
  105. A rule has a callback function, and drivers can register arbitrary functions
  106. to compute the target parameter. ALSA PCM core registers some rules to the
  107. runtime as a default.
  108. Each driver can join in the interaction as long as it prepared for two stuffs
  109. in a callback of struct snd_pcm_ops.open.
  110. 1. In the callback, drivers are expected to change a member of
  111. struct snd_pcm_hardware type in the runtime, according to
  112. capacities of corresponding hardware.
  113. 2. In the same callback, drivers are also expected to register additional rules
  114. of constraints into the runtime when several parameters have dependencies
  115. due to hardware design.
  116. The driver can refers to result of the interaction in a callback of
  117. struct snd_pcm_ops.hw_params, however it should not change the
  118. content.
  119. Tracepoints in this category are designed to trace changes of the
  120. mask/interval parameters. When ALSA PCM core changes them, ``hw_mask_param`` or
  121. ``hw_interval_param`` event is probed according to type of the changed parameter.
  122. ALSA PCM core also has a pretty print format for each of the tracepoints. Below
  123. is an example for ``hw_mask_param``.
  124. ::
  125. hw_mask_param: pcmC0D0p 001/023 FORMAT 00000000000000000000001000000044 00000000000000000000001000000044
  126. Below is an example for ``hw_interval_param``.
  127. ::
  128. hw_interval_param: pcmC0D0p 000/023 BUFFER_SIZE 0 0 [0 4294967295] 0 1 [0 4294967295]
  129. The first three fields are common. They represent name of ALSA PCM character
  130. device, rules of constraint and name of the changed parameter, in order. The
  131. field for rules of constraint consists of two sub-fields; index of applied rule
  132. and total number of rules added to the runtime. As an exception, the index 000
  133. means that the parameter is changed by ALSA PCM core, regardless of the rules.
  134. The rest of field represent state of the parameter before/after changing. These
  135. fields are different according to type of the parameter. For parameters of mask
  136. type, the fields represent hexadecimal dump of content of the parameter. For
  137. parameters of interval type, the fields represent values of each member of
  138. ``empty``, ``integer``, ``openmin``, ``min``, ``max``, ``openmax`` in
  139. struct snd_interval in this order.
  140. Tracepoints in drivers
  141. ======================
  142. Some drivers have tracepoints for developers' convenience. For them, please
  143. refer to each documentation or implementation.