git: 1b1f80ae1cfd - stable/13 - sound: Remove CTLFLAG_NEEDGIANT from some sysctls.

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Mon, 10 Jan 2022 00:30:25 UTC
The branch stable/13 has been updated by mav:

URL: https://cgit.FreeBSD.org/src/commit/?id=1b1f80ae1cfd97968ea3832d4e51df3ec7ba275c

commit 1b1f80ae1cfd97968ea3832d4e51df3ec7ba275c
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2021-12-27 01:37:55 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-01-10 00:29:59 +0000

    sound: Remove CTLFLAG_NEEDGIANT from some sysctls.
    
    While there, remove some dead code.
    
    MFC after:      2 weeks
    
    (cherry picked from commit 3b4c5433229ac912929b77edee0b4dc001d70fe5)
---
 sys/dev/sound/clone.c           | 101 ++--------------------------------------
 sys/dev/sound/clone.h           |   4 --
 sys/dev/sound/pci/emu10kx.c     |   4 +-
 sys/dev/sound/pcm/channel.c     |   6 +--
 sys/dev/sound/pcm/feeder_rate.c |   6 +--
 sys/dev/sound/pcm/sndstat.c     |   2 +-
 sys/dev/sound/pcm/sound.c       |   8 ++--
 7 files changed, 16 insertions(+), 115 deletions(-)

diff --git a/sys/dev/sound/clone.c b/sys/dev/sound/clone.c
index 3ded510eae5c..7d3148750a1e 100644
--- a/sys/dev/sound/clone.c
+++ b/sys/dev/sound/clone.c
@@ -99,71 +99,6 @@ struct snd_clone {
 #define SND_CLONE_ASSERT(...)		KASSERT(__VA_ARGS__)
 #endif
 
-/*
- * Shamelessly ripped off from vfs_subr.c
- * We need at least 1/HZ precision as default timestamping.
- */
-enum { SND_TSP_SEC, SND_TSP_HZ, SND_TSP_USEC, SND_TSP_NSEC };
-
-static int snd_timestamp_precision = SND_TSP_HZ;
-TUNABLE_INT("hw.snd.timestamp_precision", &snd_timestamp_precision);
-
-void
-snd_timestamp(struct timespec *tsp)
-{
-	struct timeval tv;
-
-	switch (snd_timestamp_precision) {
-	case SND_TSP_SEC:
-		tsp->tv_sec = time_second;
-		tsp->tv_nsec = 0;
-		break;
-	case SND_TSP_HZ:
-		getnanouptime(tsp);
-		break;
-	case SND_TSP_USEC:
-		microuptime(&tv);
-		TIMEVAL_TO_TIMESPEC(&tv, tsp);
-		break;
-	case SND_TSP_NSEC:
-		nanouptime(tsp);
-		break;
-	default:
-		snd_timestamp_precision = SND_TSP_HZ;
-		getnanouptime(tsp);
-		break;
-	}
-}
-
-#if defined(SND_DIAGNOSTIC) || defined(SND_DEBUG)
-static int
-sysctl_hw_snd_timestamp_precision(SYSCTL_HANDLER_ARGS)
-{
-	int err, val;
-
-	val = snd_timestamp_precision;
-	err = sysctl_handle_int(oidp, &val, 0, req);
-	if (err == 0 && req->newptr != NULL) {
-		switch (val) {
-		case SND_TSP_SEC:
-		case SND_TSP_HZ:
-		case SND_TSP_USEC:
-		case SND_TSP_NSEC:
-			snd_timestamp_precision = val;
-			break;
-		default:
-			break;
-		}
-	}
-
-	return (err);
-}
-SYSCTL_PROC(_hw_snd, OID_AUTO, timestamp_precision,
-    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 0, sizeof(int),
-    sysctl_hw_snd_timestamp_precision, "I",
-    "timestamp precision (0=s 1=hz 2=us 3=ns)");
-#endif
-
 /*
  * snd_clone_create() : Return opaque allocated clone manager.
  */
@@ -189,7 +124,7 @@ snd_clone_create(int typemask, int maxunit, int deadline, uint32_t flags)
 	    maxunit;
 	c->deadline = deadline;
 	c->flags = flags;
-	snd_timestamp(&c->tsp);
+	getnanouptime(&c->tsp);
 	TAILQ_INIT(&c->head);
 
 	return (c);
@@ -296,17 +231,6 @@ snd_clone_setdeadline(struct snd_clone *c, int deadline)
 	return (c->deadline);
 }
 
-int
-snd_clone_gettime(struct snd_clone *c, struct timespec *tsp)
-{
-	SND_CLONE_ASSERT(c != NULL, ("NULL snd_clone"));
-	SND_CLONE_ASSERT(tsp != NULL, ("NULL timespec"));
-
-	*tsp = c->tsp;
-
-	return (0);
-}
-
 uint32_t
 snd_clone_getflags(struct snd_clone *c)
 {
@@ -327,25 +251,6 @@ snd_clone_setflags(struct snd_clone *c, uint32_t flags)
 	return (c->flags);
 }
 
-int
-snd_clone_getdevtime(struct cdev *dev, struct timespec *tsp)
-{
-	struct snd_clone_entry *ce;
-
-	SND_CLONE_ASSERT(dev != NULL, ("NULL dev"));
-	SND_CLONE_ASSERT(tsp != NULL, ("NULL timespec"));
-
-	ce = dev->si_drv2;
-	if (ce == NULL)
-		return (ENODEV);
-
-	SND_CLONE_ASSERT(ce->parent != NULL, ("NULL parent"));
-
-	*tsp = ce->tsp;
-
-	return (0);
-}
-
 uint32_t
 snd_clone_getdevflags(struct cdev *dev)
 {
@@ -411,7 +316,7 @@ snd_clone_gc(struct snd_clone *c)
 	if (!(c->flags & SND_CLONE_GC_ENABLE) || c->size == 0)
 		return (0);
 
-	snd_timestamp(&now);
+	getnanouptime(&now);
 
 	/*
 	 * Bail out if the last clone handler was invoked below the deadline
@@ -642,7 +547,7 @@ snd_clone_alloc(struct snd_clone *c, struct cdev **dev, int *unit, int tmask)
 	allocunit = (*unit == -1) ? 0 : *unit;
 	curpid = curthread->td_proc->p_pid;
 
-	snd_timestamp(&now);
+	getnanouptime(&now);
 
 	TAILQ_FOREACH(ce, &c->head, link) {
 		/*
diff --git a/sys/dev/sound/clone.h b/sys/dev/sound/clone.h
index 54b26e31c8b4..bcfa504ad003 100644
--- a/sys/dev/sound/clone.h
+++ b/sys/dev/sound/clone.h
@@ -99,8 +99,6 @@ struct snd_clone;
 
 #define SND_CLONE_DEVMASK	SND_CLONE_ALLOC
 
-void snd_timestamp(struct timespec *);
-
 struct snd_clone *snd_clone_create(int, int, int, uint32_t);
 int snd_clone_busy(struct snd_clone *);
 int snd_clone_enable(struct snd_clone *);
@@ -110,10 +108,8 @@ int snd_clone_getmaxunit(struct snd_clone *);
 int snd_clone_setmaxunit(struct snd_clone *, int);
 int snd_clone_getdeadline(struct snd_clone *);
 int snd_clone_setdeadline(struct snd_clone *, int);
-int snd_clone_gettime(struct snd_clone *, struct timespec *);
 uint32_t snd_clone_getflags(struct snd_clone *);
 uint32_t snd_clone_setflags(struct snd_clone *, uint32_t);
-int snd_clone_getdevtime(struct cdev *, struct timespec *);
 uint32_t snd_clone_getdevflags(struct cdev *);
 uint32_t snd_clone_setdevflags(struct cdev *, uint32_t);
 int snd_clone_gc(struct snd_clone *);
diff --git a/sys/dev/sound/pci/emu10kx.c b/sys/dev/sound/pci/emu10kx.c
index 5ae760845008..784fd7e27ae1 100644
--- a/sys/dev/sound/pci/emu10kx.c
+++ b/sys/dev/sound/pci/emu10kx.c
@@ -1569,7 +1569,7 @@ emu_addefxmixer(struct emu_sc_info *sc, const char *mix_name, const int mix_id,
 		snprintf(sysctl_name, 32, "_%s", mix_name);
 		SYSCTL_ADD_PROC(sc->ctx,
 		    SYSCTL_CHILDREN(sc->root), OID_AUTO, sysctl_name,
-		    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, sc, mix_id,
+		    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, mix_id,
 		    sysctl_emu_mixer_control, "I", "");
 	}
 
@@ -1609,7 +1609,7 @@ emu_digitalswitch(struct emu_sc_info *sc)
 {
 	/* XXX temporary? */
 	SYSCTL_ADD_PROC(sc->ctx, SYSCTL_CHILDREN(sc->root), OID_AUTO,
-	    "_digital", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
+	    "_digital", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
 	    sc, 0, sysctl_emu_digitalswitch_control, "I",
 	    "Enable digital output");
 
diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c
index 9574697f8656..065bf6ee2c5c 100644
--- a/sys/dev/sound/pcm/channel.c
+++ b/sys/dev/sound/pcm/channel.c
@@ -69,7 +69,7 @@ sysctl_hw_snd_latency(SYSCTL_HANDLER_ARGS)
 	return err;
 }
 SYSCTL_PROC(_hw_snd, OID_AUTO, latency,
-    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0, sizeof(int),
+    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int),
     sysctl_hw_snd_latency, "I",
     "buffering latency (0=low ... 10=high)");
 
@@ -92,7 +92,7 @@ sysctl_hw_snd_latency_profile(SYSCTL_HANDLER_ARGS)
 	return err;
 }
 SYSCTL_PROC(_hw_snd, OID_AUTO, latency_profile,
-    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0, sizeof(int),
+    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int),
     sysctl_hw_snd_latency_profile, "I",
     "buffering latency profile (0=aggressive 1=safe)");
 
@@ -115,7 +115,7 @@ sysctl_hw_snd_timeout(SYSCTL_HANDLER_ARGS)
 	return err;
 }
 SYSCTL_PROC(_hw_snd, OID_AUTO, timeout,
-    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0, sizeof(int),
+    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int),
     sysctl_hw_snd_timeout, "I",
     "interrupt timeout (1 - 10) seconds");
 
diff --git a/sys/dev/sound/pcm/feeder_rate.c b/sys/dev/sound/pcm/feeder_rate.c
index 88a58461b1ed..f6bb1836089b 100644
--- a/sys/dev/sound/pcm/feeder_rate.c
+++ b/sys/dev/sound/pcm/feeder_rate.c
@@ -186,7 +186,7 @@ sysctl_hw_snd_feeder_rate_min(SYSCTL_HANDLER_ARGS)
 	return (0);
 }
 SYSCTL_PROC(_hw_snd, OID_AUTO, feeder_rate_min,
-    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0, sizeof(int),
+    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int),
     sysctl_hw_snd_feeder_rate_min, "I",
     "minimum allowable rate");
 
@@ -209,7 +209,7 @@ sysctl_hw_snd_feeder_rate_max(SYSCTL_HANDLER_ARGS)
 	return (0);
 }
 SYSCTL_PROC(_hw_snd, OID_AUTO, feeder_rate_max,
-    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0, sizeof(int),
+    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int),
     sysctl_hw_snd_feeder_rate_max, "I",
     "maximum allowable rate");
 
@@ -232,7 +232,7 @@ sysctl_hw_snd_feeder_rate_round(SYSCTL_HANDLER_ARGS)
 	return (0);
 }
 SYSCTL_PROC(_hw_snd, OID_AUTO, feeder_rate_round,
-    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0, sizeof(int),
+    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int),
     sysctl_hw_snd_feeder_rate_round, "I",
     "sample rate converter rounding threshold");
 
diff --git a/sys/dev/sound/pcm/sndstat.c b/sys/dev/sound/pcm/sndstat.c
index 31c4a1b14a79..7eb21c6840e7 100644
--- a/sys/dev/sound/pcm/sndstat.c
+++ b/sys/dev/sound/pcm/sndstat.c
@@ -101,7 +101,7 @@ sysctl_hw_sndverbose(SYSCTL_HANDLER_ARGS)
 	return (error);
 }
 SYSCTL_PROC(_hw_snd, OID_AUTO, verbose,
-    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0, sizeof(int),
+    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int),
     sysctl_hw_sndverbose, "I",
     "verbosity level");
 
diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c
index 663ec84f93b6..dcc2180fe88a 100644
--- a/sys/dev/sound/pcm/sound.c
+++ b/sys/dev/sound/pcm/sound.c
@@ -1045,7 +1045,7 @@ pcm_sysinit(device_t dev)
             OID_AUTO, "buffersize", CTLFLAG_RD, &d->bufsz, 0, "allocated buffer size");
 	SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
 	    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
-	    "bitperfect", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, d,
+	    "bitperfect", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, d,
 	    sizeof(d), sysctl_dev_pcm_bitperfect, "I",
 	    "bit-perfect playback/recording (0=disable, 1=enable)");
 	SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
@@ -1056,18 +1056,18 @@ pcm_sysinit(device_t dev)
 #ifdef SND_DEBUG
 	SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
 	    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
-	    "clone_flags", CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT,
+	    "clone_flags", CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
 	    d, sizeof(d), sysctl_dev_pcm_clone_flags, "IU",
 	    "clone flags");
 	SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
 	    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
-	    "clone_deadline", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT,
+	    "clone_deadline", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
 	    d, sizeof(d), sysctl_dev_pcm_clone_deadline, "I",
 	    "clone expiration deadline (ms)");
 	SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
 	    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
 	    "clone_gc",
-	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, d, sizeof(d),
+	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, d, sizeof(d),
 	    sysctl_dev_pcm_clone_gc, "I", "clone garbage collector");
 #endif
 	if (d->flags & SD_F_AUTOVCHAN)