Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb New dtrace usb provider, with a handful of probe...



details:   https://anonhg.NetBSD.org/src/rev/d97cf5cd330d
branches:  trunk
changeset: 969392:d97cf5cd330d
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Feb 19 16:03:30 2020 +0000

description:
New dtrace usb provider, with a handful of probes in usb.c.

diffstat:

 sys/dev/usb/usb.c     |  80 +++++++++++++++++++++++++++++++++++++++++++++++++-
 sys/dev/usb/usb_sdt.h |  36 ++++++++++++++++++++++
 2 files changed, 113 insertions(+), 3 deletions(-)

diffs (243 lines):

diff -r b17923926ccf -r d97cf5cd330d sys/dev/usb/usb.c
--- a/sys/dev/usb/usb.c Wed Feb 19 16:02:50 2020 +0000
+++ b/sys/dev/usb/usb.c Wed Feb 19 16:03:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb.c,v 1.182 2020/02/12 15:59:44 riastradh Exp $      */
+/*     $NetBSD: usb.c,v 1.183 2020/02/19 16:03:30 riastradh Exp $      */
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.182 2020/02/12 15:59:44 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.183 2020/02/19 16:03:30 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -65,6 +65,7 @@
 #include <sys/atomic.h>
 #include <sys/sysctl.h>
 #include <sys/compat_stub.h>
+#include <sys/sdt.h>
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
@@ -73,6 +74,7 @@
 #include <dev/usb/usb_verbose.h>
 #include <dev/usb/usb_quirks.h>
 #include <dev/usb/usbhist.h>
+#include <dev/usb/usb_sdt.h>
 
 #include "ioconf.h"
 
@@ -155,6 +157,54 @@
 
 static struct usb_taskq usb_taskq[USB_NUM_TASKQS];
 
+/* XXX wrong place */
+#ifdef KDTRACE_HOOKS
+#define        __dtrace_used
+#else
+#define        __dtrace_used   __unused
+#endif
+
+SDT_PROVIDER_DEFINE(usb);
+
+SDT_PROBE_DEFINE3(usb, kernel, task, add,
+    "struct usbd_device *"/*dev*/, "struct usb_task *"/*task*/, "int"/*q*/);
+SDT_PROBE_DEFINE2(usb, kernel, task, rem__start,
+    "struct usbd_device *"/*dev*/, "struct usb_task *"/*task*/);
+SDT_PROBE_DEFINE3(usb, kernel, task, rem__done,
+    "struct usbd_device *"/*dev*/,
+    "struct usb_task *"/*task*/,
+    "bool"/*removed*/);
+SDT_PROBE_DEFINE4(usb, kernel, task, rem__wait__start,
+    "struct usbd_device *"/*dev*/,
+    "struct usb_task *"/*task*/,
+    "int"/*queue*/,
+    "kmutex_t *"/*interlock*/);
+SDT_PROBE_DEFINE5(usb, kernel, task, rem__wait__done,
+    "struct usbd_device *"/*dev*/,
+    "struct usb_task *"/*task*/,
+    "int"/*queue*/,
+    "kmutex_t *"/*interlock*/,
+    "bool"/*done*/);
+
+SDT_PROBE_DEFINE1(usb, kernel, task, start,  "struct usb_task *"/*task*/);
+SDT_PROBE_DEFINE1(usb, kernel, task, done,  "struct usb_task *"/*task*/);
+
+SDT_PROBE_DEFINE1(usb, kernel, bus, needs__explore,
+    "struct usbd_bus *"/*bus*/);
+SDT_PROBE_DEFINE1(usb, kernel, bus, needs__reattach,
+    "struct usbd_bus *"/*bus*/);
+SDT_PROBE_DEFINE1(usb, kernel, bus, discover__start,
+    "struct usbd_bus *"/*bus*/);
+SDT_PROBE_DEFINE1(usb, kernel, bus, discover__done,
+    "struct usbd_bus *"/*bus*/);
+SDT_PROBE_DEFINE1(usb, kernel, bus, explore__start,
+    "struct usbd_bus *"/*bus*/);
+SDT_PROBE_DEFINE1(usb, kernel, bus, explore__done,
+    "struct usbd_bus *"/*bus*/);
+
+SDT_PROBE_DEFINE1(usb, kernel, event, add,  "struct usb_event *"/*uep*/);
+SDT_PROBE_DEFINE1(usb, kernel, event, drop,  "struct usb_event *"/*uep*/);
+
 dev_type_open(usbopen);
 dev_type_close(usbclose);
 dev_type_read(usbread);
@@ -412,6 +462,7 @@
        struct usb_taskq *taskq;
 
        USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
+       SDT_PROBE3(usb, kernel, task, add,  dev, task, queue);
 
        KASSERT(0 <= queue);
        KASSERT(queue < USB_NUM_TASKQS);
@@ -446,6 +497,7 @@
        unsigned queue;
 
        USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
+       SDT_PROBE2(usb, kernel, task, rem__start,  dev, task);
 
        while ((queue = task->queue) != USB_NUM_TASKQS) {
                struct usb_taskq *taskq = &usb_taskq[queue];
@@ -454,11 +506,14 @@
                        TAILQ_REMOVE(&taskq->tasks, task, next);
                        task->queue = USB_NUM_TASKQS;
                        mutex_exit(&taskq->lock);
+                       SDT_PROBE3(usb, kernel, task, rem__done,
+                           dev, task, true);
                        return true; /* removed from the queue */
                }
                mutex_exit(&taskq->lock);
        }
 
+       SDT_PROBE3(usb, kernel, task, rem__done,  dev, task, false);
        return false;           /* was not removed from the queue */
 }
 
@@ -489,6 +544,8 @@
        bool removed;
 
        USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
+       SDT_PROBE4(usb, kernel, task, rem__wait__start,
+           dev, task, queue, interlock);
        ASSERT_SLEEPABLE();
        KASSERT(0 <= queue);
        KASSERT(queue < USB_NUM_TASKQS);
@@ -527,6 +584,8 @@
        if (interlock && !removed)
                mutex_enter(interlock);
 
+       SDT_PROBE5(usb, kernel, task, rem__wait__done,
+           dev, task, queue, interlock, removed);
        return removed;
 }
 
@@ -629,8 +688,10 @@
 
                        if (!mpsafe)
                                KERNEL_LOCK(1, curlwp);
+                       SDT_PROBE1(usb, kernel, task, start,  task);
                        task->fun(task->arg);
                        /* Can't dereference task after this point.  */
+                       SDT_PROBE1(usb, kernel, task, done,  task);
                        if (!mpsafe)
                                KERNEL_UNLOCK_ONE(curlwp);
 
@@ -1021,12 +1082,16 @@
         * Also, we now have bus->ub_lock held, and in combination
         * with ub_exploring, avoids interferring with polling.
         */
+       SDT_PROBE1(usb, kernel, bus, discover__start,  bus);
        while (bus->ub_needsexplore && !sc->sc_dying) {
                bus->ub_needsexplore = 0;
                mutex_exit(sc->sc_bus->ub_lock);
+               SDT_PROBE1(usb, kernel, bus, explore__start,  bus);
                bus->ub_roothub->ud_hub->uh_explore(bus->ub_roothub);
+               SDT_PROBE1(usb, kernel, bus, explore__done,  bus);
                mutex_enter(bus->ub_lock);
        }
+       SDT_PROBE1(usb, kernel, bus, discover__done,  bus);
 }
 
 void
@@ -1034,6 +1099,7 @@
 {
 
        USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
+       SDT_PROBE1(usb, kernel, bus, needs__explore,  dev->ud_bus);
 
        mutex_enter(dev->ud_bus->ub_lock);
        dev->ud_bus->ub_needsexplore = 1;
@@ -1046,6 +1112,7 @@
 {
 
        USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
+       SDT_PROBE1(usb, kernel, bus, needs__reattach,  dev->ud_bus);
 
        mutex_enter(dev->ud_bus->ub_lock);
        dev->ud_powersrc->up_reattach = 1;
@@ -1127,12 +1194,19 @@
        ueq->ue = *uep;
        ueq->ue.ue_type = type;
        TIMEVAL_TO_TIMESPEC(&thetime, &ueq->ue.ue_time);
+       SDT_PROBE1(usb, kernel, event, add,  uep);
 
        mutex_enter(&usb_event_lock);
        if (++usb_nevents >= USB_MAX_EVENTS) {
                /* Too many queued events, drop an old one. */
                DPRINTF("event dropped", 0, 0, 0, 0);
-               (void)usb_get_next_event(0);
+#ifdef KDTRACE_HOOKS
+               struct usb_event oue;
+               if (usb_get_next_event(&oue))
+                       SDT_PROBE1(usb, kernel, event, drop,  &oue);
+#else
+               usb_get_next_event(NULL);
+#endif
        }
        SIMPLEQ_INSERT_TAIL(&usb_events, ueq, next);
        cv_signal(&usb_event_cv);
diff -r b17923926ccf -r d97cf5cd330d sys/dev/usb/usb_sdt.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/usb_sdt.h     Wed Feb 19 16:03:30 2020 +0000
@@ -0,0 +1,36 @@
+/*     $NetBSD: usb_sdt.h,v 1.1 2020/02/19 16:03:30 riastradh Exp $    */
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef        _USB_SDT_H_
+#define        _USB_SDT_H_
+
+#include <sys/sdt.h>
+
+SDT_PROVIDER_DECLARE(usb);
+
+#endif /* _USB_SDT_H_ */



Home | Main Index | Thread Index | Old Index