| 50 | static uint32_t cpu_id; |
| 51 | |
| 52 | static int |
| 53 | check_cur_freq(__rte_unused unsigned int lcore_id, uint32_t idx, bool turbo) |
| 54 | { |
| 55 | #define TEST_POWER_CONVERT_TO_DECIMAL 10 |
| 56 | #define MAX_LOOP 100 |
| 57 | FILE *f; |
| 58 | char fullpath[PATH_MAX]; |
| 59 | char buf[BUFSIZ]; |
| 60 | enum power_management_env env; |
| 61 | uint32_t cur_freq; |
| 62 | uint32_t freq_conv; |
| 63 | int ret = -1; |
| 64 | int i; |
| 65 | |
| 66 | if (snprintf(fullpath, sizeof(fullpath), |
| 67 | TEST_POWER_SYSFILE_CPUINFO_FREQ, cpu_id) < 0) { |
| 68 | return 0; |
| 69 | } |
| 70 | f = fopen(fullpath, "r"); |
| 71 | if (f == NULL) { |
| 72 | if (snprintf(fullpath, sizeof(fullpath), |
| 73 | TEST_POWER_SYSFILE_SCALING_FREQ, cpu_id) < 0) { |
| 74 | return 0; |
| 75 | } |
| 76 | f = fopen(fullpath, "r"); |
| 77 | if (f == NULL) { |
| 78 | return 0; |
| 79 | } |
| 80 | } |
| 81 | for (i = 0; i < MAX_LOOP; i++) { |
| 82 | fflush(f); |
| 83 | if (fgets(buf, sizeof(buf), f) == NULL) |
| 84 | goto fail_all; |
| 85 | |
| 86 | cur_freq = strtoul(buf, NULL, TEST_POWER_CONVERT_TO_DECIMAL); |
| 87 | freq_conv = cur_freq; |
| 88 | |
| 89 | env = rte_power_get_env(); |
| 90 | if (env == PM_ENV_CPPC_CPUFREQ || env == PM_ENV_PSTATE_CPUFREQ) { |
| 91 | /* convert the frequency to nearest 100000 value |
| 92 | * Ex: if cur_freq=1396789 then freq_conv=1400000 |
| 93 | * Ex: if cur_freq=800030 then freq_conv=800000 |
| 94 | */ |
| 95 | freq_conv = (cur_freq + TEST_FREQ_ROUNDING_DELTA) |
| 96 | / TEST_ROUND_FREQ_TO_N_100000; |
| 97 | freq_conv = freq_conv * TEST_ROUND_FREQ_TO_N_100000; |
| 98 | } else if (env == PM_ENV_AMD_PSTATE_CPUFREQ) { |
| 99 | freq_conv = cur_freq > freqs[idx] ? (cur_freq - freqs[idx]) : |
| 100 | (freqs[idx] - cur_freq); |
| 101 | if (freq_conv <= TEST_FREQ_ROUNDING_DELTA) { |
| 102 | /* workaround: current frequency may deviate from |
| 103 | * nominal freq. Allow deviation of up to 50Mhz. |
| 104 | */ |
| 105 | printf("Current frequency deviated from nominal " |
| 106 | "frequency by %d Khz!\n", freq_conv); |
| 107 | freq_conv = freqs[idx]; |
| 108 | } |
| 109 | } |
no test coverage detected