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.
38 #include "guest_channel.h"
39 #include "channel_commands.h"
40 #include "rte_power_kvm_vm.h"
41 #include "rte_power_common.h"
43 #define FD_PATH "/dev/virtio-ports/virtio.serial.port.poweragent"
45 static struct channel_packet pkt[CHANNEL_CMDS_MAX_VM_CHANNELS];
49 rte_power_kvm_vm_init(unsigned lcore_id)
51 if (lcore_id >= CHANNEL_CMDS_MAX_VM_CHANNELS) {
52 RTE_LOG(ERR, POWER, "Core(%u) is out of range 0...%d\n",
53 lcore_id, CHANNEL_CMDS_MAX_VM_CHANNELS-1);
56 pkt[lcore_id].command = CPU_POWER;
57 pkt[lcore_id].resource_id = lcore_id;
58 return guest_channel_host_connect(FD_PATH, lcore_id);
62 rte_power_kvm_vm_exit(unsigned lcore_id)
64 guest_channel_host_disconnect(lcore_id);
69 rte_power_kvm_vm_freqs(__attribute__((unused)) unsigned lcore_id,
70 __attribute__((unused)) uint32_t *freqs,
71 __attribute__((unused)) uint32_t num)
73 RTE_LOG(ERR, POWER, "rte_power_freqs is not implemented "
74 "for Virtual Machine Power Management\n");
79 rte_power_kvm_vm_get_freq(__attribute__((unused)) unsigned lcore_id)
81 RTE_LOG(ERR, POWER, "rte_power_get_freq is not implemented "
82 "for Virtual Machine Power Management\n");
87 rte_power_kvm_vm_set_freq(__attribute__((unused)) unsigned lcore_id,
88 __attribute__((unused)) uint32_t index)
90 RTE_LOG(ERR, POWER, "rte_power_set_freq is not implemented "
91 "for Virtual Machine Power Management\n");
96 send_msg(unsigned lcore_id, uint32_t scale_direction)
100 if (lcore_id >= CHANNEL_CMDS_MAX_VM_CHANNELS) {
101 RTE_LOG(ERR, POWER, "Core(%u) is out of range 0...%d\n",
102 lcore_id, CHANNEL_CMDS_MAX_VM_CHANNELS-1);
105 pkt[lcore_id].unit = scale_direction;
106 ret = guest_channel_send_msg(&pkt[lcore_id], lcore_id);
109 RTE_LOG(DEBUG, POWER, "Error sending message: %s\n",
110 ret > 0 ? strerror(ret) : "channel not connected");
115 rte_power_kvm_vm_freq_up(unsigned lcore_id)
117 return send_msg(lcore_id, CPU_POWER_SCALE_UP);
121 rte_power_kvm_vm_freq_down(unsigned lcore_id)
123 return send_msg(lcore_id, CPU_POWER_SCALE_DOWN);
127 rte_power_kvm_vm_freq_max(unsigned lcore_id)
129 return send_msg(lcore_id, CPU_POWER_SCALE_MAX);
133 rte_power_kvm_vm_freq_min(unsigned lcore_id)
135 return send_msg(lcore_id, CPU_POWER_SCALE_MIN);