Page MenuHomeFreeBSD

sound: Untangle dsp_cdevs[] and dsp_unit2name() confusion
ClosedPublic

Authored by christos on Oct 19 2024, 5:06 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Dec 14, 12:26 PM
Unknown Object (File)
Tue, Dec 10, 2:46 PM
Unknown Object (File)
Thu, Dec 5, 8:12 AM
Unknown Object (File)
Thu, Dec 5, 6:46 AM
Unknown Object (File)
Wed, Dec 4, 4:48 PM
Unknown Object (File)
Fri, Nov 29, 9:23 PM
Unknown Object (File)
Nov 24 2024, 3:25 PM
Unknown Object (File)
Nov 21 2024, 6:46 AM
Subscribers

Details

Summary

Before de8c0d15a64fa ("sound: Get rid of snd_clone and use
DEVFS_CDEVPRIV(9)"), sound(4) would create one device for each allocated
channel. The device names would be chosen from dsp_cdevs[], and created
with dsp_unit2name(). Additionally, dsp_cdevs[] was also used to match
these devices names, as well as OSSv4 aliases in dsp_clone().

Since sound(4) does not create separate devices for each channel
anymore, the meaning and use dsp_cdevs[] has changed. Part of it no
longer corresponds to devices at all, but instead is used to create
channel names, and another part is used to match only OSSv4 aliases in
dsp_clone().

To address this confusion, separate dsp_cdevs[] into a dsp_aliases[]
array, and move dsp_unit2name() to pcm/channel.c and rename it to
chn_mkname().

While here, get rid of the SND_DEV_DSPHW_* channel types, and simply use
the existing PCMDIR_* constants as the channel types. There is no need
to duplicate the same meaning twice.

Sponsored by: The FreeBSD Foundation
MFC after: 2 days

Diff Detail

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

Event Timeline

Make some cases fallthrough in chn_init() switch statement.

This simplifies the code quite a bit, nice! Some nitpicks in the inline comments.

sys/dev/sound/pcm/channel.c
1178–1186

Is there still a reason to keep the chn_names array like this when all access goes through chn_mkname()? Could be mapped in a switch maybe?

1221–1223

If I read style(9) correctly, there should be fallthrough comment:

Elements in a switch statement that cascade should have a FALLTHROUGH comment.

1224–1227

Same here.

sys/dev/sound/pcm/dsp.c
2233–2234

Is there a need to create the channel name here? I don't see devname or buf used in any way, except for a check that it's not NULL. Like this it's just a costly check of the channel type, no?

christos marked 4 inline comments as done.

Address Florian's comments:

  • Get rid of chn_names[] and integrate it into a switch statement in chn_mkname().
  • Refactor dsp_oss_engineinfo() to not use chn_mkname(). Should give us some performance boost as well.

s/rec/record/ in chn_mkname().

sys/dev/sound/pcm/channel.c
1188

IMHO these would be more readable as "dsp%d.play.%d" quasi template strings. Not really important though.

sys/dev/sound/pcm/dsp.c
2242–2246

Shouldn't we continue to iterate through the pcm units here?

sys/dev/sound/pcm/channel.c
1188

This way we'd duplicate dsp%d...%d in all the switch cases, though.

sys/dev/sound/pcm/dsp.c
2242–2246

Yes, I updated the diff in my local tree yesterday, but forgot to update it here as well.

Remove redundant chn_mkname() call in vchan_passthrough().

sys/dev/sound/pcm/channel.c
1188

Alternatively, move the separating dots into the printf literal: "dsp%d.%s.%d"

sys/dev/sound/pcm/dsp.c
2242–2246

Ok, but don't we also have to unlock the CHN_LOCK(ch); here?

sys/dev/sound/pcm/dsp.c
2242–2246

My bad, forget about last comment - the question is whether ch is set to NULL when the channel is not found?

christos added inline comments.
sys/dev/sound/pcm/channel.c
1188

I agree with this.

sys/dev/sound/pcm/dsp.c
2242–2246

It is.

christos marked 3 inline comments as done.

Address Florian's comments for chn_mkname().

sys/dev/sound/pcm/dsp.c
2242–2246

Indeed, it's set to NULL by the SLIST implementation. Is that behavior guaranteed or documented somewhere? Don't know about FreeBSD src customs, but in other projects I wouldn't rely on that if it's not part of the documented interface.

christos added inline comments.
sys/dev/sound/pcm/dsp.c
2242–2246

I see that it's documented for TAILQ_FOREACH, but I am not sure why it's not for the other queue(3) types.
@des @imp Any info on this?

sys/dev/sound/pcm/channel.c
1221–1223

I guess style(9) should be more explicit - FALLTHROUGH is needed when it otherwise looks like a break is missing, but not for multiple cases that share the same body. Note that style(9)'s FALLTHROUGH example has code for case 'a': and the FALLTHROUGH indicates that it's intentional to fall through to the case 'b': code. So leave these ones out.

Submitted D47242 for a style.9 update.

christos marked an inline comment as done.

Remove "FALLTHROUGH".

@emaste: Thanks for the clarification on style(9)'s FALLTHROUGH part.

@christos: Sorry for the misleading comment.

So is the patch good to go?

I'm still undecided on the CHN_FOREACH() postcondition of ch == NULL. Tried to find precedence, but I only see implementations that set additional variables like found = true;. Although unlikely to change, this may result in a really hard to spot error when the postcondition doesn't hold.

So is the patch good to go?

I'm still undecided on the CHN_FOREACH() postcondition of ch == NULL. Tried to find precedence, but I only see implementations that set additional variables like found = true;. Although unlikely to change, this may result in a really hard to spot error when the postcondition doesn't hold.

Both imp@ and markj@ confirmed that this behavior is more or less guaranteed, and plenty of code relies on that assumption already.

This revision is now accepted and ready to land.Oct 24 2024, 11:25 AM