Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: core: Add tracepoints for device allocation and state changes

Introduce new tracepoints to the USB core to improve debuggability of
USB device lifecycle events.

The following tracepoints are added:

- usb_alloc_dev: Triggered when a new USB device structure is allocated,
providing insights into early device setup.
- usb_set_device_state: Triggered when the USB device state changes,
allowing observation of the device's state transitions.

These tracepoints capture detailed information about the USB device,
including its name, speed, state, bus current value, and authorized
flag. This will aid developers in diagnosing issues related to device
enumeration within the USB subsystem.

Examples:
usb_alloc_dev: usb 1-1 speed UNKNOWN state attached 0mA [authorized]
usb_set_device_state: usb 1-1 speed UNKNOWN state powered 0mA [authorized]
usb_set_device_state: usb 1-1 speed full-speed state default 500mA [authorized]
usb_set_device_state: usb 1-1 speed full-speed state default 500mA [authorized]
usb_set_device_state: usb 1-1 speed full-speed state addressed 500mA [authorized]
usb_set_device_state: usb 1-1 speed full-speed state configured 500mA [authorized]
usb_set_device_state: usb 1-1 speed full-speed state suspended 500mA [authorized]
usb_set_device_state: usb 1-1 speed full-speed state not attached 500mA [authorized]

Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://patch.msgid.link/20251015-usbcore-tracing-v2-2-5a14b5b9d4e0@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Kuen-Han Tsai and committed by
Greg Kroah-Hartman
071786e2 c05ebd0e

+75 -1
+4 -1
drivers/usb/core/Makefile
··· 3 3 # Makefile for USB Core files and filesystem 4 4 # 5 5 6 + # define_trace.h needs to know how to find our header 7 + CFLAGS_trace.o := -I$(src) 8 + 6 9 usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o 7 10 usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o 8 11 usbcore-y += devio.o notify.o generic.o quirks.o devices.o 9 - usbcore-y += phy.o port.o 12 + usbcore-y += phy.o port.o trace.o 10 13 11 14 usbcore-$(CONFIG_OF) += of.o 12 15 usbcore-$(CONFIG_USB_XHCI_SIDEBAND) += offload.o
+2
drivers/usb/core/hub.c
··· 41 41 #include "hub.h" 42 42 #include "phy.h" 43 43 #include "otg_productlist.h" 44 + #include "trace.h" 44 45 45 46 #define USB_VENDOR_GENESYS_LOGIC 0x05e3 46 47 #define USB_VENDOR_SMSC 0x0424 ··· 2155 2154 2156 2155 udev->state = new_state; 2157 2156 update_port_device_state(udev); 2157 + trace_usb_set_device_state(udev); 2158 2158 } 2159 2159 2160 2160 static void recursively_mark_NOTATTACHED(struct usb_device *udev)
+6
drivers/usb/core/trace.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (C) 2025 Google LLC 4 + */ 5 + #define CREATE_TRACE_POINTS 6 + #include "trace.h"
+61
drivers/usb/core/trace.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Copyright (C) 2025 Google LLC 4 + */ 5 + #undef TRACE_SYSTEM 6 + #define TRACE_SYSTEM usbcore 7 + 8 + #if !defined(_USB_CORE_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) 9 + #define _USB_CORE_TRACE_H 10 + 11 + #include <linux/types.h> 12 + #include <linux/tracepoint.h> 13 + #include <linux/usb.h> 14 + 15 + DECLARE_EVENT_CLASS(usb_core_log_usb_device, 16 + TP_PROTO(struct usb_device *udev), 17 + TP_ARGS(udev), 18 + TP_STRUCT__entry( 19 + __string(name, dev_name(&udev->dev)) 20 + __field(enum usb_device_speed, speed) 21 + __field(enum usb_device_state, state) 22 + __field(unsigned short, bus_mA) 23 + __field(unsigned, authorized) 24 + ), 25 + TP_fast_assign( 26 + __assign_str(name); 27 + __entry->speed = udev->speed; 28 + __entry->state = udev->state; 29 + __entry->bus_mA = udev->bus_mA; 30 + __entry->authorized = udev->authorized; 31 + ), 32 + TP_printk("usb %s speed %s state %s %dmA [%s]", 33 + __get_str(name), 34 + usb_speed_string(__entry->speed), 35 + usb_state_string(__entry->state), 36 + __entry->bus_mA, 37 + __entry->authorized ? "authorized" : "unauthorized") 38 + ); 39 + 40 + DEFINE_EVENT(usb_core_log_usb_device, usb_set_device_state, 41 + TP_PROTO(struct usb_device *udev), 42 + TP_ARGS(udev) 43 + ); 44 + 45 + DEFINE_EVENT(usb_core_log_usb_device, usb_alloc_dev, 46 + TP_PROTO(struct usb_device *udev), 47 + TP_ARGS(udev) 48 + ); 49 + 50 + 51 + #endif /* _USB_CORE_TRACE_H */ 52 + 53 + /* this part has to be here */ 54 + 55 + #undef TRACE_INCLUDE_PATH 56 + #define TRACE_INCLUDE_PATH . 57 + 58 + #undef TRACE_INCLUDE_FILE 59 + #define TRACE_INCLUDE_FILE trace 60 + 61 + #include <trace/define_trace.h>
+2
drivers/usb/core/usb.c
··· 46 46 #include <linux/dma-mapping.h> 47 47 48 48 #include "hub.h" 49 + #include "trace.h" 49 50 50 51 const char *usbcore_name = "usbcore"; 51 52 ··· 747 746 #endif 748 747 749 748 dev->authorized = usb_dev_authorized(dev, usb_hcd); 749 + trace_usb_alloc_dev(dev); 750 750 return dev; 751 751 } 752 752 EXPORT_SYMBOL_GPL(usb_alloc_dev);