软件属于网站开发吗,北京有名的设计公司有哪些,网站服务器建设,django做视频网站为了弄清楚在多cpu系统中是如何实现实时调度的#xff0c;先引入以下几个概念#xff1a;cpu的状态#xff1a;我们知道#xff0c;在linux系统中#xff0c;任务的优先级为0~140。INVALID:(-1)该cpu不可用IDLE(0):140NORMAL(1)#xff1a;100~139对应于普通任务的优先级…为了弄清楚在多cpu系统中是如何实现实时调度的先引入以下几个概念cpu的状态我们知道在linux系统中任务的优先级为0~140。INVALID:(-1)该cpu不可用IDLE(0):140NORMAL(1)100~139对应于普通任务的优先级RT0~RT99(2~102)对应于实时任务的优先级进程优先级在linux内核中每个进程都有一个task_struct,其中与优先级相关的属性包括1、prio对于非实时进程而言prionormal_prio99-rt_priority(prio的值越大则进程的优先级越小)2、normal_prio99-rt_priority3、static_prio:100nice4、rt_priority:0非实时任务[1,99]实时任务值越大优先级越高。在调度时使用了prio其数值0对应最高优先级99为最低实时优先级。Prio和normal_prio数值越大优先级越小而rt_priority的数值越大优先级越大。task balance在多cpu系统中为了保证各个cpu上实时任务的负载均衡引入了push和pull操作1、push操作当当前cpu上有多于一个的实时任务那么需要使用pull操作看看是否可以将还未运行的实时任务移动到其他的cpu上主要操作由push_rt_task函数完成。static int push_rt_task(struct rq *rq){struct task_struct *next_task;struct rq *lowest_rq;int ret 0;///如果当前队列不是超载状态则直接返回if (!rq-rt.overloaded)return 0;///选择rq中下一个进程next_task pick_next_pushable_task(rq);if (!next_task)return 0;retry:......///如果下一个进程的优先级比当前进程的优先级高那么需要执行的不是push操作而是重新调度if (unlikely(next_task-prio curr-prio)) {resched_task(rq-curr);return 0;}......///寻找那个cpu的rq符合条件将其rq上锁lowest_rq find_lock_lowest_rq(next_task, rq);///如果没有找到合适的rq我们则需要判断到底还要不要再找因为在find_lock_lowest_rq函数中释放了当前rq上的锁因此可能会导致当前rq上没有需要push的任务在这种情况下我们就不用再试如果需要push的任务还在那么则进入retry继续尝试。if (!lowest_rq) {struct task_struct *task;task pick_next_pushable_task(rq);if (task_cpu(next_task) rq-cpu task next_task) {goto out;}if (!task)goto out;put_task_struct(next_task);next_task task;goto retry;}///执行任务迁移相关的工作。deactivate_task(rq, next_task, 0);set_task_cpu(next_task, lowest_rq-cpu);activate_task(lowest_rq, next_task, 0);ret 1;resched_task(lowest_rq-curr);double_unlock_balance(rq, lowest_rq);out:put_task_struct(next_task);return ret;}2、pull操作与push操作相反pull操作用于当前cpu的rq比较空闲想要主动调入实时任务该操作主要由pull_rt_task完成。static int pull_rt_task(struct rq *this_rq){int this_cpu this_rq-cpu, ret 0, cpu;struct task_struct *p;struct rq *src_rq;if (likely(!rt_overloaded(this_rq)))return 0;///查找每一个超载的cpufor_each_cpu(cpu, this_rq-rd-rto_mask) {......///src_rq需要pull的cpu。src_rq cpu_rq(cpu);///如果src_rq的下一个任务的优先级高于当前cpu的优先级则什么都不用做因为src_cpu会主动执行pull操作。if (src_rq-rt.highest_prio.next this_rq-rt.highest_prio.curr)continue;double_lock_balance(this_rq, src_rq);///判断是否有需要被pull的任务没有则退出if (src_rq-rt.rt_nr_running 1)goto skip;///找到src_rq上最高优先级的任务p pick_next_highest_task_rt(src_rq, this_cpu);if (p (p-prio rt.highest_prio.curr)) {WARN_ON(p src_rq-curr);WARN_ON(!p-on_rq);if (p-prio curr-prio)goto skip;ret 1;deactivate_task(src_rq, p, 0);set_task_cpu(p, this_cpu);activate_task(this_rq, p, 0);}skip:double_unlock_balance(this_rq, src_rq);}return ret;}