ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Xv6 Operating System Organization

2021-02-27 21:31:55  阅读:370  来源: 互联网

标签:kernel process system System Operating user address Organization mode


Meaning Unknown's Head Image

Operating System Organization

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

文章目录

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

OrganizationDescriptionUpsideDownside
monolithic kernelthe entire OS resides in the kernel with full privilegeconvenient,
easier for different parts of the OS to cooperate
complex interfaces,
easy to make a mistake,
a mistake is fatal
microkernelminimize 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:

FileDescription
bio.cDisk block cache for the file system.
console.cConnect to the user keyboard and screen.
entry.SVery first boot instructions.
exec.cexec() system call.
file.cFile descriptor support.
fs.cFile system.
kalloc.cPhysical page allocator.
kernelvec.SHandle traps from kernel, and timer interrupts.
log.cFile system logging and crash recovery.
main.cControl initialization of other modules during boot.
pipe.cPipes.
plic.cRISC-V interrupt controller.
printf.cFormatted output to the console.
proc.cProcesses and scheduling.
sleeplock.cLocks that yield the CPU.
spinlock.cLocks that don’t yield the CPU.
start.cEarly machine-mode boot code.
string.cC string and byte-array library.
swtch.SThread switching.
syscall.cDispatch system calls to handling function.
sysfile.cFile-related system calls.
sysproc.cProcess-related system calls.
trampoline.SAssembly code to switch between user and kernel.
trap.c Ccode to handle and return from traps and interrupts.
uart.cSerial-port console device driver.
virtio_disk.cDisk device driver.
vm.cManage 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 = 2 38 − 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,系随机选取的图片,仅用于检测屏幕显示的机械、光电性能,与文章的任何内容及观点无关,也并不代表本人局部或全部同意、支持或者反对其中的任何内容及观点。如有侵权,联系删除。

标签:kernel,process,system,System,Operating,user,address,Organization,mode
来源: https://blog.csdn.net/u012419550/article/details/114192498

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有