Message ID | 20240910090951.332773-1-kobayashi.da-06@fujitsu.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [v3] Export PBEC Data register into sysfs | expand |
Hi Kobayashi,Daisuke, 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.11-rc7 next-20240910] [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/Kobayashi-Daisuke/Export-PBEC-Data-register-into-sysfs/20240910-170834 base: https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next patch link: https://lore.kernel.org/r/20240910090951.332773-1-kobayashi.da-06%40fujitsu.com patch subject: [PATCH v3] Export PBEC Data register into sysfs config: arm-randconfig-002-20240911 (https://download.01.org/0day-ci/archive/20240911/202409110845.zaUjhBmy-lkp@intel.com/config) compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project bf684034844c660b778f0eba103582f582b710c9) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240911/202409110845.zaUjhBmy-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/202409110845.zaUjhBmy-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from drivers/pci/pci-sysfs.c:18: In file included from include/linux/pci.h:1646: In file included from include/linux/dmapool.h:14: In file included from include/linux/scatterlist.h:8: In file included from include/linux/mm.h:2228: include/linux/vmstat.h:514:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion] 514 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_" | ~~~~~~~~~~~ ^ ~~~ >> drivers/pci/pci-sysfs.c:663:3: error: use of undeclared identifier 'dev_attr_pbec'; did you mean 'dev_attr_irq'? 663 | &dev_attr_pbec.attr, | ^~~~~~~~~~~~~ | dev_attr_irq drivers/pci/pci-sysfs.c:76:8: note: 'dev_attr_irq' declared here 76 | static DEVICE_ATTR_RO(irq); | ^ include/linux/device.h:199:26: note: expanded from macro 'DEVICE_ATTR_RO' 199 | struct device_attribute dev_attr_##_name = __ATTR_RO(_name) | ^ <scratch space>:58:1: note: expanded from here 58 | dev_attr_irq | ^ 1 warning and 1 error generated. vim +663 drivers/pci/pci-sysfs.c 657 658 static struct attribute *pcie_dev_attrs[] = { 659 &dev_attr_current_link_speed.attr, 660 &dev_attr_current_link_width.attr, 661 &dev_attr_max_link_width.attr, 662 &dev_attr_max_link_speed.attr, > 663 &dev_attr_pbec.attr, 664 NULL, 665 }; 666
diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci index ecf47559f495..be1911d948ef 100644 --- a/Documentation/ABI/testing/sysfs-bus-pci +++ b/Documentation/ABI/testing/sysfs-bus-pci @@ -500,3 +500,20 @@ Description: console drivers from the device. Raw users of pci-sysfs resourceN attributes must be terminated prior to resizing. Success of the resizing operation is not guaranteed. + +What: /sys/bus/pci/devices/.../power_budget +Date: September 2024 +Contact: Kobayashi Daisuke <kobayashi.da-06@fujitsu.com> +Description: + This file provides information about the PCIe power budget + for the device. It is a read-only file that outputs the values + of the Power Budgeting Data Register for each power state as a + series of 32-bit hexadecimal values. Each line represents a + single Power Budgeting Data register entry, containing the + power budget for a specific power state. + + The specific interpretation of these values depends on the + device and the PCIe specification. Refer to the PCIe + specification for detailed information about the Power + Budgeting Data register, including the encoding of power + states and the interpretation of Base Power and Data Scale. diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 2321fdfefd7d..468c929a9347 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -182,6 +182,33 @@ static ssize_t resource_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(resource); +static ssize_t power_budget_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct pci_dev *pci_dev = to_pci_dev(dev); + size_t len = 0; + int i, pos; + u32 data; + + pos = pci_find_ext_capability(pci_dev, PCI_EXT_CAP_ID_PWR); + if (!pos) + return -EINVAL; + + for (i = 0; i < 0xff; i++) { + pci_write_config_byte(pci_dev, pos + PCI_PWR_DSR, (u8)i); + pci_read_config_dword(pci_dev, pos + PCI_PWR_DATA, &data); + if (!data) { + if (len == 0) + return -EINVAL; + break; + } + len += sysfs_emit_at(buf, len, "%04x\n", data); + } + + return len; +} +static DEVICE_ATTR_RO(power_budget); + static ssize_t max_link_speed_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -629,6 +656,7 @@ static struct attribute *pcie_dev_attrs[] = { &dev_attr_current_link_width.attr, &dev_attr_max_link_width.attr, &dev_attr_max_link_speed.attr, + &dev_attr_pbec.attr, NULL, };
This proposal aims to add a feature that outputs PCIe device power consumption information to sysfs. Add support for PBEC (Power Budgeting Extended Capability) output to the PCIe driver. PBEC is defined in the PCIe specification(PCIe r6.0, sec 7.8.1) and is a standard method for obtaining device power consumption information. PCIe devices can significantly impact the overall power consumption of a system. However, obtaining PCIe device power consumption information has traditionally been difficult. The PBEC Data register changes depending on the value of the PBEC Data Select register. To obtain all PBEC Data register values defined in the device, obtain the value of the PBEC Data register while changing the value of the PBEC Data Select register. Signed-off-by: "Kobayashi,Daisuke" <kobayashi.da-06@fujitsu.com> --- Documentation/ABI/testing/sysfs-bus-pci | 17 +++++++++++++++ drivers/pci/pci-sysfs.c | 28 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+)