Allow the frequency to be changed

This commit is contained in:
Baptiste Wicht 2016-08-06 16:07:20 +02:00
parent eb812462ba
commit c273940e74
3 changed files with 22 additions and 0 deletions

View File

@ -64,6 +64,11 @@ void queue_system_process(pid_t pid);
*/
void queue_async_init_task(void (*fun)());
/*!
* \brief Lets the scheduler know that the timer frequency has been updated
*/
void frequency_updated(uint64_t old_frequency, uint64_t new_frequency);
} //end of namespace scheduler
#endif

View File

@ -953,3 +953,16 @@ void scheduler::queue_system_process(scheduler::pid_t pid){
void scheduler::queue_async_init_task(void (*fun)()){
init_tasks.emplace_back(fun);
}
void scheduler::frequency_updated(uint64_t old_frequency, uint64_t new_frequency){
// Cannot be interrupted during frequency update
direct_int_lock lock;
double ratio = old_frequency / double(new_frequency);
for(auto& process : pcb){
if(process.state == process_state::SLEEPING){
process.sleep_timeout *= ratio;
}
}
}

View File

@ -75,7 +75,11 @@ uint64_t timer::frequency(){
}
void timer::frequency(uint64_t freq){
auto old_frequency = _timer_frequency;
_timer_frequency = freq;
logging::logf(logging::log_level::DEBUG, "timer: Frequency set to %u Hz\n", freq);
scheduler::frequency_updated(old_frequency, _timer_frequency);
}