@@ -2081,15 +2081,25 @@ static int pp_dpm_clk_default_attr_update(struct amdgpu_device *adev, struct amd
20812081 * for user application to monitor various board reated attributes.
20822082 *
20832083 * The amdgpu driver provides a sysfs API for reporting board attributes. Presently,
2084- * only two types of attributes are reported, baseboard temperature and
2085- * gpu board temperature. Both of them are reported as binary files.
2084+ * seven types of attributes are reported. Baseboard temperature and
2085+ * gpu board temperature are reported as binary files. Npm status, current node power limit,
2086+ * max node power limit, node power and global ppt residency is reported as ASCII text file.
20862087 *
20872088 * * .. code-block:: console
20882089 *
20892090 * hexdump /sys/bus/pci/devices/.../board/baseboard_temp
20902091 *
20912092 * hexdump /sys/bus/pci/devices/.../board/gpuboard_temp
20922093 *
2094+ * hexdump /sys/bus/pci/devices/.../board/npm_status
2095+ *
2096+ * hexdump /sys/bus/pci/devices/.../board/cur_node_power_limit
2097+ *
2098+ * hexdump /sys/bus/pci/devices/.../board/max_node_power_limit
2099+ *
2100+ * hexdump /sys/bus/pci/devices/.../board/node_power
2101+ *
2102+ * hexdump /sys/bus/pci/devices/.../board/global_ppt_resid
20932103 */
20942104
20952105/**
@@ -2168,8 +2178,129 @@ static ssize_t amdgpu_get_gpuboard_temp_metrics(struct device *dev,
21682178 return size ;
21692179}
21702180
2181+ /**
2182+ * DOC: cur_node_power_limit
2183+ *
2184+ * The amdgpu driver provides a sysfs API for retrieving current node power limit.
2185+ * The file cur_node_power_limit is used for this.
2186+ */
2187+ static ssize_t amdgpu_show_cur_node_power_limit (struct device * dev ,
2188+ struct device_attribute * attr , char * buf )
2189+ {
2190+ struct drm_device * ddev = dev_get_drvdata (dev );
2191+ struct amdgpu_device * adev = drm_to_adev (ddev );
2192+ u32 nplimit ;
2193+ int r ;
2194+
2195+ /* get the current node power limit */
2196+ r = amdgpu_pm_get_sensor_generic (adev , AMDGPU_PP_SENSOR_NODEPOWERLIMIT ,
2197+ (void * )& nplimit );
2198+ if (r )
2199+ return r ;
2200+
2201+ return sysfs_emit (buf , "%u\n" , nplimit );
2202+ }
2203+
2204+ /**
2205+ * DOC: node_power
2206+ *
2207+ * The amdgpu driver provides a sysfs API for retrieving current node power.
2208+ * The file node_power is used for this.
2209+ */
2210+ static ssize_t amdgpu_show_node_power (struct device * dev ,
2211+ struct device_attribute * attr , char * buf )
2212+ {
2213+ struct drm_device * ddev = dev_get_drvdata (dev );
2214+ struct amdgpu_device * adev = drm_to_adev (ddev );
2215+ u32 npower ;
2216+ int r ;
2217+
2218+ /* get the node power */
2219+ r = amdgpu_pm_get_sensor_generic (adev , AMDGPU_PP_SENSOR_NODEPOWER ,
2220+ (void * )& npower );
2221+ if (r )
2222+ return r ;
2223+
2224+ return sysfs_emit (buf , "%u\n" , npower );
2225+ }
2226+
2227+ /**
2228+ * DOC: npm_status
2229+ *
2230+ * The amdgpu driver provides a sysfs API for retrieving current node power management status.
2231+ * The file npm_status is used for this. It shows the status as enabled or disabled based on
2232+ * current node power value. If node power is zero, status is disabled else enabled.
2233+ */
2234+ static ssize_t amdgpu_show_npm_status (struct device * dev ,
2235+ struct device_attribute * attr , char * buf )
2236+ {
2237+ struct drm_device * ddev = dev_get_drvdata (dev );
2238+ struct amdgpu_device * adev = drm_to_adev (ddev );
2239+ u32 npower ;
2240+ int r ;
2241+
2242+ /* get the node power */
2243+ r = amdgpu_pm_get_sensor_generic (adev , AMDGPU_PP_SENSOR_NODEPOWER ,
2244+ (void * )& npower );
2245+ if (r )
2246+ return r ;
2247+
2248+ return sysfs_emit (buf , "%s\n" , npower ? "enabled" : "disabled" );
2249+ }
2250+
2251+ /**
2252+ * DOC: global_ppt_resid
2253+ *
2254+ * The amdgpu driver provides a sysfs API for retrieving global ppt residency.
2255+ * The file global_ppt_resid is used for this.
2256+ */
2257+ static ssize_t amdgpu_show_global_ppt_resid (struct device * dev ,
2258+ struct device_attribute * attr , char * buf )
2259+ {
2260+ struct drm_device * ddev = dev_get_drvdata (dev );
2261+ struct amdgpu_device * adev = drm_to_adev (ddev );
2262+ u32 gpptresid ;
2263+ int r ;
2264+
2265+ /* get the global ppt residency */
2266+ r = amdgpu_pm_get_sensor_generic (adev , AMDGPU_PP_SENSOR_GPPTRESIDENCY ,
2267+ (void * )& gpptresid );
2268+ if (r )
2269+ return r ;
2270+
2271+ return sysfs_emit (buf , "%u\n" , gpptresid );
2272+ }
2273+
2274+ /**
2275+ * DOC: max_node_power_limit
2276+ *
2277+ * The amdgpu driver provides a sysfs API for retrieving maximum node power limit.
2278+ * The file max_node_power_limit is used for this.
2279+ */
2280+ static ssize_t amdgpu_show_max_node_power_limit (struct device * dev ,
2281+ struct device_attribute * attr , char * buf )
2282+ {
2283+ struct drm_device * ddev = dev_get_drvdata (dev );
2284+ struct amdgpu_device * adev = drm_to_adev (ddev );
2285+ u32 max_nplimit ;
2286+ int r ;
2287+
2288+ /* get the max node power limit */
2289+ r = amdgpu_pm_get_sensor_generic (adev , AMDGPU_PP_SENSOR_MAXNODEPOWERLIMIT ,
2290+ (void * )& max_nplimit );
2291+ if (r )
2292+ return r ;
2293+
2294+ return sysfs_emit (buf , "%u\n" , max_nplimit );
2295+ }
2296+
21712297static DEVICE_ATTR (baseboard_temp , 0444 , amdgpu_get_baseboard_temp_metrics , NULL) ;
21722298static DEVICE_ATTR (gpuboard_temp , 0444 , amdgpu_get_gpuboard_temp_metrics , NULL) ;
2299+ static DEVICE_ATTR (cur_node_power_limit , 0444 , amdgpu_show_cur_node_power_limit , NULL) ;
2300+ static DEVICE_ATTR (node_power , 0444 , amdgpu_show_node_power , NULL) ;
2301+ static DEVICE_ATTR (global_ppt_resid , 0444 , amdgpu_show_global_ppt_resid , NULL) ;
2302+ static DEVICE_ATTR (max_node_power_limit , 0444 , amdgpu_show_max_node_power_limit , NULL) ;
2303+ static DEVICE_ATTR (npm_status , 0444 , amdgpu_show_npm_status , NULL) ;
21732304
21742305static struct attribute * board_attrs [] = {
21752306 & dev_attr_baseboard_temp .attr ,
@@ -4534,6 +4665,7 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
45344665{
45354666 enum amdgpu_sriov_vf_mode mode ;
45364667 uint32_t mask = 0 ;
4668+ uint32_t tmp ;
45374669 int ret ;
45384670
45394671 if (adev -> pm .sysfs_initialized )
@@ -4600,6 +4732,21 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
46004732 & amdgpu_board_attr_group );
46014733 if (ret )
46024734 goto err_out0 ;
4735+ if (amdgpu_pm_get_sensor_generic (adev , AMDGPU_PP_SENSOR_MAXNODEPOWERLIMIT ,
4736+ (void * )& tmp ) != - EOPNOTSUPP ) {
4737+ sysfs_add_file_to_group (& adev -> dev -> kobj ,
4738+ & dev_attr_cur_node_power_limit .attr ,
4739+ amdgpu_board_attr_group .name );
4740+ sysfs_add_file_to_group (& adev -> dev -> kobj , & dev_attr_node_power .attr ,
4741+ amdgpu_board_attr_group .name );
4742+ sysfs_add_file_to_group (& adev -> dev -> kobj , & dev_attr_global_ppt_resid .attr ,
4743+ amdgpu_board_attr_group .name );
4744+ sysfs_add_file_to_group (& adev -> dev -> kobj ,
4745+ & dev_attr_max_node_power_limit .attr ,
4746+ amdgpu_board_attr_group .name );
4747+ sysfs_add_file_to_group (& adev -> dev -> kobj , & dev_attr_npm_status .attr ,
4748+ amdgpu_board_attr_group .name );
4749+ }
46034750 }
46044751
46054752 adev -> pm .sysfs_initialized = true;
0 commit comments