platform/x86/amd/hsmp: Unify socket/cpu sysfs
Subsystems (4)
cover platform/x86/amd/hsmp: Unify socket/cpu sysfs
From: Suma Hegde <[email protected]>
This series aligns the ACPI and platform HSMP drivers on a common sysfs layout and reduces duplication.
- Create /sys/devices/platform/amd_hsmp/socket/socketN/ for the platform driver, and matching socketN links from the ACPI path
- Add platform telemetry sysfs, then move shared show handlers into a new sysfs.c used by both drivers
- Expose per-CPU boost_limit under amd_hsmp/cpu/cpuX/
- Gate read and write visibility on separate message IDs
- Add sysfs for additional HSMP control and telemetry messages, and document the shared socket path and the new files
This series applies on top of HSMP client series v8 and a rebase of the HSMP dynamic bitmap series onto client v8. The rebased patch set for dynamic bitmap series has not been posted. Based on the changes in client series, dynamic bitmap series and this series(unify sysfs) will be rebased again and sent.
Suma Hegde (8):
platform/x86/amd/hsmp: Create socket sysfs directory in platform
driver
platform/x86/amd/hsmp: Add amd_hsmp/socket sysfs links for ACPI
devices
platform/x86/amd/hsmp: Rename the HSMP_BIN_ATTR_GRP macro platform/x86/amd/hsmp: plat: Add sysfs files to display HSMP telemetry platform/x86/amd/hsmp: Move common sysfs show handlers to sysfs.c platform/x86/amd/hsmp: Add per-CPU sysfs attributes for ACPI and
platform
platform/x86/amd/hsmp: Add wr_msg_id for sysfs attribute visibility platform/x86/amd/hsmp: Add sysfs support for new HSMP messages
Documentation/arch/x86/amd_hsmp.rst | 33 +- drivers/platform/x86/amd/hsmp/Makefile | 4 +- drivers/platform/x86/amd/hsmp/acpi.c | 331 ++++------- drivers/platform/x86/amd/hsmp/plat.c | 412 ++++++++++++- drivers/platform/x86/amd/hsmp/sysfs.c | 762 +++++++++++++++++++++++++ drivers/platform/x86/amd/hsmp/sysfs.h | 112 ++++ 6 files changed, 1420 insertions(+), 234 deletions(-) create mode 100644 drivers/platform/x86/amd/hsmp/sysfs.c create mode 100644 drivers/platform/x86/amd/hsmp/sysfs.h
Signature · 1 line
2.34.1
PATCH 1/8 platform/x86/amd/hsmp: Create socket sysfs directory in platform driver
From: Suma Hegde <[email protected]>
The platform driver exposes per-socket attributes directly under the amd_hsmp device as socketN/. Attribute groups can only create one subdirectory level under that device, so an intermediate socket/ directory cannot be expressed through dev_groups alone.
Create a socket/ kobject under the amd_hsmp platform device and attach the per-socket attribute groups there, yielding /sys/devices/platform/amd_hsmp/socket/socketN/ as the common layout for both drivers.
--- drivers/platform/x86/amd/hsmp/plat.c | 43 +++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-)
drivers/platform/x86/amd/hsmp/plat.c +42 -1
@@ -42,6 +42,9 @@static struct hsmp_plat_device *hsmp_pdev; +/* Parent for per-socket attribute groups: amd_hsmp/socket/socketN/ */ +static struct kobject *hsmp_sock_kobj; +static int amd_hsmp_pci_rdwr (struct hsmp_socket *sock,u32 offset,u32 *value,bool write) {
@@ -232,9 +235,43 @@ static int init_platform_device(struct device *dev)* the global socket pointer, all before devres frees the array. Registered as * a devres action so it runs on both remove and probe failure. */ + +static int hsmp_create_socket_sysfs (struct device *dev) +{ +int ret; + + hsmp_sock_kobj =kobject_create_and_add ("socket" , &dev->kobj); +if (!hsmp_sock_kobj) { +dev_err (dev,"Failed to create socket kobject\n" ); +return -ENOMEM ; + } + + ret =sysfs_create_groups (hsmp_sock_kobj, hsmp_groups); +if (ret) { +dev_err (dev,"Failed to create socket attribute groups\n" ); +kobject_put (hsmp_sock_kobj); + hsmp_sock_kobj =NULL ; +return ret; + } + +return 0 ; +} + +static void hsmp_destroy_socket_sysfs (void ) +{ +if (!hsmp_sock_kobj) +return ; + +sysfs_remove_groups (hsmp_sock_kobj, hsmp_groups); +kobject_del (hsmp_sock_kobj); +kobject_put (hsmp_sock_kobj); + hsmp_sock_kobj =NULL ; +} +static void hsmp_pltdrv_release (void *data) {guard (rwsem_write)(&hsmp_sock_rwsem); +hsmp_destroy_socket_sysfs ();hsmp_unmap_metric_tbls (hsmp_pdev);hsmp_destroy_metric_read_locks (hsmp_pdev); hsmp_pdev->sock =NULL ;
@@ -271,6 +308,10 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev)return ret; } + ret =hsmp_create_socket_sysfs (&pdev->dev); +if (ret) +return ret; + ret =hsmp_misc_register (&pdev->dev);if (ret) {dev_err (&pdev->dev,"Failed to register misc device\n" );
@@ -283,6 +324,7 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev)static void hsmp_pltdrv_remove (struct platform_device *pdev) { +hsmp_destroy_socket_sysfs ();hsmp_misc_deregister (); }
@@ -291,7 +333,6 @@ static struct platform_driver amd_hsmp_driver = { .remove = hsmp_pltdrv_remove, .driver = { .name = DRIVER_NAME, - .dev_groups = hsmp_groups, }, };
Signature · 1 line
2.34.1
PATCH 2/8 platform/x86/amd/hsmp: Add amd_hsmp/socket sysfs links for ACPI devices
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
The platform driver now exposes per-socket attributes at /sys/devices/platform/amd_hsmp/socket/socketN/, while the ACPI driver registers each socket as AMDI0097:0X under /sys/devices/platform/. Userspace still has to know which driver probed to find the attributes.
Create /sys/devices/platform/amd_hsmp/socket/ in the ACPI driver and, for each socket, add a socketN symlink to the corresponding AMDI0097:0X device so both drivers share the same amd_hsmp/socket/ path.
--- drivers/platform/x86/amd/hsmp/acpi.c | 48 +++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-)
drivers/platform/x86/amd/hsmp/acpi.c +47 -1
@@ -45,6 +45,9 @@static struct hsmp_plat_device *hsmp_pdev; +static struct kobject *amd_hsmp_kobj; +static struct kobject *hsmp_sock_kobj; +/* * Tracks the ACPI socket platform devices that share the socket array and the * /dev/hsmp misc device. The first probe initializes it, each further probe
@@ -661,11 +664,34 @@ static int init_acpi(struct device *dev)dev_info (dev,"Failed to register HSMP sensors with hwmon\n" ); } +if (hsmp_sock_kobj) { +snprintf (sock->name,sizeof (sock->name),"socket%u" , sock->sock_ind); + ret =sysfs_create_link (hsmp_sock_kobj, &dev->kobj, sock->name); +if (ret) +dev_warn (dev, +"Failed to create symlink for %s\n" , sock->name); + } +dev_set_drvdata (dev, sock);return 0 ; } +static void hsmp_create_sysfs_kobjects (struct device *dev) +{ +/* Create amd_hsmp directory under /sys/devices/platform/ */ + amd_hsmp_kobj =kobject_create_and_add ("amd_hsmp" , + &platform_bus.kobj); +if (!amd_hsmp_kobj) { +dev_err (dev,"Failed to create amd_hsmp kobject\n" ); +return ; + } + + hsmp_sock_kobj =kobject_create_and_add ("socket" , amd_hsmp_kobj); +if (!hsmp_sock_kobj) +dev_warn (dev,"Failed to create socket kobject\n" ); +} +static const struct bin_attribute hsmp_metric_tbl_attr = { .attr = { .name =HSMP_METRICS_TABLE_NAME , .mode =0444 }, .read = hsmp_metric_tbl_acpi_read,
@@ -754,6 +780,16 @@ static void hsmp_acpi_sock_release(struct kref *kref)hsmp_misc_deregister ();hsmp_unmap_metric_tbls (hsmp_pdev);hsmp_destroy_metric_read_locks (hsmp_pdev); +if (hsmp_sock_kobj) { +kobject_del (hsmp_sock_kobj); +kobject_put (hsmp_sock_kobj); + hsmp_sock_kobj =NULL ; + } +if (amd_hsmp_kobj) { +kobject_del (amd_hsmp_kobj); +kobject_put (amd_hsmp_kobj); + amd_hsmp_kobj =NULL ; + }kfree (hsmp_pdev->sock); hsmp_pdev->sock =NULL ; hsmp_pdev->num_sockets =0 ;
@@ -783,9 +819,14 @@ static void hsmp_acpi_probe_failure_cleanup(struct device *dev)lockdep_assert_held_write (&hsmp_sock_rwsem); -if (sock) +if (sock) { sock->dev =NULL ; +/* Remove per-socket symlink from amd_hsmp/socket/ */ +if (hsmp_sock_kobj) +sysfs_remove_link (hsmp_sock_kobj, sock->name); + } +kref_put (&hsmp_acpi_sock_kref, hsmp_acpi_sock_release); }
@@ -820,6 +861,7 @@ static int hsmp_acpi_probe(struct platform_device *pdev)return -ENOMEM ;hsmp_init_metric_read_locks (hsmp_pdev); +hsmp_create_sysfs_kobjects (&pdev->dev);kref_init (&hsmp_acpi_sock_kref); }else {kref_get (&hsmp_acpi_sock_kref);
@@ -878,6 +920,10 @@ static void hsmp_acpi_remove(struct platform_device *pdev)*/ sock->dev =NULL ; +/* Remove per-socket symlink from amd_hsmp/socket/ */ +if (sock && hsmp_sock_kobj) +sysfs_remove_link (hsmp_sock_kobj, sock->name); +kref_put (&hsmp_acpi_sock_kref, hsmp_acpi_sock_release); }
Signature · 1 line
2.34.1
PATCH 3/8 platform/x86/amd/hsmp: Rename the HSMP_BIN_ATTR_GRP macro
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
Rename HSMP_BIN_ATTR_GRP to HSMP_ATTR_GRP so the same helper can describe attribute groups that carry both binary and regular attributes.
--- drivers/platform/x86/amd/hsmp/plat.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/platform/x86/amd/hsmp/plat.c +9 -9
@@ -120,21 +120,21 @@ HSMP_BIN_ATTR(5, *sock5_attr_list);HSMP_BIN_ATTR (6 , *sock6_attr_list);HSMP_BIN_ATTR (7 , *sock7_attr_list); -#define HSMP_BIN_ATTR_GRP (index, _list, _name) \ +#define HSMP_ATTR_GRP (index, _list, _name) \ static const struct attribute_group sock##index##_attr_grp = { \ .bin_attrs = _list, \ .is_bin_visible = hsmp_is_sock_attr_visible, \ .name = #_name, \ } -HSMP_BIN_ATTR_GRP (0 , sock0_attr_list, socket0); -HSMP_BIN_ATTR_GRP (1 , sock1_attr_list, socket1); -HSMP_BIN_ATTR_GRP (2 , sock2_attr_list, socket2); -HSMP_BIN_ATTR_GRP (3 , sock3_attr_list, socket3); -HSMP_BIN_ATTR_GRP (4 , sock4_attr_list, socket4); -HSMP_BIN_ATTR_GRP (5 , sock5_attr_list, socket5); -HSMP_BIN_ATTR_GRP (6 , sock6_attr_list, socket6); -HSMP_BIN_ATTR_GRP (7 , sock7_attr_list, socket7); +HSMP_ATTR_GRP (0 , sock0_attr_list, socket0); +HSMP_ATTR_GRP (1 , sock1_attr_list, socket1); +HSMP_ATTR_GRP (2 , sock2_attr_list, socket2); +HSMP_ATTR_GRP (3 , sock3_attr_list, socket3); +HSMP_ATTR_GRP (4 , sock4_attr_list, socket4); +HSMP_ATTR_GRP (5 , sock5_attr_list, socket5); +HSMP_ATTR_GRP (6 , sock6_attr_list, socket6); +HSMP_ATTR_GRP (7 , sock7_attr_list, socket7);static const struct attribute_group *hsmp_groups[] = { &sock0_attr_grp,
Signature · 1 line
2.34.1
PATCH 4/8 platform/x86/amd/hsmp: plat: Add sysfs files to display HSMP telemetry
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
Move common sysfs definitions (struct hsmp_sys_attr, GENMASK masks, freqlimit_srcnames, to_hsmp_sys_attr macro) to a new shared header sysfs.h.
Add sysfs telemetry show functions and per-socket device attribute groups to the platform driver (plat.c), mirroring the existing ACPI driver functionality.
Update documentation to reflect sysfs file availability for both ACPI and platform device based drivers.
--- Documentation/arch/x86/amd_hsmp.rst | 4 +- drivers/platform/x86/amd/hsmp/acpi.c | 36 +-- drivers/platform/x86/amd/hsmp/plat.c | 421 +++++++++++++++++++++++++- drivers/platform/x86/amd/hsmp/sysfs.h | 49 +++ 4 files changed, 469 insertions(+), 41 deletions(-) create mode 100644 drivers/platform/x86/amd/hsmp/sysfs.h
Documentation/arch/x86/amd_hsmp.rst +3 -1
@@ -88,7 +88,9 @@ The same is defined in the amd_hsmp.h header. 2. HSMP telemetry sysfs files -Following sysfs files are available at /sys/devices/platform/AMDI0097:0X/. +Following sysfs files are available at /sys/devices/platform/AMDI0097:0X/ for +ACPI based driver and /sys/devices/platform/amd_hsmp/socketX/ for platform +device based driver. * c0_residency_input: Percentage of cores in C0 state. * prochot_status: Reports 1 if the processor is at thermal threshold value,
drivers/platform/x86/amd/hsmp/acpi.c +5 -31
@@ -22,6 +22,7 @@#include <linux/ioport.h> #include <linux/kref.h> #include <linux/kstrtox.h> +#include <linux/limits.h> #include <linux/lockdep.h> #include <linux/module.h> #include <linux/platform_device.h>
@@ -35,6 +36,7 @@#include <uapi/asm-generic/errno-base.h> #include "hsmp.h" +#include "sysfs.h" #define DRIVER_NAME "hsmp_acpi"
@@ -59,11 +61,6 @@ static struct kobject *hsmp_sock_kobj;*/ static struct kref hsmp_acpi_sock_kref; -struct hsmp_sys_attr { -struct device_attribute dattr; -u32 msg_id; -}; -static int amd_hsmp_acpi_rdwr (struct hsmp_socket *sock,u32 offset,u32 *value,bool write) {
@@ -296,8 +293,6 @@ static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobjreturn hsmp_metric_tbl_read (sock, buf, count); } -#define to_hsmp_sys_attr (_attr) container_of(_attr, struct hsmp_sys_attr, dattr) -static umode_t hsmp_is_sock_attr_visible (struct kobject *kobj,const struct bin_attribute *battr,int id) {
@@ -398,17 +393,6 @@ static ssize_t hsmp_msg_resp32_show(struct device *dev, struct device_attributereturn sysfs_emit (buf,"%u\n" , data); } -#define DDR_MAX_BW_MASK GENMASK(31, 20) -#define DDR_UTIL_BW_MASK GENMASK(19, 8) -#define DDR_UTIL_BW_PERC_MASK GENMASK(7, 0) -#define FW_VER_MAJOR_MASK GENMASK(23, 16) -#define FW_VER_MINOR_MASK GENMASK(15, 8) -#define FW_VER_DEBUG_MASK GENMASK(7, 0) -#define FMAX_MASK GENMASK(31, 16) -#define FMIN_MASK GENMASK(15, 0) -#define FREQ_LIMIT_MASK GENMASK(31, 16) -#define FREQ_SRC_IND_MASK GENMASK(15, 0) -static ssize_t hsmp_ddr_max_bw_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -473,7 +457,7 @@ static ssize_t hsmp_msg_fw_ver_show(struct device *dev, struct device_attribute }static ssize_t hsmp_fclk_show (struct device *dev,struct device_attribute *attr, -char *buf) +char *buf) {struct hsmp_sys_attr *hattr =to_hsmp_sys_attr (attr);struct hsmp_socket *sock =dev_get_drvdata (dev);
@@ -488,7 +472,7 @@ static ssize_t hsmp_fclk_show(struct device *dev, struct device_attribute *attr, }static ssize_t hsmp_mclk_show (struct device *dev,struct device_attribute *attr, -char *buf) +char *buf) {struct hsmp_sys_attr *hattr =to_hsmp_sys_attr (attr);struct hsmp_socket *sock =dev_get_drvdata (dev);
@@ -547,17 +531,6 @@ static ssize_t hsmp_freq_limit_show(struct device *dev, struct device_attributereturn sysfs_emit (buf,"%lu\n" ,FIELD_GET (FREQ_LIMIT_MASK , data)); } -static const char *const freqlimit_srcnames[] = { -"cHTC-Active" , -"PROCHOT" , -"TDC limit" , -"PPT Limit" , -"OPN Max" , -"Reliability Limit" , -"APML Agent" , -"HSMP Agent" , -}; -static ssize_t hsmp_freq_limit_source_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -706,6 +679,7 @@ static const struct bin_attribute *hsmp_attr_list[] = {#define HSMP_DEV_ATTR (_name, _msg_id, _show, _mode) \ static struct hsmp_sys_attr hattr_##_name = { \ .dattr = __ATTR(_name, _mode, _show, NULL), \ + .sock_ind = U16_MAX, \ .msg_id = _msg_id, \ }
drivers/platform/x86/amd/hsmp/plat.c +412 -9
453 lines not on this page · raw message
drivers/platform/x86/amd/hsmp/sysfs.h new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 5/8 platform/x86/amd/hsmp: Move common sysfs show handlers to sysfs.c
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
The ACPI and platform HSMP drivers had duplicated implementations for telemetry sysfs show handlers (DDR BW, firmware version, FCLK/MCLK, freq limits, etc.).
Move these shared handlers into a new common file, sysfs.c, and expose their declarations via sysfs.h. Keep socket selection behavior the same for both paths by using hsmp_sysfs_sock_ind():
- ACPI: derive socket index from dev_get_drvdata() when sock_ind is U16_MAX
- Platform: use per-attribute sock_ind directly
Update the HSMP Makefile to build sysfs.o into both hsmp_acpi and amd_hsmp modules.
No functional change intended.
--- drivers/platform/x86/amd/hsmp/Makefile | 4 +- drivers/platform/x86/amd/hsmp/acpi.c | 181 --------------------- drivers/platform/x86/amd/hsmp/plat.c | 170 -------------------- drivers/platform/x86/amd/hsmp/sysfs.c | 211 +++++++++++++++++++++++++ drivers/platform/x86/amd/hsmp/sysfs.h | 34 ++-- 5 files changed, 236 insertions(+), 364 deletions(-) create mode 100644 drivers/platform/x86/amd/hsmp/sysfs.c
drivers/platform/x86/amd/hsmp/Makefile +2 -2
@@ -8,6 +8,6 @@ obj-$(CONFIG_AMD_HSMP) += hsmp_common.o hsmp_common-y := hsmp.o hsmp_common-$(CONFIG_HWMON) += hwmon.o obj-$(CONFIG_AMD_HSMP_PLAT) += amd_hsmp.o -amd_hsmp-y := plat.o +amd_hsmp-y := plat.o sysfs.o obj-$(CONFIG_AMD_HSMP_ACPI) += hsmp_acpi.o -hsmp_acpi-y := acpi.o +hsmp_acpi-y := acpi.o sysfs.o
drivers/platform/x86/amd/hsmp/acpi.c +0 -181
193 lines not on this page · raw message
drivers/platform/x86/amd/hsmp/plat.c +0 -170
182 lines not on this page · raw message
drivers/platform/x86/amd/hsmp/sysfs.c new file +211 -0
211 lines not on this page · raw message
drivers/platform/x86/amd/hsmp/sysfs.h +23 -11
@@ -21,17 +21,6 @@ struct hsmp_sys_attr {u32 msg_id; }; -static const char *const freqlimit_srcnames[] = { -"cHTC-Active" , -"PROCHOT" , -"TDC limit" , -"PPT Limit" , -"OPN Max" , -"Reliability Limit" , -"APML Agent" , -"HSMP Agent" , -}; -#define DDR_MAX_BW_MASK GENMASK(31, 20)#define DDR_UTIL_BW_MASK GENMASK(19, 8)#define DDR_UTIL_BW_PERC_MASK GENMASK(7, 0)
@@ -46,4 +35,27 @@ static const char * const freqlimit_srcnames[] = {#define to_hsmp_sys_attr (_dev_attr) \ container_of(_dev_attr, struct hsmp_sys_attr, dattr) +ssize_t hsmp_msg_resp32_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_ddr_max_bw_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_ddr_util_bw_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_ddr_util_bw_perc_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_msg_fw_ver_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_fclk_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_mclk_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_clk_fmax_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_clk_fmin_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_freq_limit_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_freq_limit_source_show (struct device *dev,struct device_attribute *attr, +char *buf); +#endif /* HSMP_SYSFS_H */
Signature · 1 line
2.34.1
PATCH 6/8 platform/x86/amd/hsmp: Add per-CPU sysfs attributes for ACPI and platform
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
Expose per-CPU boost_limit under /sys/devices/platform/amd_hsmp/cpu/cpuX/ from both the ACPI and platform drivers so userspace does not depend on which driver probed.
Create a cpu/ kobject hierarchy with per-CPU entries that map to HSMP_GET_BOOST_LIMIT / HSMP_SET_BOOST_LIMIT. Keep the shared boost_limit handlers, cpu_kobj_info tracking, and create/remove helpers in sysfs.c; each driver still owns the parent cpu/ kobject lifetime.
--- Documentation/arch/x86/amd_hsmp.rst | 9 ++ drivers/platform/x86/amd/hsmp/acpi.c | 17 +++ drivers/platform/x86/amd/hsmp/plat.c | 44 ++++++ drivers/platform/x86/amd/hsmp/sysfs.c | 185 ++++++++++++++++++++++++++ drivers/platform/x86/amd/hsmp/sysfs.h | 7 + 5 files changed, 262 insertions(+)
Documentation/arch/x86/amd_hsmp.rst +9 -0
@@ -110,6 +110,15 @@ device based driver. * pwr_current_active_freq_limit_source: Source of current active frequency limit. +3. Per-CPU sysfs files + +Per-CPU attributes are available under +/sys/devices/platform/amd_hsmp/cpu/cpuX/ for both the ACPI and platform +drivers. + +* boost_limit: Get/set the per-CPU boost limit in MHz (HSMP_GET_BOOST_LIMIT / + HSMP_SET_BOOST_LIMIT). Writable range is 100-10000 MHz. + ACPI device object format ========================= The ACPI object format expected from the amd_hsmp driver
drivers/platform/x86/amd/hsmp/acpi.c +17 -0
@@ -47,6 +47,7 @@ static struct hsmp_plat_device *hsmp_pdev;static struct kobject *amd_hsmp_kobj;static struct kobject *hsmp_sock_kobj; +static struct kobject *hsmp_cpu_kobj;/* * Tracks the ACPI socket platform devices that share the socket array and the
@@ -464,6 +465,8 @@ static int init_acpi(struct device *dev) "Failed to create symlink for %s\n", sock->name); } +hsmp_create_per_cpu_kobjects (dev, hsmp_cpu_kobj, sock); +dev_set_drvdata (dev, sock);return 0 ;
@@ -482,6 +485,10 @@ static void hsmp_create_sysfs_kobjects(struct device *dev) hsmp_sock_kobj =kobject_create_and_add ("socket" , amd_hsmp_kobj);if (!hsmp_sock_kobj)dev_warn (dev,"Failed to create socket kobject\n" ); + + hsmp_cpu_kobj =kobject_create_and_add ("cpu" , amd_hsmp_kobj); +if (!hsmp_cpu_kobj) +dev_warn (dev,"Failed to create cpu kobject\n" ); }static const struct bin_attribute hsmp_metric_tbl_attr = {
@@ -578,6 +585,11 @@ static void hsmp_acpi_sock_release(struct kref *kref)kobject_put (hsmp_sock_kobj); hsmp_sock_kobj =NULL ; } +if (hsmp_cpu_kobj) { +kobject_del (hsmp_cpu_kobj); +kobject_put (hsmp_cpu_kobj); + hsmp_cpu_kobj =NULL ; + }if (amd_hsmp_kobj) {kobject_del (amd_hsmp_kobj);kobject_put (amd_hsmp_kobj);
@@ -618,6 +630,9 @@ static void hsmp_acpi_probe_failure_cleanup(struct device *dev)/* Remove per-socket symlink from amd_hsmp/socket/ */ if (hsmp_sock_kobj)sysfs_remove_link (hsmp_sock_kobj, sock->name); + +hsmp_remove_per_cpu_kobjects (sock); +dev_set_drvdata (dev,NULL ); }kref_put (&hsmp_acpi_sock_kref, hsmp_acpi_sock_release);
@@ -717,6 +732,8 @@ static void hsmp_acpi_remove(struct platform_device *pdev)if (sock && hsmp_sock_kobj)sysfs_remove_link (hsmp_sock_kobj, sock->name); +hsmp_remove_per_cpu_kobjects (sock); +kref_put (&hsmp_acpi_sock_kref, hsmp_acpi_sock_release); }
drivers/platform/x86/amd/hsmp/plat.c +44 -0
74 lines not on this page · raw message
drivers/platform/x86/amd/hsmp/sysfs.c +185 -0
200 lines not on this page · raw message
drivers/platform/x86/amd/hsmp/sysfs.h +7 -0
@@ -15,6 +15,9 @@#include <linux/device.h> #include <linux/types.h> +struct hsmp_socket ; +struct kobject ; +struct hsmp_sys_attr {struct device_attribute dattr;u16 sock_ind;
@@ -58,4 +61,8 @@ ssize_t hsmp_freq_limit_show(struct device *dev, struct device_attribute *attr,ssize_t hsmp_freq_limit_source_show (struct device *dev,struct device_attribute *attr,char *buf); +void hsmp_create_per_cpu_kobjects (struct device *dev,struct kobject *cpu_parent, +struct hsmp_socket *sock); +void hsmp_remove_per_cpu_kobjects (struct hsmp_socket *sock); +#endif /* HSMP_SYSFS_H */
Signature · 1 line
2.34.1
PATCH 7/8 platform/x86/amd/hsmp: Add wr_msg_id for sysfs attribute visibility
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
RW sysfs attributes may use different GET and SET message IDs. Add wr_msg_id to hsmp_sys_attr and consult it from the ACPI and platform is_visible helpers when deciding write mode. Add HSMP_DEV_ATTR_W for write-only attributes that only have a store handler.
Share the attribute initializer as HSMP_SYS_ATTR in sysfs.h. The ACPI and platform wrappers still differ in symbol name and socket index.
--- drivers/platform/x86/amd/hsmp/acpi.c | 26 +++++++++------ drivers/platform/x86/amd/hsmp/plat.c | 46 ++++++++++++++++++++++----- drivers/platform/x86/amd/hsmp/sysfs.h | 16 +++++++++- 3 files changed, 69 insertions(+), 19 deletions(-)
drivers/platform/x86/amd/hsmp/acpi.c +16 -10
@@ -351,13 +351,14 @@ static umode_t hsmp_is_sock_dev_attr_visible(struct kobject *kobj, writable = !!(mode &0200 );/* -* File is both readable and writeable. Some platforms support only set/write operation. -* Some platforms support only get/read operation. Update the file mode accordingly. +* File is both readable and writeable. Some platforms support only +* set/write, some only get/read. RW attrs may also use different +* GET/SET message IDs — gate each direction on msg_id / wr_msg_id. */ if (readable && writable) {if (is_read_msg_enabled (sock, hattr->msg_id)) mode_updated |= mode &0444 ; -if (is_write_msg_enabled (sock, hattr->msg_id)) +if (is_write_msg_enabled (sock, hattr->wr_msg_id)) mode_updated |=0200 ;return mode_updated; }
@@ -370,7 +371,7 @@ static umode_t hsmp_is_sock_dev_attr_visible(struct kobject *kobj,/* Write-only attribute */ if (writable) { -if (is_write_msg_enabled (sock, hattr->msg_id)) +if (is_write_msg_enabled (sock, hattr->wr_msg_id))return mode; }
@@ -502,12 +503,17 @@ static const struct bin_attribute *hsmp_attr_list[] = { NULL }; -#define HSMP_DEV_ATTR (_name, _msg_id, _show, _mode) \ -static struct hsmp_sys_attr hattr_##_name = { \ - .dattr = __ATTR(_name, _mode, _show, NULL), \ - .sock_ind = U16_MAX, \ - .msg_id = _msg_id, \ -} +#define HSMP_DEV_ATTR (_name, _msg_id, _show, _mode) \ + HSMP_SYS_ATTR(_name, _name, _mode, _show, NULL, U16_MAX, \ + _msg_id, _msg_id) + +#define HSMP_DEV_ATTR_RW (_name, _rd_msg_id, _wr_msg_id, _show, _store, _mode) \ + HSMP_SYS_ATTR(_name, _name, _mode, _show, _store, U16_MAX, \ + _rd_msg_id, _wr_msg_id) + +#define HSMP_DEV_ATTR_W (_name, _msg_id, _store, _mode) \ + HSMP_SYS_ATTR(_name, _name, _mode, NULL, _store, U16_MAX, \ + _msg_id, _msg_id)HSMP_DEV_ATTR (c0_residency_input,HSMP_GET_C0_PERCENT , hsmp_msg_resp32_show,0444 );HSMP_DEV_ATTR (prochot_status,HSMP_GET_PROC_HOT , hsmp_msg_resp32_show,0444 );
drivers/platform/x86/amd/hsmp/plat.c +38 -8
67 lines not on this page · raw message
drivers/platform/x86/amd/hsmp/sysfs.h +15 -1
@@ -21,7 +21,8 @@ struct kobject;struct hsmp_sys_attr {struct device_attribute dattr;u16 sock_ind; -u32 msg_id; +u32 msg_id;/* message ID used for read / GET enable checks */ +u32 wr_msg_id;/* message ID used for write / SET enable checks */ };#define DDR_MAX_BW_MASK GENMASK(31, 20)
@@ -38,6 +39,19 @@ struct hsmp_sys_attr {#define to_hsmp_sys_attr (_dev_attr) \ container_of(_dev_attr, struct hsmp_sys_attr, dattr) +/* +* Build one hsmp_sys_attr. Callers pick the C symbol (_var) and socket +* index; msg_id is the GET/read id and wr_msg_id is the SET/write id. +*/ +#define HSMP_SYS_ATTR (_var, _name, _mode, _show, _store, _sock_ind, \ + _rd_msg_id, _wr_msg_id) \ +static struct hsmp_sys_attr hattr_##_var = { \ + .dattr = __ATTR(_name, _mode, _show, _store), \ + .sock_ind = _sock_ind, \ + .msg_id = _rd_msg_id, \ + .wr_msg_id = _wr_msg_id, \ +} +ssize_t hsmp_msg_resp32_show (struct device *dev,struct device_attribute *attr,char *buf); ssize_t hsmp_ddr_max_bw_show(struct device *dev, struct device_attribute *attr,
Signature · 1 line
2.34.1
PATCH 8/8 platform/x86/amd/hsmp: Add sysfs support for new HSMP messages
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
Add sysfs attributes and handlers for additional HSMP controls and telemetry, including DFC/PC6/CC6 enable, rail isolation policy, APB disable, socket power limit, socket power, and tdelta.
Expose cclk_boost_limit as a write-only file that sets HSMP_SET_BOOST_LIMIT_SOCKET through HSMP_DEV_ATTR_W.
Document the shared socket path and the new sysfs files.
--- Documentation/arch/x86/amd_hsmp.rst | 26 +- drivers/platform/x86/amd/hsmp/acpi.c | 29 ++ drivers/platform/x86/amd/hsmp/plat.c | 46 +++- drivers/platform/x86/amd/hsmp/sysfs.c | 366 ++++++++++++++++++++++++++ drivers/platform/x86/amd/hsmp/sysfs.h | 30 +++ 5 files changed, 492 insertions(+), 5 deletions(-)
Documentation/arch/x86/amd_hsmp.rst +22 -4
@@ -72,7 +72,7 @@ most of the system management information from SMU in one go. The metrics table is made available as hexadecimal sysfs binary file under per socket sysfs directory created at -/sys/devices/platform/amd_hsmp/socket%d/metrics_bin +/sys/devices/platform/amd_hsmp/socket/socket%d/metrics_bin Note: lseek() is not supported as entire metrics table is read.
@@ -88,9 +88,14 @@ The same is defined in the amd_hsmp.h header. 2. HSMP telemetry sysfs files -Following sysfs files are available at /sys/devices/platform/AMDI0097:0X/ for -ACPI based driver and /sys/devices/platform/amd_hsmp/socketX/ for platform -device based driver. +Both drivers expose the same per-socket files at +/sys/devices/platform/amd_hsmp/socket/socketN/. The ACPI driver also +keeps the files on the AMDI0097:0X device; socketN under amd_hsmp/socket/ +is a symlink to that device. The platform driver creates socketN as a +directory under amd_hsmp/socket/. + +A file that is normally readable and writable is created read-only or +write-only when the platform enables only that direction of the message. * c0_residency_input: Percentage of cores in C0 state. * prochot_status: Reports 1 if the processor is at thermal threshold value,
@@ -109,6 +114,19 @@ device based driver. in MHz. * pwr_current_active_freq_limit_source: Source of current active frequency limit. +* socket_power: Average package power in mWatts (read only). +* socket_power_limit: Current socket power limit in mWatts. Write accepts + 1000-1000000 mWatts. +* socket_power_limit_max: Maximum socket power limit in mWatts (read only). +* cclk_boost_limit: Socket boost limit in MHz (write only). Accepted range + is 100-10000 MHz. +* tdelta: Socket thermal behaviour (read only). +* apb_disable: Read/write. 1 disables APB, 0 enables it. +* dfc_enable: Read/write DF C-state enable. 1 enables, 0 disables. +* pc6_enable: Read/write PC6 enable. 1 enables, 0 disables. +* cc6_enable: Read/write CC6 enable for all cores. 1 enables, 0 disables. +* rail_iso_freq_policy: Read/write CPU rail isolation frequency policy. + 1 enables independent control, 0 disables it. 3. Per-CPU sysfs files
drivers/platform/x86/amd/hsmp/acpi.c +29 -0
@@ -531,6 +531,25 @@ HSMP_DEV_ATTR(pwr_current_active_freq_limit, HSMP_GET_SOCKET_FREQ_LIMIT, hsmp_freq_limit_show, 0444);HSMP_DEV_ATTR (pwr_current_active_freq_limit_source,HSMP_GET_SOCKET_FREQ_LIMIT , hsmp_freq_limit_source_show,0444 ); +HSMP_DEV_ATTR (socket_power,HSMP_GET_SOCKET_POWER , hsmp_msg_resp32_show,0444 ); +HSMP_DEV_ATTR (socket_power_limit_max,HSMP_GET_SOCKET_POWER_LIMIT_MAX , hsmp_msg_resp32_show,0444 ); +HSMP_DEV_ATTR (tdelta,HSMP_READ_TDELTA , hsmp_msg_resp32_show,0444 ); +HSMP_DEV_ATTR_RW (socket_power_limit,HSMP_GET_SOCKET_POWER_LIMIT , +HSMP_SET_SOCKET_POWER_LIMIT , + hsmp_socket_power_limit_show, hsmp_socket_power_limit_store,0644 ); +HSMP_DEV_ATTR_W (cclk_boost_limit,HSMP_SET_BOOST_LIMIT_SOCKET , + hsmp_cclk_boost_limit_store,0200 ); +HSMP_DEV_ATTR_RW (apb_disable,HSMP_SET_DF_PSTATE ,HSMP_SET_DF_PSTATE , + hsmp_apb_disable_show, hsmp_apb_disable_store,0644 ); +HSMP_DEV_ATTR_RW (dfc_enable,HSMP_DFC_ENABLE_CTRL ,HSMP_DFC_ENABLE_CTRL , + hsmp_dfc_enable_show, hsmp_dfc_enable_store,0644 ); +HSMP_DEV_ATTR_RW (pc6_enable,HSMP_PC6_ENABLE ,HSMP_PC6_ENABLE , + hsmp_pc6_enable_show, hsmp_pc6_enable_store,0644 ); +HSMP_DEV_ATTR_RW (cc6_enable,HSMP_CC6_ENABLE ,HSMP_CC6_ENABLE , + hsmp_cc6_enable_show, hsmp_cc6_enable_store,0644 ); +HSMP_DEV_ATTR_RW (rail_iso_freq_policy,HSMP_CPU_RAIL_ISO_FREQ_POLICY , +HSMP_CPU_RAIL_ISO_FREQ_POLICY , + hsmp_rail_iso_freq_policy_show, hsmp_rail_iso_freq_policy_store,0644 );static struct attribute *hsmp_dev_attr_list[] = { &hattr_c0_residency_input.dattr.attr,
@@ -547,6 +566,16 @@ static struct attribute *hsmp_dev_attr_list[] = { &hattr_clk_fmin.dattr.attr, &hattr_pwr_current_active_freq_limit.dattr.attr, &hattr_pwr_current_active_freq_limit_source.dattr.attr, + &hattr_socket_power_limit_max.dattr.attr, + &hattr_socket_power_limit.dattr.attr, + &hattr_socket_power.dattr.attr, + &hattr_cclk_boost_limit.dattr.attr, + &hattr_tdelta.dattr.attr, + &hattr_apb_disable.dattr.attr, + &hattr_cc6_enable.dattr.attr, + &hattr_rail_iso_freq_policy.dattr.attr, + &hattr_pc6_enable.dattr.attr, + &hattr_dfc_enable.dattr.attr,NULL };
drivers/platform/x86/amd/hsmp/plat.c +45 -1
64 lines not on this page · raw message
drivers/platform/x86/amd/hsmp/sysfs.c +366 -0
378 lines not on this page · raw message
drivers/platform/x86/amd/hsmp/sysfs.h +30 -0
@@ -75,6 +75,36 @@ ssize_t hsmp_freq_limit_show(struct device *dev, struct device_attribute *attr,ssize_t hsmp_freq_limit_source_show (struct device *dev,struct device_attribute *attr,char *buf); +ssize_t hsmp_dfc_enable_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_dfc_enable_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count); +ssize_t hsmp_pc6_enable_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_pc6_enable_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count); +ssize_t hsmp_cc6_enable_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_cc6_enable_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count); +ssize_t hsmp_rail_iso_freq_policy_show (struct device *dev, +struct device_attribute *attr,char *buf); +ssize_t hsmp_rail_iso_freq_policy_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); +ssize_t hsmp_cclk_boost_limit_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); +ssize_t hsmp_apb_disable_show (struct device *dev,struct device_attribute *attr, +char *buf); +ssize_t hsmp_apb_disable_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count); +ssize_t hsmp_socket_power_limit_show (struct device *dev, +struct device_attribute *attr,char *buf); +ssize_t hsmp_socket_power_limit_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); +void hsmp_create_per_cpu_kobjects (struct device *dev,struct kobject *cpu_parent,struct hsmp_socket *sock);void hsmp_remove_per_cpu_kobjects (struct hsmp_socket *sock);
Signature · 1 line
2.34.1
Ilpo Järvinen
maintainerQuoted 5 lines · Suma Hegde
From: Suma Hegde <[email protected]>
This series aligns the ACPI and platform HSMP drivers on a common sysfs layout and reduces duplication.
Quoted 8 lines
- Create
/sys/devices/platform/amd_hsmp/socket/socketN/for the platform driver, and matching socketN links from the ACPI path
- Add platform telemetry sysfs, then move shared show handlers into a newsysfs.cused by both drivers
- Expose per-CPUboost_limitunder amd_hsmp/cpu/cpuX/
- Gate read and write visibility on separate message IDs
- Add sysfs for additional HSMP control and telemetry messages, and document the shared socket path and the new files
Hi,
This seems to largely overlap with Erwan's series:
https://lore.kernel.org/platform-driver-x86/[email protected]/
...I don't know what are Erwan's plans as there has not been an update but at least the approach he used in the first patch seems better than yours (I don't know why you didn't put the common code into common?).
Your series didn't even apply cleanup because of the deps so sashiko didn't get to review it at all but it likely finds some of the problem that I got when LLM compared these series, about your series it says:
1. Build failure when both drivers are built in (patch 5). sysfs.o is linked into both the amd_hsmp and hsmp_acpi modules, and its functions are not static. With AMD_HSMP_PLAT=y and AMD_HSMP_ACPI=y (both tristates, so this is allowed) the kernel link should fail with "multiple definition" errors. As modules, it's still a duplicated object. Erwan avoided this by putting sysfs.o in hsmp_common.
2. Mismatched function types (patches 4 and 8). The device-style file handlers (struct device_attribute) are attached to a plain kobject. Plain kobjects call their file handlers through kobj_attr_show()/kobj_attr_store(), which expect struct kobj_attribute handlers. It only works because the two structs happen to have the same layout and the handlers never actually use the dev argument. With kCFI enabled (CONFIG_CFI_CLANG), this indirect call should trip the CFI check.
3. Possible deadlock on removal (patches 1 and 6). Removing sysfs files waits for any reads or writes still running, and those take hsmp_sock_rwsem for read inside hsmp_send_message(). Suma removes files while holding that lock for write:
- in hsmp_pltdrv_release() (the platform probe-failure path);
- more importantly, the hsmp_remove_per_cpu_kobjects() calls in ACPI remove and probe-failure cleanup.
Erwan's patch 2 commit message describes exactly this problem and adds lockdep_assert_not_held() to guard against it. The base tree isn't visible to me, so I'm inferring from the context lines that ACPI remove holds the lock at that point.
4. Breaks an existing path. /sys/devices/platform/amd_hsmp/socketN/metrics_bin is documented, and patch 1 moves it to .../socket/socketN/ without leaving anything at the old location.
5. Plain directories under /sys/devices. This applies to socket/, cpu/, cpuX/, and to the ACPI driver creating its own amd_hsmp directory under platform_bus. They produce no uevents, so udev never sees them, and sysfs maintainers usually reject this. The cpu/cpuX names also look like /sys/devices/system/cpu/cpuX.
6. Per-CPU implementation (patch 6).
- It uses a static cpu_kobj_info[NR_CPUS] table, which is large on big configs and, because of item 1, duplicated in both modules.
- Every read, write and visibility check scans the whole table to find its CPU.
- It loops with for_each_possible_cpu, so CPUs that are possible but not present get entries too, and x86_cpu_to_apicid for those is probably not a valid APIC ID.
- The cpu_id field is never used.
7. Duplicates existing hwmon files (patch 8). socket_power, socket_power_limit and socket_power_limit_max repeat what hwmon.c already exposes as power1_input, power1_cap and power1_cap_max.
8. apb_disable looks wrong (patch 8).
- It reads with "bit 31 = get" and uses bit 8 on HSMP_SET_DF_PSTATE. In the upstream descriptor table that message is SET-only, with one argument and no response.
- Turning APB back on normally goes through HSMP_SET_AUTO_DF_PSTATE.
- With response_sz = 1 the message probably fails the driver's own message-format check.
Unless a newer protocol version redefines this message, it's worth checking against the spec.
9. Minor.
- In patch 4, freqlimit_srcnames is a static array in a header, so every file that includes it gets a copy. Patch 5 fixes this.
- Patch 4's doc says the platform path is amd_hsmp/socketX/, though patch 1 already moved it. Patch 8 fixes this too.
- The value ranges checked on writes (100–10000 MHz, 1–1000 W) are arbitrary.
I haven't spent time on checking each these individually.
Signature · 1 line
i.
Quoted 33 lines
This series applies on top of HSMP client series v8 and a rebase of the HSMP dynamic bitmap series onto client v8. The rebased patch set for dynamic bitmap series has not been posted. Based on the changes in client series, dynamic bitmap series and this series(unify sysfs) will be rebased again and sent.
Signed-off-by Muthusamy Ramalingam <[email protected]>Signed-off-by Suma Hegde <[email protected]>Suma Hegde (8):
platform/x86/amd/hsmp: Create socket sysfs directory in platform
driver
platform/x86/amd/hsmp: Add amd_hsmp/socket sysfs links for ACPI
devices
platform/x86/amd/hsmp: Rename theHSMP_BIN_ATTR_GRPmacro platform/x86/amd/hsmp: plat: Add sysfs files to display HSMP telemetry platform/x86/amd/hsmp: Move common sysfs show handlers tosysfs.cplatform/x86/amd/hsmp: Add per-CPU sysfs attributes for ACPI and
platform
platform/x86/amd/hsmp: Addwr_msg_idfor sysfs attribute visibility platform/x86/amd/hsmp: Add sysfs support for new HSMP messagesDocumentation/arch/x86/amd_hsmp.rst | 33 +- drivers/platform/x86/amd/hsmp/Makefile | 4 +- drivers/platform/x86/amd/hsmp/acpi.c | 331 ++++------- drivers/platform/x86/amd/hsmp/plat.c | 412 ++++++++++++- drivers/platform/x86/amd/hsmp/sysfs.c | 762 +++++++++++++++++++++++++ drivers/platform/x86/amd/hsmp/sysfs.h | 112 ++++ 6 files changed, 1420 insertions(+), 234 deletions(-) create mode 100644 drivers/platform/x86/amd/hsmp/sysfs.c create mode 100644 drivers/platform/x86/amd/hsmp/sysfs.h