PCI: Add PCIe bandwidth controller
Subsystems (5)
Ilpo Järvinen
maintainerv9 cover PCI: Add PCIe bandwidth controller
Hi all,
This series adds PCIe bandwidth controller (bwctrl) and associated PCIe cooling driver to the thermal core side for limiting PCIe Link Speed due to thermal reasons. PCIe bandwidth controller is a PCI express bus port service driver. A cooling device is created for each port the service driver finds to support changing speeds.
This series only adds support for controlling PCIe Link Speed. Controlling PCIe Link Width might also be useful but there is no mechanism for that until PCIe 6.0 (L0p) so Link Width throttling is not added by this series.
v9:
- Split RMW ops doc reformat into own patch before adding LNKCTL2.
- Comment reserved 0 LSB even better than it already was.
- Consider portdrv future plans:
- Use devm helpers for mem alloc, IRQ, and mutex init.
- Don't use get/set_service_data().
- Split rwsem into two to avoid recursive locking splat through pcie_retrain_link().
- Small wording improvements to commit messages (from Jonathan)
v8:
- Removed CONFIG_PCIE_BWCTRL (use CONFIG_PCIEPORTBUS)
- Removed locking wrappers that dealt with the CONFIG variations
- Protect macro parameter with parenthesis to be on the safe side
v7:
- Rebased on top of Maciej's latest Target Speed quirk patches
- Target Speed quirk runs very early, w/o ->subordinate existing yet. This required adapting logic:
- Move Supported Link Speeds back to pci_dev
- Check for ->subordinate == NULL where necessary
- Cannot always take bwctrl's per port mutex (in pcie_bwctrl_data)
- Cleaned up locking in pcie_set_target_speed() using wrappers
- Allowed removing confusing __pcie_set_target_speed()
- Fix building with CONFIG_PCI=n
- Correct error check in pcie_lbms_seen()
- Don't return error for an empty bus that remains at 2.5GT
- Use rwsem to protect ->link_bwctrl setup and bwnotif enable
- Clear LBMS in remove_board()
- Adding export for pcie_get_supported_speeds() was unnecessary
- Call bwctrl's init before hotplug.
- Added local variable 'bus' into a few functions
v6:
- Removed unnecessary PCI_EXP_LNKCAP_SLS mask from PCIE_LNKCAP_SLS2SPEED()
- Split error handling in pcie_bwnotif_irq_thread()
- pci_info() -> pci_dbg() on bwctrl probe success path
- Handle cooling device pointer -Exx codes in bwctrl probe
- Reorder port->link_bwctrl setup / bwnotif enable for symmetry
- Handle LBMS count == 0 in PCIe quirk by checking LBMS (avoids a race between quirk and bwctrl)
- Use cleanup.h in PCIe cooling device's register
v5:
- Removed patches: LNKCTL2 RMW driver patches went in separately
- Refactor pcie_update_link_speed() to read LNKSTA + add __ variant for hotplug that has LNKSTA value at hand
- Make series fully compatible with the Target Speed quirk
- LBMS counter added, quirk falls back to LBMS bit when bwctrl =n
- Separate LBMS patch from set target speed patches
- Always provide pcie_bwctrl_change_speed() even if bwctrl =n so drivers don't need to come up their own version (also required by the Target Speed quirk)
- Remove devm_* (based on Lukas' comment on some other service driver patch)
- Convert to use cleanup.h
- Renamed functions/struct to have shorter names
v4:
- Merge Port's and Endpoint's Supported Link Speeds Vectors into supported_speeds in the struct pci_bus
- Reuse pcie_get_speed_cap()'s code for pcie_get_supported_speeds()
- Setup supported_speeds with PCI_EXP_LNKCAP2_SLS_2_5GB when no Endpoint exists
- Squash revert + add bwctrl patches into one
- Change to use threaded IRQ + IRQF_ONESHOT
- Enable also LABIE / LABS
- Convert Link Speed selection to use bit logic instead of loop
- Allocate before requesting IRQ during probe
- Use devm_*()
- Use u8 for speed_conv array instead of u16
- Removed READ_ONCE()
- Improve changelogs, comments, and Kconfig
- Name functions slightly more consistently
- Use bullet list for RMW protected registers in docs
v3:
- Correct hfi1 shortlog prefix
- Improve error prints in hfi1
- Add L: linux-pci to the MAINTAINERS entry
v2:
- Adds LNKCTL2 to RMW safe list in Documentation/PCI/pciebus-howto.rst
- Renamed cooling devices from PCIe_Port_* to PCIe_Port_Link_Speed_* in order to plan for possibility of adding Link Width cooling devices later on
- Moved struct thermal_cooling_device declaration to the correct patch
- Small tweaks to Kconfig texts
- Series rebased to resolve conflict (in the selftest list)
Ilpo Järvinen (9):
Documentation PCI: Reformat RMW ops documentation
PCI: Protect Link Control 2 Register with RMW locking
PCI: Store all PCIe Supported Link Speeds
PCI: Refactor pcie_update_link_speed()
PCI/quirks: Abstract LBMS seen check into own function PCI/bwctrl: Re-add BW notification portdrv as PCIe BW controller PCI/bwctrl: Add API to set PCIe Link Speed
thermal: Add PCIe cooling driver selftests/pcie_bwctrl: Create selftests
Documentation/PCI/pciebus-howto.rst | 14 +- MAINTAINERS | 9 + drivers/pci/hotplug/pciehp_ctrl.c | 5 + drivers/pci/hotplug/pciehp_hpc.c | 2 +- drivers/pci/pci.c | 62 ++- drivers/pci/pci.h | 38 +- drivers/pci/pcie/Makefile | 2 +- drivers/pci/pcie/bwctrl.c | 366 ++++++++++++++++++ drivers/pci/pcie/portdrv.c | 9 +- drivers/pci/pcie/portdrv.h | 6 +- drivers/pci/probe.c | 15 +- drivers/pci/quirks.c | 32 +- drivers/thermal/Kconfig | 9 + drivers/thermal/Makefile | 2 + drivers/thermal/pcie_cooling.c | 80 ++++ include/linux/pci-bwctrl.h | 28 ++ include/linux/pci.h | 24 +- include/uapi/linux/pci_regs.h | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/pcie_bwctrl/Makefile | 2 + .../pcie_bwctrl/set_pcie_cooling_state.sh | 122 ++++++ .../selftests/pcie_bwctrl/set_pcie_speed.sh | 67 ++++ 22 files changed, 843 insertions(+), 53 deletions(-) create mode 100644 drivers/pci/pcie/bwctrl.c create mode 100644 drivers/thermal/pcie_cooling.c create mode 100644 include/linux/pci-bwctrl.h create mode 100644 tools/testing/selftests/pcie_bwctrl/Makefile create mode 100755 tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh create mode 100755 tools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh
Signature · 1 line
2.39.5
Ilpo Järvinen
maintainerPATCH v9 1/9 Documentation PCI: Reformat RMW ops documentation
Extract the list of RMW protected PCIe Capability registers into a bullet list to make them easier to pick up on a glance. An upcoming change is going to add one more register among them so it will be much cleaner to have them as bullets.
--- Documentation/PCI/pciebus-howto.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
Documentation/PCI/pciebus-howto.rst +8 -5
@@ -217,8 +217,11 @@ capability structure except the PCI Express capability structure, that is shared between many drivers including the service drivers. RMW Capability accessors (pcie_capability_clear_and_set_word(), pcie_capability_set_word(), and pcie_capability_clear_word()) protect -a selected set of PCI Express Capability Registers (Link Control -Register and Root Control Register). Any change to those registers -should be performed using RMW accessors to avoid problems due to -concurrent updates. For the up-to-date list of protected registers, -see pcie_capability_clear_and_set_word(). +a selected set of PCI Express Capability Registers: + +* Link Control Register +* Root Control Register + +Any change to those registers should be performed using RMW accessors to +avoid problems due to concurrent updates. For the up-to-date list of +protected registers, see pcie_capability_clear_and_set_word().
Signature · 1 line
2.39.5
Ilpo Järvinen
maintainerPATCH v9 2/9 PCI: Protect Link Control 2 Register with RMW locking
In reply to Ilpo JärvinenPCIe Bandwidth Controller performs RMW accesses the Link Control 2 Register which can occur concurrently to other sources of Link Control 2 Register writes. Therefore, add Link Control 2 Register among the PCI Express Capability Registers that need RMW locking.
--- Documentation/PCI/pciebus-howto.rst | 1 + include/linux/pci.h | 1 + 2 files changed, 2 insertions(+)
Documentation/PCI/pciebus-howto.rst +1 -0
@@ -221,6 +221,7 @@ a selected set of PCI Express Capability Registers: * Link Control Register * Root Control Register +* Link Control 2 Register Any change to those registers should be performed using RMW accessors to avoid problems due to concurrent updates. For the up-to-date list of
include/linux/pci.h +1 -0
@@ -1274,6 +1274,7 @@ static inline int pcie_capability_clear_and_set_word(struct pci_dev *dev, {switch (pos) {case PCI_EXP_LNKCTL : +case PCI_EXP_LNKCTL2 :case PCI_EXP_RTCTL :return pcie_capability_clear_and_set_word_locked (dev, pos, clear, set);
Signature · 1 line
2.39.5
Ilpo Järvinen
maintainerPATCH v9 3/9 PCI: Store all PCIe Supported Link Speeds
In reply to Ilpo JärvinenPCIe bandwidth controller added by a subsequent commit will require selecting PCIe Link Speeds that are lower than the Maximum Link Speed.
The struct pci_bus only stores max_bus_speed. Even if PCIe r6.1 sec 8.2.1 currently disallows gaps in supported Link Speeds, the Implementation Note in PCIe r6.1 sec 7.5.3.18, recommends determining supported Link Speeds using the Supported Link Speeds Vector in the Link Capabilities 2 Register (when available) to "avoid software being confused if a future specification defines Links that do not require support for all slower speeds."
Reuse code in pcie_get_speed_cap() to add pcie_get_supported_speeds() to query the Supported Link Speeds Vector of a PCIe device. The value is taken directly from the Supported Link Speeds Vector or synthetized from the Max Link Speed in the Link Capabilities Register when the Link Capabilities 2 Register is not available.
The Supported Link Speeds Vector in the Link Capabilities Register 2 corresponds to the bus below on Root Ports and Downstream Ports, whereas it corresponds to the bus above on Upstream Ports and Endpoints (PCIe r6.1 sec 7.5.3.18):
"Supported Link Speeds Vector - This field indicates the supported Link speed(s) of the associated Port."
Add supported_speeds into the struct pci_dev that caches the Supported Link Speeds Vector.
supported_speeds contains a set of Link Speeds only in the case where PCIe Link Speed can be determined. The Root Complex Integrated Endpoints do not have a well-defined Link Speed because they do not seem to implement either of the Link Capabilities Registers, which is allowed by PCIe r6.1 sec 7.5.3 (the same limitation applies to determining cur_bus_speed and max_bus_speed that are PCI_SPEED_UNKNOWN in such case). This is of no concern from PCIe bandwidth controller point of view because such devices are not attached into a PCIe Root Port that could be controlled.
supported_speeds field keeps the extra reserved zero at the least significant bit to match the Link Capabilities 2 Register layout.
An attempt was made to store supported_speeds field into the struct pci_bus as an intersection of the both ends of the Link, however, the subordinate struct pci_bus is not available early enough. The Target Speed quirk (in pcie_failed_link_retrain()) can run either during initial scan or later requiring it to use the API PCIe bandwidth controller provides to set the Target Link Speed in order to co-exist with the bandwidth controller. When the Target Speed quirk is calling the bandwidth controller during initial scan, the struct pci_bus is not yet initialized. As such, storing supported_speeds into the struct pci_bus is not viable.
--- drivers/pci/pci.c | 60 +++++++++++++++++++++++++---------- drivers/pci/probe.c | 3 ++ include/linux/pci.h | 11 ++++++- include/uapi/linux/pci_regs.h | 1 + 4 files changed, 57 insertions(+), 18 deletions(-)
drivers/pci/pci.c +43 -17
@@ -6189,38 +6189,64 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,EXPORT_SYMBOL (pcie_bandwidth_available);/** -* pcie_get_speed_cap - query for the PCI device's link speed capability +* pcie_get_supported_speeds - query Supported Link Speed Vector * @dev: PCI device to query * -* Query the PCI device speed capability. Return the maximum link speed -* supported by the device. +* Query @dev supported link speeds. +* +* Implementation Note in PCIe r6.0.1 sec 7.5.3.18 recommends determining +* supported link speeds using the Supported Link Speeds Vector in the Link +* Capabilities 2 Register (when available). +* +* Link Capabilities 2 was added in PCIe r3.0, sec 7.8.18. +* +* Without Link Capabilities 2, i.e., prior to PCIe r3.0, Supported Link +* Speeds field in Link Capabilities is used and only 2.5 GT/s and 5.0 GT/s +* speeds were defined. +* +* For @dev without Supported Link Speed Vector, the field is synthetized +* from the Max Link Speed field in the Link Capabilities Register. +* +* Return: Supported Link Speeds Vector (+ reserved 0 at LSB). */ -enum pci_bus_speed pcie_get_speed_cap (struct pci_dev *dev) +u8 pcie_get_supported_speeds (struct pci_dev *dev) {u32 lnkcap2, lnkcap; +u8 speeds; +pcie_capability_read_dword (dev,PCI_EXP_LNKCAP2 , &lnkcap2);/* -* Link Capabilities 2 was added in PCIe r3.0, sec 7.8.18. The -* implementation note there recommends using the Supported Link -* Speeds Vector in Link Capabilities 2 when supported. -* -* Without Link Capabilities 2, i.e., prior to PCIe r3.0, software -* should use the Supported Link Speeds field in Link Capabilities, -* where only 2.5 GT/s and 5.0 GT/s speeds were defined. +* Speeds retain the reserved 0 at LSB before PCIe Supported Link +* Speeds Vector to allow using SLS Vector bit defines directly. */ -pcie_capability_read_dword (dev,PCI_EXP_LNKCAP2 , &lnkcap2); + speeds = lnkcap2 &PCI_EXP_LNKCAP2_SLS ;/* PCIe r3.0-compliant */ -if (lnkcap2) -return PCIE_LNKCAP2_SLS2SPEED (lnkcap2); +if (speeds) +return speeds;pcie_capability_read_dword (dev,PCI_EXP_LNKCAP , &lnkcap); + +/* Synthetize from the Max Link Speed field */ if ((lnkcap &PCI_EXP_LNKCAP_SLS ) ==PCI_EXP_LNKCAP_SLS_5_0GB ) -return PCIE_SPEED_5_0GT ; + speeds =PCI_EXP_LNKCAP2_SLS_5_0GB |PCI_EXP_LNKCAP2_SLS_2_5GB ;else if ((lnkcap &PCI_EXP_LNKCAP_SLS ) ==PCI_EXP_LNKCAP_SLS_2_5GB ) -return PCIE_SPEED_2_5GT ; + speeds =PCI_EXP_LNKCAP2_SLS_2_5GB ; + +return speeds; +} -return PCI_SPEED_UNKNOWN ; +/** +* pcie_get_speed_cap - query for the PCI device's link speed capability +* @dev: PCI device to query +* +* Query the PCI device speed capability. +* +* Return: the maximum link speed supported by the device. +*/ +enum pci_bus_speed pcie_get_speed_cap (struct pci_dev *dev) +{ +return PCIE_LNKCAP2_SLS2SPEED (dev->supported_speeds); }EXPORT_SYMBOL (pcie_get_speed_cap);
drivers/pci/probe.c +3 -0
@@ -1947,6 +1947,9 @@ int pci_setup_device(struct pci_dev *dev)set_pcie_untrusted (dev); +if (pci_is_pcie (dev)) + dev->supported_speeds =pcie_get_supported_speeds (dev); +/* "Unknown power state" */ dev->current_state =PCI_UNKNOWN ;
include/linux/pci.h +10 -1
@@ -303,6 +303,7 @@ enum pci_bus_speed { PCI_SPEED_UNKNOWN = 0xff, }; +u8 pcie_get_supported_speeds (struct pci_dev *dev);enum pci_bus_speed pcie_get_speed_cap (struct pci_dev *dev);enum pcie_link_width pcie_get_width_cap (struct pci_dev *dev);
@@ -318,7 +319,14 @@ struct pci_sriov;struct pci_p2pdma ;struct rcec_ea ; -/* The pci_dev structure describes PCI devices */ +/* struct pci_dev - describes a PCI device +* +* @supported_speeds: PCIe Supported Link Speeds Vector (+ reserved 0 at +* LSB). 0 when the supported speeds cannot be +* determined (e.g., for Root Complex Integrated +* Endpoints without the relevant Capability +* Registers). +*/ struct pci_dev {struct list_head bus_list;/* Node in per-bus list */ struct pci_bus *bus;/* Bus this device is on */
@@ -522,6 +530,7 @@ struct pci_dev {struct npem *npem;/* Native PCIe Enclosure Management */ #endif u16 acs_cap;/* ACS Capability offset */ +u8 supported_speeds;/* Supported Link Speeds Vector */ phys_addr_t rom;/* Physical address if not from BAR */ size_t romlen;/* Length if not from BAR */ /*
include/uapi/linux/pci_regs.h +1 -0
@@ -678,6 +678,7 @@#define PCI_EXP_DEVSTA2 0x2a/* Device Status 2 */ #define PCI_CAP_EXP_RC_ENDPOINT_SIZEOF_V2 0x2c/* end of v2 EPs w/o link */ #define PCI_EXP_LNKCAP2 0x2c/* Link Capabilities 2 */ +#define PCI_EXP_LNKCAP2_SLS 0x000000fe/* Supported Link Speeds Vector */ #define PCI_EXP_LNKCAP2_SLS_2_5GB 0x00000002/* Supported Speed 2.5GT/s */ #define PCI_EXP_LNKCAP2_SLS_5_0GB 0x00000004/* Supported Speed 5GT/s */ #define PCI_EXP_LNKCAP2_SLS_8_0GB 0x00000008/* Supported Speed 8GT/s */
Signature · 1 line
2.39.5
Re: [PATCH v9 3/9] PCI: Store all PCIe Supported Link Speeds
include/linux/pci.h enum pci_bus_speed { · line 309
Quoted 12 lines · Ilpo Järvinen
include/linux/pci.h +1
-0@@ -303,6 +303,7 @@ enum pci_bus_speed { PCI_SPEED_UNKNOWN = 0xff, }; +u8 pcie_get_supported_speeds (struct pci_dev *dev);enum pci_bus_speed pcie_get_speed_cap (struct pci_dev *dev);enum pcie_link_width pcie_get_width_cap (struct pci_dev *dev);
I realize this is now already queued as commit 73ee11953294 on pci/bwctrl, nevertheless one belated comment:
Since there are no callers of pcie_get_supported_speeds() outside the PCI core, the above declaration should probably rather live in drivers/pci/pci.h.
Thanks,
Lukas
Re: [PATCH v9 3/9] PCI: Store all PCIe Supported Link Speeds
Quoted 16 lines · Lukas Wunner
include/linux/pci.h enum pci_bus_speed { · line 308
Quoted 11 lines · Ilpo Järvinen
include/linux/pci.h +1
-0@@ -303,6 +303,7 @@ enum pci_bus_speed { PCI_SPEED_UNKNOWN = 0xff, }; +u8 pcie_get_supported_speeds (struct pci_dev *dev);enum pci_bus_speed pcie_get_speed_cap (struct pci_dev *dev);enum pcie_link_width pcie_get_width_cap (struct pci_dev *dev);I realize this is now already queued as commit
73ee11953294on pci/bwctrl, nevertheless one belated comment:
Quoted 3 lines
Since there are no callers of
pcie_get_supported_speeds()outside the PCI core, the above declaration should probably rather live indrivers/pci/pci.h.
I moved them, thanks!
I noticed duplicate declarations for pcie_get_speed_cap() and pcie_get_width_cap(), so I'll add a patch to drop them from drivers/pci/pci.h.
Bjorn
Re: [PATCH v9 3/9] PCI: Store all PCIe Supported Link Speeds
Quoted 17 lines · Bjorn Helgaas
Quoted 16 lines · Lukas Wunner
include/linux/pci.h enum pci_bus_speed { · line 308
Quoted 11 lines · Ilpo Järvinen
include/linux/pci.h +1
-0@@ -303,6 +303,7 @@ enum pci_bus_speed { PCI_SPEED_UNKNOWN = 0xff, }; +u8 pcie_get_supported_speeds (struct pci_dev *dev);enum pci_bus_speed pcie_get_speed_cap (struct pci_dev *dev);enum pcie_link_width pcie_get_width_cap (struct pci_dev *dev);I realize this is now already queued as commit
73ee11953294on pci/bwctrl, nevertheless one belated comment:
Quoted 5 lines
Quoted 3 lines
Since there are no callers of
pcie_get_supported_speeds()outside the PCI core, the above declaration should probably rather live indrivers/pci/pci.h.I moved them, thanks!
Thanks for taking care of that.
Quoted 3 lines
I noticed duplicate declarations for
pcie_get_speed_cap()andpcie_get_width_cap(), so I'll add a patch to drop them fromdrivers/pci/pci.h.
I also noticed the same. FWIW,
for that patch of yours.
Signature · 1 line
i.
Ilpo Järvinen
maintainerPATCH v9 4/9 PCI: Refactor pcie_update_link_speed()
In reply to Ilpo Järvinenpcie_update_link_speed() is passed the Link Status register but not all callers have that value at hand nor need the value.
Refactor pcie_update_link_speed() to include reading the Link Status register and create __pcie_update_link_speed() which can be used by the hotplug code that has the register value at hand beforehand (and needs the value for other purposes).
--- drivers/pci/hotplug/pciehp_hpc.c | 2 +- drivers/pci/pci.h | 7 ++++++- drivers/pci/probe.c | 12 +++++++----- 3 files changed, 14 insertions(+), 7 deletions(-)
drivers/pci/hotplug/pciehp_hpc.c +1 -1
@@ -319,7 +319,7 @@ int pciehp_check_link_status(struct controller *ctrl)return -1 ; } -pcie_update_link_speed (ctrl->pcie->port->subordinate, lnk_status); +__pcie_update_link_speed (ctrl->pcie->port->subordinate, lnk_status);if (!found) { ctrl_info(ctrl, "Slot(%s): No device found\n",
drivers/pci/pci.h +6 -1
@@ -378,7 +378,12 @@ enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev);enum pcie_link_width pcie_get_width_cap (struct pci_dev *dev);void __pcie_print_link_status (struct pci_dev *dev,bool verbose);void pcie_report_downtraining (struct pci_dev *dev); -void pcie_update_link_speed (struct pci_bus *bus,u16 link_status); + +static inline void __pcie_update_link_speed (struct pci_bus *bus,u16 linksta) +{ + bus->cur_bus_speed = pcie_link_speed[linksta &PCI_EXP_LNKSTA_CLS ]; +} +void pcie_update_link_speed (struct pci_bus *bus);/* Single Root I/O Virtualization */ struct pci_sriov {
drivers/pci/probe.c +7 -5
@@ -742,9 +742,13 @@ const char *pci_speed_string(enum pci_bus_speed speed) }EXPORT_SYMBOL_GPL (pci_speed_string); -void pcie_update_link_speed (struct pci_bus *bus,u16 linksta) +void pcie_update_link_speed (struct pci_bus *bus) { - bus->cur_bus_speed = pcie_link_speed[linksta &PCI_EXP_LNKSTA_CLS ]; +struct pci_dev *bridge = bus->self; +u16 linksta; + +pcie_capability_read_word (bridge,PCI_EXP_LNKSTA , &linksta); +__pcie_update_link_speed (bus, linksta); }EXPORT_SYMBOL_GPL (pcie_update_link_speed);
@@ -827,13 +831,11 @@ static void pci_set_bus_speed(struct pci_bus *bus)if (pci_is_pcie (bridge)) {u32 linkcap; -u16 linksta;pcie_capability_read_dword (bridge,PCI_EXP_LNKCAP , &linkcap); bus->max_bus_speed = pcie_link_speed[linkcap &PCI_EXP_LNKCAP_SLS ]; -pcie_capability_read_word (bridge,PCI_EXP_LNKSTA , &linksta); -pcie_update_link_speed (bus, linksta); +pcie_update_link_speed (bus); } }
Signature · 1 line
2.39.5
Ilpo Järvinen
maintainerPATCH v9 5/9 PCI/quirks: Abstract LBMS seen check into own function
In reply to Ilpo JärvinenThe Target Speed quirk in pcie_failed_link_retrain() uses the presence of LBMS bit as one of the triggering conditions effectively monopolizing the use of that bit. An upcoming change will introduce a PCIe bandwidth controller which sets up an interrupt to track LBMS. As LBMS will be cleared by the interrupt handler, the Target Speed quirk will no longer be able to observe LBMS directly.
As a preparatory step for the change, extract the LBMS seen check from pcie_failed_link_retrain() into a new function pcie_lmbs_seen().
--- drivers/pci/quirks.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/pci/quirks.c +6 -2
@@ -33,6 +33,11 @@#include <linux/switchtec.h> #include "pci.h" +static bool pcie_lbms_seen (struct pci_dev *dev,u16 lnksta) +{ +return lnksta &PCI_EXP_LNKSTA_LBMS ; +} +/* * Retrain the link of a downstream PCIe port by hand if necessary. *
@@ -96,8 +101,7 @@ int pcie_failed_link_retrain(struct pci_dev *dev)pcie_capability_read_word (dev,PCI_EXP_LNKCTL2 , &lnkctl2);pcie_capability_read_word (dev,PCI_EXP_LNKSTA , &lnksta); -if ((lnksta & (PCI_EXP_LNKSTA_LBMS |PCI_EXP_LNKSTA_DLLLA )) == -PCI_EXP_LNKSTA_LBMS ) { +if (!(lnksta &PCI_EXP_LNKSTA_DLLLA ) &&pcie_lbms_seen (dev, lnksta)) {u16 oldlnkctl2 = lnkctl2;pci_info (dev,"broken device, retraining non-functional downstream link at 2.5GT/s\n" );
Signature · 1 line
2.39.5
Ilpo Järvinen
maintainerPATCH v9 6/9 PCI/bwctrl: Re-add BW notification portdrv as PCIe BW controller
In reply to Ilpo JärvinenThis mostly reverts the commit b4c7d2076b4e ("PCI/LINK: Remove bandwidth notification"). An upcoming commit extends this driver building PCIe bandwidth controller on top of it.
The PCIe bandwidth notification were first added in the commit e8303bb7a75c ("PCI/LINK: Report degraded links via link bandwidth notification") but later had to be removed. The significant changes compared with the old bandwidth notification driver include:
1) Don't print the notifications into kernel log, just keep the Link Speed cached in struct pci_bus updated. While somewhat unfortunate, the log spam was the source of complaints that eventually lead to the removal of the bandwidth notifications driver (see the links below for further information).
2) Besides the Link Bandwidth Management Interrupt, enable also Link Autonomous Bandwidth Interrupt to cover the other source of bandwidth changes.
3) Use threaded IRQ with IRQF_ONESHOT to handle Bandwidth Notification Interrupts to address the problem fixed in the commit 3e82a7f9031f ("PCI/LINK: Supply IRQ handler so level-triggered IRQs are acked")).
4) Handle Link Speed updates robustly. Refresh the cached Link Speed when enabling Bandwidth Notification Interrupts, and solve the race between Link Speed read and LBMS/LABS update in pcie_bwnotif_irq_thread().
5) Use concurrency safe LNKCTL RMW operations.
6) The driver is now called PCIe bwctrl (bandwidth controller) instead of just bandwidth notifications because of increased scope and functionality within the driver.
7) Coexist with the Target Link Speed quirk in pcie_failed_link_retrain(). Provide LBMS counting API for it.
8) Tweaks to variable/functions names for consistency and length reasons.
Bandwidth Notifications enable the cur_bus_speed in the struct pci_bus to keep track PCIe Link Speed changes.
--- MAINTAINERS | 6 + drivers/pci/hotplug/pciehp_ctrl.c | 5 + drivers/pci/pci.c | 2 +- drivers/pci/pci.h | 11 ++ drivers/pci/pcie/Makefile | 2 +- drivers/pci/pcie/bwctrl.c | 187 ++++++++++++++++++++++++++++++ drivers/pci/pcie/portdrv.c | 9 +- drivers/pci/pcie/portdrv.h | 6 +- drivers/pci/quirks.c | 9 +- include/linux/pci.h | 2 + 10 files changed, 230 insertions(+), 9 deletions(-) create mode 100644 drivers/pci/pcie/bwctrl.c
MAINTAINERS +6 -0
@@ -17933,6 +17933,12 @@ F: include/linux/of_pci.h F: include/linux/pci* F: include/uapi/linux/pci* +PCIE BANDWIDTH CONTROLLER +M: Ilpo Järvinen <[email protected]> +L: [email protected] +S: Supported +F: drivers/pci/pcie/bwctrl.c + PCIE DRIVER FOR AMAZON ANNAPURNA LABS M: Jonathan Chocron <[email protected]> L: [email protected]
drivers/pci/hotplug/pciehp_ctrl.c +5 -0
@@ -19,6 +19,8 @@#include <linux/types.h> #include <linux/pm_runtime.h> #include <linux/pci.h> + +#include "../pci.h" #include "pciehp.h" /* The following routines constitute the bulk of the
@@ -127,6 +129,9 @@ static void remove_board(struct controller *ctrl, bool safe_removal)pciehp_set_indicators (ctrl,PCI_EXP_SLTCTL_PWR_IND_OFF ,INDICATOR_NOOP ); + +/* Don't carry LBMS indications across */ +pcie_reset_lbms_count (ctrl->pcie->port); }static int pciehp_enable_slot (struct controller *ctrl);
drivers/pci/pci.c +1 -1
@@ -4740,7 +4740,7 @@ int pcie_retrain_link(struct pci_dev *pdev, bool use_lt)* to track link speed or width changes made by hardware itself * in attempt to correct unreliable link operation. */ -pcie_capability_write_word (pdev,PCI_EXP_LNKSTA ,PCI_EXP_LNKSTA_LBMS ); +pcie_reset_lbms_count (pdev);return rc; }
drivers/pci/pci.h +11 -0
@@ -697,6 +697,17 @@ static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { }static inline void pcie_ecrc_get_policy (char *str) { }#endif +#ifdef CONFIG_PCIEPORTBUS +void pcie_reset_lbms_count (struct pci_dev *port); +int pcie_lbms_count (struct pci_dev *port,unsigned long *val); +#else +static inline void pcie_reset_lbms_count (struct pci_dev *port) {} +static inline int pcie_lbms_count (struct pci_dev *port,unsigned long *val) +{ +return -EOPNOTSUPP ; +} +#endif +struct pci_dev_reset_methods {u16 vendor;u16 device;
drivers/pci/pcie/Makefile +1 -1
@@ -4,7 +4,7 @@ pcieportdrv-y := portdrv.o rcec.o -obj-$(CONFIG_PCIEPORTBUS) += pcieportdrv.o +obj-$(CONFIG_PCIEPORTBUS) += pcieportdrv.o bwctrl.o obj-y += aspm.o obj-$(CONFIG_PCIEAER) += aer.o err.o
drivers/pci/pcie/bwctrl.c new file +187 -0
187 lines not on this page · raw message
drivers/pci/pcie/portdrv.c +5 -4
@@ -68,7 +68,7 @@ static int pcie_message_numbers(struct pci_dev *dev, int mask,*/ if (mask & (PCIE_PORT_SERVICE_PME |PCIE_PORT_SERVICE_HP | -PCIE_PORT_SERVICE_BWNOTIF )) { +PCIE_PORT_SERVICE_BWCTRL )) {pcie_capability_read_word (dev,PCI_EXP_FLAGS , ®16); *pme =FIELD_GET (PCI_EXP_FLAGS_IRQ , reg16); nvec = *pme +1 ;
@@ -150,11 +150,11 @@ static int pcie_port_enable_irq_vec(struct pci_dev *dev, int *irqs, int mask)/* PME, hotplug and bandwidth notification share an MSI/MSI-X vector */ if (mask & (PCIE_PORT_SERVICE_PME |PCIE_PORT_SERVICE_HP | -PCIE_PORT_SERVICE_BWNOTIF )) { +PCIE_PORT_SERVICE_BWCTRL )) { pcie_irq =pci_irq_vector (dev, pme); irqs[PCIE_PORT_SERVICE_PME_SHIFT ] = pcie_irq; irqs[PCIE_PORT_SERVICE_HP_SHIFT ] = pcie_irq; - irqs[PCIE_PORT_SERVICE_BWNOTIF_SHIFT ] = pcie_irq; + irqs[PCIE_PORT_SERVICE_BWCTRL_SHIFT ] = pcie_irq; }if (mask &PCIE_PORT_SERVICE_AER )
@@ -271,7 +271,7 @@ static int get_port_device_capability(struct pci_dev *dev)pcie_capability_read_dword (dev,PCI_EXP_LNKCAP , &linkcap);if (linkcap &PCI_EXP_LNKCAP_LBNC ) - services |=PCIE_PORT_SERVICE_BWNOTIF ; + services |=PCIE_PORT_SERVICE_BWCTRL ; }return services;
@@ -828,6 +828,7 @@ static void __init pcie_init_services(void)pcie_aer_init ();pcie_pme_init ();pcie_dpc_init (); +pcie_bwctrl_init ();pcie_hp_init (); }
drivers/pci/pcie/portdrv.h +4 -2
@@ -20,8 +20,8 @@#define PCIE_PORT_SERVICE_HP (1 << PCIE_PORT_SERVICE_HP_SHIFT)#define PCIE_PORT_SERVICE_DPC_SHIFT 3/* Downstream Port Containment */ #define PCIE_PORT_SERVICE_DPC (1 << PCIE_PORT_SERVICE_DPC_SHIFT) -#define PCIE_PORT_SERVICE_BWNOTIF_SHIFT 4/* Bandwidth notification */ -#define PCIE_PORT_SERVICE_BWNOTIF (1 << PCIE_PORT_SERVICE_BWNOTIF_SHIFT) +#define PCIE_PORT_SERVICE_BWCTRL_SHIFT 4/* Bandwidth Controller (notifications) */ +#define PCIE_PORT_SERVICE_BWCTRL (1 << PCIE_PORT_SERVICE_BWCTRL_SHIFT)#define PCIE_PORT_DEVICE_MAXSERVICES 5
@@ -51,6 +51,8 @@ int pcie_dpc_init(void);static inline int pcie_dpc_init (void ) {return 0 ; }#endif +int pcie_bwctrl_init (void ); +/* Port Type */ #define PCIE_ANY_PORT (~0)
drivers/pci/quirks.c +8 -1
@@ -35,7 +35,14 @@static bool pcie_lbms_seen (struct pci_dev *dev,u16 lnksta) { -return lnksta &PCI_EXP_LNKSTA_LBMS ; +unsigned long count; +int ret; + + ret =pcie_lbms_count (dev, &count); +if (ret <0 ) +return lnksta &PCI_EXP_LNKSTA_LBMS ; + +return count >0 ; }/*
include/linux/pci.h +2 -0
@@ -314,6 +314,7 @@ struct pci_vpd { };struct irq_affinity ; +struct pcie_bwctrl_data ;struct pcie_link_state ;struct pci_sriov ;struct pci_p2pdma ;
@@ -503,6 +504,7 @@ struct pci_dev { unsigned int dpc_rp_extensions:1;u8 dpc_rp_log_size;#endif +struct pcie_bwctrl_data *link_bwctrl; #ifdef CONFIG_PCI_ATS union { struct pci_sriov *sriov; /* PF: SR-IOV info */
Signature · 1 line
2.39.5
Re: [PATCH v9 6/9] PCI/bwctrl: Re-add BW notification portdrv as PCIe BW controller
Quoted 55 lines · Ilpo Järvinen
This mostly reverts the commit
b4c7d2076b4e("PCI/LINK: Remove bandwidth notification"). An upcoming commit extends this driver building PCIe bandwidth controller on top of it.The PCIe bandwidth notification were first added in the commit
e8303bb7a75c("PCI/LINK: Report degraded links via link bandwidth notification") but later had to be removed. The significant changes compared with the old bandwidth notification driver include:1) Don't print the notifications into kernel log, just keep the Link Speed cached in struct
pci_busupdated. While somewhat unfortunate,
the log spam was the source of complaints that eventually lead to the removal of the bandwidth notifications driver (see the links below for further information).2) Besides the Link Bandwidth Management Interrupt, enable also Link Autonomous Bandwidth Interrupt to cover the other source of bandwidth changes.
3) Use threaded IRQ with
IRQF_ONESHOTto handle Bandwidth Notification
Interrupts to address the problem fixed in the commit3e82a7f9031f("PCI/LINK: Supply IRQ handler so level-triggered IRQs are acked")).4) Handle Link Speed updates robustly. Refresh the cached Link Speed when enabling Bandwidth Notification Interrupts, and solve the race
between Link Speed read and LBMS/LABS update inpcie_bwnotif_irq_thread().5) Use concurrency safe LNKCTL RMW operations.
6) The driver is now called PCIe bwctrl (bandwidth controller) instead
of just bandwidth notifications because of increased scope and functionality within the driver.7) Coexist with the Target Link Speed quirk in
pcie_failed_link_retrain(). Provide LBMS counting API for it.8) Tweaks to variable/functions names for consistency and length reasons.
Bandwidth Notifications enable the
cur_bus_speedin the structpci_bus
to keep track PCIe Link Speed changes.Link:
https://lore.kernel.org/all/[email protected]/
Link:
https://lore.kernel.org/linux-pci/[email protected]/
Link:
https://lore.kernel.org/linux-pci/[email protected]/
Quoted 5 lines
of bwnotif
Signed-off-by Ilpo Järvinen <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>---
Hi Ilpo,
I bisected a v6.13-rc1 boot hang on my personal workstation to this patch. Sadly I don't have much details like a panic or so because the boot hangs before any kernel messages, or at least they're not visible long enough to see. I haven't yet looked into the code as I wanted to raise awareness first. Since the commit doesn't revert cleanly on v6.13-rc1 I also haven't tried that yet.
Here are some details on my system:
- AMD Ryzen 9 3900X
- ASRock X570 Creator Motherboard
- Radeon RX 5600 XT
- Intel JHL7540 Thunderbolt 3 USB Controller (only USB 2 plugged)
- Intel 82599 10 Gigabit NIC with SR-IOV enabled with 2 VFs
- Intel n I211 Gigabit NIC
- Intel Wi-Fi 6 AX200
- Aquantia AQtion AQC107 NIC
If you have patches or things to try just ask.
Thanks,
Niklas
Re: [PATCH v9 6/9] PCI/bwctrl: Re-add BW notification portdrv as PCIe BW controller
Quoted 10 lines · Niklas Schnelle
Quoted 9 lines · Ilpo Järvinen
This mostly reverts the commit
b4c7d2076b4e("PCI/LINK: Remove bandwidth notification"). An upcoming commit extends this driver building PCIe bandwidth controller on top of it.The PCIe bandwidth notification were first added in the commit
e8303bb7a75c("PCI/LINK: Report degraded links via link bandwidth notification") but later had to be removed. The significant changes compared with the old bandwidth notification driver include:
---8<---
Quoted 21 lines
Quoted 1 line
---
Hi Ilpo,
I bisected a v6.13-rc1 boot hang on my personal workstation to this patch. Sadly I don't have much details like a panic or so because the boot hangs before any kernel messages, or at least they're not visible long enough to see. I haven't yet looked into the code as I wanted to raise awareness first. Since the commit doesn't revert cleanly on v6.13-rc1 I also haven't tried that yet.
Here are some details on my system:
- AMD Ryzen 9 3900X
- ASRock X570 Creator Motherboard
- Radeon RX 5600 XT
- Intel JHL7540 Thunderbolt 3 USB Controller (only USB 2 plugged)
- Intel 82599 10 Gigabit NIC with SR-IOV enabled with 2 VFs
- Intel n I211 Gigabit NIC
- Intel Wi-Fi 6 AX200
- Aquantia AQtion AQC107 NIC
Quoted 5 lines
If you have patches or things to try just ask.
Thanks,
Niklas
Ok I can now at least confirm that bluntly disabling the new bwctrl driver with the below diff on top of v6.13-rc1 circumvents the boot hang I'm seeing. So it's definitely this.
drivers/pci/pcie/portdrv.c +1 -1
@@ -828,7 +828,7 @@ static void __init pcie_init_services(void)pcie_aer_init ();pcie_pme_init ();pcie_dpc_init (); -pcie_bwctrl_init (); +/* pcie_bwctrl_init(); */ pcie_hp_init (); }
Re: [PATCH v9 6/9] PCI/bwctrl: Re-add BW notification portdrv as PCIe BW controller
Quoted 48 lines · Niklas Schnelle
Quoted 10 lines · Niklas Schnelle
Quoted 9 lines · Ilpo Järvinen
This mostly reverts the commit
b4c7d2076b4e("PCI/LINK: Remove bandwidth notification"). An upcoming commit extends this driver building PCIe bandwidth controller on top of it.The PCIe bandwidth notification were first added in the commit
e8303bb7a75c("PCI/LINK: Report degraded links via link bandwidth notification") but later had to be removed. The significant changes compared with the old bandwidth notification driver include:---8<---
Quoted 21 lines
Quoted 1 line
---
Hi Ilpo,
I bisected a v6.13-rc1 boot hang on my personal workstation to this patch. Sadly I don't have much details like a panic or so because the boot hangs before any kernel messages, or at least they're not visible long enough to see. I haven't yet looked into the code as I wanted to raise awareness first. Since the commit doesn't revert cleanly on v6.13-rc1 I also haven't tried that yet.
Here are some details on my system:
- AMD Ryzen 9 3900X
- ASRock X570 Creator Motherboard
- Radeon RX 5600 XT
- Intel JHL7540 Thunderbolt 3 USB Controller (only USB 2 plugged)
- Intel 82599 10 Gigabit NIC with SR-IOV enabled with 2 VFs
- Intel n I211 Gigabit NIC
- Intel Wi-Fi 6 AX200
- Aquantia AQtion AQC107 NICQuoted 5 lines
If you have patches or things to try just ask.
Thanks,
NiklasOk I can now at least confirm that bluntly disabling the new bwctrl driver with the below diff on top of v6.13-rc1 circumvents the boot hang I'm seeing. So it's definitely this.
drivers/pci/pcie/portdrv.c +0
-0
drivers/pci/pcie/portdrv.c static void __init pcie_init_services(void) · line 834
Quoted 8 lines
drivers/pci/pcie/portdrv.c +1
-1@@ -828,7 +828,7 @@ static void __init pcie_init_services(void)pcie_aer_init ();pcie_pme_init ();pcie_dpc_init (); -pcie_bwctrl_init (); +/* pcie_bwctrl_init(); */ pcie_hp_init (); }
Also here is the full lspci -vvv output running the above on v6.13-rc1:
https://paste.js.org/9UwQIMp7eSgp
Also note that I have CONFIG_PCIE_THERMAL unset so it's also not the cooling device portion that's causing the issue. Next I guess I should narrow it down to the specific port where enabling the bandwidth monitoring is causing trouble, not yet sure how best to do this with this many devices.
Thanks,
Niklas
Re: [PATCH v9 6/9] PCI/bwctrl: Re-add BW notification portdrv as PCIe BW controller
Quoted 61 lines · Niklas Schnelle
Quoted 48 lines · Niklas Schnelle
Quoted 10 lines · Niklas Schnelle
Quoted 9 lines · Ilpo Järvinen
This mostly reverts the commit
b4c7d2076b4e("PCI/LINK: Remove bandwidth notification"). An upcoming commit extends this driver building PCIe bandwidth controller on top of it.The PCIe bandwidth notification were first added in the commit
e8303bb7a75c("PCI/LINK: Report degraded links via link bandwidth notification") but later had to be removed. The significant changes compared with the old bandwidth notification driver include:---8<---
Quoted 21 lines
Quoted 1 line
---
Hi Ilpo,
I bisected a v6.13-rc1 boot hang on my personal workstation to this patch. Sadly I don't have much details like a panic or so because the boot hangs before any kernel messages, or at least they're not visible long enough to see. I haven't yet looked into the code as I wanted to raise awareness first. Since the commit doesn't revert cleanly on v6.13-rc1 I also haven't tried that yet.
Here are some details on my system:
- AMD Ryzen 9 3900X
- ASRock X570 Creator Motherboard
- Radeon RX 5600 XT
- Intel JHL7540 Thunderbolt 3 USB Controller (only USB 2 plugged)
- Intel 82599 10 Gigabit NIC with SR-IOV enabled with 2 VFs
- Intel n I211 Gigabit NIC
- Intel Wi-Fi 6 AX200
- Aquantia AQtion AQC107 NICQuoted 5 lines
If you have patches or things to try just ask.
Thanks,
NiklasOk I can now at least confirm that bluntly disabling the new bwctrl driver with the below diff on top of v6.13-rc1 circumvents the boot hang I'm seeing. So it's definitely this.
drivers/pci/pcie/portdrv.c +0
-0drivers/pci/pcie/portdrv.c static void __init pcie_init_services(void) · line 834
Quoted 8 lines
drivers/pci/pcie/portdrv.c +1
-1@@ -828,7 +828,7 @@ static void __init pcie_init_services(void)pcie_aer_init ();pcie_pme_init ();pcie_dpc_init (); -pcie_bwctrl_init (); +/* pcie_bwctrl_init(); */ pcie_hp_init (); }Also here is the full lspci -vvv output running the above on v6.13-rc1:
https://paste.js.org/9UwQIMp7eSgp
Quoted 8 lines
Also note that I have
CONFIG_PCIE_THERMALunset so it's also not the cooling device portion that's causing the issue. Next I guess I should narrow it down to the specific port where enabling the bandwidth monitoring is causing trouble, not yet sure how best to do this with this many devices.Thanks,
Niklas
Ok did some fiddeling and it's the thunderbolt ports. The below diff works around the issue. That said I guess for a proper fix this would should get filtered by the port service matching? Also as can be seen in lspci the port still claims to support bandwidth management so maybe other thunderbolt ports actually do.
Thanks,
Niklas
drivers/pci/pcie/bwctrl.c +3 -0
@@ -294,6 +294,9 @@ static int pcie_bwnotif_probe(struct pcie_device *srv)struct pci_dev *port = srv->port;int ret; +if (srv->port->is_thunderbolt) +return -EOPNOTSUPP ; +struct pcie_bwctrl_data *data =devm_kzalloc (&srv->device,sizeof (*data),GFP_KERNEL );if (!data)
Re: [PATCH v9 6/9] PCI/bwctrl: Re-add BW notification portdrv as PCIe BW controller
[cc += Mika, start of thread:
https://lore.kernel.org/all/[email protected]/
]
Quoted 23 lines · Niklas Schnelle
Quoted 8 lines
Quoted 8 lines · Niklas Schnelle
Quoted 7 lines
I bisected a v6.13-rc1 boot hang on my personal workstation to this patch. Sadly I don't have much details like a panic or so because the boot hangs before any kernel messages, or at least they're not visible long enough to see. I haven't yet looked into the code as I wanted to raise awareness first. Since the commit doesn't revert cleanly on v6.13-rc1 I also haven't tried that yet.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Here are some details on my system:
- AMD Ryzen 9 3900X
- ASRock X570 Creator Motherboard
- Radeon RX 5600 XT
- Intel JHL7540 Thunderbolt 3 USB Controller (only USB 2 plugged)
- Intel 82599 10 Gigabit NIC with SR-IOV enabled with 2 VFs
- Intel n I211 Gigabit NIC
- Intel Wi-Fi 6 AX200
- Aquantia AQtion AQC107 NICOk did some fiddeling and it's the thunderbolt ports. The below diff works around the issue. That said I guess for a proper fix this would should get filtered by the port service matching? Also as can be seen in lspci the port still claims to support bandwidth management so maybe other thunderbolt ports actually do.
[...]
drivers/pci/pcie/bwctrl.c static int pcie_bwnotif_probe(struct pcie_device *srv) · line 299
Quoted 9 lines
drivers/pci/pcie/bwctrl.c +3
-0@@ -294,6 +294,9 @@ static int pcie_bwnotif_probe(struct pcie_device *srv)struct pci_dev *port = srv->port;int ret; +if (srv->port->is_thunderbolt) +return -EOPNOTSUPP ; +
Thanks for reporting and analyzing this.
The PCIe bandwidth controller is only instantiated on Downstream Ports. Per the spec, Thunderbolt PCIe Downstream Ports are just tunnel endpoints with a fake Max Link Speed of 2.5 GT/s (USB4 v2 sec 11.2.1):
"Max Link Speed field in the Link Capabilities Register set to 0001b
(data rate of 2.5 GT/s only).
Note: These settings do not represent actual throughput. Throughput is implementation specific and based on the USB4 Fabric performance."
So your patch does make sense in so far as the link speed of Thunderbolt PCIe Downstream Ports is fixed to 2.5 GT/s and cannot be throttled because that's already the lowest possible PCIe speed. The actual speed is determined by the Thunderbolt links.
The check for the is_thunderbolt bit should be moved to the if-clause in get_port_device_capability() which sets the PCIE_PORT_SERVICE_BWCTRL bit in the services mask.
Alternatively, it may be worth considering not to instantiate the bandwidth controller if the only link speed supported is 2.5 GT/s.
We should try to find out what actually causes the boot hang (some interrupt storm maybe?), but that can hopefully be done internally at Intel if the boot hang is reproducible.
Thanks,
Lukas
Re: [PATCH v9 6/9] PCI/bwctrl: Re-add BW notification portdrv as PCIe BW controller
Quoted 56 lines · Lukas Wunner
[cc += Mika, start of thread:
https://lore.kernel.org/all/[email protected]/
]Quoted 23 lines · Niklas Schnelle
Quoted 8 lines
Quoted 8 lines · Niklas Schnelle
Quoted 7 lines
I bisected a v6.13-rc1 boot hang on my personal workstation to this patch. Sadly I don't have much details like a panic or so because the boot hangs before any kernel messages, or at least they're not visible long enough to see. I haven't yet looked into the code as I wanted to raise awareness first. Since the commit doesn't revert cleanly on v6.13-rc1 I also haven't tried that yet.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Here are some details on my system:
- AMD Ryzen 9 3900X
- ASRock X570 Creator Motherboard
- Radeon RX 5600 XT
- Intel JHL7540 Thunderbolt 3 USB Controller (only USB 2 plugged)
- Intel 82599 10 Gigabit NIC with SR-IOV enabled with 2 VFs
- Intel n I211 Gigabit NIC
- Intel Wi-Fi 6 AX200
- Aquantia AQtion AQC107 NICOk did some fiddeling and it's the thunderbolt ports. The below diff works around the issue. That said I guess for a proper fix this would should get filtered by the port service matching? Also as can be seen in lspci the port still claims to support bandwidth management so maybe other thunderbolt ports actually do.
[...]
drivers/pci/pcie/bwctrl.c static int pcie_bwnotif_probe(struct pcie_device *srv) · line 299
Quoted 9 lines
drivers/pci/pcie/bwctrl.c +3
-0@@ -294,6 +294,9 @@ static int pcie_bwnotif_probe(struct pcie_device *srv)struct pci_dev *port = srv->port;int ret; +if (srv->port->is_thunderbolt) +return -EOPNOTSUPP ; +Thanks for reporting and analyzing this.
The PCIe bandwidth controller is only instantiated on Downstream Ports. Per the spec, Thunderbolt PCIe Downstream Ports are just tunnel endpoints with a fake Max Link Speed of 2.5 GT/s (USB4 v2 sec 11.2.1):
"Max Link Speed field in the Link Capabilities Register set to 0001b
(data rate of 2.5 GT/s only).
Note: These settings do not represent actual throughput. Throughput is implementation specific and based on the USB4 Fabric performance."So your patch does make sense in so far as the link speed of Thunderbolt PCIe Downstream Ports is fixed to 2.5 GT/s and cannot be throttled because that's already the lowest possible PCIe speed. The actual speed is determined by the Thunderbolt links.
Quoted 6 lines
The check for the
is_thunderboltbit should be moved to the if-clause inget_port_device_capability()which sets thePCIE_PORT_SERVICE_BWCTRLbit in the services mask.Alternatively, it may be worth considering not to instantiate the bandwidth controller if the only link speed supported is 2.5 GT/s.
Thanks for the great explanation. I think your last point is also a good one, if 2.5 GT/s is the only possible link speed why even instantiate the bandwidth controller. As get_port_device_capability() already reads PCI_EXP_LNKCAP we also have that information right there already. Since I put time and effort in already I've gone ahead and cooked up a patch with this approach and will send that shortly.
Quoted 4 lines
We should try to find out what actually causes the boot hang (some interrupt storm maybe?), but that can hopefully be done internally at Intel if the boot hang is reproducible.
Makes sense, I do remember that this was one of very few motherboards for AMD CPUs with Thunderbolt.
Thanks,
Niklas
Re: [PATCH v9 6/9] PCI/bwctrl: Re-add BW notification portdrv as PCIe BW controller
In reply to Niklas Schnelle[cc += Evert]
Quoted 9 lines · Niklas Schnelle
Quoted 8 lines · Ilpo Järvinen
This mostly reverts the commit
b4c7d2076b4e("PCI/LINK: Remove bandwidth notification"). An upcoming commit extends this driver building PCIe bandwidth controller on top of it.The PCIe bandwidth notification were first added in the commit
e8303bb7a75c("PCI/LINK: Report degraded links via link bandwidth notification") but later had to be removed. The significant changes compared with the old bandwidth notification driver include:
[...]
Quoted 6 lines
I bisected a v6.13-rc1 boot hang on my personal workstation to this patch. Sadly I don't have much details like a panic or so because the boot hangs before any kernel messages, or at least they're not visible long enough to see. I haven't yet looked into the code as I wanted to raise awareness first. Since the commit doesn't revert cleanly on v6.13-rc1 I also haven't tried that yet.
Hi Niklas,
another regression caused by bandwidth control was reported, this time it's a hang on shutdown (instead of on boot) and this time we root-caused it instead of just working around it.
Here's the proposed fix:
https://lore.kernel.org/r/0ee5faf5395cad8d29fb66e1ec444c8d882a4201.1735852688.git.lukas@wunner.de/
Could you test this on top of v6.13-rc1 (or any other rc which does not include 774c71c52aa4 ("PCI/bwctrl: Enable only if more than one speed is supported")?
I suspect that it may fix the issue you were seeing as well and I'm curious whether that suspicion is correct.
Thanks!
Lukas
Ilpo Järvinen
maintainerPATCH v9 7/9 PCI/bwctrl: Add API to set PCIe Link Speed
In reply to Ilpo JärvinenCurrently, PCIe Link Speeds are adjusted by custom code rather than in a common function provided in PCI core. PCIe bandwidth controller (bwctrl) introduces an in-kernel API to set PCIe Link Speed.
Convert Target Speed quirk to use the new API. The Target Speed quirk runs very early when bwctrl is not yet probed for a Port and can also run later when bwctrl is already setup for the Port, which requires the per port mutex (set_speed_mutex) to be only taken if the bwctrl setup is already complete.
The new API is also intended to be used in an upcoming commit that adds a thermal cooling device to throttle PCIe bandwidth when thermal thresholds are reached.
The PCIe bandwidth control procedure is as follows. The highest speed supported by the Port and the PCIe device which is not higher than the requested speed is selected and written into the Target Link Speed in the Link Control 2 Register. Then bandwidth controller retrains the PCIe Link.
Bandwidth Notifications enable the cur_bus_speed in the struct pci_bus to keep track PCIe Link Speed changes. While Bandwidth Notifications should also be generated when bandwidth controller alters the PCIe Link Speed, a few platforms do not deliver LMBS interrupt after Link Training as expected. Thus, after changing the Link Speed, bandwidth controller makes additional read for the Link Status Register to ensure cur_bus_speed is consistent with the new PCIe Link Speed.
--- drivers/pci/pci.h | 20 +++++ drivers/pci/pcie/bwctrl.c | 178 ++++++++++++++++++++++++++++++++++++-- drivers/pci/quirks.c | 17 +--- include/linux/pci.h | 10 +++ 4 files changed, 206 insertions(+), 19 deletions(-)
drivers/pci/pci.h +20 -0
@@ -331,6 +331,17 @@ void pci_disable_bridge_window(struct pci_dev *dev);struct pci_bus *pci_bus_get (struct pci_bus *bus);void pci_bus_put (struct pci_bus *bus); +#define PCIE_LNKCAP_SLS2SPEED (lnkcap) \ +({ \ + ((lnkcap) == PCI_EXP_LNKCAP_SLS_64_0GB ? PCIE_SPEED_64_0GT : \ + (lnkcap) == PCI_EXP_LNKCAP_SLS_32_0GB ? PCIE_SPEED_32_0GT : \ + (lnkcap) == PCI_EXP_LNKCAP_SLS_16_0GB ? PCIE_SPEED_16_0GT : \ + (lnkcap) == PCI_EXP_LNKCAP_SLS_8_0GB ? PCIE_SPEED_8_0GT : \ + (lnkcap) == PCI_EXP_LNKCAP_SLS_5_0GB ? PCIE_SPEED_5_0GT : \ + (lnkcap) == PCI_EXP_LNKCAP_SLS_2_5GB ? PCIE_SPEED_2_5GT : \ + PCI_SPEED_UNKNOWN); \ +}) +/* PCIe link information from Link Capabilities 2 */ #define PCIE_LNKCAP2_SLS2SPEED (lnkcap2) \ ((lnkcap2) & PCI_EXP_LNKCAP2_SLS_64_0GB ? PCIE_SPEED_64_0GT : \
@@ -341,6 +352,15 @@ void pci_bus_put(struct pci_bus *bus); (lnkcap2) & PCI_EXP_LNKCAP2_SLS_2_5GB ? PCIE_SPEED_2_5GT : \ PCI_SPEED_UNKNOWN) +#define PCIE_LNKCTL2_TLS2SPEED (lnkctl2) \ + ((lnkctl2) == PCI_EXP_LNKCTL2_TLS_64_0GT ? PCIE_SPEED_64_0GT : \ + (lnkctl2) == PCI_EXP_LNKCTL2_TLS_32_0GT ? PCIE_SPEED_32_0GT : \ + (lnkctl2) == PCI_EXP_LNKCTL2_TLS_16_0GT ? PCIE_SPEED_16_0GT : \ + (lnkctl2) == PCI_EXP_LNKCTL2_TLS_8_0GT ? PCIE_SPEED_8_0GT : \ + (lnkctl2) == PCI_EXP_LNKCTL2_TLS_5_0GT ? PCIE_SPEED_5_0GT : \ + (lnkctl2) == PCI_EXP_LNKCTL2_TLS_2_5GT ? PCIE_SPEED_2_5GT : \ + PCI_SPEED_UNKNOWN) +/* PCIe speed to Mb/s reduced by encoding overhead */ #define PCIE_SPEED2MBS_ENC (speed) \ ((speed) == PCIE_SPEED_64_0GT ? 64000*1/1 : \
drivers/pci/pcie/bwctrl.c +172 -6
224 lines not on this page · raw message
drivers/pci/quirks.c +4 -13
@@ -113,16 +113,11 @@ int pcie_failed_link_retrain(struct pci_dev *dev)pci_info (dev,"broken device, retraining non-functional downstream link at 2.5GT/s\n" ); - lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS ; - lnkctl2 |=PCI_EXP_LNKCTL2_TLS_2_5GT ; -pcie_capability_write_word (dev,PCI_EXP_LNKCTL2 , lnkctl2); - - ret =pcie_retrain_link (dev, false); + ret =pcie_set_target_speed (dev,PCIE_SPEED_2_5GT , false);if (ret) {pci_info (dev,"retraining failed\n" ); -pcie_capability_write_word (dev,PCI_EXP_LNKCTL2 , - oldlnkctl2); -pcie_retrain_link (dev, true); +pcie_set_target_speed (dev,PCIE_LNKCTL2_TLS2SPEED (oldlnkctl2), + true);return ret; }
@@ -136,11 +131,7 @@ int pcie_failed_link_retrain(struct pci_dev *dev)pci_info (dev,"removing 2.5GT/s downstream link speed restriction\n" );pcie_capability_read_dword (dev,PCI_EXP_LNKCAP , &lnkcap); - lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS ; - lnkctl2 |= lnkcap &PCI_EXP_LNKCAP_SLS ; -pcie_capability_write_word (dev,PCI_EXP_LNKCTL2 , lnkctl2); - - ret =pcie_retrain_link (dev, false); + ret =pcie_set_target_speed (dev,PCIE_LNKCAP_SLS2SPEED (lnkcap), false);if (ret) {pci_info (dev,"retraining failed\n" );return ret;
include/linux/pci.h +10 -0
@@ -1798,9 +1798,19 @@ static inline int pci_irqd_intx_xlate(struct irq_domain *d,#ifdef CONFIG_PCIEPORTBUS extern bool pcie_ports_disabled;extern bool pcie_ports_native; + +int pcie_set_target_speed (struct pci_dev *port,enum pci_bus_speed speed_req, +bool use_lt);#else #define pcie_ports_disabled true#define pcie_ports_native false + +static inline int pcie_set_target_speed (struct pci_dev *port, +enum pci_bus_speed speed_req, +bool use_lt) +{ +return -EOPNOTSUPP ; +}#endif #define PCIE_LINK_STATE_L0S (BIT(0) | BIT(1))/* Upstr/dwnstr L0s */
Signature · 1 line
2.39.5
Re: [PATCH v9 7/9] PCI/bwctrl: Add API to set PCIe Link Speed
Quoted 1 line · Ilpo Järvinen
+EXPORT_SYMBOL_GPL(pcie_set_target_speed);
My apologies for another belated comment on this series. This patch is now a688ab21eb72 on pci/bwctrl:
I note that pcie_set_target_speed() is not called my a modular user (CONFIG_PCIE_THERMAL is bool, not tristate), so the above-quoted export isn't really necessary right now. I don't know if it was added intentionally because some modular user is expected to show up in the near future.
drivers/pci/pcie/bwctrl.c static int pcie_bwnotif_probe(struct pcie_device *srv) · line 302
Quoted 8 lines
drivers/pci/pcie/bwctrl.c +1
-0@@ -135,6 +296,7 @@ static int pcie_bwnotif_probe(struct pcie_device *srv)if (!data)return -ENOMEM ; +devm_mutex_init (&srv->device, &data->set_speed_mutex); ret = devm_request_threaded_irq(&srv->device, srv->irq, NULL, pcie_bwnotif_irq_thread, IRQF_SHARED | IRQF_ONESHOT,
We generally try to avoid devm_*() functions in port service drivers because if we later on move them into the PCI core (which is the plan), we'll have to unroll them. Not the end of the world that they're used here, just not ideal.
Thanks,
Lukas
Ilpo Järvinen
maintainerRe: [PATCH v9 7/9] PCI/bwctrl: Add API to set PCIe Link Speed
Quoted 11 lines · Lukas Wunner
Quoted 1 line · Ilpo Järvinen
+EXPORT_SYMBOL_GPL(pcie_set_target_speed);
My apologies for another belated comment on this series. This patch is now
a688ab21eb72on pci/bwctrl:I note that
pcie_set_target_speed()is not called my a modular user (CONFIG_PCIE_THERMALis bool, not tristate), so the above-quoted export isn't really necessary right now. I don't know if it was added intentionally because some modular user is expected to show up in the near future.
Its probably a thinko to add it at all but then there have been talk about other users interested in the API too so it's not far fetched we could see a user. No idea about timelines though.
There are some AMD GPU drivers tweaking the TLS field on their own but they also touch some HW specific registers (although, IIRC, they only touch Endpoint'sTLS). I was thinking of converting them but I'm unsure if that yields something very straightforward and ends up producing a working conversion or not (without ability to test with the HW). But TBH, not on my highest priority item.
Quoted 4 lines
Quoted 4 lines
drivers/pci/pcie/bwctrl.c +0
-0@@ -135,6 +296,7 @@ static int pcie_bwnotif_probe(struct pcie_device *srv)if (!data)return -ENOMEM ;
Quoted 9 lines
drivers/pci/pcie/bwctrl.c static int pcie_bwnotif_probe(struct pcie_device *srv) · line 302
Quoted 4 lines
drivers/pci/pcie/bwctrl.c +1
-0+devm_mutex_init (&srv->device, &data->set_speed_mutex); ret = devm_request_threaded_irq(&srv->device, srv->irq, NULL, pcie_bwnotif_irq_thread, IRQF_SHARED | IRQF_ONESHOT,We generally try to avoid devm_*() functions in port service drivers because if we later on move them into the PCI core (which is the plan), we'll have to unroll them. Not the end of the world that they're used here, just not ideal.
I think Jonathan disagrees with you on that:
https://lore.kernel.org/linux-pci/[email protected]/
:-)
Signature · 1 line
i.
Re: [PATCH v9 7/9] PCI/bwctrl: Add API to set PCIe Link Speed
Quoted 39 lines · On Tue, 12 Nov 2024 18:01:50 +0200 (EET) Ilpo Järvinen…
Quoted 11 lines · Lukas Wunner
Quoted 1 line · Ilpo Järvinen
+EXPORT_SYMBOL_GPL(pcie_set_target_speed);
My apologies for another belated comment on this series. This patch is now
a688ab21eb72on pci/bwctrl:I note that
pcie_set_target_speed()is not called my a modular user (CONFIG_PCIE_THERMALis bool, not tristate), so the above-quoted export isn't really necessary right now. I don't know if it was added intentionally because some modular user is expected to show up in the near future.Its probably a thinko to add it at all but then there have been talk about other users interested in the API too so it's not far fetched we could see a user. No idea about timelines though.
There are some AMD GPU drivers tweaking the TLS field on their own but they also touch some HW specific registers (although, IIRC, they only touch Endpoint'sTLS). I was thinking of converting them but I'm unsure if that yields something very straightforward and ends up producing a working conversion or not (without ability to test with the HW). But TBH, not on my highest priority item.
Quoted 4 lines
Quoted 4 lines
drivers/pci/pcie/bwctrl.c +0
-0@@ -135,6 +296,7 @@ static int pcie_bwnotif_probe(struct pcie_device *srv)if (!data)return -ENOMEM ;Quoted 9 lines
drivers/pci/pcie/bwctrl.c static int pcie_bwnotif_probe(struct pcie_device *srv) · line 302
Quoted 4 lines
drivers/pci/pcie/bwctrl.c +1
-0+devm_mutex_init (&srv->device, &data->set_speed_mutex); ret = devm_request_threaded_irq(&srv->device, srv->irq, NULL, pcie_bwnotif_irq_thread, IRQF_SHARED | IRQF_ONESHOT,We generally try to avoid devm_*() functions in port service drivers because if we later on move them into the PCI core (which is the plan), we'll have to unroll them. Not the end of the world that they're used here, just not ideal.
Quoted 3 lines
I think Jonathan disagrees with you on that:
Indeed - you beat me to it ;)
There is no practical way to move most of the port driver code into the PCI core and definitely not interrupts. It is a shame though as I'd much prefer if we could do so. At LPC other issues some as power management were called out as being very hard to handle, but to me the interrupt bit is a single relatively easy to understand blocker.
I've been very slow on getting back to this, but my current plan would
1) Split up the bits of portdrv subdrivers that are actually core code (things like the AER counters etc) The current mix in the same files makes it hard to reason about lifetimes etc.
2) Squash all the portdrv sub drivers into simple library style calls so no pretend devices, everything registered directly. That cleans up a lot of the layering and still provides reusable code if it makes sense to have multiple drivers for ports or to reuse this code for something else. Note that along the way I'll check we can build the portdrv as a module - I don't plan to actually do that, but it shows the layering / abstractions all work if it is possible. That will probably make use of devm_ where appropriate as it simplifies a lot of paths.
3) Add the MSIX stuff to support 'new' child drivers but only where dynamic MSIX is supported.
4) Register new child devices where the layering does make sense. So where we are actually binding drivers that can be unbound etc. Only for cases where dynamic MSI-X is available.
I hope to get back to this in a week or so.
Jonathan
Quoted 3 lines
:-)
Ilpo Järvinen
maintainerRe: [PATCH v9 7/9] PCI/bwctrl: Add API to set PCIe Link Speed
Quoted 60 lines · Jonathan Cameron
Quoted 39 lines · On Tue, 12 Nov 2024 18:01:50 +0200 (EET) Ilpo Järvinen…
Quoted 11 lines · Lukas Wunner
Quoted 1 line · Ilpo Järvinen
+EXPORT_SYMBOL_GPL(pcie_set_target_speed);
My apologies for another belated comment on this series. This patch is now
a688ab21eb72on pci/bwctrl:I note that
pcie_set_target_speed()is not called my a modular user (CONFIG_PCIE_THERMALis bool, not tristate), so the above-quoted export isn't really necessary right now. I don't know if it was added intentionally because some modular user is expected to show up in the near future.Its probably a thinko to add it at all but then there have been talk about other users interested in the API too so it's not far fetched we could see a user. No idea about timelines though.
There are some AMD GPU drivers tweaking the TLS field on their own but they also touch some HW specific registers (although, IIRC, they only touch Endpoint'sTLS). I was thinking of converting them but I'm unsure if that yields something very straightforward and ends up producing a working conversion or not (without ability to test with the HW). But TBH, not on my highest priority item.
Quoted 4 lines
Quoted 4 lines
drivers/pci/pcie/bwctrl.c +0
-0@@ -135,6 +296,7 @@ static int pcie_bwnotif_probe(struct pcie_device *srv)if (!data)return -ENOMEM ;Quoted 9 lines
drivers/pci/pcie/bwctrl.c static int pcie_bwnotif_probe(struct pcie_device *srv) · line 302
Quoted 4 lines
drivers/pci/pcie/bwctrl.c +1
-0+devm_mutex_init (&srv->device, &data->set_speed_mutex); ret = devm_request_threaded_irq(&srv->device, srv->irq, NULL, pcie_bwnotif_irq_thread, IRQF_SHARED | IRQF_ONESHOT,We generally try to avoid devm_*() functions in port service drivers because if we later on move them into the PCI core (which is the plan), we'll have to unroll them. Not the end of the world that they're used here, just not ideal.
Quoted 3 lines
I think Jonathan disagrees with you on that:
Indeed - you beat me to it ;)
There is no practical way to move most of the port driver code into the PCI core and definitely not interrupts. It is a shame though as I'd much prefer if we could do so. At LPC other issues some as power management were called out as being very hard to handle, but to me the interrupt bit is a single relatively easy to understand blocker.
I've been very slow on getting back to this, but my current plan would
1) Split up the bits of portdrv subdrivers that are actually core code (things like the AER counters etc) The current mix in the same files makes it hard to reason about lifetimes etc.
Quoted 9 lines
2) Squash all the portdrv sub drivers into simple library style calls so no pretend devices, everything registered directly. That cleans up a lot of the layering and still provides reusable code if it makes sense to have multiple drivers for ports or to reuse this code for something else. Note that along the way I'll check we can build the portdrv as a module - I don't plan to actually do that, but it shows the layering / abstractions all work if it is possible. That will probably make use of
devm_where appropriate as it simplifies a lot of paths.
I'm sorry to be a bit of a spoilsport here but quirks make calls to ASPM code and now also to bwctrl set Link Speed API so I'm not entire sure if you can actual succeed in that module test.
(It's just something that again indicates both would belong to PCI core but sadly that direction is out of options).
Signature · 1 line
i.
Quoted 15 lines
3) Add the MSIX stuff to support 'new' child drivers but only where dynamic MSIX is supported.
4) Register new child devices where the layering does make sense. So where we are actually binding drivers that can be unbound etc. Only for cases where dynamic MSI-X is available.
I hope to get back to this in a week or so.
Jonathan
Quoted 3 lines
:-)
Re: [PATCH v9 7/9] PCI/bwctrl: Add API to set PCIe Link Speed
Quoted 72 lines · On Mon, 18 Nov 2024 15:17:53 +0200 (EET) Ilpo Järvinen…
Quoted 60 lines · Jonathan Cameron
Quoted 39 lines · On Tue, 12 Nov 2024 18:01:50 +0200 (EET) Ilpo Järvinen…
Quoted 11 lines · Lukas Wunner
Quoted 1 line · Ilpo Järvinen
+EXPORT_SYMBOL_GPL(pcie_set_target_speed);
My apologies for another belated comment on this series. This patch is now
a688ab21eb72on pci/bwctrl:I note that
pcie_set_target_speed()is not called my a modular user (CONFIG_PCIE_THERMALis bool, not tristate), so the above-quoted export isn't really necessary right now. I don't know if it was added intentionally because some modular user is expected to show up in the near future.Its probably a thinko to add it at all but then there have been talk about other users interested in the API too so it's not far fetched we could see a user. No idea about timelines though.
There are some AMD GPU drivers tweaking the TLS field on their own but they also touch some HW specific registers (although, IIRC, they only touch Endpoint'sTLS). I was thinking of converting them but I'm unsure if that yields something very straightforward and ends up producing a working conversion or not (without ability to test with the HW). But TBH, not on my highest priority item.
Quoted 4 lines
Quoted 4 lines
drivers/pci/pcie/bwctrl.c +0
-0@@ -135,6 +296,7 @@ static int pcie_bwnotif_probe(struct pcie_device *srv)if (!data)return -ENOMEM ;Quoted 9 lines
drivers/pci/pcie/bwctrl.c static int pcie_bwnotif_probe(struct pcie_device *srv) · line 302
Quoted 4 lines
drivers/pci/pcie/bwctrl.c +1
-0+devm_mutex_init (&srv->device, &data->set_speed_mutex); ret = devm_request_threaded_irq(&srv->device, srv->irq, NULL, pcie_bwnotif_irq_thread, IRQF_SHARED | IRQF_ONESHOT,We generally try to avoid devm_*() functions in port service drivers because if we later on move them into the PCI core (which is the plan), we'll have to unroll them. Not the end of the world that they're used here, just not ideal.
Quoted 3 lines
I think Jonathan disagrees with you on that:
Indeed - you beat me to it ;)
There is no practical way to move most of the port driver code into the PCI core and definitely not interrupts. It is a shame though as I'd much prefer if we could do so. At LPC other issues some as power management were called out as being very hard to handle, but to me the interrupt bit is a single relatively easy to understand blocker.
I've been very slow on getting back to this, but my current plan would
1) Split up the bits of portdrv subdrivers that are actually core code (things like the AER counters etc) The current mix in the same files makes it hard to reason about lifetimes etc.
Quoted 9 lines
2) Squash all the portdrv sub drivers into simple library style calls so no pretend devices, everything registered directly. That cleans up a lot of the layering and still provides reusable code if it makes sense to have multiple drivers for ports or to reuse this code for something else. Note that along the way I'll check we can build the portdrv as a module - I don't plan to actually do that, but it shows the layering / abstractions all work if it is possible. That will probably make use of
devm_where appropriate as it simplifies a lot of paths.
Quoted 7 lines
I'm sorry to be a bit of a spoilsport here but quirks make calls to ASPM code and now also to bwctrl set Link Speed API so I'm not entire sure if you can actual succeed in that module test.
(It's just something that again indicates both would belong to PCI core but sadly that direction is out of options).
It may involve some bodges, but it is still a path to checking the layer splits at least make 'some' sense. Also that the resulting library style code is suitable for reuse. Possibly with an exception for a few parts.
Thanks for the pointers to where the pitfalls lie!
Jonathan
Re: [PATCH v9 7/9] PCI/bwctrl: Add API to set PCIe Link Speed
In reply to Lukas WunnerQuoted 11 lines · Lukas Wunner
Quoted 1 line · Ilpo Järvinen
+EXPORT_SYMBOL_GPL(pcie_set_target_speed);
My apologies for another belated comment on this series. This patch is now
a688ab21eb72on pci/bwctrl:I note that
pcie_set_target_speed()is not called my a modular user (CONFIG_PCIE_THERMALis bool, not tristate), so the above-quoted export isn't really necessary right now. I don't know if it was added intentionally because some modular user is expected to show up in the near future.
Dropped the export for now, we can add it back if/when needed.
Bjorn
Re: [PATCH v9 7/9] PCI/bwctrl: Add API to set PCIe Link Speed
In reply to Ilpo Järvinendrivers/pci/pcie/bwctrl.c static int pcie_bwnotif_probe(struct pcie_device *srv) · line 312
Quoted 13 lines · Ilpo Järvinen
drivers/pci/pcie/bwctrl.c +5
-3@@ -142,9 +304,11 @@ static int pcie_bwnotif_probe(struct pcie_device *srv)if (ret)return ret; - scoped_guard(rwsem_write, &pcie_bwctrl_lbms_rwsem) { - port->link_bwctrl =no_free_ptr (data); -pcie_bwnotif_enable (srv); + scoped_guard(rwsem_write, &pcie_bwctrl_setspeed_rwsem) { + scoped_guard(rwsem_write, &pcie_bwctrl_lbms_rwsem) { + port->link_bwctrl =no_free_ptr (data); +pcie_bwnotif_enable (srv); + } }
The "data" pointer is allocated with devm_kzalloc(). There's no __free(kfree) anywhere.
So what's the motivation for the no_free_ptr()?
Is this a remnant of an earlier version of the patch set that can be deleted or is there actually a purpose to it?
Thanks,
Lukas
Ilpo Järvinen
maintainerRe: [PATCH v9 7/9] PCI/bwctrl: Add API to set PCIe Link Speed
Quoted 18 lines · Lukas Wunner
drivers/pci/pcie/bwctrl.c static int pcie_bwnotif_probe(struct pcie_device *srv) · line 312
Quoted 13 lines · Ilpo Järvinen
drivers/pci/pcie/bwctrl.c +5
-3@@ -142,9 +304,11 @@ static int pcie_bwnotif_probe(struct pcie_device *srv)if (ret)return ret; - scoped_guard(rwsem_write, &pcie_bwctrl_lbms_rwsem) { - port->link_bwctrl =no_free_ptr (data); -pcie_bwnotif_enable (srv); + scoped_guard(rwsem_write, &pcie_bwctrl_setspeed_rwsem) { + scoped_guard(rwsem_write, &pcie_bwctrl_lbms_rwsem) { + port->link_bwctrl =no_free_ptr (data); +pcie_bwnotif_enable (srv); + } }The "data" pointer is allocated with
devm_kzalloc(). There's no__free(kfree)anywhere.
Quoted 3 lines
So what's the motivation for the
no_free_ptr()?
Is this a remnant of an earlier version of the patch set that can be deleted or is there actually a purpose to it?
Remnant it was so it is okay to remove it in your fix.
Signature · 1 line
i.
Ilpo Järvinen
maintainerPATCH v9 8/9 thermal: Add PCIe cooling driver
In reply to Ilpo JärvinenAdd a thermal cooling driver to provide path to access PCIe bandwidth controller using the usual thermal interfaces.
A cooling device is instantiated for controllable PCIe Ports from the bwctrl service driver.
If registering the cooling device fails, allow bwctrl's probe to succeed regardless. As cdev in that case contains IS_ERR() pseudo "pointer", clean that up inside the probe function so the remove side doesn't need to suddenly make an odd looking IS_ERR() check.
The thermal side state 0 means no throttling, i.e., maximum supported PCIe Link Speed.
--- MAINTAINERS | 2 + drivers/pci/pcie/bwctrl.c | 13 ++++++ drivers/thermal/Kconfig | 9 ++++ drivers/thermal/Makefile | 2 + drivers/thermal/pcie_cooling.c | 80 ++++++++++++++++++++++++++++++++++ include/linux/pci-bwctrl.h | 28 ++++++++++++ 6 files changed, 134 insertions(+) create mode 100644 drivers/thermal/pcie_cooling.c create mode 100644 include/linux/pci-bwctrl.h
MAINTAINERS +2 -0
@@ -17938,6 +17938,8 @@ M: Ilpo Järvinen <[email protected]> L: [email protected] S: Supported F: drivers/pci/pcie/bwctrl.c +F: drivers/thermal/pcie_cooling.c +F: include/linux/pci-bwctrl.h PCIE DRIVER FOR AMAZON ANNAPURNA LABS M: Jonathan Chocron <[email protected]>
drivers/pci/pcie/bwctrl.c +13 -0
@@ -27,6 +27,7 @@#include <linux/interrupt.h> #include <linux/mutex.h> #include <linux/pci.h> +#include <linux/pci-bwctrl.h> #include <linux/rwsem.h> #include <linux/slab.h> #include <linux/types.h>
@@ -38,10 +39,12 @@* struct pcie_bwctrl_data - PCIe bandwidth controller * @set_speed_mutex: Serializes link speed changes * @lbms_count: Count for LBMS (since last reset) +* @cdev: thermal cooling device associated with the port */ struct pcie_bwctrl_data {struct mutex set_speed_mutex;atomic_t lbms_count; +struct thermal_cooling_device *cdev; };/*
@@ -313,11 +316,21 @@ static int pcie_bwnotif_probe(struct pcie_device *srv)pci_dbg (port,"enabled with IRQ %d\n" , srv->irq); +/* Don't fail on errors. Don't leave IS_ERR() "pointer" into ->cdev */ + port->link_bwctrl->cdev =pcie_cooling_device_register (port); +if (IS_ERR (port->link_bwctrl->cdev)) + port->link_bwctrl->cdev =NULL ; +return 0 ; }static void pcie_bwnotif_remove (struct pcie_device *srv) { +struct pcie_bwctrl_data *data = srv->port->link_bwctrl; + +if (data->cdev) +pcie_cooling_device_unregister (data->cdev); +pcie_bwnotif_disable (srv->port);scoped_guard (rwsem_write, &pcie_bwctrl_setspeed_rwsem)
drivers/thermal/Kconfig +9 -0
@@ -220,6 +220,15 @@ config DEVFREQ_THERMAL If you want this support, you should say Y here. +config PCIE_THERMAL + bool "PCIe cooling support" + depends on PCIEPORTBUS + help + This implements PCIe cooling mechanism through bandwidth reduction + for PCIe devices. + + If you want this support, you should say Y here. + config THERMAL_EMULATION bool "Thermal emulation mode support" help
drivers/thermal/Makefile +2 -0
@@ -31,6 +31,8 @@ thermal_sys-$(CONFIG_CPU_IDLE_THERMAL) += cpuidle_cooling.o # devfreq cooling thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o +thermal_sys-$(CONFIG_PCIE_THERMAL) += pcie_cooling.o + obj-$(CONFIG_K3_THERMAL) += k3_bandgap.o k3_j72xx_bandgap.o # platform thermal drivers obj-y += broadcom/
drivers/thermal/pcie_cooling.c new file +80 -0
80 lines not on this page · raw message
include/linux/pci-bwctrl.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* PCIe bandwidth controller +* +* Copyright (C) 2023-2024 Intel Corporation +*/ + +#ifndef LINUX_PCI_BWCTRL_H +#define LINUX_PCI_BWCTRL_H + +#include <linux/pci.h> + +struct thermal_cooling_device ; + +#ifdef CONFIG_PCIE_THERMAL +struct thermal_cooling_device *pcie_cooling_device_register (struct pci_dev *port); +void pcie_cooling_device_unregister (struct thermal_cooling_device *cdev); +#else +static inline struct thermal_cooling_device *pcie_cooling_device_register (struct pci_dev *port) +{ +return NULL ; +} +static inline void pcie_cooling_device_unregister (struct thermal_cooling_device *cdev) +{ +} +#endif + +#endif
Signature · 1 line
2.39.5
Re: [PATCH v9 8/9] thermal: Add PCIe cooling driver
drivers/pci/pcie/bwctrl.c static int pcie_bwnotif_probe(struct pcie_device *srv) · line 333
Quoted 7 lines · Ilpo Järvinen
static void
pcie_bwnotif_remove(struct pcie_device *srv){drivers/pci/pcie/bwctrl.c +5
-0+struct pcie_bwctrl_data *data = srv->port->link_bwctrl; + +if (data->cdev) +pcie_cooling_device_unregister (data->cdev); +
Just noting a minor nit here in what is now commit 7206400cda87 on pci/bwctrl: The NULL pointer check for data->cdev seems redundant as pcie_cooling_device_unregister() just calls thermal_cooling_device_unregister(), which in turn contains this at the top:
if (!cdev) return;
Thanks,
Lukas
Re: [PATCH v9 8/9] thermal: Add PCIe cooling driver
Quoted 15 lines · Lukas Wunner
drivers/pci/pcie/bwctrl.c static int pcie_bwnotif_probe(struct pcie_device *srv) · line 333
Quoted 7 lines · Ilpo Järvinen
static void
pcie_bwnotif_remove(struct pcie_device *srv){drivers/pci/pcie/bwctrl.c +5
-0+struct pcie_bwctrl_data *data = srv->port->link_bwctrl; + +if (data->cdev) +pcie_cooling_device_unregister (data->cdev); +Just noting a minor nit here in what is now commit
7206400cda87on pci/bwctrl: The NULL pointer check fordata->cdevseems redundant aspcie_cooling_device_unregister()just callsthermal_cooling_device_unregister(), which in turn contains this at the top:
Quoted 2 lines
if (!cdev) return;
Thanks, I dropped this NULL pointer check locally.
Ilpo Järvinen
maintainerPATCH v9 9/9 selftests/pcie_bwctrl: Create selftests
In reply to Ilpo JärvinenCreate selftests for PCIe BW control through the PCIe cooling device sysfs interface.
First, the BW control selftest finds the PCIe Port to test with. By default, the PCIe Port with the highest Link Speed is selected but another PCIe Port can be provided with -d parameter.
The actual test steps the cur_state of the cooling device one-by-one from max_state to what the cur_state was initially. The speed change is confirmed by observing the current_link_speed for the corresponding PCIe Port.
--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/pcie_bwctrl/Makefile | 2 + .../pcie_bwctrl/set_pcie_cooling_state.sh | 122 ++++++++++++++++++ .../selftests/pcie_bwctrl/set_pcie_speed.sh | 67 ++++++++++ 5 files changed, 193 insertions(+) create mode 100644 tools/testing/selftests/pcie_bwctrl/Makefile create mode 100755 tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh create mode 100755 tools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh
MAINTAINERS +1 -0
@@ -17940,6 +17940,7 @@ S: Supported F: drivers/pci/pcie/bwctrl.c F: drivers/thermal/pcie_cooling.c F: include/linux/pci-bwctrl.h +F: tools/testing/selftests/pcie_bwctrl/ PCIE DRIVER FOR AMAZON ANNAPURNA LABS M: Jonathan Chocron <[email protected]>
tools/testing/selftests/Makefile +1 -0
@@ -72,6 +72,7 @@ TARGETS += net/packetdrill TARGETS += net/rds TARGETS += net/tcp_ao TARGETS += nsfs +TARGETS += pcie_bwctrl TARGETS += perf_events TARGETS += pidfd TARGETS += pid_namespace
tools/testing/selftests/pcie_bwctrl/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +TEST_PROGS = set_pcie_cooling_state.sh +include ../lib.mk
tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh new file +122 -0
122 lines not on this page · raw message
tools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.39.5
Bjorn Helgaas
AppliedQuoted 136 lines · Ilpo Järvinen
Hi all,
This series adds PCIe bandwidth controller (bwctrl) and associated PCIe cooling driver to the thermal core side for limiting PCIe Link Speed due to thermal reasons. PCIe bandwidth controller is a PCI express bus port service driver. A cooling device is created for each port the service driver finds to support changing speeds.
This series only adds support for controlling PCIe Link Speed. Controlling PCIe Link Width might also be useful but there is no mechanism for that until PCIe 6.0 (L0p) so Link Width throttling is not added by this series.
v9:
- Split RMW ops doc reformat into own patch before adding LNKCTL2.
- Comment reserved 0 LSB even better than it already was.
- Consider portdrv future plans:
- Use devm helpers for mem alloc, IRQ, and mutex init.
- Don't use get/set_service_data().
- Split rwsem into two to avoid recursive locking splat throughpcie_retrain_link().
- Small wording improvements to commit messages (from Jonathan)v8:
- RemovedCONFIG_PCIE_BWCTRL(useCONFIG_PCIEPORTBUS)
- Removed locking wrappers that dealt with the CONFIG variations
- Protect macro parameter with parenthesis to be on the safe sidev7:
- Rebased on top of Maciej's latest Target Speed quirk patches
- Target Speed quirk runs very early, w/o ->subordinate existing yet. This required adapting logic:
- Move Supported Link Speeds back topci_dev
- Check for ->subordinate == NULL where necessary
- Cannot always take bwctrl's per port mutex (inpcie_bwctrl_data)
- Cleaned up locking inpcie_set_target_speed()using wrappers
- Allowed removing confusing__pcie_set_target_speed()
- Fix building withCONFIG_PCI=n
- Correct error check inpcie_lbms_seen()
- Don't return error for an empty bus that remains at 2.5GT
- Use rwsem to protect ->link_bwctrl setup and bwnotif enable
- Clear LBMS inremove_board()
- Adding export forpcie_get_supported_speeds()was unnecessary
- Call bwctrl's init before hotplug.
- Added local variable 'bus' into a few functionsv6:
- Removed unnecessaryPCI_EXP_LNKCAP_SLSmask fromPCIE_LNKCAP_SLS2SPEED()
- Split error handling inpcie_bwnotif_irq_thread()
-pci_info()->pci_dbg()on bwctrl probe success path
- Handle cooling device pointer -Exx codes in bwctrl probe
- Reorderport->link_bwctrlsetup / bwnotif enable for symmetry
- Handle LBMS count == 0 in PCIe quirk by checking LBMS (avoids a race between quirk and bwctrl)
- Usecleanup.hin PCIe cooling device's registerv5:
- Removed patches: LNKCTL2 RMW driver patches went in separately
- Refactorpcie_update_link_speed()to read LNKSTA + add __ variant for hotplug that has LNKSTA value at hand
- Make series fully compatible with the Target Speed quirk
- LBMS counter added, quirk falls back to LBMS bit when bwctrl =n
- Separate LBMS patch from set target speed patches
- Always providepcie_bwctrl_change_speed()even if bwctrl =n so drivers don't need to come up their own version (also required by the Target Speed quirk)
- Remove devm_* (based on Lukas' comment on some other service driver patch)
- Convert to usecleanup.h
- Renamed functions/struct to have shorter namesv4:
- Merge Port's and Endpoint's Supported Link Speeds Vectors intosupported_speedsin the structpci_bus
- Reuse pcie_get_speed_cap()'s code forpcie_get_supported_speeds()
- Setupsupported_speedswithPCI_EXP_LNKCAP2_SLS_2_5GBwhen no Endpoint exists
- Squash revert + add bwctrl patches into one
- Change to use threaded IRQ +IRQF_ONESHOT
- Enable also LABIE / LABS
- Convert Link Speed selection to use bit logic instead of loop
- Allocate before requesting IRQ during probe
- Use devm_*()
- Use u8 forspeed_convarray instead of u16
- RemovedREAD_ONCE()
- Improve changelogs, comments, andKconfig
- Name functions slightly more consistently
- Use bullet list for RMW protected registers in docsv3:
- Correct hfi1 shortlog prefix
- Improve error prints in hfi1
- Add L: linux-pci to theMAINTAINERSentryv2:
- Adds LNKCTL2 to RMW safe list inDocumentation/PCI/pciebus-howto.rst
- Renamed cooling devices from PCIe_Port_* to PCIe_Port_Link_Speed_* in order to plan for possibility of adding Link Width cooling devices later on
- Moved structthermal_cooling_devicedeclaration to the correct patch
- Small tweaks toKconfigtexts
- Series rebased to resolve conflict (in the selftest list)Ilpo Järvinen (9):
Documentation PCI: Reformat RMW ops documentation
PCI: Protect Link Control 2 Register with RMW locking
PCI: Store all PCIe Supported Link Speeds
PCI: Refactorpcie_update_link_speed()
PCI/quirks: Abstract LBMS seen check into own function PCI/bwctrl: Re-add BW notification portdrv as PCIe BW controller PCI/bwctrl: Add API to set PCIe Link Speed
thermal: Add PCIe cooling driver selftests/pcie_bwctrl: Create selftestsDocumentation/PCI/pciebus-howto.rst | 14 +- MAINTAINERS | 9 + drivers/pci/hotplug/pciehp_ctrl.c | 5 + drivers/pci/hotplug/pciehp_hpc.c | 2 +- drivers/pci/pci.c | 62 ++- drivers/pci/pci.h | 38 +- drivers/pci/pcie/Makefile | 2 +- drivers/pci/pcie/bwctrl.c | 366 ++++++++++++++++++ drivers/pci/pcie/portdrv.c | 9 +- drivers/pci/pcie/portdrv.h | 6 +- drivers/pci/probe.c | 15 +- drivers/pci/quirks.c | 32 +- drivers/thermal/Kconfig | 9 + drivers/thermal/Makefile | 2 + drivers/thermal/pcie_cooling.c | 80 ++++ include/linux/pci-bwctrl.h | 28 ++ include/linux/pci.h | 24 +- include/uapi/linux/pci_regs.h | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/pcie_bwctrl/Makefile | 2 + .../pcie_bwctrl/set_pcie_cooling_state.sh | 122 ++++++
Quoted 8 lines
.../selftests/pcie_bwctrl/set_pcie_speed.sh | 67 ++++ 22 files changed, 843 insertions(+), 53 deletions(-) create mode 100644 drivers/pci/pcie/bwctrl.c create mode 100644 drivers/thermal/pcie_cooling.c create mode 100644 include/linux/pci-bwctrl.h create mode 100644 tools/testing/selftests/pcie_bwctrl/Makefile create mode 100755 tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh create mode 100755 tools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh
Applied to pci/bwctrl for v6.13, thanks Ilpo (and Alexandru, for the bandwidth notification interrupt support)!
[+cc Bart, Amit, Neil, Caleb]
Quoted 7 lines · Bjorn Helgaas
Quoted 5 lines · Ilpo Järvinen
This series adds PCIe bandwidth controller (bwctrl) and associated PCIe cooling driver to the thermal core side for limiting PCIe Link Speed due to thermal reasons. PCIe bandwidth controller is a PCI express bus port service driver. A cooling device is created for each port the service driver finds to support changing speeds.
Quoted 8 lines
Quoted 5 lines
drivers/pci/pcie/bwctrl.c | 366 ++++++++++++++++++ include/linux/pci-bwctrl.h | 28 ++ tools/testing/selftests/pcie_bwctrl/Makefile | 2 + .../pcie_bwctrl/set_pcie_cooling_state.sh | 122 ++++++ .../selftests/pcie_bwctrl/set_pcie_speed.sh | 67 ++++Applied to pci/bwctrl for v6.13, thanks Ilpo (and Alexandru, for the bandwidth notification interrupt support)!
How attached are we to "bwctrl" and "pwrctl" as the names?
I just noticed that we have "ctrl" for bandwidth control but "ctl" for power control, which is slightly annoying to keep straight.
"ctrl" is more common in the tree:
$ find -name \*ctrl\*[ch] | wc -l 691 $ find -name \*ctl\*[ch] | wc -l 291
so I would prefer that, although "pwrctl" is already in the tree (as of v6.11), so it would be more disruptive to change it than to rename "bwctrl".
Quoted 27 lines · Bjorn Helgaas
[+cc Bart, Amit, Neil, Caleb]
Quoted 7 lines · Bjorn Helgaas
Quoted 5 lines · Ilpo Järvinen
This series adds PCIe bandwidth controller (bwctrl) and associated PCIe cooling driver to the thermal core side for limiting PCIe Link Speed due to thermal reasons. PCIe bandwidth controller is a PCI express bus port service driver. A cooling device is created for each port the service driver finds to support changing speeds.
Quoted 8 lines
Quoted 5 lines
drivers/pci/pcie/bwctrl.c | 366 ++++++++++++++++++ include/linux/pci-bwctrl.h | 28 ++ tools/testing/selftests/pcie_bwctrl/Makefile | 2 + .../pcie_bwctrl/set_pcie_cooling_state.sh | 122 ++++++ .../selftests/pcie_bwctrl/set_pcie_speed.sh | 67 ++++Applied to pci/bwctrl for v6.13, thanks Ilpo (and Alexandru, for the bandwidth notification interrupt support)!
How attached are we to "bwctrl" and "pwrctl" as the names?
I just noticed that we have "ctrl" for bandwidth control but "ctl" for power control, which is slightly annoying to keep straight.
"ctrl" is more common in the tree:
Quoted 8 lines
$ find -name \*ctrl\*[ch] | wc -l 691 $ find -name \*ctl\*[ch] | wc -l 291so I would prefer that, although "pwrctl" is already in the tree (as of v6.11), so it would be more disruptive to change it than to rename "bwctrl".
"pwrctl" is shorter and it was the only reason for me to choose it over pwrctrl.
Bart
Ilpo Järvinen
maintainerQuoted 26 lines · Bjorn Helgaas
[+cc Bart, Amit, Neil, Caleb]
Quoted 7 lines · Bjorn Helgaas
Quoted 5 lines · Ilpo Järvinen
This series adds PCIe bandwidth controller (bwctrl) and associated PCIe cooling driver to the thermal core side for limiting PCIe Link Speed due to thermal reasons. PCIe bandwidth controller is a PCI express bus port service driver. A cooling device is created for each port the service driver finds to support changing speeds.
Quoted 8 lines
Quoted 5 lines
drivers/pci/pcie/bwctrl.c | 366 ++++++++++++++++++ include/linux/pci-bwctrl.h | 28 ++ tools/testing/selftests/pcie_bwctrl/Makefile | 2 + .../pcie_bwctrl/set_pcie_cooling_state.sh | 122 ++++++ .../selftests/pcie_bwctrl/set_pcie_speed.sh | 67 ++++Applied to pci/bwctrl for v6.13, thanks Ilpo (and Alexandru, for the bandwidth notification interrupt support)!
How attached are we to "bwctrl" and "pwrctl" as the names?
I just noticed that we have "ctrl" for bandwidth control but "ctl" for power control, which is slightly annoying to keep straight.
"ctrl" is more common in the tree:
Quoted 8 lines
$ find -name \*ctrl\*[ch] | wc -l 691 $ find -name \*ctl\*[ch] | wc -l 291so I would prefer that, although "pwrctl" is already in the tree (as of v6.11), so it would be more disruptive to change it than to rename "bwctrl".
I personally don't mind what the name is.
However, what I've noted is that visually those two are so similar that my brains will mix them on a glance anyway. Maybe the length difference would help on that confusion too, remains to be seen.
Signature · 1 line
i.
Hello,
[...]
Quoted 7 lines
How attached are we to "bwctrl" and "pwrctl" as the names?
I just noticed that we have "ctrl" for bandwidth control but "ctl" for power control, which is slightly annoying to keep straight.
"ctrl" is more common in the tree:
Quoted 8 lines
$ find -name \*ctrl\*[ch] | wc -l 691 $ find -name \*ctl\*[ch] | wc -l 291so I would prefer that, although "pwrctl" is already in the tree (as of v6.11), so it would be more disruptive to change it than to rename "bwctrl".
If I may, I would also lean towards the "pwrctrl" name. The "ctl" suffix makes me think of a command-line utility, a CLI, so to speak, where such suffix is commonly used e.g., sysctl, etcdctl, kubectl; also, all the systemd binaries, etc.
Krzysztof