Linux kernel 在linux调度程序中,yield_task_fair()做什么
这是linux调度器中的一个函数,用于实现路径为root/kernel/sched/FAIR.c的完全公平调度器 () 现在我想逐行了解这个函数的作用。如有任何回复或与完整文件的链接,将不胜感激Linux kernel 在linux调度程序中,yield_task_fair()做什么,linux-kernel,Linux Kernel,这是linux调度器中的一个函数,用于实现路径为root/kernel/sched/FAIR.c的完全公平调度器 () 现在我想逐行了解这个函数的作用。如有任何回复或与完整文件的链接,将不胜感激 static void yield_task_fair(struct rq *rq) { struct task_struct *curr = rq->curr; struct cfs_rq *cfs_rq = task_cfs_rq(curr); struct sched_entity *se
static void yield_task_fair(struct rq *rq)
{
struct task_struct *curr = rq->curr;
struct cfs_rq *cfs_rq = task_cfs_rq(curr);
struct sched_entity *se = &curr->se;
/*
* Are we the only task in the tree?
*/
if (unlikely(rq->nr_running == 1))
return;
clear_buddies(cfs_rq, se);
if (curr->policy != SCHED_BATCH) {
update_rq_clock(rq);
/*
* Update run-time statistics of the 'current'.
*/
update_curr(cfs_rq);
/*
* Tell update_rq_clock() that we've just updated,
* so we don't do microscopic update in schedule()
* and double the fastpath cost.
*/
rq->skip_clock_update = 1;
}
set_skip_buddy(se);
}
获取当前运行队列
struct task_struct *curr = rq->curr;
获取runqueue中与CFS相关的字段,sched.h中的结构定义
struct cfs_rq *cfs_rq = task_cfs_rq(curr);
这是当前正在运行的任务,它的容器将是当前任务的任务结构
struct sched_entity *se = &curr->se;
/*
* Are we the only task in the tree?
*/
if (unlikely(rq->nr_running == 1))
return;
从“下一个”、“上一个”和“跳过”对其自身进行分层清理,以便不再拾取它
(见附件)
SCHED_批处理用于非交互式任务。Rest在代码注释中解释
if (curr->policy != SCHED_BATCH) {
update_rq_clock(rq);
/*
* Update run-time statistics of the 'current'.
*/
update_curr(cfs_rq);
/*
* Tell update_rq_clock() that we've just updated,
* so we don't do microscopic update in schedule()
* and double the fastpath cost.
*/
rq->skip_clock_update = 1;
}
将此任务设置为下一个跳过候选任务。当没有其他候选人时,将运行跳过。选中pick_next_entity以了解有关其功能的更多信息
set_skip_buddy(se);
}
要获得内核源代码的完整文档,请尝试cscope(+ctags)或awesomeweb界面
获取当前运行队列
struct task_struct *curr = rq->curr;
获取runqueue中与CFS相关的字段,sched.h中的结构定义
struct cfs_rq *cfs_rq = task_cfs_rq(curr);
这是当前正在运行的任务,它的容器将是当前任务的任务结构
struct sched_entity *se = &curr->se;
/*
* Are we the only task in the tree?
*/
if (unlikely(rq->nr_running == 1))
return;
从“下一个”、“上一个”和“跳过”对其自身进行分层清理,以便不再拾取它
(见附件)
SCHED_批处理用于非交互式任务。Rest在代码注释中解释
if (curr->policy != SCHED_BATCH) {
update_rq_clock(rq);
/*
* Update run-time statistics of the 'current'.
*/
update_curr(cfs_rq);
/*
* Tell update_rq_clock() that we've just updated,
* so we don't do microscopic update in schedule()
* and double the fastpath cost.
*/
rq->skip_clock_update = 1;
}
将此任务设置为下一个跳过候选任务。当没有其他候选人时,将运行跳过。选中pick_next_entity以了解有关其功能的更多信息
set_skip_buddy(se);
}
有关内核源代码的完整文档,请尝试cscope(+ctags)或很棒的web界面非常感谢您的回答!这很有帮助!只是一些小问题!只是一些小问题!我不明白这部分:clear_buddies(cfs_rq,se);我读了你发送的链接,但不幸的是没有理解!什么是“老兄”?你能解释一下这个函数吗?此外我不理解“update_curr(cfs_rq);”好友是运行队列中的特定任务-最后、下一个和跳过-通过调用
set_last_buddy
、set_next_buddy
和set_skip_buddy
分配,然后用于选择要运行的下一个任务。试着去理解这个问题update\u curr
仅用于维护统计数据,并不重要-例如,对于CPU记帐(参见虚拟化中的CPU配额?)和记录数据的常规更新,例如,您可以通过用户空间中的procfs读取。非常感谢您的回答!这很有帮助!只是一些小问题!只是一些小问题!我不明白这部分:clear_buddies(cfs_rq,se);我读了你发送的链接,但不幸的是没有理解!什么是“老兄”?你能解释一下这个函数吗?此外我不理解“update_curr(cfs_rq);”好友是运行队列中的特定任务-最后、下一个和跳过-通过调用set_last_buddy
、set_next_buddy
和set_skip_buddy
分配,然后用于选择要运行的下一个任务。试着去理解这个问题update\u curr
仅用于维护统计数据,并不重要,例如用于CPU记帐(参见虚拟化中的CPU配额?)和用于记录数据的常规更新,例如,您可以通过用户空间中的procfs读取这些数据。