aboutsummaryrefslogtreecommitdiffstats
path: root/examples/vm_power_manager
diff options
context:
space:
mode:
Diffstat (limited to 'examples/vm_power_manager')
-rw-r--r--examples/vm_power_manager/channel_monitor.c12
-rw-r--r--examples/vm_power_manager/main.c15
-rw-r--r--examples/vm_power_manager/oob_monitor_x86.c23
-rw-r--r--examples/vm_power_manager/power_manager.c2
4 files changed, 37 insertions, 15 deletions
diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c
index 5da53154..b5b7c678 100644
--- a/examples/vm_power_manager/channel_monitor.c
+++ b/examples/vm_power_manager/channel_monitor.c
@@ -158,7 +158,8 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt)
if (ret)
return ret;
} else if (!strcmp(key, "name")) {
- strcpy(pkt->vm_name, json_string_value(value));
+ strlcpy(pkt->vm_name, json_string_value(value),
+ sizeof(pkt->vm_name));
} else if (!strcmp(key, "command")) {
char command[32];
snprintf(command, 32, "%s", json_string_value(value));
@@ -835,18 +836,13 @@ read_json_packet(struct channel_info *chan_info)
indent--;
if ((indent > 0) || (idx > 0))
idx++;
- if (indent == 0)
+ if (indent <= 0)
json_data[idx] = 0;
if (idx >= MAX_JSON_STRING_LEN-1)
break;
} while (indent > 0);
- if (indent > 0)
- /*
- * We've broken out of the read loop without getting
- * a closing brace, so throw away the data
- */
- json_data[idx] = 0;
+ json_data[idx] = '\0';
if (strlen(json_data) == 0)
continue;
diff --git a/examples/vm_power_manager/main.c b/examples/vm_power_manager/main.c
index 893bf4cd..5fa13fe6 100644
--- a/examples/vm_power_manager/main.c
+++ b/examples/vm_power_manager/main.c
@@ -31,9 +31,15 @@
#include "vm_power_cli.h"
#include "oob_monitor.h"
#include "parse.h"
+#ifdef RTE_LIBRTE_IXGBE_PMD
#include <rte_pmd_ixgbe.h>
+#endif
+#ifdef RTE_LIBRTE_I40E_PMD
#include <rte_pmd_i40e.h>
+#endif
+#ifdef RTE_LIBRTE_BNXT_PMD
#include <rte_pmd_bnxt.h>
+#endif
#define RX_RING_SIZE 1024
#define TX_RING_SIZE 1024
@@ -175,6 +181,7 @@ parse_args(int argc, char **argv)
if (cnt < 0) {
printf("Invalid core-list - [%s]\n",
optarg);
+ free(oob_enable);
break;
}
for (i = 0; i < ci->core_count; i++) {
@@ -369,14 +376,21 @@ main(int argc, char **argv)
for (w = 0; w < MAX_VFS; w++) {
eth.addr_bytes[5] = w + 0xf0;
+ ret = -ENOTSUP;
+#ifdef RTE_LIBRTE_IXGBE_PMD
ret = rte_pmd_ixgbe_set_vf_mac_addr(portid,
w, &eth);
+#endif
+#ifdef RTE_LIBRTE_I40E_PMD
if (ret == -ENOTSUP)
ret = rte_pmd_i40e_set_vf_mac_addr(
portid, w, &eth);
+#endif
+#ifdef RTE_LIBRTE_BNXT_PMD
if (ret == -ENOTSUP)
ret = rte_pmd_bnxt_set_vf_mac_addr(
portid, w, &eth);
+#endif
switch (ret) {
case 0:
@@ -390,7 +404,6 @@ main(int argc, char **argv)
break;
}
printf("\n");
- break;
}
}
}
diff --git a/examples/vm_power_manager/oob_monitor_x86.c b/examples/vm_power_manager/oob_monitor_x86.c
index 589c604e..ebd96b20 100644
--- a/examples/vm_power_manager/oob_monitor_x86.c
+++ b/examples/vm_power_manager/oob_monitor_x86.c
@@ -33,10 +33,10 @@ static float
apply_policy(int core)
{
struct core_info *ci;
- uint64_t counter;
+ uint64_t counter = 0;
uint64_t branches, branch_misses;
- uint32_t last_branches, last_branch_misses;
- int hits_diff, miss_diff;
+ uint64_t last_branches, last_branch_misses;
+ int64_t hits_diff, miss_diff;
float ratio;
int ret;
@@ -54,6 +54,7 @@ apply_policy(int core)
core);
branches = counter;
+ counter = 0;
ret = pread(ci->cd[core].msr_fd, &counter,
sizeof(counter), IA32_PERFCTR1);
if (ret < 0)
@@ -66,13 +67,25 @@ apply_policy(int core)
ci->cd[core].last_branches = branches;
ci->cd[core].last_branch_misses = branch_misses;
- hits_diff = (int)branches - (int)last_branches;
+ /*
+ * Intentional right shift to make MSB 0 to avoid
+ * possible signed overflow or truncation.
+ */
+ branches >>= 1;
+ last_branches >>= 1;
+ hits_diff = (int64_t)branches - (int64_t)last_branches;
if (hits_diff <= 0) {
/* Likely a counter overflow condition, skip this round */
return -1.0;
}
- miss_diff = (int)branch_misses - (int)last_branch_misses;
+ /*
+ * Intentional right shift to make MSB 0 to avoid
+ * possible signed overflow or truncation.
+ */
+ branch_misses >>= 1;
+ last_branch_misses >>= 1;
+ miss_diff = (int64_t)branch_misses - (int64_t)last_branch_misses;
if (miss_diff <= 0) {
/* Likely a counter overflow condition, skip this round */
return -1.0;
diff --git a/examples/vm_power_manager/power_manager.c b/examples/vm_power_manager/power_manager.c
index f9e8c0ab..318fb025 100644
--- a/examples/vm_power_manager/power_manager.c
+++ b/examples/vm_power_manager/power_manager.c
@@ -157,7 +157,7 @@ power_manager_get_current_frequency(unsigned core_num)
rte_spinlock_lock(&global_core_freq_info[core_num].power_sl);
index = rte_power_get_freq(core_num);
rte_spinlock_unlock(&global_core_freq_info[core_num].power_sl);
- if (index >= POWER_MGR_MAX_CPUS)
+ if (index >= RTE_MAX_LCORE_FREQS)
freq = 0;
else
freq = global_core_freq_info[core_num].freqs[index];