In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
The scheduling operation of the kernel is divided into two parts: trigger and execution, which only sets the TIF_NEED_RESCHED flag of the current process when it is triggered, and completes the selection and switching of the process through the schedule () function. The TIF_NEED_RESCHED bit in the thread_info- > flags of the current process indicates that the schedule () function needs to be called for scheduling. The kernel sets this flag in two cases, one is when the clock interrupt is checked periodically, and the other is when the awakened process has a higher priority than the running process.
When updating the status of the current task periodically:
Schedule_tick () is called in the scheduled interrupt handling function to handle periodic checking and processing of scheduling. The calling path is tick_periodic ()-> update_process_times ()-> scheduler_tick () or tick_sched_handle ()-> update_process_times ()-> scheduler_tick (), which is mainly used to update the clock of the ready queue, the CPU load and the running time statistics of the current task, as shown below:
/ / linux-3.13/kernel/sched/core.cvoid scheduler_tick (void) {int cpu = smp_processor_id (); / / get the current cpu number struct rq * rq = cpu_rq (cpu); / / get the rq (ready queue) of the corresponding cpu struct task_struct * curr = rq- > curr; / / get the currently running task sched_clock_tick (); raw_spin_lock (& rq- > lock) Update_rq_clock (rq); / update queue clock curr- > sched_class- > task_tick (rq, curr, 0); / / call the function update_cpu_load_active (rq) corresponding to the scheduling class of the current task; / / update the load raw_spin_unlock of this processor (& rq- > lock); perf_event_task_tick (); # ifdef CONFIG_SMP rq- > idle_balance = idle_cpu (cpu) Trigger_load_balance (rq, cpu); / / load balancing # endif rq_last_tick_reset (rq) if necessary;}
Where curr- > sched_class- > task_tick (rq, curr, 0); this line of code calls the task_tick () function of the scheduling class of the current task, which determines whether the TIF_NEED_RESCHED flag needs to be set on the current task according to the specific situation, and finally calls set_tsk_need_resched () to set the flag if necessary. It is important to note that the flag is only set and the schedule () function is not executed, which is used to decide whether or not to execute the schedule () function at the end of the return code of various system calls and interrupts.
When the task of sleep is awakened:
When the event that the sleep task is waiting for arrives, the kernel (such as the driver's interrupt handler) will call wake_up () to wake up the related task, and eventually call try_to_wake_up (). It does three things: add the task back to the ready queue, set the run flag to TASK_RUNNING, and set the TIF_NEED_RESCHED flag for the current task if the awakened task can preempt the currently running task.
After setting the TIF_NEED_RESCHED flag, there are only two times when the schedule () function is actually called. The first is to decide whether to call the schedule () function according to the TIF_NEED_RESCHED flag when the system call or interrupt returns (in terms of efficiency, finish the processing while the kernel is still in the kernel state) The second situation is that the current task needs sleep for reasons, and the schedule () function is called immediately after the process sleeps, which is also more common in the kernel, such as disks, network cards and other device drivers.
Reference: "inside Linux Technology"
PS: when I first started learning the Linux kernel, it was easy to be filled with all kinds of structures and concepts, and it was a mess. At this time, it is necessary to make their respective functions and their mutual matching reasonable and clear, and recommend this book. After watching "Linux Kernel Design and implementation", we can compare each other, the effect is good.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.