Linux Kernel development (1)

本文深入探讨了Linux内核中的完全公平调度器(CFS)原理与实现细节,包括时间会计、进程选择、抢占与上下文切换等核心概念,并介绍了实时调度策略及与之相关的系统调用。

asm/thread_info.h

linux/threads.h   /proc/sys/kernel/pid_max

linux/sched.h

kernel/fork.c

linux/kthread.h    struct task_struct *kthread_create

Process Priority

  1. Process Priority
  2. Timeslice
  3. The Scheduling Policy in Action

Specifically, CFS determines that the text editor has run for less time than the video encoder. Attempting to give all processes a fair share of the processor, it then preempts the video encoder and enables the text editor to run.

Scheduler Classes

  1. Process Scheduling in Unix Systems
  2. Fair Scheduling

Each scheduler class has a priority.The base scheduler code, which is defined in kernel/sched.c, iterates over each scheduler class in order of priority.

CFS is defined in kernel/sched_fair.c.

The Linux Scheduling Implementation

With the discussion of the motivation for and logic of CFS behind us, we can now explore CFS’s actual implementation, which lives in kernel/sched_fair.c.

  1. Time Accounting: The Scheduler Entity Structure; The Virtual Runtime
  2. Process Selection: Picking the Next Task; Adding Processes to the Tree; Removing Processes from the Tree
          This is, in fact, the core of CFS’s scheduling algorithm: Pick the task with the smallest vruntime.That’s it!
  3. The Scheduler Entry Point:
         The main entry point into the process schedule is the function schedule(), defined in kernel/sched.c.
  4. Sleeping and Waking Up: Wait Queues, Waking Up

Preemption and Context Switching

  1. User Preemption
    Calls switch_to(), declared in , to switch the processor state from the previous process’s to the current’s.
  2. Kernel Preemption

Real-Time Scheduling Policies

Via the scheduling classes framework, these real-time policies are managed not by the Completely Fair Scheduler, but by a special real-time scheduler, defined in kernel/sched_rt.c.

Scheduler-Related System Calls

Scheduling Policy and Priority-Related System Calls

Processor Affinity System Calls

Yielding Processor Time

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值