4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <rte_atomic.h>
36 #include "rte_power.h"
37 #include "rte_power_acpi_cpufreq.h"
38 #include "rte_power_kvm_vm.h"
39 #include "rte_power_common.h"
41 enum power_management_env global_default_env = PM_ENV_NOT_SET;
43 volatile uint32_t global_env_cfg_status = 0;
45 /* function pointers */
46 rte_power_freqs_t rte_power_freqs = NULL;
47 rte_power_get_freq_t rte_power_get_freq = NULL;
48 rte_power_set_freq_t rte_power_set_freq = NULL;
49 rte_power_freq_change_t rte_power_freq_up = NULL;
50 rte_power_freq_change_t rte_power_freq_down = NULL;
51 rte_power_freq_change_t rte_power_freq_max = NULL;
52 rte_power_freq_change_t rte_power_freq_min = NULL;
53 rte_power_freq_change_t rte_power_turbo_status;
54 rte_power_freq_change_t rte_power_freq_enable_turbo;
55 rte_power_freq_change_t rte_power_freq_disable_turbo;
58 rte_power_set_env(enum power_management_env env)
60 if (rte_atomic32_cmpset(&global_env_cfg_status, 0, 1) == 0) {
63 if (env == PM_ENV_ACPI_CPUFREQ) {
64 rte_power_freqs = rte_power_acpi_cpufreq_freqs;
65 rte_power_get_freq = rte_power_acpi_cpufreq_get_freq;
66 rte_power_set_freq = rte_power_acpi_cpufreq_set_freq;
67 rte_power_freq_up = rte_power_acpi_cpufreq_freq_up;
68 rte_power_freq_down = rte_power_acpi_cpufreq_freq_down;
69 rte_power_freq_min = rte_power_acpi_cpufreq_freq_min;
70 rte_power_freq_max = rte_power_acpi_cpufreq_freq_max;
71 rte_power_turbo_status = rte_power_acpi_turbo_status;
72 rte_power_freq_enable_turbo = rte_power_acpi_enable_turbo;
73 rte_power_freq_disable_turbo = rte_power_acpi_disable_turbo;
74 } else if (env == PM_ENV_KVM_VM) {
75 rte_power_freqs = rte_power_kvm_vm_freqs;
76 rte_power_get_freq = rte_power_kvm_vm_get_freq;
77 rte_power_set_freq = rte_power_kvm_vm_set_freq;
78 rte_power_freq_up = rte_power_kvm_vm_freq_up;
79 rte_power_freq_down = rte_power_kvm_vm_freq_down;
80 rte_power_freq_min = rte_power_kvm_vm_freq_min;
81 rte_power_freq_max = rte_power_kvm_vm_freq_max;
82 rte_power_turbo_status = rte_power_kvm_vm_turbo_status;
83 rte_power_freq_enable_turbo = rte_power_kvm_vm_enable_turbo;
84 rte_power_freq_disable_turbo = rte_power_kvm_vm_disable_turbo;
86 RTE_LOG(ERR, POWER, "Invalid Power Management Environment(%d) set\n",
88 rte_power_unset_env();
91 global_default_env = env;
97 rte_power_unset_env(void)
99 if (rte_atomic32_cmpset(&global_env_cfg_status, 1, 0) != 0)
100 global_default_env = PM_ENV_NOT_SET;
103 enum power_management_env
104 rte_power_get_env(void) {
105 return global_default_env;
109 rte_power_init(unsigned lcore_id)
113 if (global_default_env == PM_ENV_ACPI_CPUFREQ) {
114 return rte_power_acpi_cpufreq_init(lcore_id);
116 if (global_default_env == PM_ENV_KVM_VM) {
117 return rte_power_kvm_vm_init(lcore_id);
119 /* Auto detect Environment */
120 RTE_LOG(INFO, POWER, "Attempting to initialise ACPI cpufreq power "
122 ret = rte_power_acpi_cpufreq_init(lcore_id);
124 rte_power_set_env(PM_ENV_ACPI_CPUFREQ);
128 RTE_LOG(INFO, POWER, "Attempting to initialise VM power management...\n");
129 ret = rte_power_kvm_vm_init(lcore_id);
131 rte_power_set_env(PM_ENV_KVM_VM);
134 RTE_LOG(ERR, POWER, "Unable to set Power Management Environment for lcore "
141 rte_power_exit(unsigned lcore_id)
143 if (global_default_env == PM_ENV_ACPI_CPUFREQ)
144 return rte_power_acpi_cpufreq_exit(lcore_id);
145 if (global_default_env == PM_ENV_KVM_VM)
146 return rte_power_kvm_vm_exit(lcore_id);
148 RTE_LOG(ERR, POWER, "Environment has not been set, unable to exit "