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