sys_clock: Fix unsafe tick count usage
The system tick count is a 64 bit quantity that gets updated from interrupt context, meaning that it's dangerously non-atomic and has to be locked. The core kernel clock code did this right. But the value was also exposed to the rest of the universe as a global variable, and virtually nothing else was doing this correctly. Even in the timer ISRs themselves, the interrupts may be themselves preempted (most of our architectures support nested interrupts) by code that wants to set timeouts and inspect system uptime. Define a z_tick_{get,set}() API, eliminate the old variable, and make sure everyone uses the right mechanism. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
parent
b8ffd9acd6
commit
317178b88f
16 changed files with 105 additions and 100 deletions
|
@ -272,7 +272,7 @@ void _timer_int_handler(void *unused)
|
|||
/* If timer not programmed or already consumed exit */
|
||||
if (!programmed_ticks) {
|
||||
if (_sys_clock_always_on) {
|
||||
_sys_clock_tick_count = _get_elapsed_clock_time();
|
||||
z_tick_set(_get_elapsed_clock_time());
|
||||
program_max_cycles();
|
||||
}
|
||||
return;
|
||||
|
@ -301,7 +301,7 @@ void _timer_int_handler(void *unused)
|
|||
|
||||
/* _sys_clock_tick_announce() could cause new programming */
|
||||
if (!programmed_ticks && _sys_clock_always_on) {
|
||||
_sys_clock_tick_count = _get_elapsed_clock_time();
|
||||
z_tick_set(_get_elapsed_clock_time());
|
||||
program_max_cycles();
|
||||
}
|
||||
#else
|
||||
|
@ -354,7 +354,7 @@ void _set_time(u32_t time)
|
|||
|
||||
programmed_ticks = time;
|
||||
|
||||
_sys_clock_tick_count = _get_elapsed_clock_time();
|
||||
z_tick_set(_get_elapsed_clock_time());
|
||||
|
||||
stale_irq_check = 1;
|
||||
|
||||
|
@ -375,7 +375,7 @@ u64_t _get_elapsed_clock_time(void)
|
|||
{
|
||||
u64_t elapsed;
|
||||
|
||||
elapsed = _sys_clock_tick_count;
|
||||
elapsed = z_tick_get();
|
||||
elapsed += ((s64_t)(_hpetMainCounterAtomic() -
|
||||
counter_last_value) / counter_load_value);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue