Page MenuHomeFreeBSD

sound: Simplify locking during device creation
AcceptedPublic

Authored by christos on Thu, Jan 16, 2:00 PM.
Tags
None
Referenced Files
F108086353: D48482.diff
Tue, Jan 21, 6:32 AM
Unknown Object (File)
Sun, Jan 19, 1:09 PM
Unknown Object (File)
Sun, Jan 19, 7:16 AM
Unknown Object (File)
Sun, Jan 19, 5:44 AM
Unknown Object (File)
Sun, Jan 19, 3:14 AM
Subscribers

Details

Summary

The mechanism of acquiring SD_F_BUSY in pcm_init() and releasing it in
pcm_register() is a leftover from the previous device creation scheme,
where pcm_init() (previously pcm_register()) would create the sysctl
nodes, as well as the device node. In this scenario, acquiring SD_F_BUSY
was necessary, in order to avoid races in case the device was accessed
before the device was ready for use. Commit 66f3eb14e955 ("sound: Move
sysctl and /dev/dspX creation to pcm_setstatus()") fixed this issue, so
we can simplify things now. Only acquire SD_F_BUSY in pcm_addchan(),
because chn_init() expects to be called with SD_F_BUSY acquired.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 61766
Build 58650: arc lint + arc unit

Event Timeline

So now we busy the pcm device during creation of each channel, but the busy state is not maintained between pcm_addchan() calls. I guess we are not worried about something happening in between those calls which might disturb initialization and registration?

So now we busy the pcm device during creation of each channel, but the busy state is not maintained between pcm_addchan() calls. I guess we are not worried about something happening in between those calls which might disturb initialization and registration?

If it wasn't for the fact that chn_init() is called during runtime as well, then I think it wouldn't make sense to busy the device in pcm_addchan() either. Is there a scenario I'm currently missing? If we're creating the sysctl and device nodes at the end of the device registration, then we are safe from the registration being disturbed by external factors (i.e a process, or the user).

So now we busy the pcm device during creation of each channel, but the busy state is not maintained between pcm_addchan() calls. I guess we are not worried about something happening in between those calls which might disturb initialization and registration?

If it wasn't for the fact that chn_init() is called during runtime as well, then I think it wouldn't make sense to busy the device in pcm_addchan() either. Is there a scenario I'm currently missing? If we're creating the sysctl and device nodes at the end of the device registration, then we are safe from the registration being disturbed by external factors (i.e a process, or the user).

Right, the model we're using here is, the device is newly created, so there are no references to it that another thread might use to somehow manipulate its state unexpectedly. Once you call pcm_addchan(), though, that's not really true anymore. At that point it's hard (for me) to say whether the busy lock is required or not.

So now we busy the pcm device during creation of each channel, but the busy state is not maintained between pcm_addchan() calls. I guess we are not worried about something happening in between those calls which might disturb initialization and registration?

If it wasn't for the fact that chn_init() is called during runtime as well, then I think it wouldn't make sense to busy the device in pcm_addchan() either. Is there a scenario I'm currently missing? If we're creating the sysctl and device nodes at the end of the device registration, then we are safe from the registration being disturbed by external factors (i.e a process, or the user).

Right, the model we're using here is, the device is newly created, so there are no references to it that another thread might use to somehow manipulate its state unexpectedly. Once you call pcm_addchan(), though, that's not really true anymore. At that point it's hard (for me) to say whether the busy lock is required or not.

Even though the channels are created, they cannot be accessed if there's no sysctl or device node yet. Isn't it the case that up until the point that we create the sysctls and device, this code is executed only by a single thread?

I should also mention that the channels pcm_addchan() creates are the primary (i.e. hardware) ones, and they are not assigned to any process at that point.

This revision is now accepted and ready to land.Thu, Jan 16, 3:48 PM

While here, move the sndstat_register() call further down to be more robust.
There is no good reason to have it where it is. I think we can include this
change in this patch.

This revision now requires review to proceed.Thu, Jan 16, 4:44 PM

@markj Could you give it a re-accept if it's good?

This revision is now accepted and ready to land.Sat, Jan 18, 3:06 PM