linux/tools/power/x86/intel-speed-select/isst-display.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/*
   3 * Intel dynamic_speed_select -- Enumerate and control features
   4 * Copyright (c) 2019 Intel Corporation.
   5 */
   6
   7#include "isst.h"
   8
   9static void printcpulist(int str_len, char *str, int mask_size,
  10                         cpu_set_t *cpu_mask)
  11{
  12        int i, first, curr_index, index;
  13
  14        if (!CPU_COUNT_S(mask_size, cpu_mask)) {
  15                snprintf(str, str_len, "none");
  16                return;
  17        }
  18
  19        curr_index = 0;
  20        first = 1;
  21        for (i = 0; i < get_topo_max_cpus(); ++i) {
  22                if (!CPU_ISSET_S(i, mask_size, cpu_mask))
  23                        continue;
  24                if (!first) {
  25                        index = snprintf(&str[curr_index],
  26                                         str_len - curr_index, ",");
  27                        curr_index += index;
  28                }
  29                index = snprintf(&str[curr_index], str_len - curr_index, "%d",
  30                                 i);
  31                curr_index += index;
  32                first = 0;
  33        }
  34}
  35
  36static void printcpumask(int str_len, char *str, int mask_size,
  37                         cpu_set_t *cpu_mask)
  38{
  39        int i, max_cpus = get_topo_max_cpus();
  40        unsigned int *mask;
  41        int size, index, curr_index;
  42
  43        size = max_cpus / (sizeof(unsigned int) * 8);
  44        if (max_cpus % (sizeof(unsigned int) * 8))
  45                size++;
  46
  47        mask = calloc(size, sizeof(unsigned int));
  48        if (!mask)
  49                return;
  50
  51        for (i = 0; i < max_cpus; ++i) {
  52                int mask_index, bit_index;
  53
  54                if (!CPU_ISSET_S(i, mask_size, cpu_mask))
  55                        continue;
  56
  57                mask_index = i / (sizeof(unsigned int) * 8);
  58                bit_index = i % (sizeof(unsigned int) * 8);
  59                mask[mask_index] |= BIT(bit_index);
  60        }
  61
  62        curr_index = 0;
  63        for (i = size - 1; i >= 0; --i) {
  64                index = snprintf(&str[curr_index], str_len - curr_index, "%08x",
  65                                 mask[i]);
  66                curr_index += index;
  67                if (i) {
  68                        strncat(&str[curr_index], ",", str_len - curr_index);
  69                        curr_index++;
  70                }
  71        }
  72
  73        free(mask);
  74}
  75
  76static void format_and_print_txt(FILE *outf, int level, char *header,
  77                                 char *value)
  78{
  79        char *spaces = "  ";
  80        static char delimiters[256];
  81        int i, j = 0;
  82
  83        if (!level)
  84                return;
  85
  86        if (level == 1) {
  87                strcpy(delimiters, " ");
  88        } else {
  89                for (i = 0; i < level - 1; ++i)
  90                        j += snprintf(&delimiters[j], sizeof(delimiters) - j,
  91                                      "%s", spaces);
  92        }
  93
  94        if (header && value) {
  95                fprintf(outf, "%s", delimiters);
  96                fprintf(outf, "%s:%s\n", header, value);
  97        } else if (header) {
  98                fprintf(outf, "%s", delimiters);
  99                fprintf(outf, "%s\n", header);
 100        }
 101}
 102
 103static int last_level;
 104static void format_and_print(FILE *outf, int level, char *header, char *value)
 105{
 106        char *spaces = "  ";
 107        static char delimiters[256];
 108        int i;
 109
 110        if (!out_format_is_json()) {
 111                format_and_print_txt(outf, level, header, value);
 112                return;
 113        }
 114
 115        if (level == 0) {
 116                if (header)
 117                        fprintf(outf, "{");
 118                else
 119                        fprintf(outf, "\n}\n");
 120
 121        } else {
 122                int j = 0;
 123
 124                for (i = 0; i < level; ++i)
 125                        j += snprintf(&delimiters[j], sizeof(delimiters) - j,
 126                                      "%s", spaces);
 127
 128                if (last_level == level)
 129                        fprintf(outf, ",\n");
 130
 131                if (value) {
 132                        if (last_level != level)
 133                                fprintf(outf, "\n");
 134
 135                        fprintf(outf, "%s\"%s\": ", delimiters, header);
 136                        fprintf(outf, "\"%s\"", value);
 137                } else {
 138                        for (i = last_level - 1; i >= level; --i) {
 139                                int k = 0;
 140
 141                                for (j = i; j > 0; --j)
 142                                        k += snprintf(&delimiters[k],
 143                                                      sizeof(delimiters) - k,
 144                                                      "%s", spaces);
 145                                if (i == level && header)
 146                                        fprintf(outf, "\n%s},", delimiters);
 147                                else
 148                                        fprintf(outf, "\n%s}", delimiters);
 149                        }
 150                        if (abs(last_level - level) < 3)
 151                                fprintf(outf, "\n");
 152                        if (header)
 153                                fprintf(outf, "%s\"%s\": {", delimiters,
 154                                        header);
 155                }
 156        }
 157
 158        last_level = level;
 159}
 160
 161static int print_package_info(int cpu, FILE *outf)
 162{
 163        char header[256];
 164
 165        if (out_format_is_json()) {
 166                snprintf(header, sizeof(header), "package-%d:die-%d:cpu-%d",
 167                         get_physical_package_id(cpu), get_physical_die_id(cpu),
 168                         cpu);
 169                format_and_print(outf, 1, header, NULL);
 170                return 1;
 171        }
 172        snprintf(header, sizeof(header), "package-%d",
 173                 get_physical_package_id(cpu));
 174        format_and_print(outf, 1, header, NULL);
 175        snprintf(header, sizeof(header), "die-%d", get_physical_die_id(cpu));
 176        format_and_print(outf, 2, header, NULL);
 177        snprintf(header, sizeof(header), "cpu-%d", cpu);
 178        format_and_print(outf, 3, header, NULL);
 179
 180        return 3;
 181}
 182
 183static void _isst_pbf_display_information(int cpu, FILE *outf, int level,
 184                                          struct isst_pbf_info *pbf_info,
 185                                          int disp_level)
 186{
 187        char header[256];
 188        char value[256];
 189
 190        snprintf(header, sizeof(header), "speed-select-base-freq-properties");
 191        format_and_print(outf, disp_level, header, NULL);
 192
 193        snprintf(header, sizeof(header), "high-priority-base-frequency(MHz)");
 194        snprintf(value, sizeof(value), "%d",
 195                 pbf_info->p1_high * DISP_FREQ_MULTIPLIER);
 196        format_and_print(outf, disp_level + 1, header, value);
 197
 198        snprintf(header, sizeof(header), "high-priority-cpu-mask");
 199        printcpumask(sizeof(value), value, pbf_info->core_cpumask_size,
 200                     pbf_info->core_cpumask);
 201        format_and_print(outf, disp_level + 1, header, value);
 202
 203        snprintf(header, sizeof(header), "high-priority-cpu-list");
 204        printcpulist(sizeof(value), value,
 205                     pbf_info->core_cpumask_size,
 206                     pbf_info->core_cpumask);
 207        format_and_print(outf, disp_level + 1, header, value);
 208
 209        snprintf(header, sizeof(header), "low-priority-base-frequency(MHz)");
 210        snprintf(value, sizeof(value), "%d",
 211                 pbf_info->p1_low * DISP_FREQ_MULTIPLIER);
 212        format_and_print(outf, disp_level + 1, header, value);
 213
 214        if (is_clx_n_platform())
 215                return;
 216
 217        snprintf(header, sizeof(header), "tjunction-temperature(C)");
 218        snprintf(value, sizeof(value), "%d", pbf_info->t_prochot);
 219        format_and_print(outf, disp_level + 1, header, value);
 220
 221        snprintf(header, sizeof(header), "thermal-design-power(W)");
 222        snprintf(value, sizeof(value), "%d", pbf_info->tdp);
 223        format_and_print(outf, disp_level + 1, header, value);
 224}
 225
 226static void _isst_fact_display_information(int cpu, FILE *outf, int level,
 227                                           int fact_bucket, int fact_avx,
 228                                           struct isst_fact_info *fact_info,
 229                                           int base_level)
 230{
 231        struct isst_fact_bucket_info *bucket_info = fact_info->bucket_info;
 232        char header[256];
 233        char value[256];
 234        int print = 0, j;
 235
 236        for (j = 0; j < ISST_FACT_MAX_BUCKETS; ++j) {
 237                if (fact_bucket != 0xff && fact_bucket != j)
 238                        continue;
 239
 240                if (!bucket_info[j].high_priority_cores_count)
 241                        break;
 242
 243                print = 1;
 244        }
 245        if (!print) {
 246                fprintf(stderr, "Invalid bucket\n");
 247                return;
 248        }
 249
 250        snprintf(header, sizeof(header), "speed-select-turbo-freq-properties");
 251        format_and_print(outf, base_level, header, NULL);
 252        for (j = 0; j < ISST_FACT_MAX_BUCKETS; ++j) {
 253                if (fact_bucket != 0xff && fact_bucket != j)
 254                        continue;
 255
 256                if (!bucket_info[j].high_priority_cores_count)
 257                        break;
 258
 259                snprintf(header, sizeof(header), "bucket-%d", j);
 260                format_and_print(outf, base_level + 1, header, NULL);
 261
 262                snprintf(header, sizeof(header), "high-priority-cores-count");
 263                snprintf(value, sizeof(value), "%d",
 264                         bucket_info[j].high_priority_cores_count);
 265                format_and_print(outf, base_level + 2, header, value);
 266
 267                if (fact_avx & 0x01) {
 268                        snprintf(header, sizeof(header),
 269                                 "high-priority-max-frequency(MHz)");
 270                        snprintf(value, sizeof(value), "%d",
 271                                 bucket_info[j].sse_trl * DISP_FREQ_MULTIPLIER);
 272                        format_and_print(outf, base_level + 2, header, value);
 273                }
 274
 275                if (fact_avx & 0x02) {
 276                        snprintf(header, sizeof(header),
 277                                 "high-priority-max-avx2-frequency(MHz)");
 278                        snprintf(value, sizeof(value), "%d",
 279                                 bucket_info[j].avx_trl * DISP_FREQ_MULTIPLIER);
 280                        format_and_print(outf, base_level + 2, header, value);
 281                }
 282
 283                if (fact_avx & 0x04) {
 284                        snprintf(header, sizeof(header),
 285                                 "high-priority-max-avx512-frequency(MHz)");
 286                        snprintf(value, sizeof(value), "%d",
 287                                 bucket_info[j].avx512_trl *
 288                                         DISP_FREQ_MULTIPLIER);
 289                        format_and_print(outf, base_level + 2, header, value);
 290                }
 291        }
 292        snprintf(header, sizeof(header),
 293                 "speed-select-turbo-freq-clip-frequencies");
 294        format_and_print(outf, base_level + 1, header, NULL);
 295        snprintf(header, sizeof(header), "low-priority-max-frequency(MHz)");
 296        snprintf(value, sizeof(value), "%d",
 297                 fact_info->lp_clipping_ratio_license_sse *
 298                         DISP_FREQ_MULTIPLIER);
 299        format_and_print(outf, base_level + 2, header, value);
 300        snprintf(header, sizeof(header),
 301                 "low-priority-max-avx2-frequency(MHz)");
 302        snprintf(value, sizeof(value), "%d",
 303                 fact_info->lp_clipping_ratio_license_avx2 *
 304                         DISP_FREQ_MULTIPLIER);
 305        format_and_print(outf, base_level + 2, header, value);
 306        snprintf(header, sizeof(header),
 307                 "low-priority-max-avx512-frequency(MHz)");
 308        snprintf(value, sizeof(value), "%d",
 309                 fact_info->lp_clipping_ratio_license_avx512 *
 310                         DISP_FREQ_MULTIPLIER);
 311        format_and_print(outf, base_level + 2, header, value);
 312}
 313
 314void isst_ctdp_display_core_info(int cpu, FILE *outf, char *prefix,
 315                                 unsigned int val, char *str0, char *str1)
 316{
 317        char header[256];
 318        char value[256];
 319        int level = 1;
 320
 321        if (out_format_is_json()) {
 322                snprintf(header, sizeof(header), "package-%d:die-%d:cpu-%d",
 323                         get_physical_package_id(cpu), get_physical_die_id(cpu),
 324                         cpu);
 325                format_and_print(outf, level++, header, NULL);
 326        } else {
 327                snprintf(header, sizeof(header), "package-%d",
 328                         get_physical_package_id(cpu));
 329                format_and_print(outf, level++, header, NULL);
 330                snprintf(header, sizeof(header), "die-%d",
 331                         get_physical_die_id(cpu));
 332                format_and_print(outf, level++, header, NULL);
 333                snprintf(header, sizeof(header), "cpu-%d", cpu);
 334                format_and_print(outf, level++, header, NULL);
 335        }
 336
 337        if (str0 && !val)
 338                snprintf(value, sizeof(value), "%s", str0);
 339        else if (str1 && val)
 340                snprintf(value, sizeof(value), "%s", str1);
 341        else
 342                snprintf(value, sizeof(value), "%u", val);
 343        format_and_print(outf, level, prefix, value);
 344
 345        format_and_print(outf, 1, NULL, NULL);
 346}
 347
 348void isst_ctdp_display_information(int cpu, FILE *outf, int tdp_level,
 349                                   struct isst_pkg_ctdp *pkg_dev)
 350{
 351        char header[256];
 352        char value[256];
 353        static int level;
 354        int i;
 355
 356        if (pkg_dev->processed)
 357                level = print_package_info(cpu, outf);
 358
 359        for (i = 0; i <= pkg_dev->levels; ++i) {
 360                struct isst_pkg_ctdp_level_info *ctdp_level;
 361                int j;
 362
 363                ctdp_level = &pkg_dev->ctdp_level[i];
 364                if (!ctdp_level->processed)
 365                        continue;
 366
 367                snprintf(header, sizeof(header), "perf-profile-level-%d",
 368                         ctdp_level->level);
 369                format_and_print(outf, level + 1, header, NULL);
 370
 371                snprintf(header, sizeof(header), "cpu-count");
 372                j = get_cpu_count(get_physical_die_id(cpu),
 373                                  get_physical_die_id(cpu));
 374                snprintf(value, sizeof(value), "%d", j);
 375                format_and_print(outf, level + 2, header, value);
 376
 377                j = CPU_COUNT_S(ctdp_level->core_cpumask_size,
 378                                ctdp_level->core_cpumask);
 379                if (j) {
 380                        snprintf(header, sizeof(header), "enable-cpu-count");
 381                        snprintf(value, sizeof(value), "%d", j);
 382                        format_and_print(outf, level + 2, header, value);
 383                }
 384
 385                if (ctdp_level->core_cpumask_size) {
 386                        snprintf(header, sizeof(header), "enable-cpu-mask");
 387                        printcpumask(sizeof(value), value,
 388                                     ctdp_level->core_cpumask_size,
 389                                     ctdp_level->core_cpumask);
 390                        format_and_print(outf, level + 2, header, value);
 391
 392                        snprintf(header, sizeof(header), "enable-cpu-list");
 393                        printcpulist(sizeof(value), value,
 394                                     ctdp_level->core_cpumask_size,
 395                                     ctdp_level->core_cpumask);
 396                        format_and_print(outf, level + 2, header, value);
 397                }
 398
 399                snprintf(header, sizeof(header), "thermal-design-power-ratio");
 400                snprintf(value, sizeof(value), "%d", ctdp_level->tdp_ratio);
 401                format_and_print(outf, level + 2, header, value);
 402
 403                snprintf(header, sizeof(header), "base-frequency(MHz)");
 404                if (!ctdp_level->sse_p1)
 405                        ctdp_level->sse_p1 = ctdp_level->tdp_ratio;
 406                snprintf(value, sizeof(value), "%d",
 407                          ctdp_level->sse_p1 * DISP_FREQ_MULTIPLIER);
 408                format_and_print(outf, level + 2, header, value);
 409
 410                if (ctdp_level->avx2_p1) {
 411                        snprintf(header, sizeof(header), "base-frequency-avx2(MHz)");
 412                        snprintf(value, sizeof(value), "%d",
 413                                 ctdp_level->avx2_p1 * DISP_FREQ_MULTIPLIER);
 414                        format_and_print(outf, level + 2, header, value);
 415                }
 416
 417                if (ctdp_level->avx512_p1) {
 418                        snprintf(header, sizeof(header), "base-frequency-avx512(MHz)");
 419                        snprintf(value, sizeof(value), "%d",
 420                                 ctdp_level->avx512_p1 * DISP_FREQ_MULTIPLIER);
 421                        format_and_print(outf, level + 2, header, value);
 422                }
 423
 424                if (ctdp_level->uncore_p1) {
 425                        snprintf(header, sizeof(header), "uncore-frequency-min(MHz)");
 426                        snprintf(value, sizeof(value), "%d",
 427                                 ctdp_level->uncore_p1 * DISP_FREQ_MULTIPLIER);
 428                        format_and_print(outf, level + 2, header, value);
 429                }
 430
 431                if (ctdp_level->uncore_p0) {
 432                        snprintf(header, sizeof(header), "uncore-frequency-max(MHz)");
 433                        snprintf(value, sizeof(value), "%d",
 434                                 ctdp_level->uncore_p0 * DISP_FREQ_MULTIPLIER);
 435                        format_and_print(outf, level + 2, header, value);
 436                }
 437
 438                if (ctdp_level->mem_freq) {
 439                        snprintf(header, sizeof(header), "mem-frequency(MHz)");
 440                        snprintf(value, sizeof(value), "%d",
 441                                 ctdp_level->mem_freq * DISP_FREQ_MULTIPLIER);
 442                        format_and_print(outf, level + 2, header, value);
 443                }
 444
 445                snprintf(header, sizeof(header),
 446                         "speed-select-turbo-freq");
 447                if (ctdp_level->fact_support) {
 448                        if (ctdp_level->fact_enabled)
 449                                snprintf(value, sizeof(value), "enabled");
 450                        else
 451                                snprintf(value, sizeof(value), "disabled");
 452                } else
 453                        snprintf(value, sizeof(value), "unsupported");
 454                format_and_print(outf, level + 2, header, value);
 455
 456                snprintf(header, sizeof(header),
 457                         "speed-select-base-freq");
 458                if (ctdp_level->pbf_support) {
 459                        if (ctdp_level->pbf_enabled)
 460                                snprintf(value, sizeof(value), "enabled");
 461                        else
 462                                snprintf(value, sizeof(value), "disabled");
 463                } else
 464                        snprintf(value, sizeof(value), "unsupported");
 465                format_and_print(outf, level + 2, header, value);
 466
 467                snprintf(header, sizeof(header),
 468                         "speed-select-core-power");
 469                if (ctdp_level->sst_cp_support) {
 470                        if (ctdp_level->sst_cp_enabled)
 471                                snprintf(value, sizeof(value), "enabled");
 472                        else
 473                                snprintf(value, sizeof(value), "disabled");
 474                } else
 475                        snprintf(value, sizeof(value), "unsupported");
 476                format_and_print(outf, level + 2, header, value);
 477
 478                if (is_clx_n_platform()) {
 479                        if (ctdp_level->pbf_support)
 480                                _isst_pbf_display_information(cpu, outf,
 481                                                              tdp_level,
 482                                                          &ctdp_level->pbf_info,
 483                                                              level + 2);
 484                        continue;
 485                }
 486
 487                if (ctdp_level->pkg_tdp) {
 488                        snprintf(header, sizeof(header), "thermal-design-power(W)");
 489                        snprintf(value, sizeof(value), "%d", ctdp_level->pkg_tdp);
 490                        format_and_print(outf, level + 2, header, value);
 491                }
 492
 493                if (ctdp_level->t_proc_hot) {
 494                        snprintf(header, sizeof(header), "tjunction-max(C)");
 495                        snprintf(value, sizeof(value), "%d", ctdp_level->t_proc_hot);
 496                        format_and_print(outf, level + 2, header, value);
 497                }
 498
 499                snprintf(header, sizeof(header), "turbo-ratio-limits-sse");
 500                format_and_print(outf, level + 2, header, NULL);
 501                for (j = 0; j < 8; ++j) {
 502                        snprintf(header, sizeof(header), "bucket-%d", j);
 503                        format_and_print(outf, level + 3, header, NULL);
 504
 505                        snprintf(header, sizeof(header), "core-count");
 506                        snprintf(value, sizeof(value), "%llu", (ctdp_level->buckets_info >> (j * 8)) & 0xff);
 507                        format_and_print(outf, level + 4, header, value);
 508
 509                        snprintf(header, sizeof(header),
 510                                "max-turbo-frequency(MHz)");
 511                        snprintf(value, sizeof(value), "%d",
 512                                 ctdp_level->trl_sse_active_cores[j] *
 513                                  DISP_FREQ_MULTIPLIER);
 514                        format_and_print(outf, level + 4, header, value);
 515                }
 516
 517                if (ctdp_level->trl_avx_active_cores[0]) {
 518                        snprintf(header, sizeof(header), "turbo-ratio-limits-avx2");
 519                        format_and_print(outf, level + 2, header, NULL);
 520                        for (j = 0; j < 8; ++j) {
 521                                snprintf(header, sizeof(header), "bucket-%d", j);
 522                                format_and_print(outf, level + 3, header, NULL);
 523
 524                                snprintf(header, sizeof(header), "core-count");
 525                                snprintf(value, sizeof(value), "%llu", (ctdp_level->buckets_info >> (j * 8)) & 0xff);
 526                                format_and_print(outf, level + 4, header, value);
 527
 528                                snprintf(header, sizeof(header), "max-turbo-frequency(MHz)");
 529                                snprintf(value, sizeof(value), "%d", ctdp_level->trl_avx_active_cores[j] * DISP_FREQ_MULTIPLIER);
 530                                format_and_print(outf, level + 4, header, value);
 531                        }
 532                }
 533
 534                if (ctdp_level->trl_avx_512_active_cores[0]) {
 535                        snprintf(header, sizeof(header), "turbo-ratio-limits-avx512");
 536                        format_and_print(outf, level + 2, header, NULL);
 537                        for (j = 0; j < 8; ++j) {
 538                                snprintf(header, sizeof(header), "bucket-%d", j);
 539                                format_and_print(outf, level + 3, header, NULL);
 540
 541                                snprintf(header, sizeof(header), "core-count");
 542                                snprintf(value, sizeof(value), "%llu", (ctdp_level->buckets_info >> (j * 8)) & 0xff);
 543                                format_and_print(outf, level + 4, header, value);
 544
 545                                snprintf(header, sizeof(header), "max-turbo-frequency(MHz)");
 546                                snprintf(value, sizeof(value), "%d", ctdp_level->trl_avx_512_active_cores[j] * DISP_FREQ_MULTIPLIER);
 547                                format_and_print(outf, level + 4, header, value);
 548                        }
 549                }
 550
 551                if (ctdp_level->pbf_support)
 552                        _isst_pbf_display_information(cpu, outf, i,
 553                                                      &ctdp_level->pbf_info,
 554                                                      level + 2);
 555                if (ctdp_level->fact_support)
 556                        _isst_fact_display_information(cpu, outf, i, 0xff, 0xff,
 557                                                       &ctdp_level->fact_info,
 558                                                       level + 2);
 559        }
 560
 561        format_and_print(outf, 1, NULL, NULL);
 562}
 563
 564static int start;
 565void isst_ctdp_display_information_start(FILE *outf)
 566{
 567        last_level = 0;
 568        format_and_print(outf, 0, "start", NULL);
 569        start = 1;
 570}
 571
 572void isst_ctdp_display_information_end(FILE *outf)
 573{
 574        format_and_print(outf, 0, NULL, NULL);
 575        start = 0;
 576}
 577
 578void isst_pbf_display_information(int cpu, FILE *outf, int level,
 579                                  struct isst_pbf_info *pbf_info)
 580{
 581        int _level;
 582
 583        _level = print_package_info(cpu, outf);
 584        _isst_pbf_display_information(cpu, outf, level, pbf_info, _level + 1);
 585        format_and_print(outf, 1, NULL, NULL);
 586}
 587
 588void isst_fact_display_information(int cpu, FILE *outf, int level,
 589                                   int fact_bucket, int fact_avx,
 590                                   struct isst_fact_info *fact_info)
 591{
 592        int _level;
 593
 594        _level = print_package_info(cpu, outf);
 595        _isst_fact_display_information(cpu, outf, level, fact_bucket, fact_avx,
 596                                       fact_info, _level + 1);
 597        format_and_print(outf, 1, NULL, NULL);
 598}
 599
 600void isst_clos_display_information(int cpu, FILE *outf, int clos,
 601                                   struct isst_clos_config *clos_config)
 602{
 603        char header[256];
 604        char value[256];
 605        int level;
 606
 607        level = print_package_info(cpu, outf);
 608
 609        snprintf(header, sizeof(header), "core-power");
 610        format_and_print(outf, level + 1, header, NULL);
 611
 612        snprintf(header, sizeof(header), "clos");
 613        snprintf(value, sizeof(value), "%d", clos);
 614        format_and_print(outf, level + 2, header, value);
 615
 616        snprintf(header, sizeof(header), "epp");
 617        snprintf(value, sizeof(value), "%d", clos_config->epp);
 618        format_and_print(outf, level + 2, header, value);
 619
 620        snprintf(header, sizeof(header), "clos-proportional-priority");
 621        snprintf(value, sizeof(value), "%d", clos_config->clos_prop_prio);
 622        format_and_print(outf, level + 2, header, value);
 623
 624        snprintf(header, sizeof(header), "clos-min");
 625        snprintf(value, sizeof(value), "%d MHz", clos_config->clos_min * DISP_FREQ_MULTIPLIER);
 626        format_and_print(outf, level + 2, header, value);
 627
 628        snprintf(header, sizeof(header), "clos-max");
 629        if (clos_config->clos_max == 0xff)
 630                snprintf(value, sizeof(value), "Max Turbo frequency");
 631        else
 632                snprintf(value, sizeof(value), "%d MHz", clos_config->clos_max * DISP_FREQ_MULTIPLIER);
 633        format_and_print(outf, level + 2, header, value);
 634
 635        snprintf(header, sizeof(header), "clos-desired");
 636        snprintf(value, sizeof(value), "%d MHz", clos_config->clos_desired * DISP_FREQ_MULTIPLIER);
 637        format_and_print(outf, level + 2, header, value);
 638
 639        format_and_print(outf, level, NULL, NULL);
 640}
 641
 642void isst_clos_display_clos_information(int cpu, FILE *outf,
 643                                        int clos_enable, int type,
 644                                        int state, int cap)
 645{
 646        char header[256];
 647        char value[256];
 648        int level;
 649
 650        level = print_package_info(cpu, outf);
 651
 652        snprintf(header, sizeof(header), "core-power");
 653        format_and_print(outf, level + 1, header, NULL);
 654
 655        snprintf(header, sizeof(header), "support-status");
 656        if (cap)
 657                snprintf(value, sizeof(value), "supported");
 658        else
 659                snprintf(value, sizeof(value), "unsupported");
 660        format_and_print(outf, level + 2, header, value);
 661
 662        snprintf(header, sizeof(header), "enable-status");
 663        if (state)
 664                snprintf(value, sizeof(value), "enabled");
 665        else
 666                snprintf(value, sizeof(value), "disabled");
 667        format_and_print(outf, level + 2, header, value);
 668
 669        snprintf(header, sizeof(header), "clos-enable-status");
 670        if (clos_enable)
 671                snprintf(value, sizeof(value), "enabled");
 672        else
 673                snprintf(value, sizeof(value), "disabled");
 674        format_and_print(outf, level + 2, header, value);
 675
 676        snprintf(header, sizeof(header), "priority-type");
 677        if (type)
 678                snprintf(value, sizeof(value), "ordered");
 679        else
 680                snprintf(value, sizeof(value), "proportional");
 681        format_and_print(outf, level + 2, header, value);
 682
 683        format_and_print(outf, level, NULL, NULL);
 684}
 685
 686void isst_clos_display_assoc_information(int cpu, FILE *outf, int clos)
 687{
 688        char header[256];
 689        char value[256];
 690        int level;
 691
 692        level = print_package_info(cpu, outf);
 693
 694        snprintf(header, sizeof(header), "get-assoc");
 695        format_and_print(outf, level + 1, header, NULL);
 696
 697        snprintf(header, sizeof(header), "clos");
 698        snprintf(value, sizeof(value), "%d", clos);
 699        format_and_print(outf, level + 2, header, value);
 700
 701        format_and_print(outf, level, NULL, NULL);
 702}
 703
 704void isst_display_result(int cpu, FILE *outf, char *feature, char *cmd,
 705                         int result)
 706{
 707        char header[256];
 708        char value[256];
 709        int level = 3;
 710
 711        if (cpu >= 0)
 712                level = print_package_info(cpu, outf);
 713
 714        snprintf(header, sizeof(header), "%s", feature);
 715        format_and_print(outf, level + 1, header, NULL);
 716        snprintf(header, sizeof(header), "%s", cmd);
 717        if (!result)
 718                snprintf(value, sizeof(value), "success");
 719        else
 720                snprintf(value, sizeof(value), "failed(error %d)", result);
 721        format_and_print(outf, level + 2, header, value);
 722
 723        format_and_print(outf, level, NULL, NULL);
 724}
 725
 726void isst_display_error_info_message(int error, char *msg, int arg_valid, int arg)
 727{
 728        FILE *outf = get_output_file();
 729        static int error_index;
 730        char header[256];
 731        char value[256];
 732
 733        if (!out_format_is_json()) {
 734                if (arg_valid)
 735                        snprintf(value, sizeof(value), "%s %d", msg, arg);
 736                else
 737                        snprintf(value, sizeof(value), "%s", msg);
 738
 739                if (error)
 740                        fprintf(outf, "Error: %s\n", value);
 741                else
 742                        fprintf(outf, "Information: %s\n", value);
 743                return;
 744        }
 745
 746        if (!start)
 747                format_and_print(outf, 0, "start", NULL);
 748
 749        if (error)
 750                snprintf(header, sizeof(header), "Error%d", error_index++);
 751        else
 752                snprintf(header, sizeof(header), "Information:%d", error_index++);
 753        format_and_print(outf, 1, header, NULL);
 754
 755        snprintf(header, sizeof(header), "message");
 756        if (arg_valid)
 757                snprintf(value, sizeof(value), "%s %d", msg, arg);
 758        else
 759                snprintf(value, sizeof(value), "%s", msg);
 760
 761        format_and_print(outf, 2, header, value);
 762        format_and_print(outf, 1, NULL, NULL);
 763        if (!start)
 764                format_and_print(outf, 0, NULL, NULL);
 765}
 766