Skip to content

Commit 8895f2b

Browse files
Update perf_counter.c
1 parent aec5ec1 commit 8895f2b

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

perf_counter.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -181,33 +181,22 @@ bool init_cycle_counter(bool bIsSysTickOccupied)
181181
*/
182182
__STATIC_INLINE int64_t check_systick(void)
183183
{
184-
int64_t lLoad = perfc_port_get_system_timer_top() + 1;
185184
int64_t lTemp = perfc_port_get_system_timer_elapsed();
186185

187186
/* Since we cannot stop counting temporarily, there are several
188187
* conditions which we should take into consideration:
189188
* - Condition 1: when assigning nTemp with the register value (LOAD-VAL),
190189
* the underflow didn't happen but when we check the PENDSTSET bit,
191-
* the underflow happens, for this condition, we should not
192-
* do any compensation. When this happens, the (LOAD-nTemp) is
193-
* smaller than PERF_CNT_COMPENSATION_THRESHOLD (a small value) as
194-
* long as LOAD is bigger than (or equals to) the
195-
* PERF_CNT_COMPENSATION_THRESHOLD;
196-
* - Condition 2: when assigning nTemp with the register value (LOAD-VAL),
197-
* the VAL is zero and underflow happened and the PENDSTSET bit
198-
* is set, for this condition, we should not do any compensation.
199-
* When this happens, the (LOAD-nTemp) is equals to zero.
200-
* - Condition 3: when assigning nTemp with the register value (LOAD-VAL),
201-
* the underflow has already happened, hence the PENDSTSET
202-
* is set, for this condition, we should compensate the return
203-
* value. When this happens, the (LOAD-nTemp) is bigger than (or
204-
* equals to) PERF_CNT_COMPENSATION_THRESHOLD.
190+
* the underflow happens, for this condition, we should recall the
191+
* perfc_port_get_system_timer_elapsed().
205192
* The following code implements an equivalent logic.
206193
*/
207194
if (perfc_port_is_system_timer_ovf_pending()){
208-
//if ((lLoad - lTemp) >= PERF_CNT_COMPENSATION_THRESHOLD) {
209-
lTemp += lLoad;
210-
//}
195+
/* refresh the elapsed just in case the counter has just overflowed/underflowed
196+
* after we called the perfc_port_get_system_timer_elapsed()
197+
*/
198+
lTemp = perfc_port_get_system_timer_elapsed();
199+
lTemp += perfc_port_get_system_timer_top() + 1;
211200
}
212201

213202
return lTemp;

0 commit comments

Comments
 (0)