欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

zircon的兩種調(diào)度理解 - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設(shè)-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設(shè)/小程序開發(fā)/軟件開發(fā)

知識

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們在追求其視覺表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營銷的便利,運(yùn)營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏壧峁┍憬莸闹С郑?

您當(dāng)前位置>首頁 » 新聞資訊 » 技術(shù)分享 >

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)案例查看更多