kernel: sched: Use ticks as time unit in time slicing.
The time slicing settings was kept in milliseconds while all related operations was based on ticks. Continuous back and forth conversion between ticks and milliseconds introduced an accumulating error due to rounding in _ms_to_ticks() and __ticks_to_ms(). As result configured time slice duration was not achieved. This commit removes excessive ticks <-> ms conversion by using ticks as time unit for all operations related to time slicing. Also, it fixes #8896 as well as #8897. Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
This commit is contained in:
parent
ee9a0615a4
commit
4a39b9ea64
2 changed files with 14 additions and 11 deletions
|
@ -591,8 +591,8 @@ struct k_thread *_priq_mq_best(struct _priq_mq *pq)
|
|||
}
|
||||
|
||||
#ifdef CONFIG_TIMESLICING
|
||||
extern s32_t _time_slice_duration; /* Measured in ms */
|
||||
extern s32_t _time_slice_elapsed; /* Measured in ms */
|
||||
extern s32_t _time_slice_duration; /* Measured in ticks */
|
||||
extern s32_t _time_slice_elapsed; /* Measured in ticks */
|
||||
extern int _time_slice_prio_ceiling;
|
||||
|
||||
void k_sched_time_slice_set(s32_t duration_in_ms, int prio)
|
||||
|
@ -600,7 +600,7 @@ void k_sched_time_slice_set(s32_t duration_in_ms, int prio)
|
|||
__ASSERT(duration_in_ms >= 0, "");
|
||||
__ASSERT((prio >= 0) && (prio < CONFIG_NUM_PREEMPT_PRIORITIES), "");
|
||||
|
||||
_time_slice_duration = duration_in_ms;
|
||||
_time_slice_duration = _ms_to_ticks(duration_in_ms);
|
||||
_time_slice_elapsed = 0;
|
||||
_time_slice_prio_ceiling = prio;
|
||||
}
|
||||
|
@ -641,10 +641,9 @@ void _update_time_slice_before_swap(void)
|
|||
}
|
||||
|
||||
u32_t remaining = _get_remaining_program_time();
|
||||
u32_t time_slice_ticks = _ms_to_ticks(_time_slice_duration);
|
||||
|
||||
if (!remaining || (_time_slice_ticks < remaining)) {
|
||||
_set_time(_time_slice_ticks);
|
||||
if (!remaining || (_time_slice_duration < remaining)) {
|
||||
_set_time(_time_slice_duration);
|
||||
} else {
|
||||
/* Account previous elapsed time and reprogram
|
||||
* timer with remaining time
|
||||
|
@ -691,6 +690,11 @@ void _sched_init(void)
|
|||
sys_dlist_init(&_kernel.ready_q.runq.queues[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_TIMESLICING
|
||||
k_sched_time_slice_set(CONFIG_TIMESLICE_SIZE,
|
||||
CONFIG_TIMESLICE_PRIORITY);
|
||||
#endif
|
||||
}
|
||||
|
||||
int _impl_k_thread_priority_get(k_tid_t thread)
|
||||
|
|
|
@ -263,8 +263,8 @@ static inline void handle_timeouts(s32_t ticks)
|
|||
|
||||
#ifdef CONFIG_TIMESLICING
|
||||
s32_t _time_slice_elapsed;
|
||||
s32_t _time_slice_duration = CONFIG_TIMESLICE_SIZE;
|
||||
int _time_slice_prio_ceiling = CONFIG_TIMESLICE_PRIORITY;
|
||||
s32_t _time_slice_duration;
|
||||
int _time_slice_prio_ceiling;
|
||||
|
||||
/*
|
||||
* Always called from interrupt level, and always only from the system clock
|
||||
|
@ -285,7 +285,7 @@ static void handle_time_slicing(s32_t ticks)
|
|||
return;
|
||||
}
|
||||
|
||||
_time_slice_elapsed += __ticks_to_ms(ticks);
|
||||
_time_slice_elapsed += ticks;
|
||||
if (_time_slice_elapsed >= _time_slice_duration) {
|
||||
|
||||
unsigned int key;
|
||||
|
@ -297,8 +297,7 @@ static void handle_time_slicing(s32_t ticks)
|
|||
irq_unlock(key);
|
||||
}
|
||||
#ifdef CONFIG_TICKLESS_KERNEL
|
||||
next_ts =
|
||||
_ms_to_ticks(_time_slice_duration - _time_slice_elapsed);
|
||||
next_ts = _time_slice_duration - _time_slice_elapsed;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue