PCI: hotplug: Add a generic RAS tracepoint for hotplug event
PATCH v6 1/1 PCI: hotplug: Add a generic RAS tracepoint for hotplug event
Hotplug events are critical indicators for analyzing hardware health, particularly in AI supercomputers where surprise link downs can significantly impact system performance and reliability.
To this end, define a new TRACING_SYSTEM named pci, add a generic RAS tracepoint for hotplug event to help healthy check, and generate tracepoints for pcie hotplug event. Add enum pci_hotplug_event in include/uapi/linux/pci.h so applications like rasdaemon can register tracepoint event handlers for it.
The output like below:
$ echo 1 > /sys/kernel/debug/tracing/events/pci/pci_hp_event/enable
$ cat /sys/kernel/debug/tracing/trace_pipe
<...>-206 [001] ..... 40.373870: pci_hp_event: 0000:00:02.0 slot:10, event:Link Down<...>-206 [001] ..... 40.374871: pci_hp_event: 0000:00:02.0 slot:10, event:Card not present
---
changes since v5:
- move define of enum to include/uapi/linux/pci.h
--- drivers/pci/hotplug/pciehp_ctrl.c | 33 ++++++++++++++++++----- drivers/pci/hotplug/trace.h | 45 +++++++++++++++++++++++++++++++ include/uapi/linux/pci.h | 31 +++++++++++++++++++++ 3 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 drivers/pci/hotplug/trace.h
drivers/pci/hotplug/pciehp_ctrl.c +27 -6
@@ -23,6 +23,9 @@#include "../pci.h" #include "pciehp.h" +#define CREATE_TRACE_POINTS +#include "trace.h" +/* The following routines constitute the bulk of the hotplug controller logic */
@@ -244,12 +247,20 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)case ON_STATE : ctrl->state =POWEROFF_STATE ;mutex_unlock (&ctrl->state_lock); -if (events &PCI_EXP_SLTSTA_DLLSC ) +if (events &PCI_EXP_SLTSTA_DLLSC ) {ctrl_info (ctrl,"Slot(%s): Link Down\n" ,slot_name (ctrl)); -if (events &PCI_EXP_SLTSTA_PDC ) +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_LINK_DOWN ); + } +if (events &PCI_EXP_SLTSTA_PDC ) {ctrl_info (ctrl,"Slot(%s): Card not present\n" ,slot_name (ctrl)); +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_CARD_NOT_PRESENT ); + }pciehp_disable_slot (ctrl,SURPRISE_REMOVAL );break ;default :
@@ -269,6 +280,9 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) INDICATOR_NOOP);ctrl_info (ctrl,"Slot(%s): Card not present\n" ,slot_name (ctrl)); +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_CARD_NOT_PRESENT ); }mutex_unlock (&ctrl->state_lock);return ;
@@ -281,12 +295,19 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)case OFF_STATE : ctrl->state =POWERON_STATE ;mutex_unlock (&ctrl->state_lock); -if (present) +if (present) {ctrl_info (ctrl,"Slot(%s): Card present\n" ,slot_name (ctrl)); -if (link_active) -ctrl_info (ctrl,"Slot(%s): Link Up\n" , -slot_name (ctrl)); +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_CARD_PRESENT ); + } +if (link_active) { +ctrl_info (ctrl,"Slot(%s): Link Up\n" ,slot_name (ctrl)); +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_LINK_UP ); + } ctrl->request_result =pciehp_enable_slot (ctrl);break ;default :
drivers/pci/hotplug/trace.h new file +45 -0
45 lines not on this page · raw message
include/uapi/linux/pci.h +31 -0
@@ -19,6 +19,7 @@#define _UAPILINUX_PCI_H#include <linux/pci_regs.h> /* The pci register defines */ +#include <linux/tracepoint.h> /* * The PCI interface treats multi-function devices as independent
@@ -39,4 +40,34 @@#define PCIIOC_MMAP_IS_MEM (PCIIOC_BASE | 0x02)/* Set mmap state to MEM space. */ #define PCIIOC_WRITE_COMBINE (PCIIOC_BASE | 0x03)/* Enable/disable write-combining. */ +#define PCI_HOTPLUG_EVENT \ + EM(PCI_HOTPLUG_LINK_UP, "Link Up") \ + EM(PCI_HOTPLUG_LINK_DOWN, "Link Down") \ + EM(PCI_HOTPLUG_CARD_PRESENT, "Card present") \ + EMe(PCI_HOTPLUG_CARD_NOT_PRESENT, "Card not present") + +/* Enums require being exported to userspace, for user tool parsing */ +#undef EM +#undef EMe +#define EM (a, b) TRACE_DEFINE_ENUM(a); +#define EMe (a, b) TRACE_DEFINE_ENUM(a); + +enum pci_hotplug_event { +PCI_HOTPLUG_LINK_UP , +PCI_HOTPLUG_LINK_DOWN , +PCI_HOTPLUG_CARD_PRESENT , +PCI_HOTPLUG_CARD_NOT_PRESENT , +}; + +PCI_HOTPLUG_EVENT + +/* +* Now redefine the EM() and EMe() macros to map the enums to the strings +* that will be printed in the output. + */ +#undef EM +#undef EMe +#define EM (a, b) {a, b}, +#define EMe (a, b) {a, b} +#endif /* _UAPILINUX_PCI_H */
Signature · 1 line
2.39.3
Steven Rostedt
maintainerQuoted 8 lines · On Wed, 15 Jan 2025 09:37:53 +0800 Shuai Xue <[email protected]> wrote:
drivers/pci/hotplug/pciehp_ctrl.c +3
-0+#define CREATE_TRACE_POINTS +#include "trace.h" +/* The following routines constitute the bulk of the hotplug controller logic */ @@ -244,12 +247,20 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)case ON_STATE :
drivers/pci/hotplug/pciehp_ctrl.c void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) · line 255
Quoted 10 lines
drivers/pci/hotplug/pciehp_ctrl.c +4
-2ctrl->state =POWEROFF_STATE ;mutex_unlock (&ctrl->state_lock); -if (events &PCI_EXP_SLTSTA_DLLSC ) +if (events &PCI_EXP_SLTSTA_DLLSC ) {ctrl_info (ctrl,"Slot(%s): Link Down\n" ,slot_name (ctrl)); -if (events &PCI_EXP_SLTSTA_PDC ) +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_LINK_DOWN );
Hmm, can't you just pass in the ctrl pointer to the tracepoint?
trace_pci_hp_event(ctrl, PCI_HOTPLUG_LINK_DOWN);
Quoted 62 lines
drivers/pci/hotplug/pciehp_ctrl.c +20
-4+ } +if (events &PCI_EXP_SLTSTA_PDC ) {ctrl_info (ctrl,"Slot(%s): Card not present\n" ,slot_name (ctrl)); +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_CARD_NOT_PRESENT ); + }pciehp_disable_slot (ctrl,SURPRISE_REMOVAL );break ;default :@@ -269,6 +280,9 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) INDICATOR_NOOP);ctrl_info (ctrl,"Slot(%s): Card not present\n" ,slot_name (ctrl)); +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_CARD_NOT_PRESENT ); }mutex_unlock (&ctrl->state_lock);return ;@@ -281,12 +295,19 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)case OFF_STATE : ctrl->state =POWERON_STATE ;mutex_unlock (&ctrl->state_lock); -if (present) +if (present) {ctrl_info (ctrl,"Slot(%s): Card present\n" ,slot_name (ctrl)); -if (link_active) -ctrl_info (ctrl,"Slot(%s): Link Up\n" , -slot_name (ctrl)); +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_CARD_PRESENT ); + } +if (link_active) { +ctrl_info (ctrl,"Slot(%s): Link Up\n" ,slot_name (ctrl)); +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_LINK_UP ); + } ctrl->request_result =pciehp_enable_slot (ctrl);break ;default :drivers/pci/hotplug/trace.h new file +11
-0@@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#if !defined(_TRACE_HW_EVENT_PCI_HP_H) || defined(TRACE_HEADER_MULTI_READ ) +#define _TRACE_HW_EVENT_PCI_HP_H + +#include <linux/tracepoint.h> + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM pci + +TRACE_EVENT(pci_hp_event, +
drivers/pci/hotplug/trace.h line 21
Quoted 10 lines
drivers/pci/hotplug/trace.h new file +10
-0+ TP_PROTO(const char *port_name, + const char *slot, + const int event), + + TP_ARGS(port_name, slot, event), + + TP_STRUCT__entry( + __string( port_name, port_name ) + __string( slot, slot ) + __field( int, event )
Then the above would be:
TP_PROTO(struct controller *ctrl, int event),
// don't really need a const int there
TP_ARGS(ctrl, event), TP_STRUCT__entry( __string( port_name, pci_name(ctrl->pcie->port) ) __string( slot, slot_name(ctrl) ) __field( int, event )
and everything else could be the same.
-- Steve
Quoted 14 lines
drivers/pci/hotplug/trace.h new file +14
-0+ ), + + TP_fast_assign( + __assign_str(port_name); +__assign_str (slot); + __entry->event = event; + ), + +TP_printk ("%s slot:%s, event:%s\n" , +__get_str (port_name), +__get_str (slot), +__print_symbolic (__entry->event,PCI_HOTPLUG_EVENT ) + ) +);
Quoted 105 lines · Steven Rostedt
Quoted 8 lines · On Wed, 15 Jan 2025 09:37:53 +0800 Shuai Xue <[email protected]> wrote:
drivers/pci/hotplug/pciehp_ctrl.c +3
-0+#define CREATE_TRACE_POINTS +#include "trace.h" +/* The following routines constitute the bulk of the hotplug controller logic */ @@ -244,12 +247,20 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)case ON_STATE :drivers/pci/hotplug/pciehp_ctrl.c void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) · line 255
Quoted 10 lines
drivers/pci/hotplug/pciehp_ctrl.c +4
-2ctrl->state =POWEROFF_STATE ;mutex_unlock (&ctrl->state_lock); -if (events &PCI_EXP_SLTSTA_DLLSC ) +if (events &PCI_EXP_SLTSTA_DLLSC ) {ctrl_info (ctrl,"Slot(%s): Link Down\n" ,slot_name (ctrl)); -if (events &PCI_EXP_SLTSTA_PDC ) +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_LINK_DOWN );Hmm, can't you just pass in the ctrl pointer to the tracepoint?
trace_pci_hp_event(ctrl, PCI_HOTPLUG_LINK_DOWN);Quoted 62 lines
drivers/pci/hotplug/pciehp_ctrl.c +20
-4+ } +if (events &PCI_EXP_SLTSTA_PDC ) {ctrl_info (ctrl,"Slot(%s): Card not present\n" ,slot_name (ctrl)); +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_CARD_NOT_PRESENT ); + }pciehp_disable_slot (ctrl,SURPRISE_REMOVAL );break ;default :@@ -269,6 +280,9 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) INDICATOR_NOOP);ctrl_info (ctrl,"Slot(%s): Card not present\n" ,slot_name (ctrl)); +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_CARD_NOT_PRESENT ); }mutex_unlock (&ctrl->state_lock);return ;@@ -281,12 +295,19 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)case OFF_STATE : ctrl->state =POWERON_STATE ;mutex_unlock (&ctrl->state_lock); -if (present) +if (present) {ctrl_info (ctrl,"Slot(%s): Card present\n" ,slot_name (ctrl)); -if (link_active) -ctrl_info (ctrl,"Slot(%s): Link Up\n" , -slot_name (ctrl)); +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_CARD_PRESENT ); + } +if (link_active) { +ctrl_info (ctrl,"Slot(%s): Link Up\n" ,slot_name (ctrl)); +trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_LINK_UP ); + } ctrl->request_result =pciehp_enable_slot (ctrl);break ;default :drivers/pci/hotplug/trace.h new file +11
-0@@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#if !defined(_TRACE_HW_EVENT_PCI_HP_H) || defined(TRACE_HEADER_MULTI_READ ) +#define _TRACE_HW_EVENT_PCI_HP_H + +#include <linux/tracepoint.h> + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM pci + +TRACE_EVENT(pci_hp_event, +drivers/pci/hotplug/trace.h line 21
Quoted 10 lines
drivers/pci/hotplug/trace.h new file +10
-0+ TP_PROTO(const char *port_name, + const char *slot, + const int event), + + TP_ARGS(port_name, slot, event), + + TP_STRUCT__entry( + __string( port_name, port_name ) + __string( slot, slot ) + __field( int, event )Then the above would be:
TP_PROTO(struct controller *ctrl, int event),// don't really need a const int there
Quoted 8 lines
TP_ARGS(ctrl, event), TP_STRUCT__entry( __string( port_name, pci_name(ctrl->pcie->port) ) __string( slot, slot_name(ctrl) ) __field( int, event )and everything else could be the same.
Maybe it's not a good idea.
I think pci_hp_event is a generic event for pciehp, shpchp, octep_hp, etc. But each hotplug driver has different struct controller and slot_name(). For example:
// drivers/pci/hotplug/pciehp.h
static inline const char *slot_name(struct controller *ctrl)
{
return hotplug_slot_name(&ctrl->hotplug_slot);
}// drivers/pci/hotplug/shpchp.h
static inline const char *slot_name(struct slot *slot)
{
return hotplug_slot_name(&slot->hotplug_slot);
}So, IMHO, pass port_name and slot_name from each driver is more simple.
+ @Lukas for hotplug part.
Quoted 4 lines
-- Steve
Thanks.
Best Regards,
Shuai
Quoted 27 lines · Shuai Xue
2025/1/15 10:41, Steven Rostedt:
Quoted 20 lines · On Wed, 15 Jan 2025 09:37:53 +0800 Shuai Xue <[email protected]> wrote:
drivers/pci/hotplug/pciehp_ctrl.c void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) · line 255
Quoted 3 lines
drivers/pci/hotplug/pciehp_ctrl.c +3
-0+trace_pci_hp_event (pci_name (ctrl->pcie->port), +slot_name (ctrl), +PCI_HOTPLUG_LINK_DOWN );Hmm, can't you just pass in the ctrl pointer to the tracepoint?
trace_pci_hp_event(ctrl, PCI_HOTPLUG_LINK_DOWN);Then the above would be:
TP_PROTO(struct controller *ctrl, int event), TP_ARGS(ctrl, event), TP_STRUCT__entry( __string( port_name, pci_name(ctrl->pcie->port) ) __string( slot, slot_name(ctrl) ) __field( int, event )Quoted 1 line
and everything else could be the same.
Maybe it's not a good idea.
I think
pci_hp_eventis a generic event for pciehp, shpchp,octep_hp, etc. But each hotplug driver has differentstruct controllerandslot_name().
[...]
Quoted 3 lines
So, IMHO, pass
port_nameandslot_namefrom each driver is more simple.+ @Lukas for hotplug part.
You're right Shuai, there's several hotplug drivers in drivers/pci/hotplug/ and pciehp is just one of them. It's quite possible that other drivers besides pciehp will want to add trace points as well. For consistency, the trace event definitions need to work for all drivers.
Thanks,
Lukas
Steven Rostedt
maintainerQuoted 13 lines · On Wed, 15 Jan 2025 10:33:39 +0100 Lukas Wunner <[email protected]> wrote:
Quoted 12 lines
Quoted 7 lines
TP_STRUCT__entry( __string( port_name, pci_name(ctrl->pcie->port) ) __string( slot, slot_name(ctrl) ) __field( int, event )and everything else could be the same.
Maybe it's not a good idea.
I think
pci_hp_eventis a generic event for pciehp, shpchp,octep_hp, etc. But each hotplug driver has differentstruct controllerandslot_name().[...]
Quoted 8 lines
Quoted 3 lines
So, IMHO, pass
port_nameandslot_namefrom each driver is more simple.+ @Lukas for hotplug part.
You're right Shuai, there's several hotplug drivers in
drivers/pci/hotplug/and pciehp is just one of them. It's quite possible that other drivers besides pciehp will want to add trace points as well. For consistency, the trace event definitions need to work for all drivers.
OK, if this is a generic trace event then it does make sense sending in the names instead of the structure.
-- Steve
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Shuai,
kernel test robot noticed the following build errors:
[auto build test ERROR on pci/next]
[also build test ERROR on pci/for-linus linus/master v6.13-rc7 next-20250117] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Shuai-Xue/PCI-hotplug-Add-a-generic-RAS-tracepoint-for-hotplug-event/20250115-094016 base: https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next patch link: https://lore.kernel.org/r/20250115013753.49126-1-xueshuai%40linux.alibaba.com patch subject: [PATCH v6] PCI: hotplug: Add a generic RAS tracepoint for hotplug event config: i386-buildonly-randconfig-004-20250116 (https://download.01.org/0day-ci/archive/20250118/[email protected]/config) compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250118/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from <built-in>:1:
>> ./usr/include/linux/pci.h:22:10: fatal error: 'linux/tracepoint.h' file not found
22 | #include <linux/tracepoint.h>
| ^~~~~~~~~~~~~~~~~~~~
1 error generated.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Shuai,
kernel test robot noticed the following build errors:
[auto build test ERROR on pci/next]
[also build test ERROR on pci/for-linus linus/master v6.13-rc7 next-20250117] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Shuai-Xue/PCI-hotplug-Add-a-generic-RAS-tracepoint-for-hotplug-event/20250115-094016 base: https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next patch link: https://lore.kernel.org/r/20250115013753.49126-1-xueshuai%40linux.alibaba.com patch subject: [PATCH v6] PCI: hotplug: Add a generic RAS tracepoint for hotplug event config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20250119/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250119/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from <command-line>:
>> ./usr/include/linux/pci.h:22:10: fatal error: linux/tracepoint.h: No such file or directory
22 | #include <linux/tracepoint.h>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 18 lines · Shuai Xue
Hotplug events are critical indicators for analyzing hardware health, particularly in AI supercomputers where surprise link downs can significantly impact system performance and reliability.
To this end, define a new
TRACING_SYSTEMnamed pci, add a generic RAS tracepoint for hotplug event to help healthy check, and generate tracepoints for pcie hotplug event. Add enumpci_hotplug_eventininclude/uapi/linux/pci.hso applications like rasdaemon can register tracepoint event handlers for it.The output like below:
$ echo 1 > /sys/kernel/debug/tracing/events/pci/pci_hp_event/enable $ cat /sys/kernel/debug/tracing/trace_pipe <...>-206 [001] ..... 40.373870: pci_hp_event: 0000:00:02.0 slot:10, event:Link Down<...>-206 [001] ..... 40.374871: pci_hp_event: 0000:00:02.0 slot:10, event:Card not present
Quoted 7 lines
Suggested-by Lukas Wunner <[email protected]>Suggested-by Steven Rostedt <[email protected]>Signed-off-by Shuai Xue <[email protected]>Reviewed-by Lukas Wunner <[email protected]>---
changes since v5:
- move define of enum toinclude/uapi/linux/pci.h
Hi, Bjorn,
As this patch missed v6.13, should I rebase on pci/main (v6.14-rc1)?
Thanks.
Shuai