On Thu, 13 Apr 2023 16:59:02 +0200, Oswald Buddenhagen wrote: > > On Thu, Apr 13, 2023 at 02:06:49PM +0200, Takashi Iwai wrote: > > On Thu, 13 Apr 2023 13:10:34 +0200, Oswald Buddenhagen wrote: > >> i don't think that's true. if an app wants to control things finely, > >> it would just use start/stop and manage the timing itself. draining > >> otoh is a convenient fire-and-forget operation. that makes it easy to > >> miss the finer details, which is why i'm so insistent that it should > >> just work out of the box. > > > > Sure, but that's still no excuse to ignore the possibility blindly. > > > it's not blindly. it's after considering it, and concluding that it's > a hypothetical problem at best. > > we could of course do a survey of actually existing publicly > accessible code, to quantify the trade-off between apps fixed and apps > broken. i actually sort of tried that ... > > first thing is that i found lots of stackoverflow answers and similar, > and *none* of them even mentioned the need to clear the rest of the > buffer. i found a bunch of libs, and none of the apidocs mentioned it > in the parts i read. i found one cross-platform how-to which did > actually mention it. yay. > > code search was trickier, with rather predictable results: > basically all hits for drain() were immediately followed by close(). > i found some simple cases of write+drain, and none of them did any > additional padding. this includes alsa's own pcm example. but never > mind, we're in agreement about this case. > most other code was some abstraction, so it would be impossible to > asses the bigger picture quickly. > that would be even more the case for apps that use mmap. so i won't > even try to provide actual data. > one thing to consider here is that most of the code are cross-platform > abstractions. under such circumstances, it seems kinda inconceivable > that the higher level code would make any assumptions about buffer > space that has not been filled with fresh samples. Those whole context should have been mentioned before the discussion... But still we'd better survey the actual usage for the decision. ATM, I still hesitate taking the behavior change in the kernel, *iff* it can be worked around differently. While the mmap situation is admittedly a corner case, the point of alsa-lib implementation is the flexibility. And, your implementation means to modify the mmapped data silently, which never happened in the past -- this is another side of coin of fixing in API side, and we don't know the side-effect to any wild applications. Some additional configuration or flexible workaround might be required, and that's often harder to apply in the kernel. And, another concern is, as already discussed, whether we really have to apply it unconditionally at every draining call. Obviously the workaround is superfluous for the drivers like USB-audio, which never overrun without the filled data. > >> and doing it all in user space is yet more code. for all i can > >> tell, it's really just layers of complexity to solve a non-problem. > > > > I don't get it: we're talking about the sw_params call in alsa-lib's > > drain function, and how can it be *so* complex...? > > > the "drain function" bit is critical here, because it kind of implies > resetting it, potentially asynchronously. but if we add a specific bit > to the kernel to enable it, then it can be actually set already when > the device is set up, and the user space would be rather > simple. however, that would overall be still a lot more code than > doing it unconditionally, and fully in kernel. Indeed we might want to take the kernel-side fix in the end, but let's check things a bit more beforehand. BTW, I guess that one missing piece in your patch is the case where the drain is called at the moment of fully filled data. You added snd_pcm_playback_silence() at snd_pcm_do_drain_init(), but in this scenario, the call wouldn't do anything at this moment. But snd_pcm_playback_silence() won't be called afterwards because runtime->silence_size = 0. So this workaround won't take effect in that case, no? thanks, Takashi