2010年9月26日 星期日

Curt @Jserv case study

難得有機會可以拜讀大師(Jserv)的作品"Curt",這是網路上有名的自由軟體作者Jserv所做的小型OS系統,系統雖小但五藏俱全,提供了sp, stat, help 的 threads,跟Schedule 的機制,系統流程主要可分成兩大部份,Step 1.boot-loader, 把image load 到RAM的low level assembly code, Step 2. start OS && schedule handle. 詳細流程可參考"國立台灣師範大學資訊工程系"的"嵌入式系統"教材. 底下小弟只是把所知到的data整理成flow表,如需詳細說明部份在Curt的Download檔裡也有說明. Step1. *initial set
*flush TLB/ICahe/DCahe
*Interrupt disable *clock set *UART Hardware 2 Console Display set *all enable && jump to RAM main() @0xc0000000 這邊也可參考類似的flow @Uboot . Step2. *OS start *initial ready_lists 4 each threads, delayed_list,termination_wait_list,termination_wait_list *set thread 2 thread table && priority/function set * run thread && schedule detection (SCHED_TIME_EXPIRE||SCHED_THREAD_REQUEST)
        //儲存CPU status && Disable Interrupt
        cpu_sr = save_cpu_sr();

        //取得最高priority 的 thread  Id
        top_prio = get_top_prio(); 

        /* If the timer expires... */
        if (sched_type == SCHED_TIME_EXPIRE) {
                /* Threads that are currently running will continue to run it
                 * at the highest priority */

                if (current_thread->prio < top_prio) {
                        current_thread->time_quantum = TIME_QUANTUM;
                        restore_cpu_sr(cpu_sr);
                        return;
                }
                /* otherwise, threads in a ready state, then run the highest
                 * priority one. */

                //取得 ready_list的 first Node 2 entry list && change context switch mode
                pnode = delete_front_list(&ready_list[top_prio]);
                if (is_empty_list(&ready_list[top_prio]))
                        prio_exist_flag[top_prio] = false;
                next_thread = entry_list(pnode, thread_struct, node);
                next_thread->state = RUNNING;
                next_thread->time_quantum = TIME_QUANTUM;

                /* Ready to change the status of the currently executing thread */
                current_thread->state = READY;
                insert_back_list(&ready_list[current_thread->prio],
                                 ¤t_thread->node);
                prio_exist_flag[current_thread->prio] = true;
                total_csw_cnt++;
                /* actual context switching */
                context_switch_in_interrupt();
        }
code ref: Jserv's 解析 CuRT 與嵌入式系統設計 放大參考here ps: 如有錯誤的地方歡迎指正,謝謝

沒有留言:

張貼留言