About kernel function _CPU_Counter_difference overflow issue
wangqiang3 at sugon.com
wangqiang3 at sugon.com
Fri Jun 18 08:25:03 UTC 2021
Hello,
When reading profiling code, I found function
'_CPU_Counter_difference' may overflow, and it will result in
'per_cpu->max_interrupt_time' become a wrong larger value.
If a cpu counter is 32bit, and it's resolution is 800ns, the counter
will overflow every 3436 seconds(_CPU_Counter_read).
Then,
_Profiling_Outer_most_interrupt_entry_and_exit->_CPU_Counter_difference
will have a incorrect result.
So,
1. Is it a bug?
static inline CPU_Counter_ticks _CPU_Counter_difference(
CPU_Counter_ticks second,
CPU_Counter_ticks first)
{
return second - first;
}
2. If it is, I want to fix it as blow:
#define MAX_COUNT_TICKS (0xFFFFFFFF)
static inline CPU_Counter_ticks _CPU_Counter_difference(
CPU_Counter_ticks second,
CPU_Counter_ticks first)
{
if (second > first) {
return second - first;
} else {
return MAX_COUNT_TICKS - first + second;
}
}
Regards!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20210618/adbf835a/attachment.html>
More information about the users
mailing list