普通进程的时间片用完后

时间:2022-08-10 21:16:47
7.4.1.2. Updating the time slice of aconventional process
If the current process is a conventional process, the scheduler_tick( ) function performs the following operations:
  1. Decreases the time slice counter (current->time_slice).

  2. Checks the time slice counter.If the time quantum is exhausted, the function performs the following operations:

    1. Invokes dequeue_task( ) to remove current from the this_rq( )->active set of runnable processes.

    2. Invokes set_tsk_need_resched( ) to set the TIF_NEED_RESCHED flag.

    3. Updates the dynamic priority of current:

          current->prio = effective_prio(current);

      The effective_prio( ) function reads the static_prio and sleep_avg fields of current, and computes the dynamic priority of the process according to the formula (2) shown in the earlier section "Scheduling of Conventional Processes."

    4. Refills the time quantum of the process:

          current->time_slice = task_timeslice(current);
          current->first_time_slice = 0;
      

    5. If the expired_timestamp field of the local runqueue data structure is equal to zero (that is, the set of expired processes is empty), writes into the field the value of the current tick:

        if (!this_rq( )->expired_timestamp)
              this_rq( )->expired_timestamp = jiffies;

    6. Inserts the current process either in the active set or in the expired set:

         if (!TASK_INTERACTIVE(current) || EXPIRED_STARVING(this_rq( )) {
              enqueue_task(current, this_rq( )->expired);
              if (current->static_prio < this_rq( )->best_expired_prio)
                  this_rq( )->best_expired_prio = current->static_prio;
          } else
              enqueue_task(current, this_rq( )->active);
      /*或者插入到过期队列中:此进程不是交互式进程或者过期队列中第一个进程的等待时间已经超过1000个时间节拍乘以可运行队列中的进程数的值
      否则仍然插入到活动队列*/
      /*某进程一个时间片用完时不会插入到睡眠队列,只有在阻塞的时候才会被插入到睡眠队列*/
      The TASK_INTERACTIVE macro yields the value one if the process is recognized as interactive using the formula (3) shown in the earlier section "Scheduling of Conventional Processes." The EXPIRED_STARVING macro checks whether the first expired process in the runqueue had to wait for more than 1000 ticks times the number of runnable processes in the runqueue plus one; if so, the macro yields the value one. The EXPIRED_STARVING macro also yields the value one if the static priority value of the current process is greater than the static priority value of an already expired process.

  3. Otherwise, if the time quantum is not exhausted (current->time_slice is not zero), checks whether the remaining time slice of the current process is too long:

    if (TASK_INTERACTIVE(p) && !((task_timeslice(p) -
             p->time_slice) % TIMESLICE_GRANULARITY(p)) &&
            (p->time_slice >= TIMESLICE_GRANULARITY(p)) &&
            (p->array == rq->active)) {
        list_del(¤t->run_list);
        list_add_tail(¤t->run_list,
                      this_rq( )->active->queue+current->prio);
        set_tsk_need_resched(p);
    }

    The TIMESLICE_GRANULARITY macro yields the product of the number of CPUs in the system and a constant proportional to the bonus of the current process (seeTable 7-3 earlier in the chapter). Basically, the time quantum of interactive processes with high static priorities is split into several pieces of TIMESLICE_GRANULARITY size, so that they do not monopolize the CPU.




    2014-6-19 22:54:55
    关于时间片(HZ)的设置和查看
    1.如果
    在arch/mips/Kconfig中

    choice
    prompt "Timer frequency"
    default HZ_250
    help
    Allows the configuration of the timer frequency.

    config HZ_48
    bool "48 HZ" if SYS_SUPPORTS_48HZ || SYS_SUPPORTS_ARBIT_HZ
    config HZ_100
    bool "100 HZ" if SYS_SUPPORTS_100HZ || SYS_SUPPORTS_ARBIT_HZ
    config HZ_128
    bool "128 HZ" if SYS_SUPPORTS_128HZ || SYS_SUPPORTS_ARBIT_HZ
    config HZ_250
    bool "250 HZ" if SYS_SUPPORTS_250HZ || SYS_SUPPORTS_ARBIT_HZ
    config HZ_256
    bool "256 HZ" if SYS_SUPPORTS_256HZ || SYS_SUPPORTS_ARBIT_HZ
    config HZ_1000
    bool "1000 HZ" if SYS_SUPPORTS_1000HZ || SYS_SUPPORTS_ARBIT_HZ
    config HZ_1024
    bool "1024 HZ" if SYS_SUPPORTS_1024HZ || SYS_SUPPORTS_ARBIT_HZ
    endchoice
    这样的话,可以通过make menuconfig来选择:  Kernel type  --->   Timer frequency (100 HZ)  ---> 

    2.如果是如下的配置
    arch/arm/Kconfig

    config HZ
    int
    default 200 if ARCH_EBSA110 || ARCH_S3C2410 || ARCH_S5P64X0 || \
    ARCH_S5P6442 || ARCH_S5PV210 || ARCH_S5PV310
    default OMAP_32K_TIMER_HZ if ARCH_OMAP && OMAP_32K_TIMER
    default AT91_TIMER_HZ if ARCH_AT91
    default SHMOBILE_TIMER_HZ if ARCH_SHMOBILE
    default 100

    则会将CONFIG_HZ写死在Kconfig中,不会在make menuconfig中显示
    可以将int那一行添加一点提示字符串,这样就会出现在menuconfig菜单中了,比如
    int “HZ”

    3.
    在arch/arm/include/asm/param.h文件中,define HZ CONFIG_HZ
    如下
    #ifndef __ASM_PARAM_H
    #define __ASM_PARAM_H

    #ifdef __KERNEL__
    # define HZ CONFIG_HZ/* Internal kernel timer frequency */
    # define USER_HZ 100/* User interfaces are in "ticks" */
    # define CLOCKS_PER_SEC (USER_HZ)/* like times() */
    #else
    # define HZ 100
    #endif
    #define EXEC_PAGESIZE 4096
    #ifndef NOGROUP
    #define NOGROUP         (-1)
    #endif
    /* max length of hostname */
    #define MAXHOSTNAMELEN  64
    #endif

    4.内核根目录下的.config也可以查看到配置过的CONFIG_HZ
    cat .config |grep HZ
    CONFIG_HZ=100

    5.查看HZ
    cat /proc/interrupts |grep timer && sleep 1&&  cat /proc/interrupts |grep timer
      7:     641083      MIPS  timer
      7:     641188      MIPS  timer

    显示为100HZ,即时间片为10ms