162306a36Sopenharmony_ci=================== 262306a36Sopenharmony_ciTracepoints in ALSA 362306a36Sopenharmony_ci=================== 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci2017/07/02 662306a36Sopenharmony_ciTakasahi Sakamoto 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciTracepoints in ALSA PCM core 962306a36Sopenharmony_ci============================ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciALSA PCM core registers ``snd_pcm`` subsystem to kernel tracepoint system. 1262306a36Sopenharmony_ciThis subsystem includes two categories of tracepoints; for state of PCM buffer 1362306a36Sopenharmony_ciand for processing of PCM hardware parameters. These tracepoints are available 1462306a36Sopenharmony_ciwhen corresponding kernel configurations are enabled. When ``CONFIG_SND_DEBUG`` 1562306a36Sopenharmony_ciis enabled, the latter tracepoints are available. When additional 1662306a36Sopenharmony_ci``SND_PCM_XRUN_DEBUG`` is enabled too, the former trace points are enabled. 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ciTracepoints for state of PCM buffer 1962306a36Sopenharmony_ci------------------------------------ 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ciThis category includes four tracepoints; ``hwptr``, ``applptr``, ``xrun`` and 2262306a36Sopenharmony_ci``hw_ptr_error``. 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ciTracepoints for processing of PCM hardware parameters 2562306a36Sopenharmony_ci----------------------------------------------------- 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ciThis category includes two tracepoints; ``hw_mask_param`` and 2862306a36Sopenharmony_ci``hw_interval_param``. 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ciIn a design of ALSA PCM core, data transmission is abstracted as PCM substream. 3162306a36Sopenharmony_ciApplications manage PCM substream to maintain data transmission for PCM frames. 3262306a36Sopenharmony_ciBefore starting the data transmission, applications need to configure PCM 3362306a36Sopenharmony_cisubstream. In this procedure, PCM hardware parameters are decided by 3462306a36Sopenharmony_ciinteraction between applications and ALSA PCM core. Once decided, runtime of 3562306a36Sopenharmony_cithe PCM substream keeps the parameters. 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ciThe parameters are described in struct snd_pcm_hw_params. This 3862306a36Sopenharmony_cistructure includes several types of parameters. Applications set preferable 3962306a36Sopenharmony_civalue to these parameters, then execute ioctl(2) with SNDRV_PCM_IOCTL_HW_REFINE 4062306a36Sopenharmony_cior SNDRV_PCM_IOCTL_HW_PARAMS. The former is used just for refining available 4162306a36Sopenharmony_ciset of parameters. The latter is used for an actual decision of the parameters. 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ciThe struct snd_pcm_hw_params structure has below members: 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci``flags`` 4662306a36Sopenharmony_ci Configurable. ALSA PCM core and some drivers handle this flag to select 4762306a36Sopenharmony_ci convenient parameters or change their behaviour. 4862306a36Sopenharmony_ci``masks`` 4962306a36Sopenharmony_ci Configurable. This type of parameter is described in 5062306a36Sopenharmony_ci struct snd_mask and represent mask values. As of PCM protocol 5162306a36Sopenharmony_ci v2.0.13, three types are defined. 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_ACCESS 5462306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_FORMAT 5562306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_SUBFORMAT 5662306a36Sopenharmony_ci``intervals`` 5762306a36Sopenharmony_ci Configurable. This type of parameter is described in 5862306a36Sopenharmony_ci struct snd_interval and represent values with a range. As of 5962306a36Sopenharmony_ci PCM protocol v2.0.13, twelve types are defined. 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_SAMPLE_BITS 6262306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_FRAME_BITS 6362306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_CHANNELS 6462306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_RATE 6562306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_PERIOD_TIME 6662306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_PERIOD_SIZE 6762306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_PERIOD_BYTES 6862306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_PERIODS 6962306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_BUFFER_TIME 7062306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_BUFFER_SIZE 7162306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_BUFFER_BYTES 7262306a36Sopenharmony_ci - SNDRV_PCM_HW_PARAM_TICK_TIME 7362306a36Sopenharmony_ci``rmask`` 7462306a36Sopenharmony_ci Configurable. This is evaluated at ioctl(2) with 7562306a36Sopenharmony_ci SNDRV_PCM_IOCTL_HW_REFINE only. Applications can select which 7662306a36Sopenharmony_ci mask/interval parameter can be changed by ALSA PCM core. For 7762306a36Sopenharmony_ci SNDRV_PCM_IOCTL_HW_PARAMS, this mask is ignored and all of parameters 7862306a36Sopenharmony_ci are going to be changed. 7962306a36Sopenharmony_ci``cmask`` 8062306a36Sopenharmony_ci Read-only. After returning from ioctl(2), buffer in user space for 8162306a36Sopenharmony_ci struct snd_pcm_hw_params includes result of each operation. 8262306a36Sopenharmony_ci This mask represents which mask/interval parameter is actually changed. 8362306a36Sopenharmony_ci``info`` 8462306a36Sopenharmony_ci Read-only. This represents hardware/driver capabilities as bit flags 8562306a36Sopenharmony_ci with SNDRV_PCM_INFO_XXX. Typically, applications execute ioctl(2) with 8662306a36Sopenharmony_ci SNDRV_PCM_IOCTL_HW_REFINE to retrieve this flag, then decide candidates 8762306a36Sopenharmony_ci of parameters and execute ioctl(2) with SNDRV_PCM_IOCTL_HW_PARAMS to 8862306a36Sopenharmony_ci configure PCM substream. 8962306a36Sopenharmony_ci``msbits`` 9062306a36Sopenharmony_ci Read-only. This value represents available bit width in MSB side of 9162306a36Sopenharmony_ci a PCM sample. When a parameter of SNDRV_PCM_HW_PARAM_SAMPLE_BITS was 9262306a36Sopenharmony_ci decided as a fixed number, this value is also calculated according to 9362306a36Sopenharmony_ci it. Else, zero. But this behaviour depends on implementations in driver 9462306a36Sopenharmony_ci side. 9562306a36Sopenharmony_ci``rate_num`` 9662306a36Sopenharmony_ci Read-only. This value represents numerator of sampling rate in fraction 9762306a36Sopenharmony_ci notation. Basically, when a parameter of SNDRV_PCM_HW_PARAM_RATE was 9862306a36Sopenharmony_ci decided as a single value, this value is also calculated according to 9962306a36Sopenharmony_ci it. Else, zero. But this behaviour depends on implementations in driver 10062306a36Sopenharmony_ci side. 10162306a36Sopenharmony_ci``rate_den`` 10262306a36Sopenharmony_ci Read-only. This value represents denominator of sampling rate in 10362306a36Sopenharmony_ci fraction notation. Basically, when a parameter of 10462306a36Sopenharmony_ci SNDRV_PCM_HW_PARAM_RATE was decided as a single value, this value is 10562306a36Sopenharmony_ci also calculated according to it. Else, zero. But this behaviour depends 10662306a36Sopenharmony_ci on implementations in driver side. 10762306a36Sopenharmony_ci``fifo_size`` 10862306a36Sopenharmony_ci Read-only. This value represents the size of FIFO in serial sound 10962306a36Sopenharmony_ci interface of hardware. Basically, each driver can assigns a proper 11062306a36Sopenharmony_ci value to this parameter but some drivers intentionally set zero with 11162306a36Sopenharmony_ci a care of hardware design or data transmission protocol. 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ciALSA PCM core handles buffer of struct snd_pcm_hw_params when 11462306a36Sopenharmony_ciapplications execute ioctl(2) with SNDRV_PCM_HW_REFINE or SNDRV_PCM_HW_PARAMS. 11562306a36Sopenharmony_ciParameters in the buffer are changed according to 11662306a36Sopenharmony_cistruct snd_pcm_hardware and rules of constraints in the runtime. The 11762306a36Sopenharmony_cistructure describes capabilities of handled hardware. The rules describes 11862306a36Sopenharmony_cidependencies on which a parameter is decided according to several parameters. 11962306a36Sopenharmony_ciA rule has a callback function, and drivers can register arbitrary functions 12062306a36Sopenharmony_cito compute the target parameter. ALSA PCM core registers some rules to the 12162306a36Sopenharmony_ciruntime as a default. 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ciEach driver can join in the interaction as long as it prepared for two stuffs 12462306a36Sopenharmony_ciin a callback of struct snd_pcm_ops.open. 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci1. In the callback, drivers are expected to change a member of 12762306a36Sopenharmony_ci struct snd_pcm_hardware type in the runtime, according to 12862306a36Sopenharmony_ci capacities of corresponding hardware. 12962306a36Sopenharmony_ci2. In the same callback, drivers are also expected to register additional rules 13062306a36Sopenharmony_ci of constraints into the runtime when several parameters have dependencies 13162306a36Sopenharmony_ci due to hardware design. 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ciThe driver can refers to result of the interaction in a callback of 13462306a36Sopenharmony_cistruct snd_pcm_ops.hw_params, however it should not change the 13562306a36Sopenharmony_cicontent. 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ciTracepoints in this category are designed to trace changes of the 13862306a36Sopenharmony_cimask/interval parameters. When ALSA PCM core changes them, ``hw_mask_param`` or 13962306a36Sopenharmony_ci``hw_interval_param`` event is probed according to type of the changed parameter. 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ciALSA PCM core also has a pretty print format for each of the tracepoints. Below 14262306a36Sopenharmony_ciis an example for ``hw_mask_param``. 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci:: 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci hw_mask_param: pcmC0D0p 001/023 FORMAT 00000000000000000000001000000044 00000000000000000000001000000044 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ciBelow is an example for ``hw_interval_param``. 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci:: 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci hw_interval_param: pcmC0D0p 000/023 BUFFER_SIZE 0 0 [0 4294967295] 0 1 [0 4294967295] 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ciThe first three fields are common. They represent name of ALSA PCM character 15662306a36Sopenharmony_cidevice, rules of constraint and name of the changed parameter, in order. The 15762306a36Sopenharmony_cifield for rules of constraint consists of two sub-fields; index of applied rule 15862306a36Sopenharmony_ciand total number of rules added to the runtime. As an exception, the index 000 15962306a36Sopenharmony_cimeans that the parameter is changed by ALSA PCM core, regardless of the rules. 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ciThe rest of field represent state of the parameter before/after changing. These 16262306a36Sopenharmony_cifields are different according to type of the parameter. For parameters of mask 16362306a36Sopenharmony_citype, the fields represent hexadecimal dump of content of the parameter. For 16462306a36Sopenharmony_ciparameters of interval type, the fields represent values of each member of 16562306a36Sopenharmony_ci``empty``, ``integer``, ``openmin``, ``min``, ``max``, ``openmax`` in 16662306a36Sopenharmony_cistruct snd_interval in this order. 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_ciTracepoints in drivers 16962306a36Sopenharmony_ci====================== 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ciSome drivers have tracepoints for developers' convenience. For them, please 17262306a36Sopenharmony_cirefer to each documentation or implementation. 173