1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
9 #include "guest_channel.h"
10 #include "channel_commands.h"
11 #include "power_kvm_vm.h"
12 #include "power_common.h"
14 #define FD_PATH "/dev/virtio-ports/virtio.serial.port.poweragent"
16 static struct channel_packet pkt[CHANNEL_CMDS_MAX_VM_CHANNELS];
20 power_kvm_vm_init(unsigned int lcore_id)
22 if (lcore_id >= CHANNEL_CMDS_MAX_VM_CHANNELS) {
23 RTE_LOG(ERR, POWER, "Core(%u) is out of range 0...%d\n",
24 lcore_id, CHANNEL_CMDS_MAX_VM_CHANNELS-1);
27 pkt[lcore_id].command = CPU_POWER;
28 pkt[lcore_id].resource_id = lcore_id;
29 return guest_channel_host_connect(FD_PATH, lcore_id);
33 power_kvm_vm_exit(unsigned int lcore_id)
35 guest_channel_host_disconnect(lcore_id);
40 power_kvm_vm_freqs(__attribute__((unused)) unsigned int lcore_id,
41 __attribute__((unused)) uint32_t *freqs,
42 __attribute__((unused)) uint32_t num)
44 RTE_LOG(ERR, POWER, "rte_power_freqs is not implemented "
45 "for Virtual Machine Power Management\n");
50 power_kvm_vm_get_freq(__attribute__((unused)) unsigned int lcore_id)
52 RTE_LOG(ERR, POWER, "rte_power_get_freq is not implemented "
53 "for Virtual Machine Power Management\n");
58 power_kvm_vm_set_freq(__attribute__((unused)) unsigned int lcore_id,
59 __attribute__((unused)) uint32_t index)
61 RTE_LOG(ERR, POWER, "rte_power_set_freq is not implemented "
62 "for Virtual Machine Power Management\n");
67 send_msg(unsigned int lcore_id, uint32_t scale_direction)
71 if (lcore_id >= CHANNEL_CMDS_MAX_VM_CHANNELS) {
72 RTE_LOG(ERR, POWER, "Core(%u) is out of range 0...%d\n",
73 lcore_id, CHANNEL_CMDS_MAX_VM_CHANNELS-1);
76 pkt[lcore_id].unit = scale_direction;
77 ret = guest_channel_send_msg(&pkt[lcore_id], lcore_id);
80 RTE_LOG(DEBUG, POWER, "Error sending message: %s\n",
81 ret > 0 ? strerror(ret) : "channel not connected");
86 power_kvm_vm_freq_up(unsigned int lcore_id)
88 return send_msg(lcore_id, CPU_POWER_SCALE_UP);
92 power_kvm_vm_freq_down(unsigned int lcore_id)
94 return send_msg(lcore_id, CPU_POWER_SCALE_DOWN);
98 power_kvm_vm_freq_max(unsigned int lcore_id)
100 return send_msg(lcore_id, CPU_POWER_SCALE_MAX);
104 power_kvm_vm_freq_min(unsigned int lcore_id)
106 return send_msg(lcore_id, CPU_POWER_SCALE_MIN);
110 power_kvm_vm_turbo_status(__attribute__((unused)) unsigned int lcore_id)
112 RTE_LOG(ERR, POWER, "rte_power_turbo_status is not implemented for Virtual Machine Power Management\n");
117 power_kvm_vm_enable_turbo(unsigned int lcore_id)
119 return send_msg(lcore_id, CPU_POWER_ENABLE_TURBO);
123 power_kvm_vm_disable_turbo(unsigned int lcore_id)
125 return send_msg(lcore_id, CPU_POWER_DISABLE_TURBO);