44 lines
1.4 KiB
Diff
44 lines
1.4 KiB
Diff
From 638b8b2fe4163a85815424549a629a6c9b113d1d Mon Sep 17 00:00:00 2001
|
|
From: zhongxuan <zhongxuan2@huawei.com>
|
|
Date: Fri, 6 Sep 2024 18:42:49 +0800
|
|
Subject: [PATCH] fix timehopping in freq_ctr_total
|
|
|
|
---
|
|
src/freq_ctr.c | 10 ++++++++--
|
|
1 file changed, 8 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/freq_ctr.c b/src/freq_ctr.c
|
|
index 54aa78f..66397a0 100644
|
|
--- a/src/freq_ctr.c
|
|
+++ b/src/freq_ctr.c
|
|
@@ -28,6 +28,7 @@ ullong freq_ctr_total(const struct freq_ctr *ctr, uint period, int pend)
|
|
{
|
|
ullong curr, past, old_curr, old_past;
|
|
uint tick, old_tick;
|
|
+ uint toofar = 0;
|
|
int remain;
|
|
|
|
tick = HA_ATOMIC_LOAD(&ctr->curr_tick);
|
|
@@ -75,13 +76,18 @@ ullong freq_ctr_total(const struct freq_ctr *ctr, uint period, int pend)
|
|
__ha_cpu_relax();
|
|
};
|
|
|
|
+ if (((tick + 2 * period) < HA_ATOMIC_LOAD(&global_now_ms)) || ((HA_ATOMIC_LOAD(&global_now_ms) + 2 * period) < tick))
|
|
+ toofar = 2;
|
|
+ else if (((tick + period) < HA_ATOMIC_LOAD(&global_now_ms)) || ((HA_ATOMIC_LOAD(&global_now_ms) + period) < tick))
|
|
+ toofar = 1;
|
|
+
|
|
remain = tick + period - HA_ATOMIC_LOAD(&global_now_ms);
|
|
- if (unlikely(remain < 0)) {
|
|
+ if (unlikely(remain < 0 || toofar)) {
|
|
/* We're past the first period, check if we can still report a
|
|
* part of last period or if we're too far away.
|
|
*/
|
|
remain += period;
|
|
- past = (remain >= 0) ? curr : 0;
|
|
+ past = (toofar != 2) ? curr : 0;
|
|
curr = 0;
|
|
}
|
|
|
|
--
|
|
2.33.0
|