Message ID | 20250115013753.49126-1-xueshuai@linux.alibaba.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [v6] PCI: hotplug: Add a generic RAS tracepoint for hotplug event | expand |
On Wed, 15 Jan 2025 09:37:53 +0800 Shuai Xue <xueshuai@linux.alibaba.com> wrote: > +#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); Hmm, can't you just pass in the ctrl pointer to the tracepoint? trace_pci_hp_event(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: > diff --git a/drivers/pci/hotplug/trace.h b/drivers/pci/hotplug/trace.h > new file mode 100644 > index 000000000000..1415ac505cb5 > --- /dev/null > +++ b/drivers/pci/hotplug/trace.h > @@ -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, > + > + 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 > + ), > + > + 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) > + ) > +);
在 2025/1/15 10:41, Steven Rostedt 写道: > On Wed, 15 Jan 2025 09:37:53 +0800 > Shuai Xue <xueshuai@linux.alibaba.com> wrote: > >> +#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); > > Hmm, can't you just pass in the ctrl pointer to the tracepoint? > > trace_pci_hp_event(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: >> diff --git a/drivers/pci/hotplug/trace.h b/drivers/pci/hotplug/trace.h >> new file mode 100644 >> index 000000000000..1415ac505cb5 >> --- /dev/null >> +++ b/drivers/pci/hotplug/trace.h >> @@ -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, >> + >> + 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. 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. > > -- Steve > > Thanks. Best Regards, Shuai
On Wed, Jan 15, 2025 at 11:59:13AM +0800, Shuai Xue wrote: > 2025/1/15 10:41, Steven Rostedt: > > On Wed, 15 Jan 2025 09:37:53 +0800 Shuai Xue <xueshuai@linux.alibaba.com> wrote: > > > + 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 ) > > > > 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(). [...] > So, IMHO, pass port_name and slot_name from 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
On Wed, 15 Jan 2025 10:33:39 +0100 Lukas Wunner <lukas@wunner.de> wrote: > > > > > > 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(). > [...] > > So, IMHO, pass port_name and slot_name from 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
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/202501181212.7IZfQ160-lkp@intel.com/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/202501181212.7IZfQ160-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202501181212.7IZfQ160-lkp@intel.com/
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.
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/202501190108.tRReJA1Z-lkp@intel.com/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/202501190108.tRReJA1Z-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202501190108.tRReJA1Z-lkp@intel.com/
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.
diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c index d603a7aa7483..f9beb4d3a9b8 100644 --- a/drivers/pci/hotplug/pciehp_ctrl.c +++ b/drivers/pci/hotplug/pciehp_ctrl.c @@ -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: diff --git a/drivers/pci/hotplug/trace.h b/drivers/pci/hotplug/trace.h new file mode 100644 index 000000000000..1415ac505cb5 --- /dev/null +++ b/drivers/pci/hotplug/trace.h @@ -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, + + 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 ) + ), + + 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) + ) +); + +#endif /* _TRACE_HW_EVENT_PCI_HP_H */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH ../../drivers/pci/hotplug +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE trace + +/* This part must be outside protection */ +#include <trace/define_trace.h> diff --git a/include/uapi/linux/pci.h b/include/uapi/linux/pci.h index a769eefc5139..58a8ad9389e3 100644 --- a/include/uapi/linux/pci.h +++ b/include/uapi/linux/pci.h @@ -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 */