知識(shí)
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X(jué)表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營(yíng)銷的便利,運(yùn)營(yíng)的高效,讓網(wǎng)站成為營(yíng)銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!
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 中,我們簡(jiǎn)單看下
void sched_reschedule() {
current_thread->state = THREAD_READY;
// idle thread doesn't go in the run queue
if (likely(!thread_is_idle(current_thread))) {
#可見會(huì)首先判斷當(dāng)前線程的時(shí)間片是否用盡,用盡的話,則加入到當(dāng)前cpu 運(yùn)行隊(duì)列的末尾,否則就插入到head,這樣下次調(diào)用這個(gè)函數(shù)的時(shí)候就會(huì)
優(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 來(lái)運(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)閱讀
- 百度小程序開發(fā)公司
- php網(wǎng)站
- 網(wǎng)站維護(hù)
- web
- 曲靖小程序開發(fā)
- 網(wǎng)站上首頁(yè)
- 網(wǎng)站建設(shè)招商
- 云南網(wǎng)絡(luò)推廣
- web服務(wù)
- 報(bào)廢車回收管理軟件
- 網(wǎng)站建設(shè)公司網(wǎng)站
- 云南網(wǎng)站建設(shè)公司地址
- 云南網(wǎng)站開發(fā)
- 小程序制作
- 電商網(wǎng)站建設(shè)
- 汽車報(bào)廢
- 報(bào)廢車
- 云南網(wǎng)站建設(shè)一條龍
- 云南網(wǎng)絡(luò)營(yíng)銷
- 云南網(wǎng)站建設(shè) 網(wǎng)絡(luò)服務(wù)
- APP
- 昆明小程序哪家好
- 江蘇小程序開發(fā)
- 云南小程序開發(fā)推薦
- typescript
- 云南花農(nóng)小程序
- 汽車報(bào)廢回收管理系統(tǒng)
- 云南網(wǎng)站建設(shè)報(bào)價(jià)
- 小程序分銷商城
- 汽車回收管理系統(tǒng)