日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

xv6解析-- 多处理器操作

發布時間:2023/12/15 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 xv6解析-- 多处理器操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

xv6可以運行多cpu的計算機上,這個os使用mycpu函數來標識初當前的cpu,使用struct cpu結構體來記錄當前的CPU狀態。使用cpus這些狀態存放于cpus數組中,使用ncpu來標志cpu的個數。

1 // Per-CPU state2 struct cpu {3 uchar apicid; // Local APIC ID 每個cpu都有一個唯一硬件ID,這個ID可以lapicid()函數進行獲取,然后存放于這個字段中。4 struct context *scheduler; // swtch() here to enter scheduler5 struct taskstate ts; // Used by x86 to find stack for interrupt6 struct segdesc gdt[NSEGS]; // x86 global descriptor table7 volatile uint started; // Has the CPU started?8 int ncli; // Depth of pushcli nesting.9 int intena; // Were interrupts enabled before pushcli?10 struct proc *proc; // The process running on this cpu or null11 };1213 extern struct cpu cpus[NCPU]; //當前系統中存在的CPU14 extern int ncpu;

?

以下函數主要功能是獲取 運行當前代碼的cpu對應的ID,然后通過這個ID在cpus數組中進行匹配,得到當前CPU信息(這個cpu信息是已經事先通過程序獲取的)

35 // Must be called with interrupts disabled to avoid the caller being36 // rescheduled between reading lapicid and running through the loop.37 struct cpu*38 mycpu(void)39 {40 int apicid, i;4142 if(readeflags()&FL_IF)43 panic("mycpu called with interrupts enabled\n");4445 apicid = lapicid();46 // APIC IDs are not guaranteed to be contiguous. Maybe we should have47 // a reverse map, or reserve a register to store &cpus[i].48 for (i = 0; i < ncpu; ++i) {49 if (cpus[i].apicid == apicid)50 return &cpus[i];51 }52 panic("unknown apicid\n");53 }

?

轉載于:https://www.cnblogs.com/Dream-Chaser/p/9158917.html

總結

以上是生活随笔為你收集整理的xv6解析-- 多处理器操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。