Skip to contentSkip to conversation

cpupower: fix amd cpu (family >= 0x17) active state issue

PATCH Superseded xufuhai 2 participants 3 messages Mar 24, 2021 – Mar 29, 2021 CPU power monitoring

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

xufuhai

author
#0 lore raw

PATCH 2/2 cpupower: fix amd cpu (family >= 0x17) active state issue

From: xufuhai <[email protected]>

If the read_msr function is executed by a non-root user, the function returns -1, which means that there is no permission to access /dev/cpu/%d/msr, but cpufreq_has_boost_support should also return -1 immediately, and should not follow the original logic to return 0, which will cause amd The cpupower tool returns the turbo active status as 0.

Reproduce procedure:
cpupower frequency-info

---
 tools/power/cpupower/utils/helpers/misc.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/power/cpupower/utils/helpers/misc.c +7 -2
index fc6e34511721..be96f9ce18eb 100644
@@ -30,10 +30,15 @@ int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active,
 		 */
 
 		if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_CPB_MSR) {
-			if (!read_msr(cpu, MSR_AMD_HWCR, &val)) {
+			ret = read_msr(cpu, MSR_AMD_HWCR, &val);
+			if (!ret) {
 				if (!(val & CPUPOWER_AMD_CPBDIS))
 					*active = 1;
-			}
+			} else
+				/* no permission to access /dev/cpu/%d/msr, return -1 immediately,
+				 * and should not follow the original logic to return 0
+				 */
+				return ret;
 		} else {
 			ret = amd_pci_get_num_boost_states(active, states);
 			if (ret)
Signature · 1 line
2.24.3 (Apple Git-128)
maintainer
#1 lore raw
Quoted 11 lines · xufuhai

From: xufuhai <[email protected]>

If the read_msr function is executed by a non-root user, the function returns -1, which means that there is no permission to access /dev/cpu/%d/msr, but cpufreq_has_boost_support should also return -1 immediately, and should not follow the original logic to return 0, which will cause amd The cpupower tool returns the turbo active status as 0.

Reproduce procedure:
cpupower frequency-info

Please run get_maintainer.pl and send patch maintainers and others suggested by the tool. I don't see this in my Inbox for me to review/accept and send it to pm maintainer.

Please include before and after the patch when you run cpupower frequency-info

thanks,
-- Shuah

author
#2 lore raw

yeah Shuah~ thanks for your reply

For this issue, not meaning "current CPU frequency" but "boost state support--->Active" during "cpupower frequency-info" command as below:

boost state support:
Supported: yes
Active: yes/no

I think the state returned from the command for amd cpu (family >= 0x17) should be like as below:

as non-root Active state:
Active: Error while evaluating Boost Capabilities on CPU xx -- are you root?

as root Active state:
Active: yes (if supported)
no (if not supprted)

I don't wanna see the state returned like below:

as non-root Active state:
Active: no

as root Active state:
Active: yes (if supported)
no (if not supprted)

I will paste the related code by detailed for showing the issue:

	if amd cpu family >= 0x17 , will run read_msr function via read /dev/cpu/%d/msr. For non-root

caller can not open msr node due to having no permission, but cpufreq_has_boost_support will return 0 to upper caller function that not means caller no permission to read /dev/cpu/%d/msr. I believe we should return negative value for the condition:

-----------------------------------------------------
/linux/tools/power/cpupower/utils/helper/misc.c
cpufreq_has_boost_support:

	if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_CPB) {
		*support = 1;

		/* AMD Family 0x17 does not utilize PCI D18F4 like prior
		 * families and has no fixed discrete boost states but
		 * has Hardware determined variable increments instead.
		 */

		if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_CPB_MSR) {
			if (!read_msr(cpu, MSR_AMD_HWCR, &val)) {
				if (!(val & CPUPOWER_AMD_CPBDIS))
					*active = 1;
			}
		} else {
			ret = amd_pci_get_num_boost_states(active, states);
			if (ret)
				return ret;
		}
	} else if (cpupower_cpu_info.caps & CPUPOWER_CAP_INTEL_IDA)
		*support = *active = 1;
	return 0;

---------------------------------------------------

Quoted 23 lines · Shuah Khan
Quoted 11 lines · xufuhai

From: xufuhai <[email protected]>

If the read_msr function is executed by a non-root user, the function returns -1, which means that there is no permission to access /dev/cpu/%d/msr, but cpufreq_has_boost_support should also return -1 immediately, and should not follow the original logic to return 0, which will cause amd The cpupower tool returns the turbo active status as 0.

Reproduce procedure:
         cpupower frequency-info

Please run get_maintainer.pl and send patch maintainers and others suggested by the tool. I don't see this in my Inbox for me to review/accept and send it to pm maintainer.

Please include before and after the patch when you run cpupower frequency-info

thanks,
-- Shuah