




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、The OS kernel: Implementing processes and Threads,Kernel Definitions and Objects Queue Structures Threads Implementing Processes and Threads Implementing Synchronization and Communication Mechanisms Interrupt Handling,Kernel Definitions and Objects,Process and thread management Interrupt and trap ha
2、ndling Resource management Input and output,OS kernel: a basic set of objects, primitive operations, data structures, and processes from which the remainder of the system may be constructed,Kernel,Interactions with kernel objects,A Process Creation Hierarchy,Queue structures,Queues in OSs -queue for
3、 PCB -queues for hardware managers -queues for synchronization -queues for shared software components Implementations of Queues -single-level queues -priority queues,Implementations of queues,Types of queues: -FIFO -priority based,Elements of queues,Operations related to queues -insert( queue Q, ele
4、ment x) -remove( queue Q, element x) -empty( queue Q),Header or descriptor of queues,Single-Level Queues,Circular array Linked list,Priority queues,Fixed-number priorities,Queue pointer,front,rear,0,1,. . .,i,. . .,N-1,. . .,. . .,. . .,Binary heap,1125,Threads,The normal implementation of processes
5、 results in much runtime overhead. To alleviate this problem, multiple “lightweight” scheduling units is implemented within a process. These units share the same resources as there host process,Create a new thread; Initiate or make a thread ready; Destroy or terminate a thread; Delay or terminate a
6、thread Delay or put a thread to sleep for a given amount of time; Synchronize threads through semaphores, events or condition variables; Perform lower-level operations, such as blocking, suspending, or scheduling a thread,Operations on threads:,Implementing processes and threads,Process and thread d
7、escriptors Implementing operations on processes Operations on threads,PCB,Identification State vector Processors Status information Creation tree other information,Structure of process descriptor,PCB,ID,Cpu_state,Processor_ID,memory,Open_files,Other_resources,list,type,priority,parent,child,. . .,pr
8、ocessors,resources,State vector,status,Creation_tree,Other information,State vector,Status information,Implementing operations on processes,Create Create(so,mo,pi,pid) p=Get_New_PCB(); pid=Get_New_PID(); p-ID=pid; p-CPU_State=s0; p-Memory=m0; p-Priority=pi; p-State.Type=“ready_s”; p-Creation_tree.Pa
9、rent=self; p-Creation_Tree.child=NULL; insert(self-Creation_tree.child,p); insert(RL,p); Scheduler(); ,Suspend suspend(pid) p=Get_PCB(pid); s=p-Status.Type; if(s=“blocked_a”)|(s=“blocked_s”) p-status.Type=“block_s”; else p-status.Type=“ready_s”; if(s=“running”) cpu=p-Processor_ID; p-CPU_State=Interr
10、upt(cpu); Scheduler(); ,Activate Activate(pid) p=Get_PCB(pid) if(p-Status.Type=“ready_s”) p-Status.Type=“ready_a”; Scheduler(); else p-status.Type=“blocked_a”; ,Destroy Destroy(pid) p=Get_PCB(pid); Kill_Tree(p); Scheduler(); Kill_Tree(p) for(each q in p-Creation_Tree.Child) Kill_Tree(q); if(p-Status
11、.Type=“running”) cpu=p-Processor_ID Interrupt(cpu); Remove(p-Status.List,p); Release_all(p-Memory); Release_all(p-Other_Resources); Close_all(p-Open_Files); Delete_PCB(p); ,Implementing synchronization and communication mechanisms,Semaphores and locks Monitor primitives Clock and time management Com
12、munication,General version of the Request/Release,Request(res) if(Free(res) Allocate(res,self); else Block(self,res); Scheduler(); Release(res) Deallocate(res,self); if(Process_Blocked_on(res,pr) Allocate(res,pr); Unblock(pr,res); Scheduler(); ,Semaphores and locks,BT:carry appointed bit to CF; BTC:
13、 carry appointed bit to CF, and reverse it; BTR: carry appointed bit to CF, and change it to 0; BTS: carry appointed bit to CF, and change it to 1;,Bit Test Instruction :,Spin Locks on Binary Semaphores,Pb(sb): do TS(R,sb); while(!R);/*wait loop*/ Vb(sb): sb=1;,General Semaphores with spin locks,P p
14、(s) s=s-1; if(s0) Pb(delay_s; V v(s) s=s+1; if(s=0) Vb(delay_s); else ,Pb(mutex_s);,Vb(mutex_s);,Vb(mutex_s);,Pb(mutex_s);,Vb(mutex_s);,Avoiding the Busy-Wait,P(s) Inhibit_Interrupts; Pb(mutex_s); s=s-1; if(s0) Block(self, Ls); Vb(mutex_s); Enable_Interrupts; Scheduler(); else Vb(mutex_s); Enable_In
15、terrupts; ,V(s) Inhibit_Interrupts; Pb(mutex_s); s=s+1; if(s=0) Unblock(q, Ls); Vb(mutex_s); Enable_Interrupts; Scheduler(); else Vb(mutex_s); Enable_Interrupts; ,Primitive and atomic operation,Priority Interrupt request Switching tasks on single CPU Switching tasks on multiple CPU,struct semaphore
16、atomic_t count; int sleepers; wait_queue_head_t wait; #if WAITQUEUE_DEBUG long _magic; #endif ;,static inline void down(struct semaphore * sem) #if WAITQUEUE_DEBUG CHECK_MAGIC(sem-_magic); #endif _asm_ _volatile_( # atomic down operationnt LOCK decl %0nt /* -sem-count */ js 2fn 1:n LOCK_SECTION_STAR
17、T() 2:tcall _down_failednt jmp 1bn LOCK_SECTION_END :=m (sem-count) :c (sem) :memory); ,asm( .textn .align 4n .globl _down_failedn _down_failed:nt #if defined(CONFIG_FRAME_POINTER) pushl %ebpnt movl %esp,%ebpnt #endif pushl %eaxnt pushl %edxnt pushl %ecxnt call _downnt popl %ecxnt popl %edxnt popl %
18、eaxnt #if defined(CONFIG_FRAME_POINTER) movl %ebp,%espnt popl %ebpnt #endif ret );,void _down(struct semaphore * sem) struct task_struct *tsk = current; DECLARE_WAITQUEUE(wait, tsk); tsk-state = TASK_UNINTERRUPTIBLE; add_wait_queue_exclusive( ,static inline void spin_lock(spinlock_t *lock) #if SPINL
19、OCK_DEBUG _label_ here; here: if (lock-magic != SPINLOCK_MAGIC) printk(eip: %pn, nopnt jle 2bnt jmp 1bn LOCK_SECTION_END,#define spin_lock_irq(lock)do local_irq_disable(); spin_lock(lock); while (0),Monitor primitives,Body of each procedure: p(mutex); procedure_body; if(urgentcnt) V(urgent); else V(
20、mutex); C.wait: condcnt_c=condcnt_c+1; if(urgentcnt) V(urgent); else V(mutex); P(condsem_c) condcnt_c=condcnt-1; C.signal: if(condcnt_c) urgentcnt=urgentcnt+1; V(condsem_c); P(urgent); urgentcnt=urgentcnt-1; ,Clock and Time Management,Wall clock timer - Update_clock - Get_Time - SetClock(tnew),Count
21、down Timers - Set_Timer(tdel) - Delay(tdel) Delay(tdel) Set_timer(tdel); P(delsem); - TimeOut() TimeOut( ) V(delsem): ,Implementing logical timers,Logical timer - tn=Create_LTimer(); - Destroy_LTimer(tn); - SetLTimer(tn,tdel);,Using a Priority Queue with Absolute Wakeup Times,Hardware timers,Wall-clock,countdown,103,12,Timer queue,TQ,a,b,TQ,Using a Priority Queue with Time Differences,Hardware timers,countdown,12,Timer queue,TQ,a,b,TQ,Communication primitives,Generic form of message-passing primitives - send(p,m) - receive(q, m) Two issues must be resolved - how does the sender know that s
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 少先队植树活动方案
- 工匠云直播活动方案
- 小班荷花画展活动方案
- 小说学校活动方案
- 干部培训活动策划方案
- 岗位能力建设活动方案
- 工厂物流活动方案
- 小规模聚集活动方案
- 工会活动叠杯子活动方案
- 小班衣服活动方案
- 2024年辽宁省沈阳沈河区七校联考物理八年级下册期末检测试题含解析
- 中药煎药室清洁及消毒记录表
- 村医培训死因监测课件
- 质量安全文明施工保证措施
- 管理授权手册7.28
- 2024届北京市石景山区七年级生物第二学期期末学业水平测试模拟试题含解析
- 运输企业安全生产管理台帐
- 射波刀技术的质量保证课件
- 龙门吊装载机司机安全教育培训记录表
- 《劳动保护知识》课件
- 09X700 智能建筑弱电工程设计与施工(上册)
评论
0/150
提交评论