From nobody Fri Oct 18 08:45:02 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XVJDb20wKz5YwHR; Fri, 18 Oct 2024 08:45:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XVJDZ6XNLz4mLc; Fri, 18 Oct 2024 08:45:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729241102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OIlKntomP9j0zBRAmntSN/orkdXYG+tNPOEOWlkLats=; b=EsdPkfarfsCBlO7HQZ2WEln7z2FCoVYCfipzeUD4RK37bYYvPv1dgsGoGMJENv9Zp7vlxL nhykwbdjWAh2f82LuMC7DtUVmGgru0k+orL9Y+XkpzGJB88EM2mpGK2WJTd7yATgwxlASv /XeK/0pzOgGkoMO0foXzGsJURvzPrGyTD6Evv0Pr9QyTui+PjTrqQnt12Uzck9O5aQBF8R TRfDBrH07vcz2zEWGPvDirANPjB6Q0RBmsRdhCV5U5KdKcTJvMocWTpr7AR1rkR+uET/r5 BEp1juJYorr7ZO4FD4EQuy9RIWAgE+fqGVJMu39TqTBnolKOnjgba71lQ4RudA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729241102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OIlKntomP9j0zBRAmntSN/orkdXYG+tNPOEOWlkLats=; b=ZvuKS2UuKzev3OP0tE93IcmtKpmaHcDuFdVHtx7I7sJrJGWe8TXJv8K4KPLbmt8far+qy8 pOofBchN24hxrazUxBmeRZ9jpqsNUPnLLcR20aH8VFLQp2g0xflaTO8YjYMGa9DD1dZOjA KSEbwZljU8BmyhLDMHza75TMnPFKWBQjnyiQbJXMN/XcLPv5MnJR4SqKFYQllupwVmPTEd swnDzf/Y58dA533CD+X2tVp8mQIw2AEgDyd60hC46ARhUvD89urZ/V1upEpOySJv+typzm K//ZMtAn/yKbdU/PgSR8voS1L6Fzw6X1Qbpu+jwncG4OuXJh+nr2yXfAdMBwRg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729241102; a=rsa-sha256; cv=none; b=Nx4oLuTwMi74sgpkzk/NWzYwffoLSGyM1WDywL552sgZJBiiPXEe+36TELieBMshz1zXmx x9d61CEz6tnqg+BtGlxxCGSQqpT4WxAdViklwBTxZsEtWuPwFK/eJK82vqCQ1mL8VQXuIv 9FPAqi+Ra/Jh9BPCfTgeGR27XKNCaWHwvxUxMSxnCYGnYlA0cTnIE6I7SRExWB1izA8g01 qL2eCyrGs6fBwiA23LQcW/b6b5mGzRPdNl9cVf6PECBhN0ddOZG/81ivGPa/8Pfqc7sBlS /M7LPnvpYHshb9qlsCKQwwkfhzOE1i6xWfAUQ1hS4YkluWqQOAVh02QgOk+fYQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XVJDZ664qzR3Q; Fri, 18 Oct 2024 08:45:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49I8j2NN088249; Fri, 18 Oct 2024 08:45:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49I8j2JR088246; Fri, 18 Oct 2024 08:45:02 GMT (envelope-from git) Date: Fri, 18 Oct 2024 08:45:02 GMT Message-Id: <202410180845.49I8j2JR088246@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 9263f854e9a6 - main - sound: Simplify channel creation and deletion process List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9263f854e9a63cc326a3d5f6331b933c4a010abf Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=9263f854e9a63cc326a3d5f6331b933c4a010abf commit 9263f854e9a63cc326a3d5f6331b933c4a010abf Author: Christos Margiolis AuthorDate: 2024-10-18 08:40:41 +0000 Commit: Christos Margiolis CommitDate: 2024-10-18 08:40:41 +0000 sound: Simplify channel creation and deletion process Currently we create and destroy channels with the following consistent pattern: - chn_init() -> pcm_chn_add() - pcm_chn_remove() -> chn_kill() Instead of calling two separate functions, merge pcm_chn_add() with chn_init(), and pcm_chn_remove() with chn_kill(). Another benefit of this change is that we avoid the confusion caused by having pcm_chn_add(), as well as pcm_addchan(). Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by: dev_submerge.ch, markj Differential Revision: https://reviews.freebsd.org/D46835 --- sys/dev/sound/pcm/channel.c | 40 +++++++++++++++++++++++ sys/dev/sound/pcm/sound.c | 78 +-------------------------------------------- sys/dev/sound/pcm/sound.h | 3 -- sys/dev/sound/pcm/vchan.c | 25 +++------------ 4 files changed, 45 insertions(+), 101 deletions(-) diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c index d1c9bc616dcf..5b0bb105c505 100644 --- a/sys/dev/sound/pcm/channel.c +++ b/sys/dev/sound/pcm/channel.c @@ -1311,6 +1311,24 @@ chn_init(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, } PCM_LOCK(d); + CHN_INSERT_SORT_ASCEND(d, c, channels.pcm); + + switch (c->type) { + case SND_DEV_DSPHW_PLAY: + d->playcount++; + break; + case SND_DEV_DSPHW_VPLAY: + d->pvchancount++; + break; + case SND_DEV_DSPHW_REC: + d->reccount++; + break; + case SND_DEV_DSPHW_VREC: + d->rvchancount++; + break; + default: + __assert_unreachable(); + } return (c); @@ -1337,11 +1355,33 @@ fail: void chn_kill(struct pcm_channel *c) { + struct snddev_info *d = c->parentsnddev; struct snd_dbuf *b = c->bufhard; struct snd_dbuf *bs = c->bufsoft; PCM_BUSYASSERT(c->parentsnddev); + PCM_LOCK(d); + CHN_REMOVE(d, c, channels.pcm); + + switch (c->type) { + case SND_DEV_DSPHW_PLAY: + d->playcount--; + break; + case SND_DEV_DSPHW_VPLAY: + d->pvchancount--; + break; + case SND_DEV_DSPHW_REC: + d->reccount--; + break; + case SND_DEV_DSPHW_VREC: + d->rvchancount--; + break; + default: + __assert_unreachable(); + } + PCM_UNLOCK(d); + if (CHN_STARTED(c)) { CHN_LOCK(c); chn_trigger(c, PCMTRIG_ABORT); diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c index da28a267c81a..e25cb359f793 100644 --- a/sys/dev/sound/pcm/sound.c +++ b/sys/dev/sound/pcm/sound.c @@ -188,74 +188,6 @@ SYSCTL_PROC(_hw_snd, OID_AUTO, default_unit, sizeof(int), sysctl_hw_snd_default_unit, "I", "default sound device"); -void -pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch) -{ - PCM_BUSYASSERT(d); - PCM_LOCKASSERT(d); - KASSERT(ch != NULL && (ch->direction == PCMDIR_PLAY || - ch->direction == PCMDIR_REC), ("Invalid pcm channel")); - - CHN_INSERT_SORT_ASCEND(d, ch, channels.pcm); - - switch (ch->type) { - case SND_DEV_DSPHW_PLAY: - d->playcount++; - break; - case SND_DEV_DSPHW_VPLAY: - d->pvchancount++; - break; - case SND_DEV_DSPHW_REC: - d->reccount++; - break; - case SND_DEV_DSPHW_VREC: - d->rvchancount++; - break; - default: - __assert_unreachable(); - } -} - -int -pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch) -{ - struct pcm_channel *tmp; - - PCM_BUSYASSERT(d); - PCM_LOCKASSERT(d); - - tmp = NULL; - - CHN_FOREACH(tmp, d, channels.pcm) { - if (tmp == ch) - break; - } - - if (tmp != ch) - return (EINVAL); - - CHN_REMOVE(d, ch, channels.pcm); - - switch (ch->type) { - case SND_DEV_DSPHW_PLAY: - d->playcount--; - break; - case SND_DEV_DSPHW_VPLAY: - d->pvchancount--; - break; - case SND_DEV_DSPHW_REC: - d->reccount--; - break; - case SND_DEV_DSPHW_VREC: - d->rvchancount--; - break; - default: - __assert_unreachable(); - } - - return (0); -} - int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo) { @@ -272,8 +204,6 @@ pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo) PCM_UNLOCK(d); return (ENODEV); } - - pcm_chn_add(d, ch); PCM_UNLOCK(d); return (0); @@ -283,7 +213,6 @@ static void pcm_killchans(struct snddev_info *d) { struct pcm_channel *ch; - int error; bool found; PCM_BUSYASSERT(d); @@ -316,12 +245,7 @@ pcm_killchans(struct snddev_info *d) pause_sbt("pcmkillchans", SBT_1MS * 5, 0, 0); continue; } - - PCM_LOCK(d); - error = pcm_chn_remove(d, ch); - PCM_UNLOCK(d); - if (error == 0) - chn_kill(ch); + chn_kill(ch); } while (!CHN_EMPTY(d, channels.pcm)); } diff --git a/sys/dev/sound/pcm/sound.h b/sys/dev/sound/pcm/sound.h index 51c9c91f6f20..f96638081cb9 100644 --- a/sys/dev/sound/pcm/sound.h +++ b/sys/dev/sound/pcm/sound.h @@ -248,9 +248,6 @@ SYSCTL_DECL(_hw_snd); int pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, pid_t pid, char *comm); -void pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch); -int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch); - int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo); unsigned int pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz); int pcm_register(device_t dev, void *devinfo, int numplay, int numrec); diff --git a/sys/dev/sound/pcm/vchan.c b/sys/dev/sound/pcm/vchan.c index 8580eb679f35..4da6f83dc0a2 100644 --- a/sys/dev/sound/pcm/vchan.c +++ b/sys/dev/sound/pcm/vchan.c @@ -710,9 +710,6 @@ vchan_create(struct pcm_channel *parent) CHN_LOCK(parent); return (ENODEV); } - - /* add us to our grandparent's channel list */ - pcm_chn_add(d, ch); PCM_UNLOCK(d); CHN_LOCK(parent); @@ -818,12 +815,7 @@ fail: CHN_REMOVE(parent, ch, children); parent->flags &= ~CHN_F_HAS_VCHAN; CHN_UNLOCK(parent); - PCM_LOCK(d); - if (pcm_chn_remove(d, ch) == 0) { - PCM_UNLOCK(d); - chn_kill(ch); - } else - PCM_UNLOCK(d); + chn_kill(ch); CHN_LOCK(parent); return (ret); @@ -833,8 +825,6 @@ int vchan_destroy(struct pcm_channel *c) { struct pcm_channel *parent; - struct snddev_info *d; - int ret; KASSERT(c != NULL && c->parentchannel != NULL && c->parentsnddev != NULL, ("%s(): invalid channel=%p", @@ -842,10 +832,9 @@ vchan_destroy(struct pcm_channel *c) CHN_LOCKASSERT(c); - d = c->parentsnddev; parent = c->parentchannel; - PCM_BUSYASSERT(d); + PCM_BUSYASSERT(c->parentsnddev); CHN_LOCKASSERT(parent); CHN_UNLOCK(c); @@ -866,18 +855,12 @@ vchan_destroy(struct pcm_channel *c) CHN_UNLOCK(parent); - /* remove us from our grandparent's channel list */ - PCM_LOCK(d); - ret = pcm_chn_remove(d, c); - PCM_UNLOCK(d); - /* destroy ourselves */ - if (ret == 0) - chn_kill(c); + chn_kill(c); CHN_LOCK(parent); - return (ret); + return (0); } int