git: 38b1cbc87b5f - stable/13 - usb(4): Make the enumeration thread nice time a variable.

From: Hans Petter Selasky <hselasky_at_FreeBSD.org>
Date: Wed, 12 Oct 2022 15:54:23 UTC
The branch stable/13 has been updated by hselasky:

URL: https://cgit.FreeBSD.org/src/commit/?id=38b1cbc87b5faefec38a81c4487877fde778be20

commit 38b1cbc87b5faefec38a81c4487877fde778be20
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2022-10-07 11:28:38 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2022-10-12 15:53:22 +0000

    usb(4): Make the enumeration thread nice time a variable.
    
    Depends on "options USB_DEBUG".
    
    Suggested by:   koobs@
    Sponsored by:   NVIDIA Networking
    
    (cherry picked from commit 8758aabb169d98f08c20f2a1fce5184434b1ddf6)
---
 sys/dev/usb/controller/usb_controller.c | 2 +-
 sys/dev/usb/usb.h                       | 1 +
 sys/dev/usb/usb_debug.c                 | 7 ++++++-
 sys/dev/usb/usb_debug.h                 | 2 ++
 4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/sys/dev/usb/controller/usb_controller.c b/sys/dev/usb/controller/usb_controller.c
index 8705c2849e4e..37f318ca98df 100644
--- a/sys/dev/usb/controller/usb_controller.c
+++ b/sys/dev/usb/controller/usb_controller.c
@@ -418,7 +418,7 @@ usb_bus_explore(struct usb_proc_msg *pm)
 #endif
 
 	/* Nice the enumeration a bit, to avoid looping too fast. */
-	usb_pause_mtx(&bus->bus_mtx, USB_MS_TO_TICKS(16));
+	usb_pause_mtx(&bus->bus_mtx, USB_MS_TO_TICKS(usb_enum_nice_time));
 }
 
 /*------------------------------------------------------------------------*
diff --git a/sys/dev/usb/usb.h b/sys/dev/usb/usb.h
index ad0381366f98..0bef7a10bc6c 100644
--- a/sys/dev/usb/usb.h
+++ b/sys/dev/usb/usb.h
@@ -123,6 +123,7 @@ MALLOC_DECLARE(M_USBDEV);
 #define	USB_RESUME_WAIT			50	/* ms */
 #define	USB_RESUME_RECOVERY		50	/* ms */
 #define	USB_EXTRA_POWER_UP_TIME		20	/* ms */
+#define	USB_ENUM_NICE_TIME		16	/* ms */
 
 #define	USB_MIN_POWER		100	/* mA */
 #define	USB_MAX_POWER		500	/* mA */
diff --git a/sys/dev/usb/usb_debug.c b/sys/dev/usb/usb_debug.c
index 5e521f7ec3a5..6ad8dce9a037 100644
--- a/sys/dev/usb/usb_debug.c
+++ b/sys/dev/usb/usb_debug.c
@@ -2,7 +2,7 @@
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
- * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
+ * Copyright (c) 2008-2022 Hans Petter Selasky
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -123,6 +123,10 @@ SYSCTL_PROC(_hw_usb_timings, OID_AUTO, extra_power_up_time,
     CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &usb_extra_power_up_time,
     sizeof(usb_extra_power_up_time), usb_timings_sysctl_handler, "IU",
     "Extra PowerUp Time");
+SYSCTL_PROC(_hw_usb_timings, OID_AUTO, enum_nice_time,
+    CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &usb_enum_nice_time,
+    sizeof(usb_enum_nice_time), usb_timings_sysctl_handler, "IU",
+    "Enumeration thread nice time");
 #endif
 
 /*------------------------------------------------------------------------*
@@ -245,6 +249,7 @@ unsigned int usb_resume_delay		= USB_RESUME_DELAY;
 unsigned int usb_resume_wait		= USB_RESUME_WAIT;
 unsigned int usb_resume_recovery	= USB_RESUME_RECOVERY;
 unsigned int usb_extra_power_up_time	= USB_EXTRA_POWER_UP_TIME;
+unsigned int usb_enum_nice_time		= USB_ENUM_NICE_TIME;
 
 /*------------------------------------------------------------------------*
  *	usb_timings_sysctl_handler
diff --git a/sys/dev/usb/usb_debug.h b/sys/dev/usb/usb_debug.h
index 87c0dcfe3d5f..3f25268629cf 100644
--- a/sys/dev/usb/usb_debug.h
+++ b/sys/dev/usb/usb_debug.h
@@ -72,6 +72,7 @@ extern unsigned int usb_resume_delay;
 extern unsigned int usb_resume_wait;
 extern unsigned int usb_resume_recovery;
 extern unsigned int usb_extra_power_up_time;
+extern unsigned int usb_enum_nice_time;
 #else
 #define usb_port_reset_delay		USB_PORT_RESET_DELAY
 #define usb_port_root_reset_delay	USB_PORT_ROOT_RESET_DELAY
@@ -83,6 +84,7 @@ extern unsigned int usb_extra_power_up_time;
 #define usb_resume_wait			USB_RESUME_WAIT
 #define usb_resume_recovery		USB_RESUME_RECOVERY
 #define usb_extra_power_up_time		USB_EXTRA_POWER_UP_TIME
+#define usb_enum_nice_time		USB_ENUM_NICE_TIME
 #endif
 
 #endif					/* _USB_DEBUG_H_ */