Operating System Organization

参考 xv6-riscv-book Chapter 2 Operating system organization

文章目录

  • Operating System Organization
    • Abstracting physical resources
    • User mode, supervisor mode, and system calls
    • Kernel organization
    • Xv6 organization
    • Process overview
      • Process
      • Thread
      • Virtual address
      • System call
    • Starting xv6 and the first process

Three requirements for OS:

  • multiplexing
  • isolation
  • interaction

Abstracting physical resources

Transparency: simplifies interaction

  • Abstract the resources into services
  • Applications don’t have to be aware of time sharing
  • Allows the OS to decide the usage of memory

User mode, supervisor mode, and system calls

Kernel organization

Organization Description Upside Downside
monolithic kernel the entire OS resides in the kernel with full privilege convenient,
easier for different parts of the OS to cooperate
complex interfaces,
easy to make a mistake,
a mistake is fatal
microkernel minimize the code that runs in supervisor mode,
execute the bulk of the OS in user mode
reduce the risk of mistakes in the kernel

(NOTE> OS services running as processes are called servers)

Xv6 organization

Xv6 kernel source files:

File Description
bio.c Disk block cache for the file system.
console.c Connect to the user keyboard and screen.
entry.S Very first boot instructions.
exec.c exec() system call.
file.c File descriptor support.
fs.c File system.
kalloc.c Physical page allocator.
kernelvec.S Handle traps from kernel, and timer interrupts.
log.c File system logging and crash recovery.
main.c Control initialization of other modules during boot.
pipe.c Pipes.
plic.c RISC-V interrupt controller.
printf.c Formatted output to the console.
proc.c Processes and scheduling.
sleeplock.c Locks that yield the CPU.
spinlock.c Locks that don’t yield the CPU.
start.c Early machine-mode boot code.
string.c C string and byte-array library.
swtch.S Thread switching.
syscall.c Dispatch system calls to handling function.
sysfile.c File-related system calls.
sysproc.c Process-related system calls.
trampoline.S Assembly code to switch between user and kernel.
trap.c C code to handle and return from traps and interrupts.
uart.c Serial-port console device driver.
virtio_disk.c Disk device driver.
vm.c Manage page tables and address spaces.

(From: pbpaste | awk '{ printf("| %s |", $1); for (i=2; i<=NF; i++) printf(" %s", $i); printf(" |\n"); }' | pbcopy)

The inter-module interfaces are defined in kernel/defs.h.

Process overview

Process

The unit of isolation: a process: an illusion to a program that it has its own private machine (private memory, CPU, file descriptors, etc.). Process is defined as struct proc (kernel/proc.h:86).

  • p->state: whether the process is allocated, ready to run, running, waiting for I/O, or exiting:
enum procstate { UNUSED, USED, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
  • p->pagetable: holds the process’s page table.

Thread

Thread (of execution): executes the process’s instructions.

A thread can be suspended and later resumed.

Threads can “block” in the kernel to wait for I/O, and resume where it left off when the I/O has finished.

Virtual address

Virtual address: Isolation of memory: virtual address -- page tables --> physical address:

MAXVA
↑    trampoline
|    trapframe
|    Heap
|    Stack (user stack)
|    Global Variables (text and data)
|    Instructions
0
  • VA is starting at zero
  • MAXVA (the maximum virtual address) defined in kernel/riscv.h:348: Xv6 uses 38 bits to look up virtual addresses in page tables: MAXVA=238−1=0x3fffffffff\textrm{MAXVA}=2^{38}-1=\textrm{0x3fffffffff}MAXVA=238−1=0x3fffffffff
  • Each process has two stacks: user stack & kernel stack (p->kstack, for a system call or interrupt, separate and protected from user code).

System call

ecall: a RISC-V instruction to make a system call:

  1. raises hardware privilege level
  2. change PC to a kernel-defined entry point, switches to a kernel stack
  3. executes the kernel instructions
  4. (system call completes) switches back to the user stack
  5. returns to user space by calling the sret instruction (lowers the hardware privilege level)
  6. resumes executing user instructions just after the system call instruction

Starting xv6 and the first process

  1. RISC-V computer powers on, self initializes
  2. runs a boot loader (stored in ROM): loads the xv6 kernel into memory at physical address 0x80000000 (range 0x0:0x80000000 contains I/O devices)
  3. (in machine mode) executes xv6 starting at _entry (kernel/entry.S:6), sets up a stack (stack0) for C code (sp = stack0 + (hartid * 4096))
  4. _entry calls into C code: function start (kernel/start.c:11)
  5. start performs configuration(page-table, interrupts…)
  6. switches to supervisor mode, PC change to main (kernel/main.c:11)
  7. main initializes several devices and subsystems
  8. creates the first process by calling userinit (kernel/proc.c:212)
  9. run initcode.S (user/initcode.S:1), do exec("/init")
  10. init (user/init.c:15) creates a console device file, opens it as file descriptors 0, 1, and 2
  11. starts a shell on the console
  12. The system is up.

EOF


// By CDFMLR 2021-02-27
printf("See you.\n");

顶部图片来自于小歪API,系随机选取的图片,仅用于检测屏幕显示的机械、光电性能,与文章的任何内容及观点无关,也并不代表本人局部或全部同意、支持或者反对其中的任何内容及观点。如有侵权,联系删除。

Xv6 Operating System Organization相关推荐

  1. xv6: a simple, Unix-like teaching operating system|Chapter 1 Operating system interfaces

    Chapter 1 Operating system interfaces 1.0 Overview ❓ Recall The job of an operating system How does ...

  2. POSIX:可移植操作系统接口(Portable Operating System Interface of UNIX,缩写为 POSIX )

    POSIX表示可移植操作系统接口(Portable Operating System Interface of UNIX,缩写为 POSIX ),POSIX标准定义了操作系统应该为应用程序提供的接口标 ...

  3. 什么是操作系统 ?WHAT IS AN OPERATING SYSTEM?

    WHAT IS AN OPERATING SYSTEM? Operating systems turn ugly hardware into beautiful abstractions. Opera ...

  4. CPT104 Operating System Concepts Note

    Word 直接复制过来标号有错误 Lecture 1 Process What is an Operating System? OS An Operating system is the heart ...

  5. How to Make a Computer Operating System

    How to Make a Computer Operating System 如何制作一个操作系统(翻译版) 原文地址:Github:How to Make a Computer Operating ...

  6. VMware vSphere Client中启动虚拟机提示No boot filename received/Operating System not found解决方法

    VMware vSphere Client中启动虚拟机提示No boot filename received/Operating System not found解决方法 参考文章: (1)VMwar ...

  7. vm虚拟机安装系统后出现operating system not found解决办法(VM装ghost 不能进系统的解决方法)

    vm虚拟机安装系统后出现operating system not found解决办法不知你使用那种软件分的区?   用DIANGEN的话,它本来就清楚列明了激活分区选项的. 如果用PQ分区的话,还必须 ...

  8. Directory lookup for the file xxx.mdf failed with the operating system error 2

    Directory lookup for the file "xxx.mdf" failed with the operating system error 2(系统找不到指定的文 ...

  9. 成功解决解决VM软件安装Linux的Ubuntu过程,打开时 Operating System not found

    成功解决解决VM软件安装Linux的Ubuntu过程,打开时 Operating System not found 目录 解决问题 解决思路 解决方法 解决问题 安装Ubuntu16.04虚拟机,打开 ...

最新文章

  1. c++ gdb 绑定源码_【Vue原理】VNode 源码版
  2. 每个程序员都应该学习使用Python或Ruby
  3. Knockout 新版应用开发教程之visible绑定
  4. 爬取百度网盘资源报user is not authorized, hitcode:119
  5. 初探DispatcherServlet#doDispatch
  6. linux 内存 virt,Linux 内存 virt res shr data swap 意义
  7. 微信公众号介绍_以及注册订阅号---微信公众号开发工作笔记0001
  8. 开发LED屏幕页面遇到的问题
  9. Docker学习笔记08-----Docker Harbor使用详解
  10. 下载kaggle数据集
  11. 【Unity3D】游戏开发数学基础
  12. 从零开始学习HTML
  13. 我的RUST学习——【第九章 9-1】panic! 与不可恢复的错误
  14. 以太坊数据库RocksDB报错:org.rocksdb.RocksDBException:Failed to create dir
  15. 什么是双因素身份认证?
  16. ADC分类及主要技术指标
  17. kafka-4.进阶,ISR,OSR,AR,LW,HW,LEO,ACK原理理论
  18. 台式计算机显示器点不亮的原因,电脑点不亮原因及处理方法
  19. 血与荣耀(第四章-命令的镣铐)
  20. 线控转向,包含设计说明书,carsim模型,MATLAB Simulink模型全套

热门文章

  1. 计算机网络第一弹——基础概念
  2. MWORKS--系统建模与仿真
  3. 【科普】之桌面操作系统
  4. 101/103/104规约应用典型问题例举【转】
  5. easyswoole默认访问html,easyswoole安装报错 解决办法
  6. 因数和以及因数个数和问题
  7. STM32的USART编程
  8. 【STM32H7教程】第65章 STM32H7的低功耗串口LPUART基础知识和HAL库API
  9. 【信号与系统】如何理解冲激信号
  10. 常见的电源问题(一)混叠效应