Linux2.6 kernel process scheduling series -- scheduler_tick () function 2. Update the time slice of the real-time process,

Source: Internet
Author: User

Linux2.6 kernel process scheduling series -- scheduler_tick () function 2. Update the time slice of the real-time process,

RT

/*** Decrease the time slice counter of the current process and check whether the time slice has been used up. * The operations executed by functions vary greatly depending on the scheduling type of processes. * // * If the process is a real-time process, the real-time process is based on the FIFO or RR type. */if (rt_task (p )) {/*** for Real-Time Processes of SCHED_RR type (time slice rotation), the time slice needs to be decreased. * For Real-Time Processes of the SCHED_FIFO type (first-in-first-out), do nothing. * exit. In this case, * the current process cannot be preemptible by a process with a lower priority or equal priority. * It is meaningless to maintain the latest time slice counter of the current process. */If (p-> policy = SCHED_RR )&&! -- P-> time_slice) {/*** for a SCHED_RR-type real-time process, if its time slice has been used up, * execute this action to seize the current process. * If necessary, it will be preemptible as soon as possible. * // * Re-calculate the time slice. It calculates the time slice based on the Static Priority of the process. */P-> time_slice = task_timeslice (p);/*** this flag is set by copy_process in the fork routine. * till now, it indicates that the process has not been run for the first time, * It has used up its time slice once and sets first_time_slice to 0. * In this way, even if it exits, it will not return the remaining time slices to the parent process. */P-> first_time_slice = 0;/*** set the scheduling flag for preemption as soon as possible. * This flag forcibly calls the schedule function so that the process to which current points can be replaced by another real-time process with the same (or higher) priority (if any. */Set_tsk_need_resched (p);/* put it at the end of the queue: * // *** put the real-time process to the end of the queue. In this way, other RR processes with the same priority * can be run in the linked list. */Requeue_task (p, rq-> active);} goto out_unlock ;}

1. Here we will explain several major subfunctions. The first is task_timeslice, which re-calculates the time slice. First, we will introduce the concept of a basic time slice.

The static priority essentially determines the basic time slice of the process. That is, the length of the time slice that the system assigns to the process when the process has used up the previous time slice. The relationship between the static priority and the Basic time slice is determined by the following formula:

As you can see, the higher the static priority (the smaller the value), the longer the Basic time slice. The result is that a process with a higher priority usually gets a longer CPU time slice than a process with a lower priority.

#define NICE_TO_PRIO(nice)(MAX_RT_PRIO + (nice) + 20)#define SCALE_PRIO(x, prio) \max(x * (MAX_PRIO - prio) / (MAX_USER_PRIO/2), MIN_TIMESLICE)static unsigned int task_timeslice(task_t *p){if (p->static_prio < NICE_TO_PRIO(0))return SCALE_PRIO(DEF_TIMESLICE*4, p->static_prio);elsereturn SCALE_PRIO(DEF_TIMESLICE, p->static_prio);}

2. The requeue_task function moves the process descriptor to the end of the running queue activity linked list corresponding to the current process priority. Put the process to which current points at the end of the linked list to ensure that it will not be selected for execution until each real-time process with the same priority can run to obtain the CPU time slice.

This is a scheduling policy based on time slice rotation. Process descriptor movement is completed in two steps: Call list_del to delete the process from the active linked list of the running queue, and then call list_add_tail to re-insert the process to the end of the same active linked list.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.