File: libcpumf_example.c

package info (click to toggle)
s390-tools 2.40.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,288 kB
  • sloc: ansic: 187,079; sh: 12,157; cpp: 5,049; makefile: 2,812; perl: 2,541; asm: 1,097; python: 697; xml: 29
file content (90 lines) | stat: -rw-r--r-- 2,499 bytes parent folder | download | duplicates (2)
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
/* Copyright IBM Corp. 2022
 *
 * s390-tools is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See LICENSE for details.
 */

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>

#include "lib/libcpumf.h"

int main(void)
{
	unsigned long min, max, speed, sfb_min, sfb_max;
	int rc, pmu, cfvn, csvn, auth;
	char *pmuname;
	cpu_set_t set;

	pmu = libcpumf_pmutype(S390_CPUMF_CF);
	if (pmu >= 0)
		printf("PMU %stype %d\n", S390_CPUMF_CF, pmu);
	else
		printf("PMU %stype error %d\n", S390_CPUMF_CF, errno);
	pmu = libcpumf_pmutype(S390_CPUMF_SF);
	if (pmu >= 0)
		printf("PMU %stype %d\n", S390_CPUMF_SF, pmu);
	else
		printf("PMU %stype error %d\n", S390_CPUMF_SF, errno);
	pmu = libcpumf_pmutype(S390_CPUMF_CFDIAG);
	if (pmu >= 0)
		printf("PMU %stype %d\n", S390_CPUMF_CFDIAG, pmu);
	else
		printf("PMU %stype error %d\n", S390_CPUMF_CFDIAG, errno);

	rc = libcpumf_cpuset_fn(S390_CPUS_ONLINE, &set);
	if (rc == 0) {
		puts("Online CPUs:");
		for (int i = 0; i < CPU_SETSIZE; ++i)
			if (CPU_ISSET(i, &set))
				printf("%d ", i);
		putchar('\n');
	}
	rc = libcpumf_cpuset("0-7,9,11-12 ,15", &set);
	if (rc == 0) {
		puts("String CPUs:");
		for (int i = 0; i < CPU_SETSIZE; ++i)
			if (CPU_ISSET(i, &set))
				printf("%d ", i);
		putchar('\n');
	} else {
		printf("libcpumf_cpuset input invalid %d\n", errno);
	}

	printf("CPUMCF support %d\n", libcpumf_have_cpumcf());
	rc = libcpumf_cpumcf_info(&cfvn, &csvn, &auth);
	printf("libcpumf_cpumcf_info %d", rc);
	if (rc)
		printf(" cfvn %d csvn %d authorization %#x", cfvn, csvn, auth);
	putchar('\n');

	printf("CPUMSF support %d\n", libcpumf_have_cpumsf());
	rc = libcpumf_cpumsf_info(&min, &max, &speed, &cfvn, &csvn);
	printf("libcpumf_cpumsf_info %d", rc);
	if (rc)
		printf(" min %ld max %ld speed %#lx basic %d diag %d", min,
		       max, speed, cfvn, csvn);
	putchar('\n');

	printf("CPUMSF have sfb %d\n", libcpumf_have_sfb());
	rc = libcpumf_sfb_info(&sfb_min, &sfb_max);
	printf("libcpumf_sfb_info %d", rc);
	if (rc)
		printf(" sfb_min %lu sfb_max %lu", sfb_min, sfb_max);
	putchar('\n');

	printf("PAI crypto support %d\n", libcpumf_have_pai_crypto());

	rc = libcpumf_pmuname(10, &pmuname);
	if (rc) {
		printf("PMU type 10 PMU name lookup error %d\n", rc);
	} else {
		printf("PMU type 10 PMU name %s\n", pmuname);
		free(pmuname);
	}

	printf("PAI NNPA support %d\n", libcpumf_have_pai_nnpa());
	printf("PAI EXTENSION support %d\n", libcpumf_have_pai_ext());
	return EXIT_SUCCESS;
}