<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:15pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
</div>
<div><span style="font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 12pt; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);">Please optimize the
following code together in new generic function.</span><br>
</div>
<div><span style="background-color: rgba(0, 0, 0, 0); color: rgb(50, 49, 48); font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 12pt;"><br>
</span></div>
<div><span style="background-color: rgba(0, 0, 0, 0); color: rgb(50, 49, 48); font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 12pt;">if (pp_funcs && pp_funcs->get_power_limit){}</span><br>
</div>
<div><span style="background-color: rgba(0, 0, 0, 0); color: rgb(50, 49, 48); font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 12pt;">please check above
codes before calling pm_runtime_xxx interfaces to avoid empty operation in pm_runtime cycle.</span></div>
<div><br>
</div>
<div>Reviewed-by: Kevin Wang <kevin1.wang@amd.com></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="margin:0px;font-size:14px;font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif"><br>
</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="margin: 0px; font-size: 12pt; font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);">Best Regards,</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="margin: 0px; font-size: 12pt; font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);">Kevin</span></div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Darren Powell <darren.powell@amd.com><br>
<b>Sent:</b> Tuesday, June 22, 2021 12:17 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Powell, Darren <Darren.Powell@amd.com><br>
<b>Subject:</b> [PATCH 1/1] amdgpu/pm: remove code duplication in show_power_cap calls</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">created generic function and call with enum from<br>
* amdgpu_hwmon_show_power_cap_max<br>
* amdgpu_hwmon_show_power_cap<br>
* amdgpu_hwmon_show_power_cap_default<br>
<br>
=== Test ===<br>
AMDGPU_PCI_ADDR=`lspci -nn | grep "VGA\|Display" | cut -d " " -f 1`<br>
AMDGPU_HWMON=`ls -la /sys/class/hwmon | grep $AMDGPU_PCI_ADDR | cut -d " " -f 10`<br>
HWMON_DIR=/sys/class/hwmon/${AMDGPU_HWMON}<br>
<br>
cp pp_show_power_cap.txt{,.old}<br>
lspci -nn | grep "VGA\|Display" > pp_show_power_cap.test.log<br>
FILES="<br>
power1_cap<br>
power1_cap_max<br>
power1_cap_default "<br>
<br>
for f in $FILES<br>
do<br>
echo $f = `cat $HWMON_DIR/$f` >> pp_show_power_cap.test.log<br>
done<br>
<br>
Signed-off-by: Darren Powell <darren.powell@amd.com><br>
---<br>
drivers/gpu/drm/amd/pm/amdgpu_pm.c | 86 +++++-------------------------<br>
1 file changed, 14 insertions(+), 72 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
index b2335a1d3f98..99c21d1a2c4e 100644<br>
--- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
+++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
@@ -2901,14 +2901,14 @@ static ssize_t amdgpu_hwmon_show_power_cap_min(struct device *dev,<br>
return sprintf(buf, "%i\n", 0);<br>
}<br>
<br>
-static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,<br>
- struct device_attribute *attr,<br>
- char *buf)<br>
+static ssize_t amdgpu_hwmon_show_power_cap_generic(struct device *dev,<br>
+ struct device_attribute *attr,<br>
+ char *buf,<br>
+ enum pp_power_limit_level pp_limit_level)<br>
{<br>
struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;<br>
enum pp_power_type power_type = to_sensor_dev_attr(attr)->index;<br>
- enum pp_power_limit_level pp_limit_level = PP_PWR_LIMIT_MAX;<br>
uint32_t limit;<br>
ssize_t size;<br>
int r;<br>
@@ -2941,85 +2941,27 @@ static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,<br>
return size;<br>
}<br>
<br>
-static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,<br>
+static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,<br>
struct device_attribute *attr,<br>
char *buf)<br>
{<br>
- struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
- const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;<br>
- enum pp_power_type power_type = to_sensor_dev_attr(attr)->index;<br>
- enum pp_power_limit_level pp_limit_level = PP_PWR_LIMIT_CURRENT;<br>
- uint32_t limit;<br>
- ssize_t size;<br>
- int r;<br>
-<br>
- if (amdgpu_in_reset(adev))<br>
- return -EPERM;<br>
- if (adev->in_suspend && !adev->in_runpm)<br>
- return -EPERM;<br>
-<br>
- r = pm_runtime_get_sync(adev_to_drm(adev)->dev);<br>
- if (r < 0) {<br>
- pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
- return r;<br>
- }<br>
-<br>
- if (pp_funcs && pp_funcs->get_power_limit)<br>
- r = pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit,<br>
- pp_limit_level, power_type);<br>
- else<br>
- r = -ENODATA;<br>
-<br>
- if (!r)<br>
- size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
- else<br>
- size = snprintf(buf, PAGE_SIZE, "\n");<br>
-<br>
- pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
- pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
+ return amdgpu_hwmon_show_power_cap_generic(dev, attr, buf, PP_PWR_LIMIT_MAX);<br>
+}<br>
<br>
- return size;<br>
+static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,<br>
+ struct device_attribute *attr,<br>
+ char *buf)<br>
+{<br>
+ return amdgpu_hwmon_show_power_cap_generic(dev, attr, buf, PP_PWR_LIMIT_CURRENT);<br>
}<br>
<br>
static ssize_t amdgpu_hwmon_show_power_cap_default(struct device *dev,<br>
struct device_attribute *attr,<br>
char *buf)<br>
{<br>
- struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
- const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;<br>
- enum pp_power_type power_type = to_sensor_dev_attr(attr)->index;<br>
- enum pp_power_limit_level pp_limit_level = PP_PWR_LIMIT_DEFAULT;<br>
- uint32_t limit;<br>
- ssize_t size;<br>
- int r;<br>
-<br>
- if (amdgpu_in_reset(adev))<br>
- return -EPERM;<br>
- if (adev->in_suspend && !adev->in_runpm)<br>
- return -EPERM;<br>
-<br>
- r = pm_runtime_get_sync(adev_to_drm(adev)->dev);<br>
- if (r < 0) {<br>
- pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
- return r;<br>
- }<br>
-<br>
- if (pp_funcs && pp_funcs->get_power_limit)<br>
- r = pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit,<br>
- pp_limit_level, power_type);<br>
- else<br>
- r = -ENODATA;<br>
-<br>
- if (!r)<br>
- size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
- else<br>
- size = snprintf(buf, PAGE_SIZE, "\n");<br>
-<br>
- pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
- pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
-<br>
- return size;<br>
+ return amdgpu_hwmon_show_power_cap_generic(dev, attr, buf, PP_PWR_LIMIT_DEFAULT);<br>
}<br>
+<br>
static ssize_t amdgpu_hwmon_show_power_label(struct device *dev,<br>
struct device_attribute *attr,<br>
char *buf)<br>
<br>
base-commit: 1971ad5abcd8575efd12d2e6639fd8f58210a8d8<br>
-- <br>
2.31.1<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7CKevin1.Wang%40amd.com%7C502816aea3734f79bf5208d93534af53%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637599322688052639%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=FnBkxT957mNoTpd3jnEHBYQZV3ImGOfmy3K0ToGKNII%3D&reserved=0">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7CKevin1.Wang%40amd.com%7C502816aea3734f79bf5208d93534af53%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637599322688052639%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=FnBkxT957mNoTpd3jnEHBYQZV3ImGOfmy3K0ToGKNII%3D&reserved=0</a><br>
</div>
</span></font></div>
</div>
</body>
</html>