arm64: perf: Prevent wraparound during overflow
[linux-2.6-microblaze.git] / arch / arm64 / kernel / perf_event.c
index aa29ecb..25a5308 100644 (file)
@@ -169,8 +169,14 @@ armpmu_event_set_period(struct perf_event *event,
                ret = 1;
        }
 
-       if (left > (s64)armpmu->max_period)
-               left = armpmu->max_period;
+       /*
+        * Limit the maximum period to prevent the counter value
+        * from overtaking the one we are about to program. In
+        * effect we are reducing max_period to account for
+        * interrupt latency (and we are being very conservative).
+        */
+       if (left > (armpmu->max_period >> 1))
+               left = armpmu->max_period >> 1;
 
        local64_set(&hwc->prev_count, (u64)-left);