mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
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>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
c05ebd0ec9
commit
071786e27d
@@ -3,10 +3,13 @@
|
||||
# Makefile for USB Core files and filesystem
|
||||
#
|
||||
|
||||
# define_trace.h needs to know how to find our header
|
||||
CFLAGS_trace.o := -I$(src)
|
||||
|
||||
usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o
|
||||
usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o
|
||||
usbcore-y += devio.o notify.o generic.o quirks.o devices.o
|
||||
usbcore-y += phy.o port.o
|
||||
usbcore-y += phy.o port.o trace.o
|
||||
|
||||
usbcore-$(CONFIG_OF) += of.o
|
||||
usbcore-$(CONFIG_USB_XHCI_SIDEBAND) += offload.o
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "hub.h"
|
||||
#include "phy.h"
|
||||
#include "otg_productlist.h"
|
||||
#include "trace.h"
|
||||
|
||||
#define USB_VENDOR_GENESYS_LOGIC 0x05e3
|
||||
#define USB_VENDOR_SMSC 0x0424
|
||||
@@ -2154,6 +2155,7 @@ static void update_usb_device_state(struct usb_device *udev,
|
||||
|
||||
udev->state = new_state;
|
||||
update_port_device_state(udev);
|
||||
trace_usb_set_device_state(udev);
|
||||
}
|
||||
|
||||
static void recursively_mark_NOTATTACHED(struct usb_device *udev)
|
||||
|
||||
6
drivers/usb/core/trace.c
Normal file
6
drivers/usb/core/trace.c
Normal file
@@ -0,0 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright (C) 2025 Google LLC
|
||||
*/
|
||||
#define CREATE_TRACE_POINTS
|
||||
#include "trace.h"
|
||||
61
drivers/usb/core/trace.h
Normal file
61
drivers/usb/core/trace.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2025 Google LLC
|
||||
*/
|
||||
#undef TRACE_SYSTEM
|
||||
#define TRACE_SYSTEM usbcore
|
||||
|
||||
#if !defined(_USB_CORE_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
|
||||
#define _USB_CORE_TRACE_H
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/tracepoint.h>
|
||||
#include <linux/usb.h>
|
||||
|
||||
DECLARE_EVENT_CLASS(usb_core_log_usb_device,
|
||||
TP_PROTO(struct usb_device *udev),
|
||||
TP_ARGS(udev),
|
||||
TP_STRUCT__entry(
|
||||
__string(name, dev_name(&udev->dev))
|
||||
__field(enum usb_device_speed, speed)
|
||||
__field(enum usb_device_state, state)
|
||||
__field(unsigned short, bus_mA)
|
||||
__field(unsigned, authorized)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__assign_str(name);
|
||||
__entry->speed = udev->speed;
|
||||
__entry->state = udev->state;
|
||||
__entry->bus_mA = udev->bus_mA;
|
||||
__entry->authorized = udev->authorized;
|
||||
),
|
||||
TP_printk("usb %s speed %s state %s %dmA [%s]",
|
||||
__get_str(name),
|
||||
usb_speed_string(__entry->speed),
|
||||
usb_state_string(__entry->state),
|
||||
__entry->bus_mA,
|
||||
__entry->authorized ? "authorized" : "unauthorized")
|
||||
);
|
||||
|
||||
DEFINE_EVENT(usb_core_log_usb_device, usb_set_device_state,
|
||||
TP_PROTO(struct usb_device *udev),
|
||||
TP_ARGS(udev)
|
||||
);
|
||||
|
||||
DEFINE_EVENT(usb_core_log_usb_device, usb_alloc_dev,
|
||||
TP_PROTO(struct usb_device *udev),
|
||||
TP_ARGS(udev)
|
||||
);
|
||||
|
||||
|
||||
#endif /* _USB_CORE_TRACE_H */
|
||||
|
||||
/* this part has to be here */
|
||||
|
||||
#undef TRACE_INCLUDE_PATH
|
||||
#define TRACE_INCLUDE_PATH .
|
||||
|
||||
#undef TRACE_INCLUDE_FILE
|
||||
#define TRACE_INCLUDE_FILE trace
|
||||
|
||||
#include <trace/define_trace.h>
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <linux/dma-mapping.h>
|
||||
|
||||
#include "hub.h"
|
||||
#include "trace.h"
|
||||
|
||||
const char *usbcore_name = "usbcore";
|
||||
|
||||
@@ -746,6 +747,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
|
||||
#endif
|
||||
|
||||
dev->authorized = usb_dev_authorized(dev, usb_hcd);
|
||||
trace_usb_alloc_dev(dev);
|
||||
return dev;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usb_alloc_dev);
|
||||
|
||||
Reference in New Issue
Block a user