mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-30 00:00:15 +01:00
update timer after updating the timer list
- revise code, increase the readability
This commit is contained in:
parent
c745503102
commit
807c210111
2 changed files with 22 additions and 16 deletions
|
@ -55,7 +55,7 @@ void check_ticks(void)
|
|||
if (!cpu_freq)
|
||||
return;
|
||||
|
||||
const uint64_t curr_rdtsc = has_rdtscp() ? rdtscp(NULL) : rdtsc();
|
||||
const uint64_t curr_rdtsc = rdtsc();
|
||||
rmb();
|
||||
|
||||
const uint64_t diff_cycles = curr_rdtsc - per_core(last_rdtsc);
|
||||
|
@ -65,7 +65,7 @@ void check_ticks(void)
|
|||
if (diff_ticks > 0) {
|
||||
set_per_core(timer_ticks, per_core(timer_ticks) + diff_ticks);
|
||||
set_per_core(last_rdtsc, curr_rdtsc);
|
||||
rmb();
|
||||
mb();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -99,8 +99,11 @@ static void timer_handler(struct state *s)
|
|||
|
||||
int timer_wait(unsigned int ticks)
|
||||
{
|
||||
uint64_t eticks = per_core(timer_ticks) + ticks;
|
||||
#ifdef DYNAMIC_TICKS
|
||||
check_ticks();
|
||||
#endif
|
||||
|
||||
uint64_t eticks = per_core(timer_ticks) + ticks;
|
||||
task_t* curr_task = per_core(current_task);
|
||||
|
||||
if (curr_task->status == TASK_IDLE)
|
||||
|
@ -119,12 +122,8 @@ int timer_wait(unsigned int ticks)
|
|||
PAUSE;
|
||||
}
|
||||
} else if (per_core(timer_ticks) < eticks) {
|
||||
check_workqueues();
|
||||
|
||||
if (per_core(timer_ticks) < eticks) {
|
||||
set_timer(eticks);
|
||||
reschedule();
|
||||
}
|
||||
set_timer(eticks);
|
||||
reschedule();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -74,7 +74,7 @@ DEFINE_PER_CORE(uint32_t, __core_id, 0);
|
|||
|
||||
static void update_timer(task_t* first)
|
||||
{
|
||||
if(first) {
|
||||
if (first) {
|
||||
if(first->timeout > get_clock_tick()) {
|
||||
timer_deadline((uint32_t) (first->timeout - get_clock_tick()));
|
||||
} else {
|
||||
|
@ -120,9 +120,9 @@ static void timer_queue_push(uint32_t core_id, task_t* task)
|
|||
timer_queue->first = timer_queue->last = task;
|
||||
task->next = task->prev = NULL;
|
||||
|
||||
#ifdef DYNAMIC_TICKS
|
||||
update_timer(task);
|
||||
#endif
|
||||
#ifdef DYNAMIC_TICKS
|
||||
update_timer(task);
|
||||
#endif
|
||||
} else {
|
||||
// lookup position where to insert task
|
||||
task_t* tmp = first;
|
||||
|
@ -148,9 +148,9 @@ static void timer_queue_push(uint32_t core_id, task_t* task)
|
|||
if(timer_queue->first == tmp) {
|
||||
timer_queue->first = task;
|
||||
|
||||
#ifdef DYNAMIC_TICKS
|
||||
update_timer(task);
|
||||
#endif
|
||||
#ifdef DYNAMIC_TICKS
|
||||
update_timer(task);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -793,6 +793,13 @@ void check_timers(void)
|
|||
wakeup_task(task->id);
|
||||
}
|
||||
|
||||
#ifdef DYNAMIC_TICKS
|
||||
task = readyqueue->timers.first;
|
||||
if (task) {
|
||||
update_timer(task);
|
||||
}
|
||||
#endif
|
||||
|
||||
spinlock_irqsave_unlock(&readyqueue->lock);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue