From nobody Tue Oct 7 13:31:58 2025 Received: from smtpbg151.qq.com (smtpbg151.qq.com [18.169.211.239]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E89AB289833; Thu, 10 Jul 2025 07:33:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.169.211.239 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752132820; cv=none; b=Vf8R25vggqkKmPQJh6rAgw01K3trmh4GPJp7b04mBV93drcPRjz8iwIH0Za+pyPaDDBjW6ww3za3+36Y9qDPe8UCt4SBowL203xsgZE2ggC6Q0DU1w3BxEHqAUlRb7hr8GUSjJbmJLkepqEw4jmCHTQ5CQqOnQ1MTihmgh5PyGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752132820; c=relaxed/simple; bh=Q/Jf3+XVh+iUCR0VCgJfYWeHyXKbJ5iuYDqX1WNlqo4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nN79JdZDsjx9uYbDHQeaqAC1VpqDluF8Jik5RjPu2W8ITX9YEqhARp2HZvBuHhGJYeZdD8cQRoPMDCl/65xqA4ANzstX2LsR234ZUj7YfSN2ztctEJWrvMpXcXFIV/ZziJA4YOOagLlu96WtM/nKGp/6WxoMcsahTHmEdWfUke0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com; spf=pass smtp.mailfrom=uniontech.com; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b=nVdYi1gd; arc=none smtp.client-ip=18.169.211.239 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniontech.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b="nVdYi1gd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1752132780; bh=eZIfjwyXRyZV9+QTOxx3kw1AO9i/MtOVaN7ILkdVRn8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=nVdYi1gdWXAmH/5KX2I7pO69faMGJasGBapByyzIv+QQSfu+/B+oFBtn124X1miU8 v85Lg6iM5df4nycepEz/9hCJeG50Jfh/lKSTrvgvH4PCiJ6eCnFGZCEnkT//eWkcRK eX0UWYllkvVJh9PhQCz4HolpTCqUGl8iSDaSP2hc= X-QQ-mid: zesmtpip2t1752132717ta1e33716 X-QQ-Originating-IP: 1m3E08q8ehv1ztCLul4rhiU7h9IeBrnWTDg9XyfvCU8= Received: from avenger-e500 ( [localhost]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 10 Jul 2025 15:31:55 +0800 (CST) X-QQ-SSF: 0002000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 8695579808043688623 EX-QQ-RecipientCnt: 13 From: WangYuli To: wangyuli@uniontech.com Cc: dmitry.torokhov@gmail.com, guanwentao@uniontech.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, niecheng1@uniontech.com, rostedt@goodmis.org, wangyuli@deepin.org, zhanjun@uniontech.com, Winston Wen Subject: [PATCH 1/2] input: Add tracepoint support Date: Thu, 10 Jul 2025 15:31:38 +0800 Message-ID: X-Mailer: git-send-email 2.50.0 In-Reply-To: <19571F312EE197A5+20250710072634.3992019-1-wangyuli@uniontech.com> References: <19571F312EE197A5+20250710072634.3992019-1-wangyuli@uniontech.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-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otJB5JwZLCD4maHSBP6rOTsJkCaBDK4hqgCLCf53Yl+465jE wuk200w+nP7YIJBw2hghExaeUo9o+RP2SJNa7nmRV+2z6PsICnOVVLT717TXa23uYUqeYDD MMa2Ow4mwjftezpyE8fgDPlsPtenezityVLJcC8tucPZCCNQJ118lvGtagd7y9+2A== X-QQ-XMRINFO: M/715EihBoGSf6IYSX1iLFg= X-QQ-RECHKSPAM: 0 Content-Type: text/plain; charset="utf-8" Introduce a set of tracepoints for the input subsystem to enable better debugging, monitoring, and performance analysis of input device operations. Suggested-by: Winston Wen Signed-off-by: WangYuli --- MAINTAINERS | 1 + drivers/input/input.c | 18 ++- include/trace/events/input.h | 251 +++++++++++++++++++++++++++++++++++ 3 files changed, 269 insertions(+), 1 deletion(-) create mode 100644 include/trace/events/input.h diff --git a/MAINTAINERS b/MAINTAINERS index 00d7dcee88cb..c1b03679a5a1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11933,6 +11933,7 @@ F: include/linux/i8042.h F: include/linux/input.h F: include/linux/input/ F: include/linux/libps2.h +F: include/trace/events/input.h F: include/linux/serio.h F: include/uapi/linux/gameport.h F: include/uapi/linux/input-event-codes.h diff --git a/drivers/input/input.c b/drivers/input/input.c index 44887e51e049..925c76a50742 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -29,6 +29,9 @@ #include "input-core-private.h" #include "input-poller.h" =20 +#define CREATE_TRACE_POINTS +#include + MODULE_AUTHOR("Vojtech Pavlik "); MODULE_DESCRIPTION("Input core"); MODULE_LICENSE("GPL"); @@ -363,6 +366,7 @@ void input_handle_event(struct input_dev *dev, =20 disposition =3D input_get_disposition(dev, type, code, &value); if (disposition !=3D INPUT_IGNORE_EVENT) { + trace_input_event(dev, type, code, value); if (type !=3D EV_SYN) add_input_randomness(type, code, value); =20 @@ -525,6 +529,7 @@ int input_grab_device(struct input_handle *handle) return -EBUSY; =20 rcu_assign_pointer(dev->grab, handle); + trace_input_grab_device(dev, handle); } =20 return 0; @@ -539,6 +544,7 @@ static void __input_release_device(struct input_handle = *handle) grabber =3D rcu_dereference_protected(dev->grab, lockdep_is_held(&dev->mutex)); if (grabber =3D=3D handle) { + trace_input_release_device(dev, handle); rcu_assign_pointer(dev->grab, NULL); /* Make sure input_pass_values() notices that grab is gone */ synchronize_rcu(); @@ -612,6 +618,7 @@ int input_open_device(struct input_handle *handle) =20 if (dev->poller) input_dev_poller_start(dev->poller); + trace_input_open_device(dev); } =20 return 0; @@ -652,6 +659,7 @@ void input_close_device(struct input_handle *handle) input_dev_poller_stop(dev->poller); if (dev->close) dev->close(dev); + trace_input_close_device(dev); } } =20 @@ -991,9 +999,13 @@ static int input_attach_handler(struct input_dev *dev,= struct input_handler *han return -ENODEV; =20 error =3D handler->connect(handler, dev, id); - if (error && error !=3D -ENODEV) + if (error && error !=3D -ENODEV) { pr_err("failed to attach handler %s to device %s, error: %d\n", handler->name, kobject_name(&dev->dev.kobj), error); + } else if (!error) { + /* Connection successful, trace it */ + trace_input_handler_connect(handler, dev, handler->minor); + } =20 return error; } @@ -1791,6 +1803,7 @@ static int input_inhibit_device(struct input_dev *dev) } =20 dev->inhibited =3D true; + trace_input_inhibit_device(dev); =20 return 0; } @@ -1818,6 +1831,7 @@ static int input_uninhibit_device(struct input_dev *d= ev) =20 scoped_guard(spinlock_irq, &dev->event_lock) input_dev_toggle(dev, true); + trace_input_uninhibit_device(dev); =20 return 0; } @@ -2216,6 +2230,7 @@ static void __input_unregister_device(struct input_de= v *dev) { struct input_handle *handle, *next; =20 + trace_input_device_unregister(dev); input_disconnect_device(dev); =20 scoped_guard(mutex, &input_mutex) { @@ -2414,6 +2429,7 @@ int input_register_device(struct input_dev *dev) input_wakeup_procfs_readers(); } =20 + trace_input_device_register(dev); if (dev->devres_managed) { dev_dbg(dev->dev.parent, "%s: registering %s with devres.\n", __func__, dev_name(&dev->dev)); diff --git a/include/trace/events/input.h b/include/trace/events/input.h new file mode 100644 index 000000000000..3c5ffcfb7c8d --- /dev/null +++ b/include/trace/events/input.h @@ -0,0 +1,251 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* input tracepoints + * + * Copyright (C) 2025 WangYuli + */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM input + +#if !defined(_TRACE_INPUT_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_INPUT_H + +#include +#include + +/** + * input_event - called when an input event is processed + * @dev: input device that generated the event + * @type: event type (EV_KEY, EV_REL, EV_ABS, etc.) + * @code: event code within the type + * @value: event value + * + * This tracepoint fires for every input event processed by the input core. + * It can be used to monitor input device activity and debug input issues. + */ +TRACE_EVENT( + input_event, + + TP_PROTO(struct input_dev *dev, unsigned int type, unsigned int code, + int value), + + TP_ARGS(dev, type, code, value), + + TP_STRUCT__entry(__string(name, dev->name ?: "unknown") __field( + unsigned int, type) __field(unsigned int, code) + __field(int, value) __field(u16, bustype) + __field(u16, vendor) + __field(u16, product)), + + TP_fast_assign(__assign_str(name); __entry->type =3D type; + __entry->code =3D code; __entry->value =3D value; + __entry->bustype =3D dev->id.bustype; + __entry->vendor =3D dev->id.vendor; + __entry->product =3D dev->id.product;), + + TP_printk( + "dev=3D%s type=3D%u code=3D%u value=3D%d bus=3D%04x vendor=3D%04x produc= t=3D%04x", + __get_str(name), __entry->type, __entry->code, __entry->value, + __entry->bustype, __entry->vendor, __entry->product)); + +/** + * input_device_register - called when an input device is registered + * @dev: input device being registered + * + * This tracepoint fires when a new input device is registered with the + * input subsystem. Useful for monitoring device hotplug events. + */ +TRACE_EVENT( + input_device_register, + + TP_PROTO(struct input_dev *dev), + + TP_ARGS(dev), + + TP_STRUCT__entry(__string(name, dev->name ?: "unknown") __string( + phys, dev->phys ?: "") __field(u16, bustype) + __field(u16, vendor) __field(u16, product) + __field(u16, version)), + + TP_fast_assign(__assign_str(name); __assign_str(phys); + __entry->bustype =3D dev->id.bustype; + __entry->vendor =3D dev->id.vendor; + __entry->product =3D dev->id.product; + __entry->version =3D dev->id.version;), + + TP_printk( + "dev=3D%s phys=3D%s bus=3D%04x vendor=3D%04x product=3D%04x version=3D%0= 4x", + __get_str(name), __get_str(phys), __entry->bustype, + __entry->vendor, __entry->product, __entry->version)); + +/** + * input_device_unregister - called when an input device is unregistered + * @dev: input device being unregistered + * + * This tracepoint fires when an input device is unregistered from the + * input subsystem. Useful for monitoring device hotplug events. + */ +TRACE_EVENT(input_device_unregister, + + TP_PROTO(struct input_dev *dev), + + TP_ARGS(dev), + + TP_STRUCT__entry(__string(name, dev->name ?: "unknown") __string( + phys, dev->phys ?: "") __field(u16, bustype) + __field(u16, vendor) + __field(u16, product)), + + TP_fast_assign(__assign_str(name); __assign_str(phys); + __entry->bustype =3D dev->id.bustype; + __entry->vendor =3D dev->id.vendor; + __entry->product =3D dev->id.product;), + + TP_printk("dev=3D%s phys=3D%s bus=3D%04x vendor=3D%04x product=3D%04x= ", + __get_str(name), __get_str(phys), __entry->bustype, + __entry->vendor, __entry->product)); + +/** + * input_handler_connect - called when an input handler connects to a devi= ce + * @handler: input handler + * @dev: input device + * @minor: assigned minor number (if applicable) + * + * This tracepoint fires when an input handler (like evdev, mousedev) conn= ects + * to an input device, creating a new input handle. + */ +TRACE_EVENT(input_handler_connect, + + TP_PROTO(struct input_handler *handler, struct input_dev *dev, + int minor), + + TP_ARGS(handler, dev, minor), + + TP_STRUCT__entry(__string(handler_name, handler->name) + __string(dev_name, dev->name ?: "unknown") + __field(int, minor)), + + TP_fast_assign(__assign_str(handler_name); __assign_str(dev_name); + __entry->minor =3D minor;), + + TP_printk("handler=3D%s dev=3D%s minor=3D%d", __get_str(handler_name), + __get_str(dev_name), __entry->minor)); + +/** + * input_grab_device - called when a device is grabbed by a handler + * @dev: input device being grabbed + * @handle: input handle doing the grab + * + * This tracepoint fires when an input device is grabbed exclusively + * by an input handler, typically for security or special processing. + */ +TRACE_EVENT(input_grab_device, + + TP_PROTO(struct input_dev *dev, struct input_handle *handle), + + TP_ARGS(dev, handle), + + TP_STRUCT__entry(__string(dev_name, dev->name ?: "unknown") + __string(handler_name, + handle->handler->name)), + + TP_fast_assign(__assign_str(dev_name); __assign_str(handler_name);), + + TP_printk("dev=3D%s grabbed_by=3D%s", __get_str(dev_name), + __get_str(handler_name))); + +/** + * input_release_device - called when a grabbed device is released + * @dev: input device being released + * @handle: input handle releasing the grab + * + * This tracepoint fires when an input device grab is released. + */ +TRACE_EVENT(input_release_device, + + TP_PROTO(struct input_dev *dev, struct input_handle *handle), + + TP_ARGS(dev, handle), + + TP_STRUCT__entry(__string(dev_name, dev->name ?: "unknown") + __string(handler_name, + handle->handler->name)), + + TP_fast_assign(__assign_str(dev_name); __assign_str(handler_name);), + + TP_printk("dev=3D%s released_by=3D%s", __get_str(dev_name), + __get_str(handler_name))); + +DECLARE_EVENT_CLASS(input_device_state, + + TP_PROTO(struct input_dev *dev), + + TP_ARGS(dev), + + TP_STRUCT__entry(__string(name, dev->name ?: "unknown") + __field(unsigned int, users) + __field(bool, inhibited)), + + TP_fast_assign(__assign_str(name); + __entry->users =3D dev->users; + __entry->inhibited =3D dev->inhibited;), + + TP_printk("dev=3D%s users=3D%u inhibited=3D%s", __get_str(name), + __entry->users, + __entry->inhibited ? "true" : "false")); + +/** + * input_open_device - called when an input device is opened + * @dev: input device being opened + * + * This tracepoint fires when the user count for an input device increases, + * typically when a userspace application opens the device. + */ +DEFINE_EVENT(input_device_state, input_open_device, + + TP_PROTO(struct input_dev *dev), + + TP_ARGS(dev)); + +/** + * input_close_device - called when an input device is closed + * @dev: input device being closed + * + * This tracepoint fires when the user count for an input device decreases, + * typically when a userspace application closes the device. + */ +DEFINE_EVENT(input_device_state, input_close_device, + + TP_PROTO(struct input_dev *dev), + + TP_ARGS(dev)); + +/** + * input_inhibit_device - called when an input device is inhibited + * @dev: input device being inhibited + * + * This tracepoint fires when an input device is inhibited (disabled), + * usually for power management or security reasons. + */ +DEFINE_EVENT(input_device_state, input_inhibit_device, + + TP_PROTO(struct input_dev *dev), + + TP_ARGS(dev)); + +/** + * input_uninhibit_device - called when an input device is uninhibited + * @dev: input device being uninhibited + * + * This tracepoint fires when an input device is uninhibited (re-enabled) + * after being previously inhibited. + */ +DEFINE_EVENT(input_device_state, input_uninhibit_device, + + TP_PROTO(struct input_dev *dev), + + TP_ARGS(dev)); + +#endif /* _TRACE_INPUT_H */ + +/* This part must be outside protection */ +#include --=20 2.50.0