net: adjust L2 length on soft VLAN insertion
[dpdk.git] / examples / vm_power_manager / oob_monitor_x86.c
index 62d503c..ebd96b2 100644 (file)
@@ -22,7 +22,6 @@ void branch_monitor_exit(void)
 /* Number of microseconds between each poll */
 #define INTERVAL 100
 #define PRINT_LOOP_COUNT (1000000/INTERVAL)
-#define RATIO_THRESHOLD 0.03
 #define IA32_PERFEVTSEL0 0x186
 #define IA32_PERFEVTSEL1 0x187
 #define IA32_PERFCTR0 0xc1
@@ -34,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;
 
@@ -55,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)
@@ -67,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;
@@ -89,7 +101,7 @@ apply_policy(int core)
 
        ratio = (float)miss_diff * (float)100 / (float)hits_diff;
 
-       if (ratio < RATIO_THRESHOLD)
+       if (ratio < ci->branch_ratio_threshold)
                power_manager_scale_core_min(core);
        else
                power_manager_scale_core_max(core);