Page MenuHomeFreeBSD

speaker(4): drop NEEDGIANT
Needs ReviewPublic

Authored by knz_thaumogen.net on Dec 10 2025, 8:42 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Jan 20, 12:29 PM
Unknown Object (File)
Fri, Jan 16, 1:42 PM
Unknown Object (File)
Fri, Jan 16, 1:33 PM
Unknown Object (File)
Fri, Jan 16, 4:43 AM
Unknown Object (File)
Thu, Jan 15, 9:56 PM
Unknown Object (File)
Thu, Jan 15, 8:54 PM
Unknown Object (File)
Thu, Jan 15, 6:14 PM
Unknown Object (File)
Wed, Jan 14, 3:38 AM
Subscribers

Details

Reviewers
imp
phk
Summary

(NB: I also uploaded this change to github PR 1922 because I wasn't sure which one is being used more these days. That PR contains more compact commit messages.)

The calls to disable_intr() / enable_intr() in spkr.c were leftover from previous refactorings and unnecessary for correctness, so this PR removes them.

My detailed analysis of why this change is correct can be found here:

The main related commit referenced in the analysis is this 2008 change by phk: e465985 - where a mutex was added to clock.c and the disable_intr/enable_intr pair could have been removed, but wasn't.

Motivation: I am a fervent spkr(4) user and would like it to persist beyond FreeBSD 16, so we needed to do something about its use of the GIANT mutex.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

knz_thaumogen.net created this revision.

My previous upload was incomplete.

knz_thaumogen.net edited the summary of this revision. (Show Details)

I don't think this is actually sufficient, but I don't think fixing it will be all that hard. sprkopen currently uses the fact that it's locked by Giant, so you'll probably want one spkr mutex to be taken in spkropen() and spkrclose() to be sure it's only opened by a single thread (and not leaking an allocation if spkr_inbuf gets clobbered`).

spkrwrite / spkrioctl might debatably need their own synchronization to provide some ordering in case something's trying to be funky and dup the fd and use it from multiple threads, but I would rather suspect that doesn't happen much / at all in practice?

sys/dev/speaker/spkr.c
30

We generally just omit it at the point that we're not setting anything

forgot an include in last revision

I am quite confused about what happened here. Can you explain the connection between my previous note and the changes made?

sprkopen currently uses the fact that it's locked by Giant, so you'll probably want one spkr mutex to be taken in spkropen() and spkrclose() to be sure it's only opened by a single thread

-> changed spkr_active to spkr_dev_busy, and using an atomic compare-and-set to obtain the "only one open at a time" semantics that you recommended.

spkrwrite / spkrioctl might debatably need their own synchronization to provide some ordering in case something's trying to be funky and dup the fd and use it from multiple threads

-> added a separate mutex spkr_lock to serialize calls to write/ioctl.

Ahh, sorry, I got confused with the missing context- can you reupload this with either git-arc or -U99999, please? It's immensely useful to be able to scroll back up and confirm where different hunks are applying

Ahh, sorry, I got confused with the missing context- can you reupload this with either git-arc or -U99999, please?

Done. But IMHO I find this workflow tremendously impractical. With github I can do 1) fine-grained commits, with separate commit per logical change and 2) git push -f to update the PR.

Here all this gets mashed up together and I need to copy-paste the diff manually in a HTML form... 😭

knz_thaumogen.net marked an inline comment as done.

forgot a return path

Ahh, sorry, I got confused with the missing context- can you reupload this with either git-arc or -U99999, please?

Done. But IMHO I find this workflow tremendously impractical. With github I can do 1) fine-grained commits, with separate commit per logical change and 2) git push -f to update the PR.

Here all this gets mashed up together and I need to copy-paste the diff manually in a HTML form... 😭

Yeah, I know. =( git-arc makes phab considerably easier to cope with for the latter point, but yeah. Let's just move to GitHub for this one.