1 // SPDX-License-Identifier: GPL-2.0
7 #include "helpers/helpers.h"
8 #include "helpers/sysfs.h"
10 #if defined(__i386__) || defined(__x86_64__)
12 #include "cpupower_intern.h"
14 #define MSR_AMD_HWCR 0xc0010015
16 int cpufreq_has_boost_support(unsigned int cpu
, int *support
, int *active
,
19 struct cpupower_cpu_info cpu_info
;
21 unsigned long long val
;
23 *support
= *active
= *states
= 0;
25 ret
= get_cpu_info(&cpu_info
);
29 if (cpupower_cpu_info
.caps
& CPUPOWER_CAP_AMD_CBP
) {
32 /* AMD Family 0x17 does not utilize PCI D18F4 like prior
33 * families and has no fixed discrete boost states but
34 * has Hardware determined variable increments instead.
37 if (cpu_info
.family
== 0x17 || cpu_info
.family
== 0x18) {
38 if (!read_msr(cpu
, MSR_AMD_HWCR
, &val
)) {
39 if (!(val
& CPUPOWER_AMD_CPBDIS
))
43 ret
= amd_pci_get_num_boost_states(active
, states
);
47 } else if (cpupower_cpu_info
.caps
& CPUPOWER_CAP_INTEL_IDA
)
48 *support
= *active
= 1;
52 int cpupower_intel_get_perf_bias(unsigned int cpu
)
54 char linebuf
[MAX_LINE_LEN
];
55 char path
[SYSFS_PATH_MAX
];
59 if (!(cpupower_cpu_info
.caps
& CPUPOWER_CAP_PERF_BIAS
))
62 snprintf(path
, sizeof(path
), PATH_TO_CPU
"cpu%u/power/energy_perf_bias", cpu
);
64 if (cpupower_read_sysfs(path
, linebuf
, MAX_LINE_LEN
) == 0)
67 val
= strtol(linebuf
, &endp
, 0);
68 if (endp
== linebuf
|| errno
== ERANGE
)
74 int cpupower_intel_set_perf_bias(unsigned int cpu
, unsigned int val
)
76 char path
[SYSFS_PATH_MAX
];
79 if (!(cpupower_cpu_info
.caps
& CPUPOWER_CAP_PERF_BIAS
))
82 snprintf(path
, sizeof(path
), PATH_TO_CPU
"cpu%u/power/energy_perf_bias", cpu
);
83 snprintf(linebuf
, sizeof(linebuf
), "%d", val
);
85 if (cpupower_write_sysfs(path
, linebuf
, 3) <= 0)
91 #endif /* #if defined(__i386__) || defined(__x86_64__) */
95 * Gather the information of all online CPUs into bitmask struct
97 void get_cpustate(void)
101 bitmask_clearall(online_cpus
);
102 bitmask_clearall(offline_cpus
);
104 for (cpu
= bitmask_first(cpus_chosen
);
105 cpu
<= bitmask_last(cpus_chosen
); cpu
++) {
107 if (cpupower_is_cpu_online(cpu
) == 1)
108 bitmask_setbit(online_cpus
, cpu
);
110 bitmask_setbit(offline_cpus
, cpu
);
118 * Print the CPU numbers of all CPUs that are online currently
120 void print_online_cpus(void)
123 char *online_cpus_str
= NULL
;
125 str_len
= online_cpus
->size
* 5;
126 online_cpus_str
= (void *)malloc(sizeof(char) * str_len
);
128 if (!bitmask_isallclear(online_cpus
)) {
129 bitmask_displaylist(online_cpus_str
, str_len
, online_cpus
);
130 printf(_("Following CPUs are online:\n%s\n"), online_cpus_str
);
134 /* print_offline_cpus
136 * Print the CPU numbers of all CPUs that are offline currently
138 void print_offline_cpus(void)
141 char *offline_cpus_str
= NULL
;
143 str_len
= offline_cpus
->size
* 5;
144 offline_cpus_str
= (void *)malloc(sizeof(char) * str_len
);
146 if (!bitmask_isallclear(offline_cpus
)) {
147 bitmask_displaylist(offline_cpus_str
, str_len
, offline_cpus
);
148 printf(_("Following CPUs are offline:\n%s\n"), offline_cpus_str
);
149 printf(_("cpupower set operation was not performed on them\n"));