1 // SPDX-License-Identifier: GPL-2.0 2 3 #include <stdio.h> 4 #include <errno.h> 5 #include <stdlib.h> 6 #include <string.h> 7 #include <math.h> 8 9 #include "helpers/helpers.h" 10 #include "cpufreq.h" 11 #include "acpi_cppc.h" 12 13 #define cppc_to_frequency(perf) (roundf(slope * (perf) + intercept)) 14 15 void cppc_show_perf_and_freq(unsigned int cpu, int no_rounding) 16 { 17 int64_t nominal = acpi_cppc_get_data(cpu, NOMINAL_PERF); 18 int64_t nominal_freq = acpi_cppc_get_data(cpu, NOMINAL_FREQ) * 1000; 19 int64_t lowest = acpi_cppc_get_data(cpu, LOWEST_PERF); 20 int64_t lowest_freq = acpi_cppc_get_data(cpu, LOWEST_FREQ) * 1000; 21 unsigned long non_linear = acpi_cppc_get_data(cpu, LOWEST_NONLINEAR_PERF); 22 unsigned long highest = acpi_cppc_get_data(cpu, HIGHEST_PERF); 23 float slope, intercept; 24 25 /* do the optional freq fields look invalid? */ 26 if (!nominal_freq || !lowest_freq || nominal == lowest) 27 return; 28 29 slope = (float)(nominal_freq - lowest_freq) / (nominal - lowest); 30 intercept = lowest_freq - slope * lowest; 31 32 printf(_(" CPPC limits:\n")); 33 printf(_(" Highest Performance: %lu. Maximum Frequency: "), 34 highest); 35 /* 36 * If boost isn't active, the cpuinfo_max doesn't indicate real max 37 * frequency. 38 */ 39 print_speed(cppc_to_frequency(highest), no_rounding); 40 printf(".\n"); 41 42 printf(_(" Nominal Performance: %lu. Nominal Frequency: "), 43 acpi_cppc_get_data(cpu, NOMINAL_PERF)); 44 print_speed(nominal_freq, no_rounding); 45 printf(".\n"); 46 47 printf(_(" Lowest Non-linear Performance: %lu. Lowest Non-linear Frequency: "), 48 non_linear); 49 print_speed(cppc_to_frequency(non_linear), no_rounding); 50 printf(".\n"); 51 52 printf(_(" Lowest Performance: %lu. Lowest Frequency: "), 53 acpi_cppc_get_data(cpu, LOWEST_PERF)); 54 print_speed(lowest_freq, no_rounding); 55 printf(".\n"); 56 } 57