Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2014 Intel Corporation
3 : : */
4 : : #include <errno.h>
5 : : #include <string.h>
6 : :
7 : : #include <rte_log.h>
8 : :
9 : : #include "rte_power_guest_channel.h"
10 : : #include "guest_channel.h"
11 : : #include "power_common.h"
12 : : #include "kvm_vm.h"
13 : :
14 : : #define FD_PATH "/dev/virtio-ports/virtio.serial.port.poweragent"
15 : :
16 : : static struct rte_power_channel_packet pkt[RTE_MAX_LCORE];
17 : :
18 : : int
19 : 0 : power_kvm_vm_check_supported(void)
20 : : {
21 : 0 : return guest_channel_host_check_exists(FD_PATH);
22 : : }
23 : :
24 : : int
25 : 1 : power_kvm_vm_init(unsigned int lcore_id)
26 : : {
27 : 1 : pkt[lcore_id].command = RTE_POWER_CPU_POWER;
28 : 1 : pkt[lcore_id].resource_id = lcore_id;
29 : 1 : return guest_channel_host_connect(FD_PATH, lcore_id);
30 : : }
31 : :
32 : : int
33 : 0 : power_kvm_vm_exit(unsigned int lcore_id)
34 : : {
35 : 0 : guest_channel_host_disconnect(lcore_id);
36 : 0 : return 0;
37 : : }
38 : :
39 : : uint32_t
40 : 0 : power_kvm_vm_freqs(__rte_unused unsigned int lcore_id,
41 : : __rte_unused uint32_t *freqs,
42 : : __rte_unused uint32_t num)
43 : : {
44 : 0 : POWER_LOG(ERR, "rte_power_freqs is not implemented "
45 : : "for Virtual Machine Power Management");
46 : 0 : return -ENOTSUP;
47 : : }
48 : :
49 : : uint32_t
50 : 0 : power_kvm_vm_get_freq(__rte_unused unsigned int lcore_id)
51 : : {
52 : 0 : POWER_LOG(ERR, "rte_power_get_freq is not implemented "
53 : : "for Virtual Machine Power Management");
54 : 0 : return -ENOTSUP;
55 : : }
56 : :
57 : : int
58 : 0 : power_kvm_vm_set_freq(__rte_unused unsigned int lcore_id,
59 : : __rte_unused uint32_t index)
60 : : {
61 : 0 : POWER_LOG(ERR, "rte_power_set_freq is not implemented "
62 : : "for Virtual Machine Power Management");
63 : 0 : return -ENOTSUP;
64 : : }
65 : :
66 : : static inline int
67 : 0 : send_msg(unsigned int lcore_id, uint32_t scale_direction)
68 : : {
69 : : int ret;
70 : :
71 : 0 : pkt[lcore_id].unit = scale_direction;
72 : 0 : ret = guest_channel_send_msg(&pkt[lcore_id], lcore_id);
73 [ # # ]: 0 : if (ret == 0)
74 : : return 1;
75 [ # # ]: 0 : POWER_LOG(DEBUG, "Error sending message: %s",
76 : : ret > 0 ? strerror(ret) : "channel not connected");
77 : 0 : return -1;
78 : : }
79 : :
80 : : int
81 : 0 : power_kvm_vm_freq_up(unsigned int lcore_id)
82 : : {
83 : 0 : return send_msg(lcore_id, RTE_POWER_SCALE_UP);
84 : : }
85 : :
86 : : int
87 : 0 : power_kvm_vm_freq_down(unsigned int lcore_id)
88 : : {
89 : 0 : return send_msg(lcore_id, RTE_POWER_SCALE_DOWN);
90 : : }
91 : :
92 : : int
93 : 0 : power_kvm_vm_freq_max(unsigned int lcore_id)
94 : : {
95 : 0 : return send_msg(lcore_id, RTE_POWER_SCALE_MAX);
96 : : }
97 : :
98 : : int
99 : 0 : power_kvm_vm_freq_min(unsigned int lcore_id)
100 : : {
101 : 0 : return send_msg(lcore_id, RTE_POWER_SCALE_MIN);
102 : : }
103 : :
104 : : int
105 : 0 : power_kvm_vm_turbo_status(__rte_unused unsigned int lcore_id)
106 : : {
107 : 0 : POWER_LOG(ERR, "rte_power_turbo_status is not implemented for Virtual Machine Power Management");
108 : 0 : return -ENOTSUP;
109 : : }
110 : :
111 : : int
112 : 0 : power_kvm_vm_enable_turbo(unsigned int lcore_id)
113 : : {
114 : 0 : return send_msg(lcore_id, RTE_POWER_ENABLE_TURBO);
115 : : }
116 : :
117 : : int
118 : 0 : power_kvm_vm_disable_turbo(unsigned int lcore_id)
119 : : {
120 : 0 : return send_msg(lcore_id, RTE_POWER_DISABLE_TURBO);
121 : : }
122 : :
123 : : struct rte_power_core_capabilities;
124 : 0 : int power_kvm_vm_get_capabilities(__rte_unused unsigned int lcore_id,
125 : : __rte_unused struct rte_power_core_capabilities *caps)
126 : : {
127 : 0 : POWER_LOG(ERR, "rte_power_get_capabilities is not implemented for Virtual Machine Power Management");
128 : 0 : return -ENOTSUP;
129 : : }
130 : :
131 : : static struct rte_power_cpufreq_ops kvm_vm_ops = {
132 : : .name = "kvm-vm",
133 : : .init = power_kvm_vm_init,
134 : : .exit = power_kvm_vm_exit,
135 : : .check_env_support = power_kvm_vm_check_supported,
136 : : .get_avail_freqs = power_kvm_vm_freqs,
137 : : .get_freq = power_kvm_vm_get_freq,
138 : : .set_freq = power_kvm_vm_set_freq,
139 : : .freq_down = power_kvm_vm_freq_down,
140 : : .freq_up = power_kvm_vm_freq_up,
141 : : .freq_max = power_kvm_vm_freq_max,
142 : : .freq_min = power_kvm_vm_freq_min,
143 : : .turbo_status = power_kvm_vm_turbo_status,
144 : : .enable_turbo = power_kvm_vm_enable_turbo,
145 : : .disable_turbo = power_kvm_vm_disable_turbo,
146 : : .get_caps = power_kvm_vm_get_capabilities
147 : : };
148 : :
149 : 303 : RTE_POWER_REGISTER_CPUFREQ_OPS(kvm_vm_ops);
|