Module Name:    src
Committed By:   riastradh
Date:           Wed Feb 19 16:03:30 UTC 2020

Modified Files:
        src/sys/dev/usb: usb.c
Added Files:
        src/sys/dev/usb: usb_sdt.h

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


To generate a diff of this commit:
cvs rdiff -u -r1.182 -r1.183 src/sys/dev/usb/usb.c
cvs rdiff -u -r0 -r1.1 src/sys/dev/usb/usb_sdt.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/usb.c
diff -u src/sys/dev/usb/usb.c:1.182 src/sys/dev/usb/usb.c:1.183
--- src/sys/dev/usb/usb.c:1.182	Wed Feb 12 15:59:44 2020
+++ src/sys/dev/usb/usb.c	Wed Feb 19 16:03:30 2020
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.18
 #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 @@ __KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.18
 #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 @@ struct usb_taskq {
 
 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 @@ usb_add_task(struct usbd_device *dev, st
 	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 @@ usb_rem_task(struct usbd_device *dev, st
 	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 @@ usb_rem_task(struct usbd_device *dev, st
 			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 @@ usb_rem_task_wait(struct usbd_device *de
 	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 @@ usb_rem_task_wait(struct usbd_device *de
 	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 @@ usb_task_thread(void *arg)
 
 			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 @@ usb_discover(struct usb_softc *sc)
 	 * 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 @@ usb_needs_explore(struct usbd_device *de
 {
 
 	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 @@ usb_needs_reattach(struct usbd_device *d
 {
 
 	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 @@ usb_add_event(int type, struct usb_event
 	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);

Added files:

Index: src/sys/dev/usb/usb_sdt.h
diff -u /dev/null src/sys/dev/usb/usb_sdt.h:1.1
--- /dev/null	Wed Feb 19 16:03:30 2020
+++ src/sys/dev/usb/usb_sdt.h	Wed Feb 19 16:03:30 2020
@@ -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_ */

Reply via email to