timing: fix timing_stop() ref counting
When there are more timing_stop() calls then timing_start(), the reference counter will go negative, resulting in the next timing_start() call not starting the timer. Without timer running, getting cycles elasped would not work. So fix the ref counting so it won't dip below zero. Fixes #30397 Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
parent
c6253fbe1a
commit
6ab4886506
1 changed files with 16 additions and 1 deletions
|
@ -46,7 +46,22 @@ void timing_start(void)
|
|||
|
||||
void timing_stop(void)
|
||||
{
|
||||
if (atomic_dec(&started_ref) > 1) {
|
||||
atomic_t old_value, new_value;
|
||||
|
||||
/* Make sure this does decrement past zero. */
|
||||
do {
|
||||
old_value = atomic_get(&started_ref);
|
||||
if (old_value <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
new_value = old_value - 1;
|
||||
} while (atomic_cas(&started_ref, old_value, new_value) == 0);
|
||||
|
||||
/*
|
||||
* new_value may be uninitialized, so use old_value here.
|
||||
*/
|
||||
if (old_value > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue