![]() I include some simple examples which you can try out. Some parts of this may not be updated to the latest kernel features, but to the best of my knowledge. This document is the result of some code experiments I did some time back to learn about how scheduling on Linux works. It robs the user of the opportunity to learn about the nitty-gritty of how it all works together.Įnough reminiscing. In a way, I think it is unfortunate that Linux is now so easy to set up. I still remember the AT command sequences! Getting access to the Internet via Lynx and email with Pine was really worth all the effort required to setup my cheap dial-up modem to connect reliably to the VSNL dial-up numbers. The thrill of seeing a shell prompt on my 386 computer after days of fighting with the install was indescribable. I should say I have been fortunate to have taken part in the earlier days of Linux. I have been working on Linux right from my days as an engineering graduate. So, with increasing value of HZ, timer interrupts happens more frequently causing more precious time accounting and allowing scheduler to reschedule tasks more frequently.As my first post on Linked-in, I thought I should write about something close to my heart. When TIF_NEED_RESCHED is set, schedule() gets called on the nearest possible occasion. check_preempt_tick() checks whether current runtime is greater than ideal runtime (timeslice), if so, calls resched_task(), which sets TIF_NEED_RESCHED flag. entity_tick() calls update_curr() to update process vruntime and then calls check_preempt_tick(). To drive preemption between tasks, hrtick() calls task_tick_fair() on each timer interrupt, which, in turn, calls entity_tick(). update_curr() is invoked periodically by the system timer and also whenever a process becomes runnable or blocks, becoming unrunnable. Vruntime variable is managed by update_curr(). ![]() So timeslice is value between sysctl_sched_latency and sysctl_sched_granularity. As this will eventually result in unacceptable switching costs, CFS imposes a floor on the timeslice assigned to each process.This floor is called the minimum granularity. But when number of running processes approaches infinity, timeslice approaches 0. ![]() Typically timeslice is target latency divided by number of running processes. On the ideal multitasking system vruntime of all the process would be identical-all tasks would have received an equal, fair share of the processor. The vruntime variable stores the virtual runtime of a process, which is the actual runtime normalized by the number of runnable processes. Increasing value of HZ makes timer interrupts happen more frequently that makes time accounting more precious, so rescheduling may occur more frequently. That's because time accounting is driven by timer interrupts. ![]() But there is no guarantee that process will be preempted in given timeslice. Increasing number on running process creates a need for shorten timeslice to guarantee appropriate target latency (but timeslice is lower bounded with minimum granularity). Thank you very much!Īs stated in Robert Love's Linux Kernel Development, the only ways to get a timeslice shorter is to increase number of running processes (or ones with less priority than others). Then how we can get a timeslice shorter than 5 ms? Please help me understand this. This timer is simply one of the queued timers that are processed by timer irq handler on every tick, timer_tick(). Timeslice is put in action by starting rq->hrtick_timer in set_next_entity(), every time a fair task is scheduled to run, and invoking resched_task() in timeout callback function hrtick(). I must be wrong here but I just cannot figure out how!Īlso knowing that HZ, or the number of system ticks per s, or the number of timer interrupts every second, is normally 200 or 100 for arm machine (and most non-desktop machines too), which gives us a 5 to 10 ms tick rate. ![]() Please correct me if I understand it wrong. I understand that Linux fair timeslice varies depending on the nr_running and the relative weight of this fair task, but through code studying, I figured out the main idea is to keep the timeslice 1 to 5 ms. Unsigned int sysctl_sched_min_granularity = 1000000ULL //1ms In sched_fair.c it has: unsigned int sysctl_sched_latency = 5000000ULL //5m ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |