diff options
author | Huang Rui <ray.huang@amd.com> | 2022-02-22 18:34:24 +0300 |
---|---|---|
committer | Shuah Khan <skhan@linuxfoundation.org> | 2022-02-23 04:37:07 +0300 |
commit | 35fdf42d90d09d2d00ef65999fe338027a6b4d8e (patch) | |
tree | 26f6b498c123881d0674f7c52a71008da621c939 /tools/power/cpupower/utils/helpers | |
parent | bf9801baa81802dac7e2a5318944ca2f4bfa74ef (diff) | |
download | linux-35fdf42d90d09d2d00ef65999fe338027a6b4d8e.tar.xz |
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>
Diffstat (limited to 'tools/power/cpupower/utils/helpers')
-rw-r--r-- | tools/power/cpupower/utils/helpers/helpers.h | 1 | ||||
-rw-r--r-- | tools/power/cpupower/utils/helpers/misc.c | 40 |
2 files changed, 41 insertions, 0 deletions
diff --git a/tools/power/cpupower/utils/helpers/helpers.h b/tools/power/cpupower/utils/helpers/helpers.h index 326491e11c6e..fa2a8c1b1d26 100644 --- a/tools/power/cpupower/utils/helpers/helpers.h +++ b/tools/power/cpupower/utils/helpers/helpers.h @@ -200,5 +200,6 @@ extern struct bitmask *offline_cpus; void get_cpustate(void); void print_online_cpus(void); void print_offline_cpus(void); +void print_speed(unsigned long speed, int no_rounding); #endif /* __CPUPOWERUTILS_HELPERS__ */ diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c index e0d3145434d3..9547b29254a7 100644 --- a/tools/power/cpupower/utils/helpers/misc.c +++ b/tools/power/cpupower/utils/helpers/misc.c @@ -164,3 +164,43 @@ void print_offline_cpus(void) printf(_("cpupower set operation was not performed on them\n")); } } + +/* + * print_speed + * + * Print the exact CPU frequency with appropriate unit + */ +void print_speed(unsigned long speed, int no_rounding) +{ + unsigned long tmp; + + if (no_rounding) { + if (speed > 1000000) + printf("%u.%06u GHz", ((unsigned int)speed / 1000000), + ((unsigned int)speed % 1000000)); + else if (speed > 1000) + printf("%u.%03u MHz", ((unsigned int)speed / 1000), + (unsigned int)(speed % 1000)); + else + printf("%lu kHz", speed); + } else { + if (speed > 1000000) { + tmp = speed % 10000; + if (tmp >= 5000) + speed += 10000; + printf("%u.%02u GHz", ((unsigned int)speed / 1000000), + ((unsigned int)(speed % 1000000) / 10000)); + } else if (speed > 100000) { + tmp = speed % 1000; + if (tmp >= 500) + speed += 1000; + printf("%u MHz", ((unsigned int)speed / 1000)); + } else if (speed > 1000) { + tmp = speed % 100; + if (tmp >= 50) + speed += 100; + printf("%u.%01u MHz", ((unsigned int)speed / 1000), + ((unsigned int)(speed % 1000) / 100)); + } + } +} |