当前位置:网站首页>十九、Xv6上下文切换(上下文切换的实现;状态机的封装与恢复)
十九、Xv6上下文切换(上下文切换的实现;状态机的封装与恢复)
2022-06-22 14:50:00 【[T]】
一、处理器虚拟化
为什么死循环不能使得计算机彻底卡死?
原理上:
1、硬件会发生中断(类似于“强行插入”的ecall(rics-v的系统调用,类似与x86的syscall))
2、切换到操作系统代码执行
3、操作系统代码可以切换到另一个进程执行
协程库:
co_yield(); //切换协程
二、虚拟化:状态机管理
寄存器组($x0...$x31,$pc),物理内存只有一份
1、寄存器虚拟化:将寄存器状态保存至内存
2、内存虚拟化:$satp的数据结构(Supervisor Address Translation and Protection Register,supervisor模式下的地址翻译和保护寄存器)
操作系统代码最重要的 invariant(单处理器)
1、操作系统开始处理系统调用/中断,所有进程的状态都将被保存至内存
struct page{int prot, void *va, *pa;}
struct proc
{
uint64_t x1, x2, ..., x31;
struct page pages[MAXPAGS];
};(1)保存
把 x1, x2, ..., x31保存到当前的proc即可
(2)恢复
把pags送到$stap对应的数据结构里
三、状态封存:体系结构相关处理
x86-64
1、中断/异常会伴随堆栈切换
(1)通过TSS指定一个”内核栈“
中断前的寄存器保存在堆栈上(典型的CISC行为)
xv6(不限于RISC-V)
1、把进程的trap trame分配到固定地址(通过$stap)
(1)trap frame保存到$sscratch
2、保存完毕后切换到内核线程执行(包括堆栈切换)
边栏推荐
- Discover the number of media new users can insert
- 转:杰克·韦尔奇:战略就是要少点沉思,敏于行动
- Ask if you want to get the start of sqlserver_ Is there a good way for LSN?
- 基础版现在SQL分析查询不能用了吗?
- Applet development - Custom expiration cache
- 【山大会议】注册页的编写
- 新版负载均衡WebClient CRUD
- uni开发微信小程序自定义相机自动检测(人像+身份证)
- 打新债安全性有多高
- [Newman] postman generates beautiful test reports
猜你喜欢

Jenkins automatically triggers compilation by checking code submissions
The MIHA tour club in June is hot! 500+ posts, more than HC, just this summer (with internal promotion method)

百行代码实现基于Redis的可靠延迟队列

数值类型和字符串之间的转换

Uni develops wechat applet to customize automatic camera detection (portrait + ID card)

Application of mongodb in Tencent retail premium code

跨界融合创意创新,助力提高文旅夜游影响力

Simulation of vector

B树和B+树
![[single chip microcomputer] [make buzzer sound] know the buzzer and let it make the sound you want](/img/cb/826b3591bafa62cc71826732eb32ef.png)
[single chip microcomputer] [make buzzer sound] know the buzzer and let it make the sound you want
随机推荐
新版负载均衡WebClient CRUD
二分查找(整数二分)
[译文] 弥合开源数据库和数据库业务之间的鸿沟
【山大会议】WebRTC基础之对等体连接
Program substitution function
普通人怎么在一年内赚到100万?
Turn to: jackwelch: strategy is to think less and be quick to act
Differences between Oracle client and server
vector的模拟实现
C语言学习-18-makefile文件编写例子以及如何生成、调用动态库
Devsecops: best practices for ci/cd pipeline security
【单片机】【让蜂鸣器发声】认识蜂鸣器,让蜂鸣器发出你想要的声音
小程序开发----自定义有效期缓存
Bridging the gap between open source databases and database services
Uni develops wechat applet to customize automatic camera detection (portrait + ID card)
知识管理在业务中的价值如何体现
小白操作Win10扩充C盘(把D盘内存分给C盘)亲测多次有效
[Newman] postman generates beautiful test reports
【山大会议】项目引入 Redux
期货怎么开户?网上期货开户安全吗?