Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/audio audio(4): Make debug messages better in audio_...



details:   https://anonhg.NetBSD.org/src/rev/beb9bf1ab43f
branches:  trunk
changeset: 365715:beb9bf1ab43f
user:      isaki <isaki%NetBSD.org@localhost>
date:      Wed Apr 20 04:41:29 2022 +0000

description:
audio(4): Make debug messages better in audio_ioctl() and mixier_ioctl().
Divide by case.  Reduce to one line if possible.

diffstat:

 sys/dev/audio/audio.c |  194 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 117 insertions(+), 77 deletions(-)

diffs (truncated from 418 to 300 lines):

diff -r dcc4013e7e57 -r beb9bf1ab43f sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c     Tue Apr 19 23:16:14 2022 +0000
+++ b/sys/dev/audio/audio.c     Wed Apr 20 04:41:29 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.124 2022/04/19 09:19:53 riastradh Exp $    */
+/*     $NetBSD: audio.c,v 1.125 2022/04/20 04:41:29 isaki Exp $        */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -181,7 +181,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.124 2022/04/19 09:19:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.125 2022/04/20 04:41:29 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2992,40 +2992,44 @@
        audio_format_query_t *query;
        u_int stamp;
        u_int offs;
-       int fd;
+       int val;
        int index;
        int error;
 
 #if defined(AUDIO_DEBUG)
        const char *ioctlnames[] = {
-               " AUDIO_GETINFO",       /* 21 */
-               " AUDIO_SETINFO",       /* 22 */
-               " AUDIO_DRAIN",         /* 23 */
-               " AUDIO_FLUSH",         /* 24 */
-               " AUDIO_WSEEK",         /* 25 */
-               " AUDIO_RERROR",        /* 26 */
-               " AUDIO_GETDEV",        /* 27 */
-               " AUDIO_GETENC",        /* 28 */
-               " AUDIO_GETFD",         /* 29 */
-               " AUDIO_SETFD",         /* 30 */
-               " AUDIO_PERROR",        /* 31 */
-               " AUDIO_GETIOFFS",      /* 32 */
-               " AUDIO_GETOOFFS",      /* 33 */
-               " AUDIO_GETPROPS",      /* 34 */
-               " AUDIO_GETBUFINFO",    /* 35 */
-               " AUDIO_SETCHAN",       /* 36 */
-               " AUDIO_GETCHAN",       /* 37 */
-               " AUDIO_QUERYFORMAT",   /* 38 */
-               " AUDIO_GETFORMAT",     /* 39 */
-               " AUDIO_SETFORMAT",     /* 40 */
+               "AUDIO_GETINFO",        /* 21 */
+               "AUDIO_SETINFO",        /* 22 */
+               "AUDIO_DRAIN",          /* 23 */
+               "AUDIO_FLUSH",          /* 24 */
+               "AUDIO_WSEEK",          /* 25 */
+               "AUDIO_RERROR",         /* 26 */
+               "AUDIO_GETDEV",         /* 27 */
+               "AUDIO_GETENC",         /* 28 */
+               "AUDIO_GETFD",          /* 29 */
+               "AUDIO_SETFD",          /* 30 */
+               "AUDIO_PERROR",         /* 31 */
+               "AUDIO_GETIOFFS",       /* 32 */
+               "AUDIO_GETOOFFS",       /* 33 */
+               "AUDIO_GETPROPS",       /* 34 */
+               "AUDIO_GETBUFINFO",     /* 35 */
+               "AUDIO_SETCHAN",        /* 36 */
+               "AUDIO_GETCHAN",        /* 37 */
+               "AUDIO_QUERYFORMAT",    /* 38 */
+               "AUDIO_GETFORMAT",      /* 39 */
+               "AUDIO_SETFORMAT",      /* 40 */
        };
+       char pre[64];
        int nameidx = (cmd & 0xff);
-       const char *ioctlname = "";
-       if (21 <= nameidx && nameidx <= 21 + __arraycount(ioctlnames))
-               ioctlname = ioctlnames[nameidx - 21];
-       TRACEF(2, file, "(%lu,'%c',%lu)%s pid=%d.%d",
-           IOCPARM_LEN(cmd), (char)IOCGROUP(cmd), cmd&0xff, ioctlname,
-           (int)curproc->p_pid, (int)l->l_lid);
+       if (21 <= nameidx && nameidx <= 21 + __arraycount(ioctlnames)) {
+               snprintf(pre, sizeof(pre), "pid=%d.%d %s",
+                   (int)curproc->p_pid, (int)l->l_lid,
+                   ioctlnames[nameidx - 21]);
+       } else {
+               snprintf(pre, sizeof(pre), "pid=%d.%d (%lu,'%c',%u)",
+                   (int)curproc->p_pid, (int)l->l_lid,
+                   IOCPARM_LEN(cmd), (char)IOCGROUP(cmd), nameidx);
+       }
 #endif
 
        error = 0;
@@ -3036,10 +3040,15 @@
 
        case FIONREAD:
                /* Get the number of bytes that can be read. */
-               if (file->rtrack) {
-                       *(int *)addr = audio_track_readablebytes(file->rtrack);
+               track = file->rtrack;
+               if (track) {
+                       val = audio_track_readablebytes(track);
+                       *(int *)addr = val;
+                       TRACET(2, track, "pid=%d.%d FIONREAD bytes=%d",
+                           (int)curproc->p_pid, (int)l->l_lid, val);
                } else {
-                       *(int *)addr = 0;
+                       TRACEF(2, file, "pid=%d.%d FIONREAD no track",
+                           (int)curproc->p_pid, (int)l->l_lid);
                }
                break;
 
@@ -3047,48 +3056,42 @@
                /* Set/Clear ASYNC I/O. */
                if (*(int *)addr) {
                        file->async_audio = curproc->p_pid;
-                       TRACEF(2, file, "FIOASYNC pid %d", file->async_audio);
                } else {
                        file->async_audio = 0;
-                       TRACEF(2, file, "FIOASYNC off");
-               }
+               }
+               TRACEF(2, file, "pid=%d.%d FIOASYNC %s",
+                   (int)curproc->p_pid, (int)l->l_lid,
+                   file->async_audio ? "on" : "off");
                break;
 
        case AUDIO_FLUSH:
                /* XXX TODO: clear errors and restart? */
+               TRACEF(2, file, "%s", pre);
                audio_file_clear(sc, file);
                break;
 
-       case AUDIO_RERROR:
-               /*
-                * Number of read bytes dropped.  We don't know where
-                * or when they were dropped (including conversion stage).
-                * Therefore, the number of accurate bytes or samples is
-                * also unknown.
-                */
-               track = file->rtrack;
-               if (track) {
-                       *(int *)addr = frametobyte(&track->usrbuf.fmt,
-                           track->dropframes);
-               }
-               break;
-
        case AUDIO_PERROR:
+       case AUDIO_RERROR:
                /*
-                * Number of write bytes dropped.  We don't know where
-                * or when they were dropped (including conversion stage).
-                * Therefore, the number of accurate bytes or samples is
-                * also unknown.
+                * Number of dropped bytes during playback/record.  We don't
+                * know where or when they were dropped (including conversion
+                * stage).  Therefore, the number of accurate bytes or samples
+                * is also unknown.
                 */
-               track = file->ptrack;
+               track = (cmd == AUDIO_PERROR) ? file->ptrack : file->rtrack;
                if (track) {
-                       *(int *)addr = frametobyte(&track->usrbuf.fmt,
+                       val = frametobyte(&track->usrbuf.fmt,
                            track->dropframes);
+                       *(int *)addr = val;
+                       TRACET(2, track, "%s bytes=%d", pre, val);
+               } else {
+                       TRACEF(2, file, "%s no track", pre);
                }
                break;
 
        case AUDIO_GETIOFFS:
                /* XXX TODO */
+               TRACEF(2, file, "%s", pre);
                ao = (struct audio_offset *)addr;
                ao->samples = 0;
                ao->deltablks = 0;
@@ -3102,6 +3105,7 @@
                        ao->samples = 0;
                        ao->deltablks = 0;
                        ao->offset = 0;
+                       TRACEF(2, file, "%s no ptrack", pre);
                        break;
                }
                mutex_enter(sc->sc_lock);
@@ -3122,17 +3126,24 @@
                        offs -= track->usrbuf.capacity;
                ao->offset = offs;
 
-               TRACET(3, track, "GETOOFFS: samples=%u deltablks=%u offset=%u",
-                   ao->samples, ao->deltablks, ao->offset);
+               TRACET(2, track, "%s samples=%u deltablks=%u offset=%u",
+                   pre, ao->samples, ao->deltablks, ao->offset);
                break;
 
        case AUDIO_WSEEK:
                /* XXX return value does not include outbuf one. */
-               if (file->ptrack)
-                       *(u_long *)addr = file->ptrack->usrbuf.used;
+               track = file->ptrack;
+               if (track) {
+                       val = track->usrbuf.used;
+                       *(u_long *)addr = val;
+                       TRACET(2, track, "%s bytes=%d", pre, val);
+               } else {
+                       TRACEF(2, file, "%s no ptrack", pre);
+               }
                break;
 
        case AUDIO_SETINFO:
+               TRACEF(2, file, "%s", pre);
                error = audio_exlock_enter(sc);
                if (error)
                        break;
@@ -3148,6 +3159,7 @@
                break;
 
        case AUDIO_GETINFO:
+               TRACEF(2, file, "%s", pre);
                error = audio_exlock_enter(sc);
                if (error)
                        break;
@@ -3156,6 +3168,7 @@
                break;
 
        case AUDIO_GETBUFINFO:
+               TRACEF(2, file, "%s", pre);
                error = audio_exlock_enter(sc);
                if (error)
                        break;
@@ -3164,20 +3177,26 @@
                break;
 
        case AUDIO_DRAIN:
-               if (file->ptrack) {
+               track = file->ptrack;
+               if (track) {
+                       TRACET(2, track, "%s", pre);
                        mutex_enter(sc->sc_lock);
-                       error = audio_track_drain(sc, file->ptrack);
+                       error = audio_track_drain(sc, track);
                        mutex_exit(sc->sc_lock);
+               } else {
+                       TRACEF(2, file, "%s no ptrack", pre);
                }
                break;
 
        case AUDIO_GETDEV:
+               TRACEF(2, file, "%s", pre);
                error = sc->hw_if->getdev(sc->hw_hdl, (audio_device_t *)addr);
                break;
 
        case AUDIO_GETENC:
                ae = (audio_encoding_t *)addr;
                index = ae->index;
+               TRACEF(2, file, "%s index=%d", pre, index);
                if (index < 0 || index >= __arraycount(audio_encodings)) {
                        error = EINVAL;
                        break;
@@ -3204,18 +3223,27 @@
                error = audio_exlock_enter(sc);
                if (error)
                        break;
-               fd = (sc->sc_props & AUDIO_PROP_FULLDUPLEX)
+               val = (sc->sc_props & AUDIO_PROP_FULLDUPLEX)
                    && (sc->sc_pmixer && sc->sc_rmixer);
                audio_exlock_exit(sc);
-               *(int *)addr = fd;
+               *(int *)addr = val;
+               TRACEF(2, file, "%s fulldup=%d", pre, val);
                break;
 
        case AUDIO_GETPROPS:
-               *(int *)addr = sc->sc_props;
+               val = sc->sc_props;
+               *(int *)addr = val;
+#if defined(AUDIO_DEBUG)
+               char pbuf[64];
+               snprintb(pbuf, sizeof(pbuf), "\x10"
+                   "\6CAPTURE" "\5PLAY" "\3INDEP" "\2MMAP" "\1FULLDUP", val);
+               TRACEF(2, file, "%s %s", pre, pbuf);
+#endif
                break;
 
        case AUDIO_QUERYFORMAT:
                query = (audio_format_query_t *)addr;
+               TRACEF(2, file, "%s index=%u", pre, query->index);
                mutex_enter(sc->sc_lock);
                error = sc->hw_if->query_format(sc->hw_hdl, query);
                mutex_exit(sc->sc_lock);
@@ -3224,6 +3252,7 @@
                break;
 
        case AUDIO_GETFORMAT:
+               TRACEF(2, file, "%s", pre);
                error = audio_exlock_enter(sc);
                if (error)
                        break;
@@ -3232,6 +3261,7 @@
                break;
 
        case AUDIO_SETFORMAT:



Home | Main Index | Thread Index | Old Index