【Linux 内核】实时调度类 ⑦ ( 实时调度类核心函数源码分析 | dequeue_task_rt 函数 | 从执行队列中移除进程 )
文章目錄
- 一、dequeue_task_rt 函數(shù) ( 從執(zhí)行隊(duì)列中移除進(jìn)程 )
- 二、update_curr_rt 函數(shù) ( 更新調(diào)度信息 )
本篇博客中 , 開(kāi)始分析 struct sched_class rt_sched_class 結(jié)構(gòu)體變量 中的各個(gè) 函數(shù)指針 指向的 函數(shù)源碼 ;
rt_sched_class 結(jié)構(gòu)體 在 Linux 內(nèi)核源碼的 linux-5.6.18\kernel\sched\rt.c 源文件中定義 , 實(shí)時(shí)調(diào)度 相關(guān)的 核心函數(shù) 也定義在該源碼中 ;
一、dequeue_task_rt 函數(shù) ( 從執(zhí)行隊(duì)列中移除進(jìn)程 )
dequeue_task_rt 函數(shù)簡(jiǎn)介 :
dequeue_task_rt 函數(shù)用于 更新 " 調(diào)度信息 " ,
將 " 實(shí)時(shí)調(diào)度實(shí)體 " sched_rt_entity 從 " 執(zhí)行隊(duì)列 " ( 紅黑樹(shù) ) 中 刪除 ,
然后將 被刪除的 " 實(shí)時(shí)調(diào)度實(shí)體 " 添加到 " 執(zhí)行隊(duì)列 " ( 紅黑樹(shù) ) 末尾 ;
dequeue_task_rt 函數(shù)分析 :
update_curr_rt(rq); 的作用是 更新 " 調(diào)度信息 " ,
dequeue_rt_entity(rt_se, flags); 作用是 將 " 實(shí)時(shí)調(diào)度實(shí)體 " rt_se , 從 " 執(zhí)行隊(duì)列 " ( 紅黑樹(shù) ) 中刪除 , 被刪除的 " 實(shí)時(shí)調(diào)度實(shí)體 " 添加到 " 執(zhí)行隊(duì)列 " ( 紅黑樹(shù) ) 末尾 ;
dequeue_pushable_task(rq, p); 作用是 將 進(jìn)程 從 哈希表 中刪除 ;
dequeue_task_rt 函數(shù)源碼 :
static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags) {struct sched_rt_entity *rt_se = &p->rt;update_curr_rt(rq);dequeue_rt_entity(rt_se, flags);dequeue_pushable_task(rq, p); }源碼路徑 : linux-5.6.18\kernel\sched\rt.c#1381
二、update_curr_rt 函數(shù) ( 更新調(diào)度信息 )
update_curr_rt(rq); 的作用是 更新 " 調(diào)度信息 " ;
update_curr_rt 函數(shù)源碼 :
/** Update the current task's runtime statistics. Skip current tasks that* are not in our scheduling class.*/ static void update_curr_rt(struct rq *rq) {struct task_struct *curr = rq->curr;struct sched_rt_entity *rt_se = &curr->rt;u64 delta_exec;u64 now;if (curr->sched_class != &rt_sched_class)return;now = rq_clock_task(rq);delta_exec = now - curr->se.exec_start;if (unlikely((s64)delta_exec <= 0))return;schedstat_set(curr->se.statistics.exec_max,max(curr->se.statistics.exec_max, delta_exec));curr->se.sum_exec_runtime += delta_exec;account_group_exec_runtime(curr, delta_exec);curr->se.exec_start = now;cgroup_account_cputime(curr, delta_exec);if (!rt_bandwidth_enabled())return;for_each_sched_rt_entity(rt_se) {struct rt_rq *rt_rq = rt_rq_of_se(rt_se);if (sched_rt_runtime(rt_rq) != RUNTIME_INF) {raw_spin_lock(&rt_rq->rt_runtime_lock);rt_rq->rt_time += delta_exec;if (sched_rt_runtime_exceeded(rt_rq))resched_curr(rq);raw_spin_unlock(&rt_rq->rt_runtime_lock);}} }源碼路徑 : linux-5.6.18\kernel\sched\rt.c#994
總結(jié)
以上是生活随笔為你收集整理的【Linux 内核】实时调度类 ⑦ ( 实时调度类核心函数源码分析 | dequeue_task_rt 函数 | 从执行队列中移除进程 )的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【Linux 内核】实时调度类 ⑥ (
- 下一篇: 【Linux 内核】SMP 对称多处理器