Repository navigation
volume: do not schedule ramping as separate task - #2619
Conversation
9ac0b60 to
9981ee3
Compare
lgirdwood
left a comment
There was a problem hiding this comment.
Do you have data ? Are we spinning on a lock or actually consuming too many cycles here ?
For standard format volume_copy uses ~6 MCPS and this task scheduling added additional ~4 MCPS, so it almost doubled time of first copy. I suspect it's due to the fact that ll scheduler's timer domain is synchronized among all the cores, so it uses good portion of uncached memory. Nevertheless, there is no reason to not move it to trigger instead of copy. |
|
@tlauda ok, I'm glad you have the data ~4MPCS seems high for scheduling but we can address that later. Maybe it's better here to do the ramp change calculation as part of copy() ? i.e. no scheduling for volume ramp, we just re-calc the ramp on every copy(). |
My thinking here is that if we sample the timestamp every time the pipeline is scheduled (and subtract the pipeline start time) then components can use this to get the "pipeline time" in order to help with any sync or for items like ramping. Not essential though, just thinking aloud as it may be something useful for future features. |
|
@lgirdwood I assume you are aware edits don't generate notifications for anyone. |
|
@paulstelian97 edit was done about 10 secs after posting so nothing lost. |
|
This is a good catch. A call to schedule() should not be a part of copy() since it is probably not expected to be speed optimized. There are for example trace() calls inside (important ones, so rather should not go to dbg level), many O(n) loops inside that could be optimized if necessary (I believe it is not). Btw schedule_task() behavior looks a bit strange, as it quits silently if there is no schedule_task handler for the specified type. It also keeps on iterating once called the handler - is this intended behavior? I am not sure how to explain that in the API documentation. |
I believe both of your observations are actually bugs in the API. Every schedule call should fail if there is no scheduler available or handler is mandatory (and I believe schedule_task handler is). Also the loop should return after first handler execution, unless we expect multiple schedulers per same type. |
9981ee3 to
389a52a
Compare
|
@lgirdwood Updated. |
|
This makes volume ramp step equals copy scheduling. If the volume is scheduled e.g. every 10 ms the zipper noise from discontinuous audio waveform would be very audible and annoying. The copy() could be of course split to reasonable length parts to avoid zipper noise. Now the macro VOL_RAMP_UPDATE_US becomes ignored. Also the topology defined volume ramp length would go wrong if scheduling is changed from every 1 ms. |
singalsu
left a comment
There was a problem hiding this comment.
You need to include component schedule rate to ramp step calculation. VOL_RAMP_STEP_CONS need to be a variable that's calculated when the scheduling is known.
The volume copy() split to 1 ms parts for ramp update need to be done later if volume is used in lower schedule rate pipelines.
|
@tlauda I maybe missing something here. But when you get a new volume set cmd, volume_ramp() should ramp up/down in increments until the target volume is reached. I do not see a while loop to continue ramping or a reccursive call to volume_ramp() in volume_ctrl_set_cmd(). What am I missing? |
|
@ranj063 No, you're right. I've missed this case. ramp_finished should be set to false, so the ramp will continue in next copies. @lgirdwood @singalsu I didn't think about such scheduling differences. Maybe we should go back to the original idea with starting task on trigger start? It will be easier that way than trying to modify this solution and hoping no mistakes will be done. MCPS are also measured for whole system ticks, so no data will be lost. |
|
@singalsu I see what you are saying, if ramp step time is < period time then we can get zipper. We need to check this at the start of copy so we can scale it correctly during the copy. |
There was a problem hiding this comment.
so you are removing the ramping actually? we did several cycles to ramp up to the target volume, now it will only do the step 1 and stop if it doesn't achieve to the target volume.
There was a problem hiding this comment.
Oh I get your point now, we will continue the ramping in the next .copy() iteration, this is good idea, even we can't finish the ramping target before the pipeline is trigger stopped, we still keep the target volume there so it should be fine.
I adjusted the vol_work() schedule rate a while ago to fix Github error about reported by @plbossart annoying noise when volume is ramped (e.g. press keys 0 - 9 on ASCII alsamixer slider). The value of 1000 us is where with the current volume scale takes some effort to hear the effect. A more dense grid would have been better but I tried to find a good trade-off for subjective volume change quality vs. resources consumed. We can schedule components/pipelies freely. I think 1 ms is max. feasible rate for a low latency system. The schedule could be also lower rate to improve cache performance etc. If volume schedule would be changed to e.g. every 2 ms or more the zipper noise issue would arrive again. I like this idea (the scheduling jitter impacts ramp) but the volume copy() should be split to max. 1ms parts so we can maintain the volume ramp update grid. Also the ramp step computation needs to take into account stream rate and component scheduling. With the independent vol_work() there was no need. The volume in the intrinsic version could be updated with good code even per sample without much overhead to completely make zipper noise issue vanish but it might be overkill. This change by the way has the benefit that without vol_work() the testbench can fully simulate volume component. There's now script volume_run.sh. Convert you wav to raw with sox and run the sound clip with that script... easy to listen zipper sounds! |
|
@singalsu So you're saying that the volume_copy will always need to execute every 1 ms, no matter what is the scheduling period for pipeline? With current pipeline scheduling implementation it's not possible to achieve. Pipelines are treated as a whole and we cannot schedule individual components separately. |
|
@tlauda Not that way! I meant that it's simple in your patch to alter the copy() function is such way that it processes a fixed amount between volume ramp updates. E.g. 3 ms scheduling. With timer based scheduling there's a bit jitter in number of frames to process in each copy() but this doesn not need to be perfect. E.g. the last block can be a bit longer or shorter. You need to calculate how many frames to call the process function to not exceed the max ramp update time so that a steady ramp slope is achieved. The N to process depends on stream sample rate. |
|
@tlauda @singalsu how are we in terms of MCPS ? if ZC is disabled there should be no impact.
|
Rough numbers for 48 kHz, 32 bit, 2 channels:
|
|
Ok, @singalsu @tlauda do these numbers look ok for you. Btw, what happens when the ramp is complete ? do the ZC numbers go back to non ZC values ?
Dividing 3 & 4 by 10 (for period size) looks reasonable to be and inline with 1 ms period.. |
Yes, they go back to non ZC values. |
|
Jenkins has known issues. Internal CI seems to be unrelated WHL failures. Retry. |
|
SOFCI TEST |
d1dcc7c to
c936880
Compare
|
@singalsu Changes applied. |
|
@tlauda out of contest question:
|
|
After merge can you do a separate PR to enable ZC volume mode in some topology to enable to keep it tested in CI? E.g. @fredoh9 and @xiulipan could suggest platforms with possibility to test such. We also need tests to check audio level envelope while volume is being controlled to ensure the ramps and mute/unmute happens. |
c936880 to
20133a7
Compare
|
There's some difference in overall ramp time in the two modes. Without ZC correct 250 ms and in this case with ZC (997 Hz sine) about 220 ms. The step logic has some flaw likely. With testbench (need #2824) Edit: Both sound OK. In spectral view there's slightly less high-frequency content with ZC and from the irregularity in noise spectra it can be seen that ZC is indeed selecting the gain update position. |
|
@singalsu Isn't it because we are always assuming ramp increment step of 1 ms? But with ZC we can get slightly lesser granularity, which ends up in faster ramp time. |
|
The step value should be recomputed for actual update if you don't add a no-updates allowed wait time. |
20133a7 to
97343d3
Compare
|
@singalsu Added ramp step recalculation. It looks like ZC has the right ramp time now. |
|
@tlauda @singalsu will try to work with @ClarexZhou @keqiaozhang to create some new test case for this feature. |
a670fd2 to
ea9f6c2
Compare
There was a problem hiding this comment.
I'm worried about this since the pre-processor can't compute this. Does this emit emulated float code?
There was a problem hiding this comment.
So the float code likely appears here. Can you check it and convert to all-integer fractional math.
There was a problem hiding this comment.
I think I don't fully understand. The macro expands to Q_CONVERT_FLOAT, which explicitly casts to float. What do you mean by converting to "all-integer fractional math"?
There was a problem hiding this comment.
The divide by 1000.0 becomes a run-time float divide if the argument to VOL_RAMP_STEP_CONST(x) is not a constant number calculated by pre-processor. Did you look into disassembly how this got handled?
Fractional arithmetic uses mostly fixed multiplication, and more costly fixed division if integer multiply by inverse is not available. I'm not sure this change emitted C library float code but since there was need to adjust memory I wonder if it happened.
There was a problem hiding this comment.
Also if things get complicated instead of step size compute (where error does accumulate a bit) the actual gain could be computed from time since volume transition start.
There was a problem hiding this comment.
@singalsu Yes, unfortunately it looks like float code is generated.
There was a problem hiding this comment.
It's off-topic but I wonder if it would be possible create compile error if argument for Q_CONVERT_FLOAT() is not a constant value. It's a useful macro but hides this risk.
singalsu
left a comment
There was a problem hiding this comment.
Please check that there's no floats math generated.
Implements functions for getting nearest zero crossing frame. They will be used to reduce zipper noise during volume ramping by updating ramp only on such frames. In the current implementation average value of all channels is used to check sample sign change. Signed-off-by: Tomasz Lauda <tomasz.lauda@linux.intel.com>
We should not be scheduling ramping as a separate task. This patch makes it a part of copy function, which allows for removal of entire schedule related code. Ramping is done in maximum of 1 ms chunks by using functions for retrieval of nearest zero crossing frame. Signed-off-by: Tomasz Lauda <tomasz.lauda@linux.intel.com>
ea9f6c2 to
5486b2f
Compare


We should not be scheduling ramping as a separate task.
This patch makes it a part of copy function, which allows
for removal of entire schedule related code.
Signed-off-by: Tomasz Lauda tomasz.lauda@linux.intel.com