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->mem_freq) {
464 			snprintf(header, sizeof(header), "max-mem-frequency(MHz)");
465 			snprintf(value, sizeof(value), "%d",
466 				 ctdp_level->mem_freq);
467 			format_and_print(outf, level + 2, header, value);
468 		}
469 
470 		if (api_version() > 1) {
471 			snprintf(header, sizeof(header), "cooling_type");
472 			snprintf(value, sizeof(value), "%d",
473 				ctdp_level->cooling_type);
474 			format_and_print(outf, level + 2, header, value);
475 		}
476 
477 		snprintf(header, sizeof(header),
478 			 "speed-select-turbo-freq");
479 		if (ctdp_level->fact_support) {
480 			if (ctdp_level->fact_enabled)
481 				snprintf(value, sizeof(value), "enabled");
482 			else
483 				snprintf(value, sizeof(value), "disabled");
484 		} else
485 			snprintf(value, sizeof(value), "unsupported");
486 		format_and_print(outf, level + 2, header, value);
487 
488 		snprintf(header, sizeof(header),
489 			 "speed-select-base-freq");
490 		if (ctdp_level->pbf_support) {
491 			if (ctdp_level->pbf_enabled)
492 				snprintf(value, sizeof(value), "enabled");
493 			else
494 				snprintf(value, sizeof(value), "disabled");
495 		} else
496 			snprintf(value, sizeof(value), "unsupported");
497 		format_and_print(outf, level + 2, header, value);
498 
499 		snprintf(header, sizeof(header),
500 			 "speed-select-core-power");
501 		if (ctdp_level->sst_cp_support) {
502 			if (ctdp_level->sst_cp_enabled)
503 				snprintf(value, sizeof(value), "enabled");
504 			else
505 				snprintf(value, sizeof(value), "disabled");
506 		} else
507 			snprintf(value, sizeof(value), "unsupported");
508 		format_and_print(outf, level + 2, header, value);
509 
510 		if (is_clx_n_platform()) {
511 			if (ctdp_level->pbf_support)
512 				_isst_pbf_display_information(id, outf,
513 							      tdp_level,
514 							  &ctdp_level->pbf_info,
515 							      level + 2);
516 			continue;
517 		}
518 
519 		if (ctdp_level->pkg_tdp) {
520 			snprintf(header, sizeof(header), "thermal-design-power(W)");
521 			snprintf(value, sizeof(value), "%d", ctdp_level->pkg_tdp);
522 			format_and_print(outf, level + 2, header, value);
523 		}
524 
525 		if (ctdp_level->t_proc_hot) {
526 			snprintf(header, sizeof(header), "tjunction-max(C)");
527 			snprintf(value, sizeof(value), "%d", ctdp_level->t_proc_hot);
528 			format_and_print(outf, level + 2, header, value);
529 		}
530 
531 		for (k = 0; k < trl_max_levels; k++) {
532 			if (!ctdp_level->trl_ratios[k][0])
533 				continue;
534 
535 			snprintf(header, sizeof(header), "turbo-ratio-limits-%s", isst_get_trl_level_name(k));
536 			format_and_print(outf, level + 2, header, NULL);
537 
538 			for (j = 0; j < 8; ++j) {
539 				snprintf(header, sizeof(header), "bucket-%d", j);
540 				format_and_print(outf, level + 3, header, NULL);
541 
542 				snprintf(header, sizeof(header), "core-count");
543 
544 				snprintf(value, sizeof(value), "%llu", (ctdp_level->trl_cores >> (j * 8)) & 0xff);
545 				format_and_print(outf, level + 4, header, value);
546 
547 				snprintf(header, sizeof(header), "max-turbo-frequency(MHz)");
548 				snprintf(value, sizeof(value), "%d", ctdp_level->trl_ratios[k][j] * isst_get_disp_freq_multiplier());
549 				format_and_print(outf, level + 4, header, value);
550 			}
551 		}
552 
553 		if (ctdp_level->pbf_support)
554 			_isst_pbf_display_information(id, outf, i,
555 						      &ctdp_level->pbf_info,
556 						      level + 2);
557 		if (ctdp_level->fact_support)
558 			_isst_fact_display_information(id, outf, i, 0xff, 0xff,
559 						       &ctdp_level->fact_info,
560 						       level + 2);
561 	}
562 
563 	format_and_print(outf, 1, NULL, NULL);
564 }
565 
566 static int start;
isst_ctdp_display_information_start(FILE * outf)567 void isst_ctdp_display_information_start(FILE *outf)
568 {
569 	last_level = 0;
570 	format_and_print(outf, 0, "start", NULL);
571 	start = 1;
572 }
573 
isst_ctdp_display_information_end(FILE * outf)574 void isst_ctdp_display_information_end(FILE *outf)
575 {
576 	format_and_print(outf, 0, NULL, NULL);
577 	start = 0;
578 }
579 
isst_pbf_display_information(struct isst_id * id,FILE * outf,int level,struct isst_pbf_info * pbf_info)580 void isst_pbf_display_information(struct isst_id *id, FILE *outf, int level,
581 				  struct isst_pbf_info *pbf_info)
582 {
583 	int _level;
584 
585 	_level = print_package_info(id, outf);
586 	_isst_pbf_display_information(id, outf, level, pbf_info, _level + 1);
587 	format_and_print(outf, 1, NULL, NULL);
588 }
589 
isst_fact_display_information(struct isst_id * id,FILE * outf,int level,int fact_bucket,int fact_avx,struct isst_fact_info * fact_info)590 void isst_fact_display_information(struct isst_id *id, FILE *outf, int level,
591 				   int fact_bucket, int fact_avx,
592 				   struct isst_fact_info *fact_info)
593 {
594 	int _level;
595 
596 	_level = print_package_info(id, outf);
597 	_isst_fact_display_information(id, outf, level, fact_bucket, fact_avx,
598 				       fact_info, _level + 1);
599 	format_and_print(outf, 1, NULL, NULL);
600 }
601 
isst_clos_display_information(struct isst_id * id,FILE * outf,int clos,struct isst_clos_config * clos_config)602 void isst_clos_display_information(struct isst_id *id, FILE *outf, int clos,
603 				   struct isst_clos_config *clos_config)
604 {
605 	char header[256];
606 	char value[256];
607 	int level;
608 
609 	level = print_package_info(id, outf);
610 
611 	snprintf(header, sizeof(header), "core-power");
612 	format_and_print(outf, level + 1, header, NULL);
613 
614 	snprintf(header, sizeof(header), "clos");
615 	snprintf(value, sizeof(value), "%d", clos);
616 	format_and_print(outf, level + 2, header, value);
617 
618 	snprintf(header, sizeof(header), "epp");
619 	snprintf(value, sizeof(value), "%d", clos_config->epp);
620 	format_and_print(outf, level + 2, header, value);
621 
622 	snprintf(header, sizeof(header), "clos-proportional-priority");
623 	snprintf(value, sizeof(value), "%d", clos_config->clos_prop_prio);
624 	format_and_print(outf, level + 2, header, value);
625 
626 	snprintf(header, sizeof(header), "clos-min");
627 	snprintf(value, sizeof(value), "%d MHz", clos_config->clos_min * isst_get_disp_freq_multiplier());
628 	format_and_print(outf, level + 2, header, value);
629 
630 	snprintf(header, sizeof(header), "clos-max");
631 	if ((clos_config->clos_max * isst_get_disp_freq_multiplier()) == 25500)
632 		snprintf(value, sizeof(value), "Max Turbo frequency");
633 	else
634 		snprintf(value, sizeof(value), "%d MHz", clos_config->clos_max * isst_get_disp_freq_multiplier());
635 	format_and_print(outf, level + 2, header, value);
636 
637 	snprintf(header, sizeof(header), "clos-desired");
638 	snprintf(value, sizeof(value), "%d MHz", clos_config->clos_desired * isst_get_disp_freq_multiplier());
639 	format_and_print(outf, level + 2, header, value);
640 
641 	format_and_print(outf, level, NULL, NULL);
642 }
643 
isst_clos_display_clos_information(struct isst_id * id,FILE * outf,int clos_enable,int type,int state,int cap)644 void isst_clos_display_clos_information(struct isst_id *id, FILE *outf,
645 					int clos_enable, int type,
646 					int state, int cap)
647 {
648 	char header[256];
649 	char value[256];
650 	int level;
651 
652 	level = print_package_info(id, outf);
653 
654 	snprintf(header, sizeof(header), "core-power");
655 	format_and_print(outf, level + 1, header, NULL);
656 
657 	snprintf(header, sizeof(header), "support-status");
658 	if (cap)
659 		snprintf(value, sizeof(value), "supported");
660 	else
661 		snprintf(value, sizeof(value), "unsupported");
662 	format_and_print(outf, level + 2, header, value);
663 
664 	snprintf(header, sizeof(header), "enable-status");
665 	if (state)
666 		snprintf(value, sizeof(value), "enabled");
667 	else
668 		snprintf(value, sizeof(value), "disabled");
669 	format_and_print(outf, level + 2, header, value);
670 
671 	snprintf(header, sizeof(header), "clos-enable-status");
672 	if (clos_enable)
673 		snprintf(value, sizeof(value), "enabled");
674 	else
675 		snprintf(value, sizeof(value), "disabled");
676 	format_and_print(outf, level + 2, header, value);
677 
678 	snprintf(header, sizeof(header), "priority-type");
679 	if (type)
680 		snprintf(value, sizeof(value), "ordered");
681 	else
682 		snprintf(value, sizeof(value), "proportional");
683 	format_and_print(outf, level + 2, header, value);
684 
685 	format_and_print(outf, level, NULL, NULL);
686 }
687 
isst_clos_display_assoc_information(struct isst_id * id,FILE * outf,int clos)688 void isst_clos_display_assoc_information(struct isst_id *id, FILE *outf, int clos)
689 {
690 	char header[256];
691 	char value[256];
692 	int level;
693 
694 	level = print_package_info(id, outf);
695 
696 	snprintf(header, sizeof(header), "get-assoc");
697 	format_and_print(outf, level + 1, header, NULL);
698 
699 	snprintf(header, sizeof(header), "clos");
700 	snprintf(value, sizeof(value), "%d", clos);
701 	format_and_print(outf, level + 2, header, value);
702 
703 	format_and_print(outf, level, NULL, NULL);
704 }
705 
isst_display_result(struct isst_id * id,FILE * outf,char * feature,char * cmd,int result)706 void isst_display_result(struct isst_id *id, FILE *outf, char *feature, char *cmd,
707 			 int result)
708 {
709 	char header[256];
710 	char value[256];
711 	int level = 3;
712 
713 	level = print_package_info(id, outf);
714 
715 	snprintf(header, sizeof(header), "%s", feature);
716 	format_and_print(outf, level + 1, header, NULL);
717 	snprintf(header, sizeof(header), "%s", cmd);
718 	if (!result)
719 		snprintf(value, sizeof(value), "success");
720 	else
721 		snprintf(value, sizeof(value), "failed(error %d)", result);
722 	format_and_print(outf, level + 2, header, value);
723 
724 	format_and_print(outf, level, NULL, NULL);
725 }
726 
isst_display_error_info_message(int error,char * msg,int arg_valid,int arg)727 void isst_display_error_info_message(int error, char *msg, int arg_valid, int arg)
728 {
729 	FILE *outf = get_output_file();
730 	static int error_index;
731 	char header[256];
732 	char value[256];
733 
734 	if (!out_format_is_json()) {
735 		if (arg_valid)
736 			snprintf(value, sizeof(value), "%s %d", msg, arg);
737 		else
738 			snprintf(value, sizeof(value), "%s", msg);
739 
740 		if (error)
741 			fprintf(outf, "Error: %s\n", value);
742 		else
743 			fprintf(outf, "Information: %s\n", value);
744 		return;
745 	}
746 
747 	if (!start)
748 		format_and_print(outf, 0, "start", NULL);
749 
750 	if (error)
751 		snprintf(header, sizeof(header), "Error%d", error_index++);
752 	else
753 		snprintf(header, sizeof(header), "Information:%d", error_index++);
754 	format_and_print(outf, 1, header, NULL);
755 
756 	snprintf(header, sizeof(header), "message");
757 	if (arg_valid)
758 		snprintf(value, sizeof(value), "%s %d", msg, arg);
759 	else
760 		snprintf(value, sizeof(value), "%s", msg);
761 
762 	format_and_print(outf, 2, header, value);
763 	format_and_print(outf, 1, NULL, NULL);
764 	if (!start)
765 		format_and_print(outf, 0, NULL, NULL);
766 }
767 
isst_trl_display_information(struct isst_id * id,FILE * outf,unsigned long long trl)768 void isst_trl_display_information(struct isst_id *id, FILE *outf, unsigned long long trl)
769 {
770 	char header[256];
771 	char value[256];
772 	int level;
773 
774 	level = print_package_info(id, outf);
775 
776 	snprintf(header, sizeof(header), "get-trl");
777 	format_and_print(outf, level + 1, header, NULL);
778 
779 	snprintf(header, sizeof(header), "trl");
780 	snprintf(value, sizeof(value), "0x%llx", trl);
781 	format_and_print(outf, level + 2, header, value);
782 
783 	format_and_print(outf, level, NULL, NULL);
784 }
785