![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Process Scheduling
文章平均质量分 55
kernel_details
这个作者很懒,什么都没留下…
展开
-
MAX_BONUS
MAX_BONUS = (40*25/100) = 10#define MAX_BONUS (MAX_USER_PRIO * PRIO_BONUS_RATIO / 100) MAX_USER_PRIO = 40----------------------------#define MAX_USER_PRIO (USER_PRIO(MAX_PRIO)) //USER_原创 2007-01-05 16:43:00 · 1290 阅读 · 0 评论 -
cpus_equal()
检测该进程当前所在处理器是否可以执行该进程,如果可以则返回1,否则返回0#define cpus_equal(src1, src2) __cpus_equal(&(src1), &(src2), NR_CPUS)static inline int __cpus_equal(const cpumask_t *src1p, const cpumask_t *src原创 2007-01-12 11:01:00 · 1480 阅读 · 0 评论 -
smp_processor_id()
unsigned int smp_processor_id(void){ unsigned long preempt_count = preempt_count(); int this_cpu = __smp_processor_id(); cpumask_t this_mask; if (likely(preempt_count)) goto out;原创 2007-01-12 11:07:00 · 9024 阅读 · 0 评论 -
resched_task()
设置进程p的thread_info中的flag域的TIF_NEED_RESCHED位,表示该进程需要调用调度程序执行进程切换static inline void resched_task(task_t *p)...{ set_tsk_need_resched(p);}static inline void set_tsk_need_resched(struct task原创 2007-01-12 11:28:00 · 3925 阅读 · 1 评论 -
TASK_PREEMPTS_CURR
如果进程p动态优先级高于当前进程current的动态优先级,则返回true,否则返回falseprio小的动态优先级高#define TASK_PREEMPTS_CURR(p, rq) ((p)->prio (rq)->curr->prio)原创 2007-01-12 17:08:00 · 1015 阅读 · 0 评论 -
NICE_TO_PRIO
用nice计算static_prio:#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)#define MAX_RT_PRIO MAX_USER_RT_PRIO#define MAX_USER_RT_PRIO 100原创 2007-01-12 17:24:00 · 1820 阅读 · 0 评论 -
requeue_task()
将进程p从优先级数组array(优先级数组array的某个元素[array->queue + p->prio]所代表的优先级队列) 中删除,并将其插入该队列的尾部static void requeue_task(struct task_struct *p, prio_array_t *array)...{ list_move_tail(&p->run_list, array->que原创 2007-01-12 17:48:00 · 1490 阅读 · 0 评论 -
dequeue_task()
将进程p从优先级数组array(优先级数组array的某个元素[array->queue + p->prio]所代表的优先级队列)中删除;查看[array->queue + p->prio]所代表的优先级队列中是否还有活跃进程,如果没有将要清除优先级位图bitmap[]static void dequeue_task(struct task_struct *p, prio_array_t原创 2007-01-12 17:53:00 · 2615 阅读 · 0 评论 -
list_del()
从entry所在的双向链表中将entry删除:static inline void list_del(struct list_head *entry)...{ __list_del(entry->prev, entry->next); entry->next = LIST_POISON1; entry->prev = LIST_POISON2;}/**//原创 2007-01-12 20:04:00 · 7774 阅读 · 0 评论 -
NS_MAX_SLEEP_AVG; JIFFIES_TO_NS; MAX_SLEEP_AVG
纳秒级最长睡眠时间为1000 000 000nsNS_MAX_SLEEP_AVG = 1000 * 1000 000 = 1000 000 000ns--------------------------------------#define NS_MAX_SLEEP_AVG (JIFFIES_TO_NS(MAX_SLEEP_AVG))将TIME个滴答转化为纳秒(ns) TIME * 1ms原创 2007-01-13 09:44:00 · 2321 阅读 · 0 评论 -
activate_task()
更新唤醒进程p的平均睡眠时间sleep_avg和动态优先级prio;记录该进程唤醒前的睡眠状态;将该进程插入活跃优先级数组static void activate_task(task_t *p, runqueue_t *rq, int local){ unsigned long long now; now = sched_clock();如果目标CPU不是本地CPU,就要补偿本地时钟器原创 2007-01-12 09:53:00 · 2809 阅读 · 0 评论 -
set_bit()
将addr的第nr位置为1 假设*addr = 0, nr = 3;则执行结果为1000(二进制数)extern __inline__ int set_bit(int nr,long * addr)...{ int mask, retval; addr += nr >> 5; //(1) mask = 1 (nr & 0x1f);原创 2007-01-12 14:59:00 · 16581 阅读 · 4 评论 -
task_timeslice()
根据进程p的静态优先级static_prio计算该进程的时间片(根据下面公式计算时间片)static inline unsigned int task_timeslice(task_t *p)...{ if (p->static_prio NICE_TO_PRIO(0)) return SCALE_PRIO(DEF_TIMESLICE*4, p->static_pri原创 2007-01-12 17:20:00 · 2291 阅读 · 0 评论 -
list_add_tail()
将new所代表的list_head插入head所索引的队列的尾部static inline void list_add_tail(struct list_head *new, struct list_head *head)...{ __list_add(new, head->prev, head);}将new所代表的list_head插入到next索引的双链表(next索引双原创 2007-01-12 17:29:00 · 33471 阅读 · 0 评论 -
__list_del()
将prev和next之间的list_head从链表中删除:static inline void __list_del(struct list_head * prev, struct list_head * next)...{ next->prev = prev; prev->next = next;} +--prev原创 2007-01-12 17:36:00 · 2655 阅读 · 0 评论 -
cpumask_of_cpu()
根据处理器编号cpu,将处理器位图的相应位置置为1(其它位为0)#define cpumask_of_cpu(cpu) /({ / typeof(_unused_cpumask_arg_) m; / if (sizeof(m) ==原创 2007-01-12 10:59:00 · 5769 阅读 · 0 评论 -
sched_info_switch()
进程prev和进程next切换前更新各自的sched_info:static inline void sched_info_switch(task_t *prev, task_t *next){ struct runqueue *rq = task_rq(prev); if (prev != rq->idle) sched_info_depart(prev); if原创 2007-01-10 10:53:00 · 1782 阅读 · 0 评论 -
sched_info_arrive()
进程t即将获得CPU控制权汇总进程t在可执行队列上所等候时间的综合;更新进程t获得CPU控制权的时间戳static inline void sched_info_arrive(task_t *t){ unsigned long now = jiffies, diff = 0; struct runqueue *rq = task_rq(t); if (t->sched_info.原创 2007-01-10 10:47:00 · 1238 阅读 · 0 评论 -
DEF_TIMESLICE MIN_TIMESLICE
进程所获得的默认时间片为100msDEF_TIMESLICE = 100ms#define DEF_TIMESLICE (100 * HZ / 1000)#define HZ 1000进程所能获得的最小时间片为5msMIN_TIMESLICE = 5 ms#define MIN_TIMESLICE max(5 * HZ / 1000, 1)#d原创 2007-01-05 15:58:00 · 1791 阅读 · 0 评论 -
MAX_PRIO MAX_RT_PRIO
MAX_PRIO = 140#define MAX_PRIO (MAX_RT_PRIO + 40) MAX_RT_PRIO = 100#define MAX_RT_PRIO MAX_USER_RT_PRIO #define MAX_USER_RT_PRIO 100原创 2007-01-09 11:14:00 · 3093 阅读 · 0 评论 -
sched_info_depart()
进程t即将失去CPU控制权汇总进程t占用CPU的时间总和;进程t所在runqueue占用CPU的时间总和static inline void sched_info_depart(task_t *t)...{ struct runqueue *rq = task_rq(t); unsigned long diff = jiffies - t->sched原创 2007-01-10 11:00:00 · 1254 阅读 · 0 评论 -
switch_to
switch_to()负责从上一个进程的处理器状态切换到新进程的处理器状态15 #define switch_to(prev,next,last) do { 16 unsigned long esi,edi; 17原创 2007-01-10 12:17:00 · 3835 阅读 · 1 评论 -
获取当前进程描述符地址 -- current
在内核代码中当需要访问当前进程的task_struct结构时使用的指针current实际上是个宏定义,它是根据当前进程的堆栈指针ESP计算出来的。#define current get_current()static inline struct task_struct * get_current(void)...{ return current_thread_info原创 2007-01-10 16:43:00 · 4184 阅读 · 0 评论 -
硬件文境
为了控制进程的执行,内核必须有能力挂起正在CPU上运行的进程,并恢复执行以前挂起的某个进程。这种行为被称为进程切换(process switch)、任务切换或者文境切换。 To control the execution of processes, the kernel must be able to suspend the execution of the process runn原创 2007-01-10 19:48:00 · 2255 阅读 · 0 评论 -
硬件文境的切换 -- __switch_to()
struct task_struct fastcall * __switch_to(struct task_struct *prev_p, struct task_struct *next_p){ struct thread_struct *prev = &prev_p->thread, *next = &next_p->thread;通过当前进程next的t原创 2007-01-11 11:11:00 · 3622 阅读 · 0 评论 -
context_switch( )
context_switch( )上下文切换: 调用switch_mm(),把虚拟内存从一个进程映射切换到新进程中 调用switch_to(),从上一个进程的处理器状态切换到新进程的处理器状态。这包括保存、恢复栈信息和寄存器信息 The context_switch( ) function sets up the address space of next.原创 2007-01-11 11:30:00 · 7215 阅读 · 1 评论 -
NS_TO_JIFFIES
NS_TO_JIFFIES 将TIME(单位为纳秒)转换为时钟滴答数(1毫秒为一个滴答)#define NS_TO_JIFFIES(TIME) ((TIME) / (1000 000 000 / HZ))#define HZ 1000 例如:TIME = 600msNS_TO_JIFFIES = 600ticks600ms = 600 000 000ns600 0原创 2007-01-09 10:57:00 · 1599 阅读 · 0 评论 -
CURRENT_BONUS(p)
CURRENT_BONUS(p)根据sleep_avg计算进程p的当前红利(bonus)#define CURRENT_BONUS(p) ( NS_TO_JIFFIES((p)->sleep_avg) * MAX_BONUS / MAX_SLEEP_AVG )例如:p->sleep_avg = 600msCURRENT_BONUS(p) = 6-----------------------原创 2007-01-09 11:04:00 · 1697 阅读 · 0 评论 -
rt_task(p)
#define rt_task(p) ( (p)->prio MAX_RT_PRIO )实时优先级范围从0到MAX_RT_PRIO减1。默认情况下,MAX_RT_PRIO为100,所以默认的实时优先级范围是从0到99。SCHED_NORMAL级进程的nice值共享了这个取值空间;它的取值范围是从MAX_RT_PRIO到(MAX_RT_PRIO+40)。也就是说,在默认情况下,nice值从-20到+原创 2007-01-09 11:34:00 · 2643 阅读 · 1 评论 -
计算动态优先级 -- effective_prio()
effective_prio()函数返回进程p的动态优先级static int effective_prio(task_t *p){ int bonus, prio;如果进程p是个实时进程,那么直接返回该实时进程的prio(实时进程的动态优先级prio不依赖于静态优先级static_prio,两者是否相等???)|----------------------------|| if (rt原创 2007-01-09 11:57:00 · 2877 阅读 · 0 评论 -
更新平均睡眠时间和动态优先级 -- recalc_task_prio( )
schedule()片段进程next被唤醒后(唤醒前处于TASK_INTERRUPTIBLE状态),现在已经被schedule()选中即将投入运行,在得到CPU控制权之前需要重新计算其sleep_avg和prio: if (!rt_task(next) && next->activated > 0) ...{ unsigned long long d原创 2007-01-09 14:27:00 · 2792 阅读 · 0 评论 -
task_rq(p)
task_rq(p) 获取进程p所在的runqueue的首地址--------------------------------------------#define task_rq(p) cpu_rq(task_cpu(p))#define cpu_rq(cpu) (&per_cpu(runqueues, (cpu)))task_cpu(p) 获取进程p所在CPU的编号----原创 2007-01-10 10:36:00 · 3533 阅读 · 0 评论 -
preempt_count()
#define preempt_count() (current_thread_info()->preempt_count)#define PREEMPT_ACTIVE 0x1000000000001 0000 0000 0000 0000 0000 0000 0000 (2)struct thread_info { ... __s32 preempt_count原创 2007-01-13 09:46:00 · 2661 阅读 · 0 评论