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