X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fvm_power_manager%2Fchannel_monitor.c;h=74df0fe20eeb52dca449524bca48d18aee6bd1a1;hb=998853bf12f8c6390ff8d0190e1151872c37266f;hp=4189bbf1bb4bf4abdc71c2fc8cae4f453c44758e;hpb=b6b22982f58da6d711a3958979cda702d8fb10f2;p=dpdk.git diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c index 4189bbf1bb..74df0fe20e 100644 --- a/examples/vm_power_manager/channel_monitor.c +++ b/examples/vm_power_manager/channel_monitor.c @@ -21,6 +21,7 @@ #else #pragma message "Jansson dev libs unavailable, not including JSON parsing" #endif +#include #include #include #include @@ -161,7 +162,7 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt) strcpy(pkt->vm_name, json_string_value(value)); } else if (!strcmp(key, "command")) { char command[32]; - snprintf(command, 32, "%s", json_string_value(value)); + strlcpy(command, json_string_value(value), 32); if (!strcmp(command, "power")) { pkt->command = CPU_POWER; } else if (!strcmp(command, "create")) { @@ -175,7 +176,7 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt) } } else if (!strcmp(key, "policy_type")) { char command[32]; - snprintf(command, 32, "%s", json_string_value(value)); + strlcpy(command, json_string_value(value), 32); if (!strcmp(command, "TIME")) { pkt->policy_to_use = TIME; } else if (!strcmp(command, "TRAFFIC")) { @@ -191,7 +192,7 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt) } } else if (!strcmp(key, "workload")) { char command[32]; - snprintf(command, 32, "%s", json_string_value(value)); + strlcpy(command, json_string_value(value), 32); if (!strcmp(command, "HIGH")) { pkt->workload = HIGH; } else if (!strcmp(command, "MEDIUM")) { @@ -237,8 +238,9 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt) for (i = 0; i < size; i++) { char mac[32]; - snprintf(mac, 32, "%s", json_string_value( - json_array_get(value, i))); + strlcpy(mac, + json_string_value(json_array_get(value, i)), + 32); set_policy_mac(pkt, i, mac); } pkt->nb_mac_to_monitor = size; @@ -250,7 +252,7 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt) (uint32_t)json_integer_value(value); } else if (!strcmp(key, "unit")) { char unit[32]; - snprintf(unit, 32, "%s", json_string_value(value)); + strlcpy(unit, json_string_value(value), 32); if (!strcmp(unit, "SCALE_UP")) { pkt->unit = CPU_POWER_SCALE_UP; } else if (!strcmp(unit, "SCALE_DOWN")) { @@ -356,7 +358,6 @@ get_pcpu_to_control(struct policy *pol) /* Convert vcpu to pcpu. */ struct vm_info info; int pcpu, count; - uint64_t mask_u64b; struct core_info *ci; ci = get_core_info(); @@ -377,13 +378,8 @@ get_pcpu_to_control(struct policy *pol) */ get_info_vm(pol->pkt.vm_name, &info); for (count = 0; count < pol->pkt.num_vcpu; count++) { - mask_u64b = - info.pcpu_mask[pol->pkt.vcpu_to_control[count]]; - for (pcpu = 0; mask_u64b; - mask_u64b &= ~(1ULL << pcpu++)) { - if ((mask_u64b >> pcpu) & 1) - pcpu_monitor(pol, ci, pcpu, count); - } + pcpu = info.pcpu_map[pol->pkt.vcpu_to_control[count]]; + pcpu_monitor(pol, ci, pcpu, count); } } else { /* @@ -441,7 +437,7 @@ update_policy(struct channel_packet *pkt) /* Copy the contents of *pkt into the policy.pkt */ policies[i].pkt = *pkt; get_pcpu_to_control(&policies[i]); - if (get_pfid(&policies[i]) == -1) { + if (get_pfid(&policies[i]) < 0) { updated = 1; break; } @@ -455,7 +451,7 @@ update_policy(struct channel_packet *pkt) if (policies[i].enabled == 0) { policies[i].pkt = *pkt; get_pcpu_to_control(&policies[i]); - if (get_pfid(&policies[i]) == -1) + if (get_pfid(&policies[i]) < 0) break; core_share_status(i); policies[i].enabled = 1; @@ -636,7 +632,7 @@ apply_policy(struct policy *pol) static int process_request(struct channel_packet *pkt, struct channel_info *chan_info) { - uint64_t core_mask; + int ret; if (chan_info == NULL) return -1; @@ -646,41 +642,37 @@ process_request(struct channel_packet *pkt, struct channel_info *chan_info) return -1; if (pkt->command == CPU_POWER) { - core_mask = get_pcpus_mask(chan_info, pkt->resource_id); - if (core_mask == 0) { - /* - * Core mask will be 0 in the case where - * hypervisor is not available so we're working in - * the host, so use the core as the mask. - */ - core_mask = 1ULL << pkt->resource_id; - } - if (__builtin_popcountll(core_mask) == 1) { + unsigned int core_num; + + if (pkt->core_type == CORE_TYPE_VIRTUAL) + core_num = get_pcpu(chan_info, pkt->resource_id); + else + core_num = pkt->resource_id; - unsigned core_num = __builtin_ffsll(core_mask) - 1; + RTE_LOG(DEBUG, CHANNEL_MONITOR, "Processing requested cmd for cpu:%d\n", + core_num); - switch (pkt->unit) { - case(CPU_POWER_SCALE_MIN): - power_manager_scale_core_min(core_num); + 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); + 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); + 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); + 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); + 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); + case(CPU_POWER_DISABLE_TURBO): + power_manager_disable_turbo_core(core_num); + break; + default: break; - default: - break; - } } } @@ -692,9 +684,13 @@ process_request(struct channel_packet *pkt, struct channel_info *chan_info) } if (pkt->command == PKT_POLICY_REMOVE) { - RTE_LOG(INFO, CHANNEL_MONITOR, - "Removing policy %s\n", pkt->vm_name); - remove_policy(pkt); + ret = remove_policy(pkt); + if (ret == 0) + RTE_LOG(INFO, CHANNEL_MONITOR, + "Removed policy %s\n", pkt->vm_name); + else + RTE_LOG(INFO, CHANNEL_MONITOR, + "Policy %s does not exist\n", pkt->vm_name); } /* @@ -771,7 +767,7 @@ read_binary_packet(struct channel_info *chan_info) buffer, buffer_len); if (n_bytes == buffer_len) break; - if (n_bytes == -1) { + if (n_bytes < 0) { err = errno; RTE_LOG(DEBUG, CHANNEL_MONITOR, "Received error on "