|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2 | | -#if defined(__i386__) || defined(__x86_64__) |
| 2 | + |
| 3 | +#include <stdio.h> |
| 4 | +#include <stdlib.h> |
3 | 5 |
|
4 | 6 | #include "helpers/helpers.h" |
5 | 7 |
|
| 8 | +#if defined(__i386__) || defined(__x86_64__) |
| 9 | + |
6 | 10 | #define MSR_AMD_HWCR 0xc0010015 |
7 | 11 |
|
8 | 12 | int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active, |
@@ -41,3 +45,63 @@ int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active, |
41 | 45 | return 0; |
42 | 46 | } |
43 | 47 | #endif /* #if defined(__i386__) || defined(__x86_64__) */ |
| 48 | + |
| 49 | +/* get_cpustate |
| 50 | + * |
| 51 | + * Gather the information of all online CPUs into bitmask struct |
| 52 | + */ |
| 53 | +void get_cpustate(void) |
| 54 | +{ |
| 55 | + unsigned int cpu = 0; |
| 56 | + |
| 57 | + bitmask_clearall(online_cpus); |
| 58 | + bitmask_clearall(offline_cpus); |
| 59 | + |
| 60 | + for (cpu = bitmask_first(cpus_chosen); |
| 61 | + cpu <= bitmask_last(cpus_chosen); cpu++) { |
| 62 | + |
| 63 | + if (cpupower_is_cpu_online(cpu) == 1) |
| 64 | + bitmask_setbit(online_cpus, cpu); |
| 65 | + else |
| 66 | + bitmask_setbit(offline_cpus, cpu); |
| 67 | + |
| 68 | + continue; |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +/* print_online_cpus |
| 73 | + * |
| 74 | + * Print the CPU numbers of all CPUs that are online currently |
| 75 | + */ |
| 76 | +void print_online_cpus(void) |
| 77 | +{ |
| 78 | + int str_len = 0; |
| 79 | + char *online_cpus_str = NULL; |
| 80 | + |
| 81 | + str_len = online_cpus->size * 5; |
| 82 | + online_cpus_str = (void *)malloc(sizeof(char) * str_len); |
| 83 | + |
| 84 | + if (!bitmask_isallclear(online_cpus)) { |
| 85 | + bitmask_displaylist(online_cpus_str, str_len, online_cpus); |
| 86 | + printf(_("Following CPUs are online:\n%s\n"), online_cpus_str); |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +/* print_offline_cpus |
| 91 | + * |
| 92 | + * Print the CPU numbers of all CPUs that are offline currently |
| 93 | + */ |
| 94 | +void print_offline_cpus(void) |
| 95 | +{ |
| 96 | + int str_len = 0; |
| 97 | + char *offline_cpus_str = NULL; |
| 98 | + |
| 99 | + str_len = offline_cpus->size * 5; |
| 100 | + offline_cpus_str = (void *)malloc(sizeof(char) * str_len); |
| 101 | + |
| 102 | + if (!bitmask_isallclear(offline_cpus)) { |
| 103 | + bitmask_displaylist(offline_cpus_str, str_len, offline_cpus); |
| 104 | + printf(_("Following CPUs are offline:\n%s\n"), offline_cpus_str); |
| 105 | + printf(_("cpupower set operation was not performed on them\n")); |
| 106 | + } |
| 107 | +} |
0 commit comments