Skip to contentSkip to conversation

cpupower: Fix no-rounding MHz frequency output

PATCH RESEND Superseded Prarit Bhargava 2 participants 3 messages Oct 23, 2017 – Oct 25, 2017 CPU power monitoring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 cpupower: Fix no-rounding MHz frequency output

Sent about a year ago ...

P.

---8<---

'cpupower frequency-info -ln' returns kHz values on systems with MHz range minimum CPU frequency range. For example, on a 800MHz to 4.20GHz system the command returns

hardware limits: 800000 MHz - 4.200000 GHz

The value of speed passed into print_speed is in kHz, so divide speed by 1000 in the MHz else-if section to get MHz.

Cc Thomas Renninger <[email protected]>
Cc Stafford Horne <[email protected]>
Cc Shuah Khan <[email protected]>
---
 tools/power/cpupower/utils/cpufreq-info.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/cpupower/utils/cpufreq-info.c +1 -1
index 3e701f0e9c14..fe7c25147b3a 100644
@@ -94,7 +94,7 @@ static void print_speed(unsigned long speed)
 			printf("%u.%06u GHz", ((unsigned int) speed/1000000),
 				((unsigned int) speed%1000000));
 		else if (speed > 100000)
-			printf("%u MHz", (unsigned int) speed);
+			printf("%u MHz", (unsigned int) speed/1000);
 		else if (speed > 1000)
 			printf("%u.%03u MHz", ((unsigned int) speed/1000),
 				(unsigned int) (speed%1000));
Signature · 1 line
2.15.0.rc0.39.g2f0e14e64
#1 lore raw
Quoted 28 lines · Prarit Bhargava

Sent about a year ago ...

P.

---8<---

'cpupower frequency-info -ln' returns kHz values on systems with MHz range minimum CPU frequency range. For example, on a 800MHz to 4.20GHz system the command returns

hardware limits: 800000 MHz - 4.200000 GHz

The value of speed passed into print_speed is in kHz, so divide speed by 1000 in the MHz else-if section to get MHz.

Cc Thomas Renninger <[email protected]>
Cc Stafford Horne <[email protected]>
Cc Shuah Khan <[email protected]>
---
 tools/power/cpupower/utils/cpufreq-info.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/cpupower/utils/cpufreq-info.c +0 -0
index 3e701f0e9c14..fe7c25147b3a 100644

tools/power/cpupower/utils/cpufreq-info.c static void print_speed(unsigned long speed) · line 97

Quoted 5 lines
tools/power/cpupower/utils/cpufreq-info.c +1 -1
@@ -94,7 +94,7 @@ static void print_speed(unsigned long speed)
 			printf("%u.%06u GHz", ((unsigned int) speed/1000000),
 				((unsigned int) speed%1000000));
 		else if (speed > 100000)
-			printf("%u MHz", (unsigned int) speed);
+			printf("%u MHz", (unsigned int) speed/1000);

This looks ok to me, but can't we just remove this condition and depend on the condition with the decimal point below?

-Stafford

Quoted 6 lines
tools/power/cpupower/utils/cpufreq-info.c +0 -0
 		else if (speed > 1000)
 			printf("%u.%03u MHz", ((unsigned int) speed/1000),
 				(unsigned int) (speed%1000));
Signature · 1 line
2.15.0.rc0.39.g2f0e14e64
#2 lore raw
Quoted 38 lines · Stafford Horne
Quoted 28 lines · Prarit Bhargava

Sent about a year ago ...

P.

---8<---

'cpupower frequency-info -ln' returns kHz values on systems with MHz range minimum CPU frequency range. For example, on a 800MHz to 4.20GHz system the command returns

hardware limits: 800000 MHz - 4.200000 GHz

The value of speed passed into print_speed is in kHz, so divide speed by 1000 in the MHz else-if section to get MHz.

Cc Thomas Renninger <[email protected]>
Cc Stafford Horne <[email protected]>
Cc Shuah Khan <[email protected]>
---
 tools/power/cpupower/utils/cpufreq-info.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/cpupower/utils/cpufreq-info.c +0 -0
index 3e701f0e9c14..fe7c25147b3a 100644

tools/power/cpupower/utils/cpufreq-info.c static void print_speed(unsigned long speed) · line 97

Quoted 5 lines
tools/power/cpupower/utils/cpufreq-info.c +1 -1
@@ -94,7 +94,7 @@ static void print_speed(unsigned long speed)
 			printf("%u.%06u GHz", ((unsigned int) speed/1000000),
 				((unsigned int) speed%1000000));
 		else if (speed > 100000)
-			printf("%u MHz", (unsigned int) speed);
+			printf("%u MHz", (unsigned int) speed/1000);

This looks ok to me, but can't we just remove this condition and depend on the condition with the decimal point below?

Quoted 5 lines

-Stafford

Quoted 3 lines
tools/power/cpupower/utils/cpufreq-info.c +0 -0
 		else if (speed > 1000)
 			printf("%u.%03u MHz", ((unsigned int) speed/1000),
 				(unsigned int) (speed%1000));

Yeah we can. I think I made a cut-and-paste error when I originally did this code. I'll submit a v2 to clean that up.

P.

Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.15.0.rc0.39.g2f0e14e64