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;
55 rte_power_set_env(enum power_management_env env)
57 if (rte_atomic32_cmpset(&global_env_cfg_status, 0, 1) == 0) {
60 if (env == PM_ENV_ACPI_CPUFREQ) {
61 rte_power_freqs = rte_power_acpi_cpufreq_freqs;
62 rte_power_get_freq = rte_power_acpi_cpufreq_get_freq;
63 rte_power_set_freq = rte_power_acpi_cpufreq_set_freq;
64 rte_power_freq_up = rte_power_acpi_cpufreq_freq_up;
65 rte_power_freq_down = rte_power_acpi_cpufreq_freq_down;
66 rte_power_freq_min = rte_power_acpi_cpufreq_freq_min;
67 rte_power_freq_max = rte_power_acpi_cpufreq_freq_max;
68 } else if (env == PM_ENV_KVM_VM) {
69 rte_power_freqs = rte_power_kvm_vm_freqs;
70 rte_power_get_freq = rte_power_kvm_vm_get_freq;
71 rte_power_set_freq = rte_power_kvm_vm_set_freq;
72 rte_power_freq_up = rte_power_kvm_vm_freq_up;
73 rte_power_freq_down = rte_power_kvm_vm_freq_down;
74 rte_power_freq_min = rte_power_kvm_vm_freq_min;
75 rte_power_freq_max = rte_power_kvm_vm_freq_max;
77 RTE_LOG(ERR, POWER, "Invalid Power Management Environment(%d) set\n",
79 rte_power_unset_env();
82 global_default_env = env;
88 rte_power_unset_env(void)
90 if (rte_atomic32_cmpset(&global_env_cfg_status, 1, 0) != 0)
91 global_default_env = PM_ENV_NOT_SET;
94 enum power_management_env
95 rte_power_get_env(void) {
96 return global_default_env;
100 rte_power_init(unsigned lcore_id)
104 if (global_default_env == PM_ENV_ACPI_CPUFREQ) {
105 return rte_power_acpi_cpufreq_init(lcore_id);
107 if (global_default_env == PM_ENV_KVM_VM) {
108 return rte_power_kvm_vm_init(lcore_id);
110 /* Auto detect Environment */
111 RTE_LOG(INFO, POWER, "Attempting to initialise ACPI cpufreq power "
113 ret = rte_power_acpi_cpufreq_init(lcore_id);
115 rte_power_set_env(PM_ENV_ACPI_CPUFREQ);
119 RTE_LOG(INFO, POWER, "Attempting to initialise VM power management...\n");
120 ret = rte_power_kvm_vm_init(lcore_id);
122 rte_power_set_env(PM_ENV_KVM_VM);
125 RTE_LOG(ERR, POWER, "Unable to set Power Management Environment for lcore "
132 rte_power_exit(unsigned lcore_id)
134 if (global_default_env == PM_ENV_ACPI_CPUFREQ)
135 return rte_power_acpi_cpufreq_exit(lcore_id);
136 if (global_default_env == PM_ENV_KVM_VM)
137 return rte_power_kvm_vm_exit(lcore_id);
139 RTE_LOG(ERR, POWER, "Environment has not been set, unable to exit "