aboutsummaryrefslogtreecommitdiffstats
path: root/tools/power/cpupower/utils/helpers/misc.c
diff options
context:
space:
mode:
authorHuang Rui <ray.huang@amd.com>2022-02-22 23:34:24 +0800
committerShuah Khan <skhan@linuxfoundation.org>2022-02-22 18:37:07 -0700
commit35fdf42d90d09d2d00ef65999fe338027a6b4d8e (patch)
tree26f6b498c123881d0674f7c52a71008da621c939 /tools/power/cpupower/utils/helpers/misc.c
parentcpupower: Enable boost state support for AMD P-State module (diff)
downloadlinux-dev-35fdf42d90d09d2d00ef65999fe338027a6b4d8e.tar.xz
linux-dev-35fdf42d90d09d2d00ef65999fe338027a6b4d8e.zip
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 '')
-rw-r--r--tools/power/cpupower/utils/helpers/misc.c40
1 files changed, 40 insertions, 0 deletions
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));
+ }
+ }
+}