1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #include <rte_atomic.h>
8 #include "power_acpi_cpufreq.h"
9 #include "power_kvm_vm.h"
10 #include "power_common.h"
12 enum power_management_env global_default_env = PM_ENV_NOT_SET;
14 volatile uint32_t global_env_cfg_status = 0;
16 /* function pointers */
17 rte_power_freqs_t rte_power_freqs = NULL;
18 rte_power_get_freq_t rte_power_get_freq = NULL;
19 rte_power_set_freq_t rte_power_set_freq = NULL;
20 rte_power_freq_change_t rte_power_freq_up = NULL;
21 rte_power_freq_change_t rte_power_freq_down = NULL;
22 rte_power_freq_change_t rte_power_freq_max = NULL;
23 rte_power_freq_change_t rte_power_freq_min = NULL;
24 rte_power_freq_change_t rte_power_turbo_status;
25 rte_power_freq_change_t rte_power_freq_enable_turbo;
26 rte_power_freq_change_t rte_power_freq_disable_turbo;
29 rte_power_set_env(enum power_management_env env)
31 if (rte_atomic32_cmpset(&global_env_cfg_status, 0, 1) == 0) {
34 if (env == PM_ENV_ACPI_CPUFREQ) {
35 rte_power_freqs = power_acpi_cpufreq_freqs;
36 rte_power_get_freq = power_acpi_cpufreq_get_freq;
37 rte_power_set_freq = power_acpi_cpufreq_set_freq;
38 rte_power_freq_up = power_acpi_cpufreq_freq_up;
39 rte_power_freq_down = power_acpi_cpufreq_freq_down;
40 rte_power_freq_min = power_acpi_cpufreq_freq_min;
41 rte_power_freq_max = power_acpi_cpufreq_freq_max;
42 rte_power_turbo_status = power_acpi_turbo_status;
43 rte_power_freq_enable_turbo = power_acpi_enable_turbo;
44 rte_power_freq_disable_turbo = power_acpi_disable_turbo;
45 } else if (env == PM_ENV_KVM_VM) {
46 rte_power_freqs = power_kvm_vm_freqs;
47 rte_power_get_freq = power_kvm_vm_get_freq;
48 rte_power_set_freq = power_kvm_vm_set_freq;
49 rte_power_freq_up = power_kvm_vm_freq_up;
50 rte_power_freq_down = power_kvm_vm_freq_down;
51 rte_power_freq_min = power_kvm_vm_freq_min;
52 rte_power_freq_max = power_kvm_vm_freq_max;
53 rte_power_turbo_status = power_kvm_vm_turbo_status;
54 rte_power_freq_enable_turbo = power_kvm_vm_enable_turbo;
55 rte_power_freq_disable_turbo = power_kvm_vm_disable_turbo;
57 RTE_LOG(ERR, POWER, "Invalid Power Management Environment(%d) set\n",
59 rte_power_unset_env();
62 global_default_env = env;
68 rte_power_unset_env(void)
70 if (rte_atomic32_cmpset(&global_env_cfg_status, 1, 0) != 0)
71 global_default_env = PM_ENV_NOT_SET;
74 enum power_management_env
75 rte_power_get_env(void) {
76 return global_default_env;
80 rte_power_init(unsigned int lcore_id)
84 if (global_default_env == PM_ENV_ACPI_CPUFREQ) {
85 return power_acpi_cpufreq_init(lcore_id);
87 if (global_default_env == PM_ENV_KVM_VM) {
88 return power_kvm_vm_init(lcore_id);
90 /* Auto detect Environment */
91 RTE_LOG(INFO, POWER, "Attempting to initialise ACPI cpufreq power "
93 ret = power_acpi_cpufreq_init(lcore_id);
95 rte_power_set_env(PM_ENV_ACPI_CPUFREQ);
99 RTE_LOG(INFO, POWER, "Attempting to initialise VM power management...\n");
100 ret = power_kvm_vm_init(lcore_id);
102 rte_power_set_env(PM_ENV_KVM_VM);
105 RTE_LOG(ERR, POWER, "Unable to set Power Management Environment for lcore "
112 rte_power_exit(unsigned int lcore_id)
114 if (global_default_env == PM_ENV_ACPI_CPUFREQ)
115 return power_acpi_cpufreq_exit(lcore_id);
116 if (global_default_env == PM_ENV_KVM_VM)
117 return power_kvm_vm_exit(lcore_id);
119 RTE_LOG(ERR, POWER, "Environment has not been set, unable to exit "