知識
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們在追求其視覺表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營銷的便利,運(yùn)營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏壧峁┍憬莸闹С郑?
zircon的兩種調(diào)度理解
發(fā)表時(shí)間:2019-7-6
發(fā)布人:葵宇科技
瀏覽次數(shù):52
zircon 實(shí)現(xiàn)兩種調(diào)度機(jī)制,一種就是fair 其實(shí)現(xiàn)在fair_scheduler.cpp中,一種是基于時(shí)間片的其實(shí)現(xiàn)在sched.cpp 中,調(diào)度器的入口都在sche_reschedule()這個(gè)函數(shù)中。
例如fair的實(shí)現(xiàn)如下:
void sched_reschedule() {
FairScheduler::Reschedule();
}
fair的實(shí)現(xiàn)是一個(gè)cpp的類。
另一中sche_reschedule()的實(shí)現(xiàn)在sched.cpp 中,我們簡單看下
void sched_reschedule() {
current_thread->state = THREAD_READY;
// idle thread doesn't go in the run queue
if (likely(!thread_is_idle(current_thread))) {
#可見會首先判斷當(dāng)前線程的時(shí)間片是否用盡,用盡的話,則加入到當(dāng)前cpu 運(yùn)行隊(duì)列的末尾,否則就插入到head,這樣下次調(diào)用這個(gè)函數(shù)的時(shí)候就會
優(yōu)先調(diào)用這個(gè)函數(shù)
if (current_thread->remaining_time_slice > 0) {
insert_in_run_queue_head(curr_cpu, current_thread);
} else {
insert_in_run_queue_tail(curr_cpu, current_thread);
}
}
sched_resched_internal();
}
void sched_resched_internal() {
thread_t* current_thread = get_current_thread();
uint cpu = arch_curr_cpu_num();
CPU_STATS_INC(reschedules);
// pick a new thread to run
#從當(dāng)前cpu 挑選一個(gè)thread 來運(yùn)行,類似于linux的RR調(diào)度
thread_t* newthread = sched_get_top_thread(cpu);
DEBUG_ASSERT(newthread);
newthread->state = THREAD_RUNNING;
thread_t* oldthread = current_thread;
oldthread->preempt_pending = false;
#計(jì)算久進(jìn)程的時(shí)間記賬
zx_time_t now = current_time();
// account for time used on the old thread
DEBUG_ASSERT(now >= oldthread->last_started_running);
zx_duration_t old_runtime = zx_time_sub_time(now, oldthread->last_started_running);
oldthread->runtime_ns = zx_duration_add_duration(oldthread->runtime_ns, old_runtime);
oldthread->remaining_time_slice = zx_duration_sub_duration(
oldthread->remaining_time_slice, MIN(old_runtime, oldthread->remaining_time_slice));
// set up quantum for the new thread if it was consumed
if (newthread->remaining_time_slice == 0) {
newthread->remaining_time_slice = THREAD_INITIAL_TIME_SLICE;
}
newthread->last_started_running = now;
#切換mmu
// see if we need to swap mmu context
if (newthread->aspace != oldthread->aspace) {
vmm_context_switch(oldthread->aspace, newthread->aspace);
}
#進(jìn)程切換
// do the low level context switch
final_context_switch(oldthread, newthread);
}
相關(guān)案例查看更多
相關(guān)閱讀
- 網(wǎng)站建設(shè)專業(yè)品牌
- 小程序生成海報(bào)
- 軟件定制公司
- 開發(fā)微信小程序
- 前端開發(fā)
- 怎么做網(wǎng)站
- 云南軟件設(shè)計(jì)
- 云南建設(shè)廳網(wǎng)站
- uniapp開發(fā)小程序
- 微分銷
- 花農(nóng)小程序
- 網(wǎng)絡(luò)公司哪家好
- 小程序被攻擊
- 小程序開發(fā)排名前十名
- 迪慶小程序開發(fā)
- 網(wǎng)站維護(hù)
- 云南省建設(shè)廳官方網(wǎng)站
- 云南網(wǎng)站建設(shè)靠譜公司
- 云南etc小程序
- 網(wǎng)絡(luò)公司報(bào)價(jià)
- 日歷組件
- typescript
- 云南手機(jī)網(wǎng)站建設(shè)
- 云南網(wǎng)站建設(shè)費(fèi)用
- 網(wǎng)站建設(shè)價(jià)格
- 網(wǎng)站建設(shè)費(fèi)用
- 云南網(wǎng)站建設(shè)專業(yè)品牌
- 云南小程序定制
- 云南軟件定制公司
- 云南省建設(shè)廳網(wǎng)站官網(wǎng)