当前位置:网站首页>十九、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、保存完毕后切换到内核线程执行(包括堆栈切换)
边栏推荐
- 百行代码实现基于Redis的可靠延迟队列
- Scala语言学习-05-递归和尾递归效率对比
- Oracle客户端和服务端的区别
- 排序之归并排序
- Rosbag使用命令
- Meet webassembly again
- Cve-2022-0847 (privilege lifting kernel vulnerability)
- Cross border integration, creativity and innovation to help improve the influence of cultural tourism night tour
- Scala language learning-06-differences between name passing parameters, value passing parameters and function passing parameters
- DevSecOps: CI/CD 流水线安全的最佳实践
猜你喜欢

Discourse 新用户可插入媒体的数量

HMS core news industry solution: let technology add humanistic temperature

各位学弟学妹,别再看教材了,时间复杂度看这篇就好了

vector的模拟实现
![[VTK] model rotation and Translation](/img/4c/76b98797574627a63c385b22637836.png)
[VTK] model rotation and Translation

pymssql模块使用指南

知识管理在业务中的价值如何体现

Gbase "library" special training of innovation and application Committee of Beijing fintech Industry Alliance

Cross border integration, creativity and innovation to help improve the influence of cultural tourism night tour

uni开发微信小程序自定义相机自动检测(人像+身份证)
随机推荐
The MIHA tour club in June is hot! 500+ posts, more than HC, just this summer (with internal promotion method)
Advanced thinking on application scenarios of standardization, maximum normalization and mean normalization
stack和queue的模拟实现
DevSecOps: CI/CD 流水线安全的最佳实践
洛谷P2466 [SDOI2008] Sue 的小球 题解
CVE-2022-0847(提权内核漏洞)
Simulation Implementation of string
pymssql模块使用指南
推進兼容適配,使能協同發展 GBase 5月適配速遞
英国考虑基于国家安全因素让Arm在伦敦上市
二分查找(整数二分)
【山大会议】多人视频通话 WebRTC 工具类搭建
jmeter关联登录302类型的接口
静态断言 static_assert
Development status of full color LED display
Huawei cloud hcdez special session and Distributed Technology Summit: Huawei cloud distributed cloud native technology and Practice
New design of databend SQL planner
Jenkins 通过检查代码提交自动触发编译
"Software defines the world, open source builds the future" 2022 open atom global open source summit will open at the end of July
对领域驱动设计DDD理解