1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2010-2022 Intel Corporation
*/
#include "test.h"
#ifndef RTE_LIB_POWER
static int
test_power_intel_uncore(void)
{
printf("Power management library not supported, skipping test\n");
return TEST_SKIPPED;
}
#else
#include <rte_power_intel_uncore.h>
#include <power_common.h>
#define MAX_UNCORE_FREQS 64
#define VALID_PKG 0
#define VALID_DIE 0
#define INVALID_PKG (rte_power_uncore_get_num_pkgs() + 1)
#define INVALID_DIE (rte_power_uncore_get_num_dies(VALID_PKG) + 1)
#define VALID_INDEX 1
#define INVALID_INDEX (MAX_UNCORE_FREQS + 1)
static int check_power_uncore_init(void)
{
int ret;
/* Test initialisation of uncore configuration*/
ret = rte_power_uncore_init(VALID_PKG, VALID_DIE);
if (ret < 0) {
printf("Cannot initialise uncore power management for pkg %u die %u, this "
"may occur if environment is not configured "
"correctly(APCI cpufreq) or operating in another valid "
"Power management environment\n", VALID_PKG, VALID_DIE);
return -1;
}
/* Unsuccessful Test */
ret = rte_power_uncore_init(INVALID_PKG, INVALID_DIE);
if (ret == 0) {
printf("Unexpectedly was able to initialise uncore power management "
"for pkg %u die %u\n", INVALID_PKG, INVALID_DIE);
return -1;
}
return 0;
}
static int
check_power_get_uncore_freq(void)
{
int ret;
/* Successfully get uncore freq */
ret = rte_power_get_uncore_freq(VALID_PKG, VALID_DIE);
if (ret < 0) {
printf("Failed to get uncore frequency for pkg %u die %u\n",
VALID_PKG, VALID_DIE);
return -1;
}
/* Unsuccessful Test */
ret = rte_power_get_uncore_freq(INVALID_PKG, INVALID_DIE);
if (ret >= 0) {
printf("Unexpectedly got invalid uncore frequency for pkg %u die %u\n",
INVALID_PKG, INVALID_DIE);
return -1;
}
return 0;
}
static int
check_power_set_uncore_freq(void)
{
int ret;
/* Successfully set uncore freq */
ret = rte_power_set_uncore_freq(VALID_PKG, VALID_DIE, VALID_INDEX);
if (ret < 0) {
printf("Failed to set uncore frequency for pkg %u die %u index %u\n",
VALID_PKG, VALID_DIE, VALID_INDEX);
return -1;
}
/* Try to unsuccessfully set invalid uncore freq index */
ret = rte_power_set_uncore_freq(VALID_PKG, VALID_DIE, INVALID_INDEX);
if (ret == 0) {
printf("Unexpectedly set invalid uncore index for pkg %u die %u index %u\n",
VALID_PKG, VALID_DIE, INVALID_INDEX);
return -1;
}
/* Unsuccessful Test */
ret = rte_power_set_uncore_freq(INVALID_PKG, INVALID_DIE, VALID_INDEX);
if (ret == 0) {
printf("Unexpectedly set invalid uncore frequency for pkg %u die %u index %u\n",
INVALID_PKG, INVALID_DIE, VALID_INDEX);
return -1;
}
return 0;
}
static int
check_power_uncore_freq_max(void)
{
int ret;
/* Successfully get max uncore freq */
ret = rte_power_uncore_freq_max(VALID_PKG, VALID_DIE);
if (ret < 0) {
printf("Failed to set max uncore frequency for pkg %u die %u\n",
VALID_PKG, VALID_DIE);
return -1;
}
/* Unsuccessful Test */
ret = rte_power_uncore_freq_max(INVALID_PKG, INVALID_DIE);
if (ret == 0) {
printf("Unexpectedly set invalid max uncore frequency for pkg %u die %u\n",
INVALID_PKG, INVALID_DIE);
return -1;
}
return 0;
}
static int
check_power_uncore_freq_min(void)
{
int ret;
/* Successfully get min uncore freq */
ret = rte_power_uncore_freq_min(VALID_PKG, VALID_DIE);
if (ret < 0) {
printf("Failed to set min uncore frequency for pkg %u die %u\n",
VALID_PKG, VALID_DIE);
return -1;
}
/* Unsuccessful Test */
ret = rte_power_uncore_freq_min(INVALID_PKG, INVALID_DIE);
if (ret == 0) {
printf("Unexpectedly set invalid min uncore frequency for pkg %u die %u\n",
INVALID_PKG, INVALID_DIE);
return -1;
}
return 0;
}
static int
check_power_uncore_get_num_freqs(void)
{
int ret;
/* Successfully get number of uncore freq */
ret = rte_power_uncore_get_num_freqs(VALID_PKG, VALID_DIE);
if (ret < 0) {
printf("Failed to get number of uncore frequencies for pkg %u die %u\n",
VALID_PKG, VALID_DIE);
return -1;
}
/* Unsuccessful Test */
ret = rte_power_uncore_get_num_freqs(INVALID_PKG, INVALID_DIE);
if (ret >= 0) {
printf("Unexpectedly got number of invalid frequencies for pkg %u die %u\n",
INVALID_PKG, INVALID_DIE);
return -1;
}
return 0;
}
static int
check_power_uncore_get_num_pkgs(void)
{
int ret;
/* Successfully get number of uncore pkgs */
ret = rte_power_uncore_get_num_pkgs();
if (ret == 0) {
printf("Failed to get number of uncore pkgs\n");
return -1;
}
return 0;
}
static int
check_power_uncore_get_num_dies(void)
{
int ret;
/* Successfully get number of uncore dies */
ret = rte_power_uncore_get_num_dies(VALID_PKG);
if (ret == 0) {
printf("Failed to get number of uncore dies for pkg %u\n",
VALID_PKG);
return -1;
}
/* Unsuccessful test */
ret = rte_power_uncore_get_num_dies(INVALID_PKG);
if (ret > 0) {
printf("Unexpectedly got number of invalid dies for pkg %u\n",
INVALID_PKG);
return -1;
}
return 0;
}
static int
check_power_uncore_exit(void)
{
int ret;
/* Successfully exit uncore power management */
ret = rte_power_uncore_exit(VALID_PKG, VALID_DIE);
if (ret < 0) {
printf("Failed to exit uncore power management for pkg %u die %u\n",
VALID_PKG, VALID_DIE);
}
/* Unsuccessful Test */
ret = rte_power_uncore_exit(INVALID_PKG, INVALID_DIE);
if (ret == 0) {
printf("Unexpectedly was able to exit uncore power management for pkg %u die %u\n",
INVALID_PKG, INVALID_DIE);
return -1;
}
return 0;
}
static int
test_power_intel_uncore(void)
{
int ret;
ret = rte_power_uncore_get_num_pkgs();
if (ret == 0) {
printf("Uncore frequency management not supported/enabled on this kernel. "
"Please enable CONFIG_INTEL_UNCORE_FREQ_CONTROL if on x86 with linux kernel"
" >= 5.6\n");
return TEST_SKIPPED;
}
ret = check_power_uncore_init();
if (ret < 0)
goto fail_all;
ret = check_power_get_uncore_freq();
if (ret < 0)
goto fail_all;
ret = check_power_set_uncore_freq();
if (ret < 0)
goto fail_all;
ret = check_power_uncore_freq_max();
if (ret < 0)
goto fail_all;
ret = check_power_uncore_freq_min();
if (ret < 0)
goto fail_all;
ret = check_power_uncore_get_num_freqs();
if (ret < 0)
goto fail_all;
ret = check_power_uncore_get_num_pkgs();
if (ret < 0)
goto fail_all;
ret = check_power_uncore_get_num_dies();
if (ret < 0)
goto fail_all;
ret = check_power_uncore_exit();
if (ret < 0)
return -1;
return 0;
fail_all:
rte_power_uncore_exit(VALID_PKG, VALID_DIE);
return -1;
}
#endif
REGISTER_TEST_COMMAND(power_intel_uncore_autotest, test_power_intel_uncore);
|