tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Refactoring sc_audiochan
Hi all,
In audio.c, sc_audiochan (list of struct audio_chan) is
a mixed list of opened audio chan and first special element.
I want to split it for readability and performance.
New sc_audiochan has opened audio chan only.
Newly added sc_hwchan is what was the first special element.
However I found that everyone referring to sc_hwchan needs
sc_hwchan->vc (struct virtual_channel), not sc_hwchan (struct
audio_chan) itself.
So it should be 'struct virtual_channel sc_hwvc',
not 'struct audio_chan sc_hwchan'.
Then I have a question. I think sc_hwvc is a good name to me
but do you have better idea?
I'll commit anyway if no opinions within a few days.
Thanks,
---
Tetsuya Isaki <isaki%pastel-flower.jp@localhost / isaki%NetBSD.org@localhost>
Index: sys/dev/audio.c
===================================================================
RCS file: /cvsroot/src/sys/dev/audio.c,v
retrieving revision 1.393
diff -u -r1.393 audio.c
--- sys/dev/audio.c 13 Aug 2017 05:04:08 -0000 1.393
+++ sys/dev/audio.c 13 Aug 2017 05:07:32 -0000
@@ -215,12 +215,12 @@
#endif
#define HW_LOCK(x) do { \
- if ((x) == SIMPLEQ_FIRST(&sc->sc_audiochan)->vc) \
+ if ((x) == sc->sc_hwvc) \
mutex_enter(sc->sc_intr_lock); \
} while (0)
#define HW_UNLOCK(x) do { \
- if ((x) == SIMPLEQ_FIRST(&sc->sc_audiochan)->vc) \
+ if ((x) == sc->sc_hwvc) \
mutex_exit(sc->sc_intr_lock); \
} while (0)
@@ -284,7 +284,7 @@
struct audio_ringbuffer *, int);
int audio_initbufs(struct audio_softc *, struct virtual_channel *);
void audio_calcwater(struct audio_softc *, struct virtual_channel *);
-int audio_drain(struct audio_softc *, struct audio_chan *);
+int audio_drain(struct audio_softc *, struct virtual_channel *);
void audio_clear(struct audio_softc *, struct virtual_channel *);
void audio_clear_intr_unlocked(struct audio_softc *sc,
struct virtual_channel *);
@@ -481,7 +481,6 @@
struct audio_softc *sc;
struct audio_attach_args *sa;
struct virtual_channel *vc;
- struct audio_chan *chan;
const struct audio_hw_if *hwp;
const struct sysctlnode *node;
void *hdlp;
@@ -517,11 +516,10 @@
sc->sc_trigger_started = false;
sc->sc_rec_started = false;
sc->sc_dying = false;
- chan = kmem_zalloc(sizeof(struct audio_chan), KM_SLEEP);
- vc = kmem_zalloc(sizeof(struct virtual_channel), KM_SLEEP);
- chan->vc = vc;
SIMPLEQ_INIT(&sc->sc_audiochan);
- SIMPLEQ_INSERT_HEAD(&sc->sc_audiochan, chan, entries);
+
+ vc = kmem_zalloc(sizeof(struct virtual_channel), KM_SLEEP);
+ sc->sc_hwvc = vc;
vc->sc_open = 0;
vc->sc_mode = 0;
vc->sc_npfilters = 0;
@@ -930,12 +928,16 @@
audio_free_ring(sc, &chan->vc->sc_mpr);
audio_free_ring(sc, &chan->vc->sc_mrr);
}
+ audio_free_ring(sc, &sc->sc_hwvc->sc_mpr);
+ audio_free_ring(sc, &sc->sc_hwvc->sc_mrr);
audio_free_ring(sc, &sc->sc_pr);
audio_free_ring(sc, &sc->sc_rr);
SIMPLEQ_FOREACH(chan, &sc->sc_audiochan, entries) {
audio_destroy_pfilters(chan->vc);
audio_destroy_rfilters(chan->vc);
}
+ audio_destroy_pfilters(sc->sc_hwvc);
+ audio_destroy_rfilters(sc->sc_hwvc);
auconv_delete_encodings(sc->sc_encodings);
@@ -948,10 +950,7 @@
sc->sc_sih_wr = NULL;
}
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
- kmem_free(chan->vc, sizeof(struct virtual_channel));
- SIMPLEQ_REMOVE(&sc->sc_audiochan, chan, audio_chan, entries);
- kmem_free(chan, sizeof(struct audio_chan));
+ kmem_free(sc->sc_hwvc, sizeof(struct virtual_channel));
kmem_free(sc->sc_mixer_state, sizeof(mixer_ctrl_t) *
(sc->sc_nmixer_states + 1));
@@ -1081,26 +1080,21 @@
void
audio_printsc(struct audio_softc *sc)
{
- struct audio_chan *chan;
-
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
-
- if (chan == NULL)
- return;
+ struct virtual_channel *vc;
+
+ vc = sc->sc_hwvc;
printf("hwhandle %p hw_if %p ", sc->hw_hdl, sc->hw_if);
- printf("open 0x%x mode 0x%x\n", chan->vc->sc_open,
- chan->vc->sc_mode);
+ printf("open 0x%x mode 0x%x\n", vc->sc_open, vc->sc_mode);
printf("rchan 0x%x wchan 0x%x ", cv_has_waiters(&sc->sc_rchan),
cv_has_waiters(&sc->sc_wchan));
printf("rring used 0x%x pring used=%d\n",
- audio_stream_get_used(&chan->vc->sc_mrr.s),
- audio_stream_get_used(&chan->vc->sc_mpr.s));
- printf("rbus 0x%x pbus 0x%x ", chan->vc->sc_rbus,
- chan->vc->sc_pbus);
- printf("blksize %d", chan->vc->sc_mpr.blksize);
- printf("hiwat %d lowat %d\n", chan->vc->sc_mpr.usedhigh,
- chan->vc->sc_mpr.usedlow);
+ audio_stream_get_used(&vc->sc_mrr.s),
+ audio_stream_get_used(&vc->sc_mpr.s));
+ printf("rbus 0x%x pbus 0x%x ", vc->sc_rbus, vc->sc_pbus);
+ printf("blksize %d", vc->sc_mpr.blksize);
+ printf("hiwat %d lowat %d\n", vc->sc_mpr.usedhigh,
+ vc->sc_mpr.usedlow);
}
void
@@ -1164,13 +1158,13 @@
int direction, size_t bufsize)
{
const struct audio_hw_if *hw;
- struct audio_chan *chan;
+ struct virtual_channel *vc;
void *hdl;
vaddr_t vstart;
vsize_t vsize;
int error;
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
+ vc = sc->sc_hwvc;
hw = sc->hw_if;
hdl = sc->hw_hdl;
/*
@@ -1182,7 +1176,7 @@
if (hw->round_buffersize)
bufsize = hw->round_buffersize(hdl, direction, bufsize);
- if (hw->allocm && (r == &chan->vc->sc_mpr || r == &chan->vc->sc_mrr)) {
+ if (hw->allocm && (r == &vc->sc_mpr || r == &vc->sc_mrr)) {
/* Hardware ringbuffer. No dedicated uvm object.*/
r->uobj = NULL;
r->s.start = hw->allocm(hdl, direction, bufsize);
@@ -1227,17 +1221,16 @@
void
audio_free_ring(struct audio_softc *sc, struct audio_ringbuffer *r)
{
- struct audio_chan *chan;
+ struct virtual_channel *vc;
vaddr_t vstart;
vsize_t vsize;
if (r->s.start == NULL)
return;
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
+ vc = sc->sc_hwvc;
- if (sc->hw_if->freem && (r == &chan->vc->sc_mpr ||
- r == &chan->vc->sc_mrr)) {
+ if (sc->hw_if->freem && (r == &vc->sc_mpr || r == &vc->sc_mrr)) {
/* Hardware ringbuffer. */
KASSERT(r->uobj == NULL);
sc->hw_if->freem(sc->hw_hdl, r->s.start, r->s.bufsize);
@@ -1585,8 +1578,6 @@
found = false;
SIMPLEQ_FOREACH(vchan, &sc->sc_audiochan, entries) {
- if (vchan == SIMPLEQ_FIRST(&sc->sc_audiochan))
- continue;
if (vchan->vc == vc) {
found = true;
break;
@@ -2022,12 +2013,10 @@
audio_initbufs(struct audio_softc *sc, struct virtual_channel *vc)
{
const struct audio_hw_if *hw;
- struct audio_chan *chan;
int error;
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
if (vc == NULL) {
- vc = chan->vc;
+ vc = sc->sc_hwvc;
sc->sc_pr.blksize = vc->sc_mrr.blksize;
sc->sc_rr.blksize = vc->sc_mrr.blksize;
}
@@ -2035,7 +2024,7 @@
DPRINTF(("audio_initbufs: mode=0x%x\n", vc->sc_mode));
hw = sc->hw_if;
if (audio_can_capture(sc) &&
- ((vc->sc_open & AUOPEN_READ) || vc == chan->vc)) {
+ ((vc->sc_open & AUOPEN_READ) || vc == sc->sc_hwvc)) {
audio_init_ringbuffer(sc, &vc->sc_mrr,
AUMODE_RECORD);
if (sc->sc_opens == 0 && hw->init_input &&
@@ -2046,11 +2035,11 @@
return error;
}
}
- if (vc == SIMPLEQ_FIRST(&sc->sc_audiochan)->vc)
+ if (vc == sc->sc_hwvc)
sc->sc_rr.blksize = vc->sc_mrr.blksize;
if (audio_can_playback(sc) &&
- ((vc->sc_open & AUOPEN_WRITE) || vc == chan->vc)) {
+ ((vc->sc_open & AUOPEN_WRITE) || vc == sc->sc_hwvc)) {
audio_init_ringbuffer(sc, &vc->sc_mpr,
AUMODE_PLAY);
vc->sc_sil_count = 0;
@@ -2062,7 +2051,7 @@
return error;
}
}
- if (vc == SIMPLEQ_FIRST(&sc->sc_audiochan)->vc)
+ if (vc == sc->sc_hwvc)
sc->sc_pr.blksize = vc->sc_mpr.blksize;
#ifdef AUDIO_INTR_TIME
@@ -2134,8 +2123,6 @@
return ENXIO;
n = 1;
SIMPLEQ_FOREACH(chan, &sc->sc_audiochan, entries) {
- if (chan == SIMPLEQ_FIRST(&sc->sc_audiochan))
- continue;
n = chan->chan + 1;
}
if (n < 0)
@@ -2328,10 +2315,9 @@
}
int
-audio_drain(struct audio_softc *sc, struct audio_chan *chan)
+audio_drain(struct audio_softc *sc, struct virtual_channel *vc)
{
struct audio_ringbuffer *cb;
- struct virtual_channel *vc;
int error, cc, i, used;
uint drops;
bool hw = false;
@@ -2340,14 +2326,13 @@
KASSERT(mutex_owned(sc->sc_intr_lock));
error = 0;
- vc = chan->vc;
DPRINTF(("audio_drain: enter busy=%d\n", vc->sc_pbus));
- cb = &chan->vc->sc_mpr;
+ cb = &vc->sc_mpr;
if (cb->mmapped)
return 0;
used = audio_stream_get_used(&cb->s);
- if (chan == SIMPLEQ_FIRST(&sc->sc_audiochan)) {
+ if (vc == sc->sc_hwvc) {
hw = true;
used += audio_stream_get_used(&sc->sc_pr.s);
}
@@ -2401,8 +2386,8 @@
drops = cb->drops;
error = 0;
while (cb->drops == drops && !error) {
- DPRINTF(("audio_drain: chan=%d used=%d, drops=%ld\n",
- chan->chan,
+ DPRINTF(("audio_drain: vc=%p used=%d, drops=%ld\n",
+ vc,
audio_stream_get_used(&vc->sc_mpr.s),
cb->drops));
mutex_exit(sc->sc_intr_lock);
@@ -2459,12 +2444,12 @@
*/
if ((flags & FWRITE) && vc->sc_pbus) {
if (!vc->sc_mpr.pause)
- audio_drain(sc, chan);
+ audio_drain(sc, chan->vc);
vc->sc_pbus = false;
}
if (sc->sc_opens == 1) {
if (vc->sc_mpr.mmapped == false)
- audio_drain(sc, SIMPLEQ_FIRST(&sc->sc_audiochan));
+ audio_drain(sc, sc->sc_hwvc);
if (hw->drain)
(void)hw->drain(sc->hw_hdl);
hw->halt_output(sc->hw_hdl);
@@ -2733,14 +2718,12 @@
int
audio_silence_copyout(struct audio_softc *sc, int n, struct uio *uio)
{
- struct audio_chan *chan;
struct virtual_channel *vc;
uint8_t zerobuf[128];
int error;
int k;
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
- vc = chan->vc;
+ vc = sc->sc_hwvc;
audio_fill_silence(&vc->sc_rparams, zerobuf, sizeof zerobuf);
error = 0;
@@ -2991,8 +2974,6 @@
KASSERT(mutex_owned(sc->sc_lock));
SIMPLEQ_FOREACH(pchan, &sc->sc_audiochan, entries) {
- if (pchan == SIMPLEQ_FIRST(&sc->sc_audiochan))
- continue;
if (pchan->chan == chan->deschan)
break;
}
@@ -3135,7 +3116,7 @@
case AUDIO_DRAIN:
DPRINTF(("AUDIO_DRAIN\n"));
mutex_enter(sc->sc_intr_lock);
- error = audio_drain(sc, pchan);
+ error = audio_drain(sc, pchan->vc);
if (!error && sc->sc_opens == 1 && hw->drain)
error = hw->drain(sc->hw_hdl);
mutex_exit(sc->sc_intr_lock);
@@ -3451,8 +3432,6 @@
int
audiostartr(struct audio_softc *sc, struct virtual_channel *vc)
{
-
- struct audio_chan *chan;
int error;
KASSERT(mutex_owned(sc->sc_lock));
@@ -3461,10 +3440,9 @@
vc->sc_mrr.s.start, audio_stream_get_used(&vc->sc_mrr.s),
vc->sc_mrr.usedhigh, vc->sc_mrr.mmapped));
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
if (!audio_can_capture(sc))
return EINVAL;
- if (vc == chan->vc)
+ if (vc == sc->sc_hwvc)
return 0;
error = 0;
@@ -3482,12 +3460,10 @@
int
audiostartp(struct audio_softc *sc, struct virtual_channel *vc)
{
- struct audio_chan *chan;
int error, used;
KASSERT(mutex_owned(sc->sc_lock));
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
error = 0;
used = audio_stream_get_used(&vc->sc_mpr.s);
DPRINTF(("audiostartp: start=%p used=%d(hi=%d blk=%d) mmapped=%d\n",
@@ -3496,7 +3472,7 @@
if (!audio_can_playback(sc))
return EINVAL;
- if (vc == chan->vc)
+ if (vc == sc->sc_hwvc)
return 0;
if (!vc->sc_mpr.mmapped && used < vc->sc_mpr.blksize) {
@@ -3513,7 +3489,7 @@
error = mix_write(sc);
if (error)
goto done;
- vc = chan->vc;
+ vc = sc->sc_hwvc;
vc->sc_mpr.s.outp =
audio_stream_add_outp(&vc->sc_mpr.s,
vc->sc_mpr.s.outp, vc->sc_mpr.blksize);
@@ -3630,13 +3606,11 @@
audio_pint(void *v)
{
struct audio_softc *sc;
- struct audio_chan *chan;
struct virtual_channel *vc;
int blksize, cc, used;
sc = v;
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
- vc = chan->vc;
+ vc = sc->sc_hwvc;
blksize = vc->sc_mpr.blksize;
if (sc->sc_dying == true || sc->sc_trigger_started == false)
@@ -3698,9 +3672,6 @@
if (!sc->sc_opens)
break; /* ignore interrupt if not open */
- if (chan == SIMPLEQ_FIRST(&sc->sc_audiochan))
- continue;
-
vc = chan->vc;
if (!vc->sc_open)
@@ -3835,7 +3806,7 @@
}
mutex_enter(sc->sc_intr_lock);
- vc = SIMPLEQ_FIRST(&sc->sc_audiochan)->vc;
+ vc = sc->sc_hwvc;
cb = &sc->sc_pr;
inp = cb->s.inp;
cc = blksize - (inp - cb->s.start) % blksize;
@@ -3909,9 +3880,6 @@
if (!sc->sc_opens)
break; /* ignore interrupt if not open */
- if (chan == SIMPLEQ_FIRST(&sc->sc_audiochan))
- continue;
-
vc = chan->vc;
if (!(vc->sc_open & AUOPEN_READ))
@@ -4102,17 +4070,13 @@
static int
audio_set_vchan_defaults(struct audio_softc *sc, u_int mode)
{
- struct audio_chan *chan;
struct virtual_channel *vc;
struct audio_info ai;
int error;
KASSERT(mutex_owned(sc->sc_lock));
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
- if (chan == NULL)
- return EINVAL;
- vc = chan->vc;
+ vc = sc->sc_hwvc;
/* default parameters */
vc->sc_rparams = sc->sc_vchan_params;
@@ -4749,7 +4713,7 @@
audio_init_record(sc, vc);
}
- if (vc == SIMPLEQ_FIRST(&sc->sc_audiochan)->vc) {
+ if (vc == sc->sc_hwvc) {
if (!cleared) {
audio_clear_intr_unlocked(sc, vc);
cleared = true;
@@ -5252,9 +5216,6 @@
mutex_enter(sc->sc_lock);
audio_mixer_capture(sc);
SIMPLEQ_FOREACH(chan, &sc->sc_audiochan, entries) {
- if (chan == SIMPLEQ_FIRST(&sc->sc_audiochan))
- continue;
-
vc = chan->vc;
if (vc->sc_pbus && !pbus)
pbus = true;
@@ -5291,10 +5252,7 @@
audio_mixer_restore(sc);
SIMPLEQ_FOREACH(chan, &sc->sc_audiochan, entries) {
- if (chan == SIMPLEQ_FIRST(&sc->sc_audiochan))
- continue;
vc = chan->vc;
-
if (vc->sc_lastinfovalid == true)
audiosetinfo(sc, &vc->sc_lastinfo, true, vc);
if (vc->sc_pbus == true && !vc->sc_mpr.pause)
@@ -5411,7 +5369,6 @@
mix_read(void *arg)
{
struct audio_softc *sc = arg;
- struct audio_chan *chan;
struct virtual_channel *vc;
stream_filter_t *filter;
stream_fetcher_t *fetcher;
@@ -5419,8 +5376,7 @@
int cc, cc1, blksize, error;
uint8_t *inp;
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
- vc = chan->vc;
+ vc = sc->sc_hwvc;
blksize = vc->sc_mrr.blksize;
cc = blksize;
error = 0;
@@ -5441,7 +5397,7 @@
if (error) {
/* XXX does this really help? */
DPRINTF(("audio_upmix restart failed: %d\n", error));
- audio_clear(sc, SIMPLEQ_FIRST(&sc->sc_audiochan)->vc);
+ audio_clear(sc, sc->sc_hwvc);
sc->sc_rec_started = false;
return error;
}
@@ -5479,7 +5435,6 @@
mix_write(void *arg)
{
struct audio_softc *sc = arg;
- struct audio_chan *chan;
struct virtual_channel *vc;
stream_filter_t *filter;
stream_fetcher_t *fetcher;
@@ -5487,8 +5442,7 @@
int cc, cc1, cc2, blksize, error, used;
uint8_t *inp, *orig, *tocopy;
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
- vc = chan->vc;
+ vc = sc->sc_hwvc;
blksize = vc->sc_mpr.blksize;
cc = blksize;
error = 0;
@@ -5552,7 +5506,7 @@
if (error) {
/* XXX does this really help? */
DPRINTF(("audio_mix restart failed: %d\n", error));
- audio_clear(sc, SIMPLEQ_FIRST(&sc->sc_audiochan)->vc);
+ audio_clear(sc, sc->sc_hwvc);
sc->sc_trigger_started = false;
}
@@ -5689,8 +5643,6 @@
j = 0;
SIMPLEQ_FOREACH(chan, &sc->sc_audiochan, entries) {
- if (chan == SIMPLEQ_FIRST(&sc->sc_audiochan))
- continue;
if (j == n)
break;
j++;
@@ -5791,13 +5743,11 @@
stream_filter_list_t *pfil, stream_filter_list_t *rfil,
const struct virtual_channel *vc)
{
- struct audio_chan *chan;
-
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
int error = 0;
+
KASSERT(mutex_owned(sc->sc_lock));
- if (vc == chan->vc && sc->hw_if->set_params != NULL) {
+ if (vc == sc->sc_hwvc && sc->hw_if->set_params != NULL) {
sc->sc_ready = true;
if (sc->sc_vchan_params.precision == 8)
play->encoding = rec->encoding = AUDIO_ENCODING_SLINEAR;
@@ -6014,13 +5964,11 @@
static int
vchan_autoconfig(struct audio_softc *sc)
{
- struct audio_chan *chan;
struct virtual_channel *vc;
uint i, j, k;
int error;
- chan = SIMPLEQ_FIRST(&sc->sc_audiochan);
- vc = chan->vc;
+ vc = sc->sc_hwvc;
error = 0;
mutex_enter(sc->sc_lock);
Index: sys/dev/audiovar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/audiovar.h,v
retrieving revision 1.62
diff -u -r1.62 audiovar.h
--- sys/dev/audiovar.h 13 Aug 2017 05:04:08 -0000 1.62
+++ sys/dev/audiovar.h 13 Aug 2017 05:07:32 -0000
@@ -183,6 +183,7 @@
const struct audio_hw_if *hw_if; /* Hardware interface */
device_t sc_dev; /* Hardware device struct */
struct chan_queue sc_audiochan; /* queue of open audio chans */
+ struct virtual_channel *sc_hwvc;
struct audio_encoding_set *sc_encodings;
struct selinfo sc_wsel; /* write selector */
@@ -224,9 +225,9 @@
* play_thread
* sc_pr
* |
- * vchan[0]->sc_pustream (First element in sc_audiochan)
+ * sc_hwvc->sc_pustream
* |
- * vchan[0]->sc_mpr
+ * sc_hwvc->sc_mpr
* |
* hardware
*/
@@ -236,10 +237,10 @@
/**
* hardware
* |
- * oc->sc_mrr oc = sc->sc_vchan[0]
+ * sc_hwvc->sc_mrr
* : Transform though filters same process as each
* : vc to IF
- * oc->sc_rustream Audio now in intermediate format (IF)
+ * sc_hwvc->sc_rustream Audio now in intermediate format (IF)
* | mix_read();
* sc_rr
* | audio_upmix vc = sc->sc_vchan[n]
Home |
Main Index |
Thread Index |
Old Index