+write_binary_packet(void *buffer,
+ size_t buffer_len,
+ struct channel_info *chan_info)
+{
+ int ret;
+
+ if (buffer_len == 0 || buffer == NULL)
+ return -1;
+
+ if (chan_info->fd < 0) {
+ RTE_LOG(ERR, CHANNEL_MONITOR, "Channel is not connected\n");
+ return -1;
+ }
+
+ while (buffer_len > 0) {
+ ret = write(chan_info->fd, buffer, buffer_len);
+ if (ret == -1) {
+ if (errno == EINTR)
+ continue;
+ RTE_LOG(ERR, CHANNEL_MONITOR, "Write function failed due to %s.\n",
+ strerror(errno));
+ return -1;
+ }
+ buffer = (char *)buffer + ret;
+ buffer_len -= ret;
+ }
+ return 0;
+}
+
+static int
+send_freq(struct rte_power_channel_packet *pkt,
+ struct channel_info *chan_info,
+ bool freq_list)
+{
+ unsigned int vcore_id = pkt->resource_id;
+ struct rte_power_channel_packet_freq_list channel_pkt_freq_list;
+ struct vm_info info;
+
+ 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)