- switch (pkt->unit) {
- case(CPU_POWER_SCALE_MIN):
- power_manager_scale_core_min(core_num);
- break;
- case(CPU_POWER_SCALE_MAX):
- power_manager_scale_core_max(core_num);
- break;
- case(CPU_POWER_SCALE_DOWN):
- power_manager_scale_core_down(core_num);
- break;
- case(CPU_POWER_SCALE_UP):
- power_manager_scale_core_up(core_num);
- break;
- case(CPU_POWER_ENABLE_TURBO):
- power_manager_enable_turbo_core(core_num);
- break;
- case(CPU_POWER_DISABLE_TURBO):
- power_manager_disable_turbo_core(core_num);
+ if (get_info_vm(pkt->vm_name, &info) != 0)
+ return -1;
+
+ if (!freq_list && vcore_id >= RTE_POWER_MAX_VCPU_PER_VM)
+ return -1;
+
+ if (!info.allow_query)
+ return -1;
+
+ channel_pkt_freq_list.command = RTE_POWER_FREQ_LIST;
+ channel_pkt_freq_list.num_vcpu = info.num_vcpus;
+
+ if (freq_list) {
+ unsigned int i;
+ for (i = 0; i < info.num_vcpus; i++)
+ channel_pkt_freq_list.freq_list[i] =
+ power_manager_get_current_frequency(info.pcpu_map[i]);
+ } else {
+ channel_pkt_freq_list.freq_list[vcore_id] =
+ power_manager_get_current_frequency(info.pcpu_map[vcore_id]);
+ }
+
+ return write_binary_packet(&channel_pkt_freq_list,
+ sizeof(channel_pkt_freq_list),
+ chan_info);
+}
+
+static int
+send_capabilities(struct rte_power_channel_packet *pkt,
+ struct channel_info *chan_info,
+ bool list_requested)
+{
+ unsigned int vcore_id = pkt->resource_id;
+ struct rte_power_channel_packet_caps_list channel_pkt_caps_list;
+ struct vm_info info;
+ struct rte_power_core_capabilities caps;
+ int ret;
+
+ if (get_info_vm(pkt->vm_name, &info) != 0)
+ return -1;
+
+ if (!list_requested && vcore_id >= RTE_POWER_MAX_VCPU_PER_VM)
+ return -1;
+
+ if (!info.allow_query)
+ return -1;
+
+ channel_pkt_caps_list.command = RTE_POWER_CAPS_LIST;
+ channel_pkt_caps_list.num_vcpu = info.num_vcpus;
+
+ if (list_requested) {
+ unsigned int i;
+ for (i = 0; i < info.num_vcpus; i++) {
+ ret = rte_power_get_capabilities(info.pcpu_map[i],
+ &caps);
+ if (ret == 0) {
+ channel_pkt_caps_list.turbo[i] =
+ caps.turbo;
+ channel_pkt_caps_list.priority[i] =
+ caps.priority;
+ } else
+ return -1;
+
+ }
+ } else {
+ ret = rte_power_get_capabilities(info.pcpu_map[vcore_id],
+ &caps);
+ if (ret == 0) {
+ channel_pkt_caps_list.turbo[vcore_id] =
+ caps.turbo;
+ channel_pkt_caps_list.priority[vcore_id] =
+ caps.priority;
+ } else
+ return -1;
+ }
+
+ return write_binary_packet(&channel_pkt_caps_list,
+ sizeof(channel_pkt_caps_list),
+ chan_info);
+}
+
+static int
+send_ack_for_received_cmd(struct rte_power_channel_packet *pkt,
+ struct channel_info *chan_info,
+ uint32_t command)
+{
+ pkt->command = command;
+ return write_binary_packet(pkt,
+ sizeof(*pkt),
+ chan_info);
+}
+
+static int
+process_request(struct rte_power_channel_packet *pkt,
+ struct channel_info *chan_info)
+{
+ int ret;
+
+ if (chan_info == NULL)
+ return -1;
+
+ uint32_t channel_connected = CHANNEL_MGR_CHANNEL_CONNECTED;
+ if (__atomic_compare_exchange_n(&(chan_info->status), &channel_connected,
+ CHANNEL_MGR_CHANNEL_PROCESSING, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED) == 0)
+ return -1;
+
+ if (pkt->command == RTE_POWER_CPU_POWER) {
+ unsigned int core_num;
+
+ if (pkt->core_type == RTE_POWER_CORE_TYPE_VIRTUAL)
+ core_num = get_pcpu(chan_info, pkt->resource_id);
+ else
+ core_num = pkt->resource_id;
+
+ RTE_LOG(DEBUG, CHANNEL_MONITOR, "Processing requested cmd for cpu:%d\n",
+ core_num);
+
+ int scale_res;
+ bool valid_unit = true;
+
+ switch (pkt->unit) {
+ case(RTE_POWER_SCALE_MIN):
+ scale_res = power_manager_scale_core_min(core_num);