读书笔记:《xv6:a simple, Unix-like teaching operating system》

Chapter0 Operating system interfaces

System callDescription
fork()Create a process
exit()Terminate the current process
wait()Wait for a child process to exit
kill(pid)Terminate process pid
getpid()Return the current process’s pid
sleep(n)Sleep for n clock ticks
exec(filename, *argv)Load a file and execute it
sbrk(n)Grow process’s memory by n bytes
open(filename, flags)Open a file; the flags indicate read/write
read(fd, buf, n)Read n bytes from an open file into buf
write(fd, buf, n)Write n bytes to an open file
close(fd)Release open file fd
dup(fd)Duplicate fd
pipe§Create a pipe and return fd’s in p
chdir(dirname)Change the current directory
mkdir(dirname)Create a new directory
mknod(name, major, minor)Create a device file
fstat(fd)Retrun info about an open file
link(f1, f2)Create another name (f2) for the file f1
unlink(filename)Remove a file

Chapter1 Operating system organization

multiplexing、isolation、interaction

Chapter2 Page tables

每个进程的页表同时包括用户内存和内核内存的映射,当用户通过中断或者系统调用转入内核时就不需要进行页表的转换了

Chapter3 Traps, interrupts, and drivers

控制从CPU转移到内核的3种情况:

  1. 系统调用:用户程序请求操作系统服务
  2. 异常:程序执行非法操作
  3. 中断:设备产生信号,等待操作系统处理

x86有4个保护等级,0(最高等级)到3(最低等级),大多数操作系统只使用了0和3,被称为kernel modeuser mode,正在执行的指令的保护等级存储在%cs寄存器的CPL

interrupt handlersinterrupt descriptor table (IDT)中定义,IDT有256个entry,每一个包含%cs%eip

intiret指令

Chapter4 Locking

spinlock

// Acquire the lock.
// Loops (spins) until the lock is acquired.
// Holding a lock for a long time may cause
// other CPUs to waste time spinning to acquire it.
void
acquire(struct spinlock *lk)
{
	pushcli(); // disable interrupts to avoid deadlock.
	if(holding(lk))
		panic("acquire");
	// The xchg is atomic.
	while(xchg(&lk−>locked, 1) != 0)
	;
	
	// Tell the C compiler and the processor to not move loads or stores 1585 // past this point, to ensure that the critical section’s memory 1586 // references happen after the lock is acquired.
	__sync_synchronize();
	
	// Record info about lock acquisition for debugging.
	lk−>cpu = mycpu();
	getcallerpcs(&lk, lk−>pcs);
}
// Release the lock.
void
release(struct spinlock *lk)
{
	if(!holding(lk))
	panic("release");
	
	lk−>pcs[0] = 0;
	lk−>cpu = 0;
	
	// Tell the C compiler and the processor to not move loads or stores 1660
	// past this point, to ensure that all the stores in the critical 1661
	// section are visible to other cores before the lock is released.
	// Both the C compiler and the hardware may re−order loads and
	// stores; __sync_synchronize() tells them both not to.
	__sync_synchronize(); 1665
	
	// Release the lock, equivalent to lk−>locked = 0.
	// This code can’t use a C assignment, since it might
	// not be atomic. A real OS would use C atomics here.
	asm volatile("movl $0, %0" : "+m" (lk−>locked) : ); 1670
	
	popcli();
}

sleeplock

持有锁的期间,释放处理器

recursivelock

函数持有该锁,任何该函数调用的函数都可以重新获取锁

Chapter5 Scheduling

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值