Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpupower: Move print_speed function into misc helper

The print_speed can be as a common function, and expose it into misc
helper header. Then it can be used on other helper files as well.

Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Huang Rui and committed by
Shuah Khan
35fdf42d bf9801ba

+52 -48
+11 -48
tools/power/cpupower/utils/cpufreq-info.c
··· 84 84 } 85 85 86 86 static int no_rounding; 87 - static void print_speed(unsigned long speed) 88 - { 89 - unsigned long tmp; 90 - 91 - if (no_rounding) { 92 - if (speed > 1000000) 93 - printf("%u.%06u GHz", ((unsigned int) speed/1000000), 94 - ((unsigned int) speed%1000000)); 95 - else if (speed > 1000) 96 - printf("%u.%03u MHz", ((unsigned int) speed/1000), 97 - (unsigned int) (speed%1000)); 98 - else 99 - printf("%lu kHz", speed); 100 - } else { 101 - if (speed > 1000000) { 102 - tmp = speed%10000; 103 - if (tmp >= 5000) 104 - speed += 10000; 105 - printf("%u.%02u GHz", ((unsigned int) speed/1000000), 106 - ((unsigned int) (speed%1000000)/10000)); 107 - } else if (speed > 100000) { 108 - tmp = speed%1000; 109 - if (tmp >= 500) 110 - speed += 1000; 111 - printf("%u MHz", ((unsigned int) speed/1000)); 112 - } else if (speed > 1000) { 113 - tmp = speed%100; 114 - if (tmp >= 50) 115 - speed += 100; 116 - printf("%u.%01u MHz", ((unsigned int) speed/1000), 117 - ((unsigned int) (speed%1000)/100)); 118 - } 119 - } 120 - 121 - return; 122 - } 123 - 124 87 static void print_duration(unsigned long duration) 125 88 { 126 89 unsigned long tmp; ··· 217 254 if (freqs) { 218 255 printf(_(" boost frequency steps: ")); 219 256 while (freqs->next) { 220 - print_speed(freqs->frequency); 257 + print_speed(freqs->frequency, no_rounding); 221 258 printf(", "); 222 259 freqs = freqs->next; 223 260 } 224 - print_speed(freqs->frequency); 261 + print_speed(freqs->frequency, no_rounding); 225 262 printf("\n"); 226 263 cpufreq_put_available_frequencies(freqs); 227 264 } ··· 240 277 return -EINVAL; 241 278 } 242 279 if (human) { 243 - print_speed(freq); 280 + print_speed(freq, no_rounding); 244 281 } else 245 282 printf("%lu", freq); 246 283 printf(_(" (asserted by call to kernel)\n")); ··· 259 296 return -EINVAL; 260 297 } 261 298 if (human) { 262 - print_speed(freq); 299 + print_speed(freq, no_rounding); 263 300 } else 264 301 printf("%lu", freq); 265 302 printf(_(" (asserted by call to hardware)\n")); ··· 279 316 280 317 if (human) { 281 318 printf(_(" hardware limits: ")); 282 - print_speed(min); 319 + print_speed(min, no_rounding); 283 320 printf(" - "); 284 - print_speed(max); 321 + print_speed(max, no_rounding); 285 322 printf("\n"); 286 323 } else { 287 324 printf("%lu %lu\n", min, max); ··· 313 350 return -EINVAL; 314 351 } 315 352 printf(_(" current policy: frequency should be within ")); 316 - print_speed(policy->min); 353 + print_speed(policy->min, no_rounding); 317 354 printf(_(" and ")); 318 - print_speed(policy->max); 355 + print_speed(policy->max, no_rounding); 319 356 320 357 printf(".\n "); 321 358 printf(_("The governor \"%s\" may decide which speed to use\n" ··· 399 436 struct cpufreq_stats *stats = cpufreq_get_stats(cpu, &total_time); 400 437 while (stats) { 401 438 if (human) { 402 - print_speed(stats->frequency); 439 + print_speed(stats->frequency, no_rounding); 403 440 printf(":%.2f%%", 404 441 (100.0 * stats->time_in_state) / total_time); 405 442 } else ··· 449 486 if (freqs) { 450 487 printf(_(" available frequency steps: ")); 451 488 while (freqs->next) { 452 - print_speed(freqs->frequency); 489 + print_speed(freqs->frequency, no_rounding); 453 490 printf(", "); 454 491 freqs = freqs->next; 455 492 } 456 - print_speed(freqs->frequency); 493 + print_speed(freqs->frequency, no_rounding); 457 494 printf("\n"); 458 495 cpufreq_put_available_frequencies(freqs); 459 496 }
+1
tools/power/cpupower/utils/helpers/helpers.h
··· 200 200 void get_cpustate(void); 201 201 void print_online_cpus(void); 202 202 void print_offline_cpus(void); 203 + void print_speed(unsigned long speed, int no_rounding); 203 204 204 205 #endif /* __CPUPOWERUTILS_HELPERS__ */
+40
tools/power/cpupower/utils/helpers/misc.c
··· 164 164 printf(_("cpupower set operation was not performed on them\n")); 165 165 } 166 166 } 167 + 168 + /* 169 + * print_speed 170 + * 171 + * Print the exact CPU frequency with appropriate unit 172 + */ 173 + void print_speed(unsigned long speed, int no_rounding) 174 + { 175 + unsigned long tmp; 176 + 177 + if (no_rounding) { 178 + if (speed > 1000000) 179 + printf("%u.%06u GHz", ((unsigned int)speed / 1000000), 180 + ((unsigned int)speed % 1000000)); 181 + else if (speed > 1000) 182 + printf("%u.%03u MHz", ((unsigned int)speed / 1000), 183 + (unsigned int)(speed % 1000)); 184 + else 185 + printf("%lu kHz", speed); 186 + } else { 187 + if (speed > 1000000) { 188 + tmp = speed % 10000; 189 + if (tmp >= 5000) 190 + speed += 10000; 191 + printf("%u.%02u GHz", ((unsigned int)speed / 1000000), 192 + ((unsigned int)(speed % 1000000) / 10000)); 193 + } else if (speed > 100000) { 194 + tmp = speed % 1000; 195 + if (tmp >= 500) 196 + speed += 1000; 197 + printf("%u MHz", ((unsigned int)speed / 1000)); 198 + } else if (speed > 1000) { 199 + tmp = speed % 100; 200 + if (tmp >= 50) 201 + speed += 100; 202 + printf("%u.%01u MHz", ((unsigned int)speed / 1000), 203 + ((unsigned int)(speed % 1000) / 100)); 204 + } 205 + } 206 + }