10/19/2007TTI-C PL-Lunch Certified Concurrent Code with Interrupts Xinyu Feng Joint work with Zhong Shao (Yale University) and Yuan Dong (Tsinghua University)

Slides:



Advertisements
Similar presentations
A Translation from Typed Assembly Language to Certified Assembly Programming Zhong Shao Yale University Joint work with Zhaozhong Ni Paper URL:
Advertisements

Chapter 6 Limited Direct Execution
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Modular Verification of Concurrent Assembly Code with Dynamic Thread Creation and Termination Xinyu Feng Yale University Joint work with Zhong Shao.
An Open Framework for Certified System Software Xinyu Feng Yale University.
Certifying Low-Level Programs with Hardware Interrupts and Preemptive Threads Xinyu Feng Toyota Technological Institute at Chicago Joint work with Zhong.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
An Open Framework for Foundational Proof-Carrying Code Xinyu Feng Yale University Joint work with Zhaozhong Ni (Yale, now at MSR), Zhong Shao (Yale) and.
Modular Verification of Assembly Code with Stack-Based Control Abstractions Xinyu Feng Yale University Joint work with Zhong Shao, Alexander Vaynberg,
On the Relationship Between Concurrent Separation Logic and Assume-Guarantee Reasoning Xinyu Feng Yale University Joint work with Rodrigo Ferreira and.
Processes 1 CS502 Spring 2006 Processes Week 2 – CS 502.
CPS110: Implementing threads/locks on a uni-processor Landon Cox.
ConcurrencyCS-3013 A-term Introduction to Concurrency ( Processes, Threads, Interrupts, etc.) CS-3013, Operating Systems A-term 2009 (Slides include.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6.
Introduction to Embedded Systems
Compositional Verification of Termination-Preserving Refinement of Concurrent Programs Hongjin Liang Univ. of Science and Technology of China (USTC) Joint.
Advanced Operating Systems CIS 720 Lecture 1. Instructor Dr. Gurdip Singh – 234 Nichols Hall –
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
Experience with Processes and Monitors in Mesa
Low-Level Program Verification. Components of a Certifying Framework certified code (machine code + proof) specifications: program safety/security/correctness.
Threads and Concurrency. A First Look at Some Key Concepts kernel The software component that controls the hardware directly, and implements the core.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Background: Operating Systems Brad Karp UCL Computer Science CS GZ03 / M th November, 2008.
OPERATING SYSTEM SUPPORT DISTRIBUTED SYSTEMS CHAPTER 6 Lawrence Heyman July 8, 2002.
CS 162 Discussion Section Week 2. Who am I? Haoyuan (HY) Li Office Hours: 1pm-3pm
CS 162 Discussion Section Week 2. Who am I? Wesley Chow Office Hours: 12pm-2pm 411 Soda Does Monday 1-3 work for everyone?
CPS110: Implementing threads Landon Cox. Recap and looking ahead Hardware OS Applications Where we’ve been Where we’re going.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
System Components ● There are three main protected modules of the System  The Hardware Abstraction Layer ● A virtual machine to configure all devices.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
Department of Computer Science and Software Engineering
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
2 Processor(s)Main MemoryDevices Process, Thread & Resource Manager Memory Manager Device Manager File Manager.
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
CHAPTER 7 CONCURRENT SOFTWARE Copyright © 2000, Daniel W. Lewis. All Rights Reserved.
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
CPS110: Implementing threads on a uni-processor Landon Cox January 29, 2008.
Chapter 6 Limited Direct Execution Chien-Chung Shen CIS/UD
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
WORKING OF SCHEDULER IN OS
Introduction to Operating Systems Concepts
Processes and threads.
Process concept.
A Practical Verification Framework for Preemptive OS Kernels
CS 6560: Operating Systems Design
CSCS 511 Operating Systems Ch3, 4 (Part B) Further Understanding Threads Dr. Frank Li Skipped sections 3.5 & 3.6 
Low-Level Program Verification
Protection of System Resources
Operating Systems: A Modern Perspective, Chapter 6
CSCI 511 Operating Systems Ch3, 4 (Part B) Further Understanding Threads Dr. Frank Li Skipped sections 3.5 & 3.6 
Threads, SMP, and Microkernels
Chapter 15, Exploring the Digital Domain
Mid Term review CSC345.
Lecture Topics: 11/1 General Operating System Concepts Processes
Separation Logic and Concurrency Verification
Implementing Processes, Threads, and Resources
CS333 Intro to Operating Systems
COMP3221: Microprocessors and Embedded Systems
Chapter 3: Process Management
Presentation transcript:

10/19/2007TTI-C PL-Lunch Certified Concurrent Code with Interrupts Xinyu Feng Joint work with Zhong Shao (Yale University) and Yuan Dong (Tsinghua University)

How to Guarantee Software Quality? Hardware We need a “certified” computing platform! Buggy? Bootloader + OS + Device DriverCertified Bootloader + OS + Device Driver Buggy? Runtime Services & LibrariesCertified Runtime Services & Libraries Buggy? Security InfrastructureCertified Security Infrastructure Uncertified legacy code becomes second-class citizen! We need firm control of the lowest-level software!

Components of a certified framework certified code (proof + machine code) machine model specifications mechanized meta-logic proof checker Proof Checker Yes CPU Specifications Proof machine code No

timer interrupt handler A mini- OS 1300 lines of 16-bit x86 asm. bootloader keyboard driver keyboard interrupt handler preemptive thread lib: spawn, exit, yield, scheduler, … sync. lib: locks and monitors … a multi-threaded user application Need a precise definition of abstraction layers! [Chuck Moor FCRC’07]

Layering of miniOS Code

C: low-level sequential code, might be tricky (e.g. context switching) [Feng et al. PLDI’06, Feng et al. TLDI’07, Ni et al. TPHOLs’07]

Layering of miniOS Code A: concurrent code, Rely-Guarantee, CSL, … PCC: [Yu&Shao ICFP’04, Feng&Shao ICFP’05, Feng et al. ESOP’07]

Layering of miniOS Code B: concurrent code with explicit interrupts How to certify ???

Concurrency with Interrupts: Challenges IR0 IR1 (1) (2) (3) (4) (5) Asymmetric preemption between handlers and non-handler code Intertwining between threads and handlers Asymmetric synchronization: cli/sti are different from locks Nesting of handlers: may not respect priorities

Contributions of Our Work An abstract machine and operational semantics –Interrupts, switch, block/unblock Program logics –Modeling concurrency/interrupt primitives in terms of memory ownership transfer Certify implementation of sync. primitives –Locks –Condition variables Hoare style, Brinch-Hanson style, Mesa style

Outline of This Talk Background: Separation Logic and Concurrency Abstract Interrupt Machine (AIM) – I –Interrupts with sequential non-handler code AIM – II –Interrupts with multi-threaded non-handler code AIM – III –Adding block/unblock primitives

Separation Logic Assertions l  n n l p  qp  q pq emp empty heap p  qp  q p  q

Separation Logic for Concurrency Key ideas: There is always a partition of memory among threads, and each thread only access its own part. The partition is dynamic: ownership of memory can be dynamically transferred. When there is ownership transfer, certain agreement is followed. Synchronization primitives can be modeled as operations that trigger memory ownership transfer.

Outline of This Talk Background: Separation Logic and Concurrency Abstract Interrupt Machine (AIM) – I –Interrupts with sequential non-handler code AIM – II –Interrupts with multi-threaded non-handler code AIM – III –Adding block/unblock primitives

AIM – I : The Machine I1I1 f1:f1: I2I2 f2:f2: ISR ih: … (code heap) C 0 r1r1 12… r2r2 r3r3 …rnrn (data heap) H (register file) R (state) S addu … cli sti iret … j f (program) P::=(C,S,pc) ::=(H,R,ie) ::={f  I} * pc ie

AIM – I : Operational Semantics Using non-determinism to model interrupts: (C, S, pc)  (C, S', pc') NextS C(pc) (S, S')NextPC C(pc) (pc, pc') (seq) (C, S, pc)  (C, S', ih) S.ie = 1S' = S| ie=0 (irq) P  P' (step) P  P'P  P'

Example: Teeter-Totter while(true){ cli; if([right] == 0){ sti; break; } [right] := [right]-1; [left] := [left]+1; sti; } print(“left wins!”); timer: if([left] == 0){ print(“right wins!”); iret; } [left] := [left]-1; [right] := [right]+1; iret; 50 left right

- { P h }INV AIM – I : The Memory Model Non-handler sti iret Handler BA cli … Memory … - { P h }INV

AIM – I : cli/sti BA INV BB B BA B B cli sti ie = 1ie = 0

AIM – I : handler BA INV irq iret ie = 1ie = 0 BA INV BA BA

AIM – I : cli/sti in handler sti cli ie = 0ie = 1 BA INV B BA B...

Example: Teeter-Totter while(true){ -{emp} cli; -{emp * INV}... [right] := [right]-1; [left] := [left]+1; -{INV} sti; -{emp} } timer: -{INV} if([left] == 0){ print(“right wins!”); -{INV} iret; } [left] := [left]-1; [right] := [right]+1; -{INV} iret; INV:  m, n. (left  m)  (right  n)  (m+n = 100)

Soundness Safety: –“Certified non-handler and hander would not get stuck”; Partial correctness: –Inserted assertions as specifications always hold whenever the specified program points are reached. Proof based on progress/preservation lemmas

Outline of This Talk Background: Separation Logic and Concurrency Abstract Interrupt Machine (AIM) – I –Interrupts with sequential non-handler code AIM – II –Interrupts with multi-threaded non-handler code AIM – III –Adding block/unblock primitives

AIM – II : The Machine I1I1 f1:f1: I2I2 f2:f2: ISR ih: … (code heap) C 0 r1r1 12… r2r2 r3r3 …rnrn (data heap) H (register file) R (state) S cli sti … switch j f (program) P::=(C,S,Q,pc) ::=(H,R,ie) ::={f  I} * pc ie pc R R R … (ready. queue) Q

AIM – II : switch A primitive implemented at layer C –Interrupt must be disabled before executing switch Operational semantics: –Put the current thread into ready Q –Resume a thread in Q (non-deterministic op)

Examples timer_0:... switch... iret timer_1: iret yield: cli switch sti ret Layer A: ie = 0: non-preemptive threads ie = 1 & timer_1: non-preemptive threads ie = 1 & timer_0: preemptive threads

Example: spin locks acquire (l): cli; while([l] == 0){ sti; cli; } [l] := 0; sti; return; release (l): cli; [l] := 1; sti; return; switch

AIM – II : Memory Model BA INV0 A C T1T1 T2T2 INV1

AIM – II : cli/sti T 1 : cli CA INV0 T1T1 T2T2 INV1 T1T1 T1T1 INV0 T1T1 T2T2 INV1 T 1 : sti ie = 1ie = 0

AIM – II : switch T1T1 T1T1 INV0 T1T1 T2T2 INV1 T 1 : switch T2T2 T2T2 INV0 T1T1 T2T2 INV1 ie = 0

Example: spin locks acquire (l): cli; while([l] == 0){ sti; cli; } [l] := 0; sti; return; release (l): cli; [l] := 1; sti; return; l 0/1 R  INV1:  b. ( l  b)  (b=0  emp  b=1  R) -{ emp } -{ R } -{ emp } -{ R }

Example: spin locks acquire (l): cli; while([l] == 0){ sti; cli; } [l] := 0; sti; return; l 0/1 R  INV1:  b. ( l  b)  (b=0  emp  b=1  R) -{ emp } -{ R } -{ emp  INV1  INV0} -{ emp } -{ emp  INV1  INV0}-{ (l  1)  R  INV0}-{ (l  0)  R  INV0} -{ INV1  INV0  R} -{ R}

Outline of This Talk Background: Separation Logic and Concurrency Abstract Interrupt Machine (AIM) – I –Interrupts with sequential non-handler code AIM – II –Interrupts with multi-threaded non-handler code AIM – III –Adding block/unblock primitives

AIM – III : The Machine f1:f1: f2:f2: ih: (code heap) C (state) S (program) P::=(C,S,B,Q,pc) ::=(H,R,ie) block unblock … pc 0 r1r1 1 2 … r2r2 r3r3 …rnrn (data heap) H (register file) R ie pc R R R … (ready. queue) Q … w1w1 w2w2 wnwn B

AIM – III : block and unblock block rs –put current thread into the block queue B(rs) –pick a thread from ready queue to execute unblock rs, rd –move a thread from B(rs) to the ready queue –put the thread id into rd, put 0 if B(rs) empty –no context switching!

Examples: locks acquire_0(l): cli; if ([l] == 0) block l; else [l] := 0; sti; return; l B(l) = Q l release_0(l): local x; cli; unblock l x; if (x == 0) [l] := 1; sti; return; 0/1 acquire_1(l): cli; while ([l] == 0) block l; [l] := 0; sti; return; release_1(l): local x; cli; unblock l x; [l] := 1; sti; return; R 

How to interpret block/unblock Threads block themselves to wait for resources. … w1w1 w2w2 wnwn B locks: wait for resources protected by locks condition variables: wait for resources over which the condition holds R1R1 R2R2 RnRn  ::= {w 0  R 0, …, w n  R n } R i can be emp !

block switch T1T1 T1T1 INV0 T1T1 T2T2 INV1 ? ! T2T2 T2T2 INV0 T1T1 T2T2 INV1 ! T2T2 T2T2 INV0 INV1 T1T1 T2T2 T1T1 T1T1 INV0 T1T1 INV1 T2T2 ! unblock Thread 1 T2T2 ! How to interpret block/unblock Thread 2 block

Examples: locks acquire_0(l): cli; if ([l] == 0) block l; else [l] := 0; sti; return; l B(l) = Q l 0/1 R   (l) = R INV1:  b, ( l  b)  (b=0  emp  b=1  R) -{ emp } -{ R } -{ emp } -{ emp  INV1  INV0} -{ emp  (l  1)  R  INV0} -{ emp  INV1  INV0   (l) } -{ emp  (l  0)  R  INV0} -{ emp  INV1  INV0  R}-{ emp  R}

Examples: locks l B(l) = Q l 0/1 R   (l) = R INV1:  b, ( l  b)  (b=0  emp  b=1  R) release_0(l): local x; cli; unblock l x; if (x == 0) [l] := 1; sti; return; -{ R } -{ emp } -{ R } -{ R  INV1  INV0}-{(x=0  R  x  0  emp)  INV1  INV0}-{ R  INV1  INV0}-{ (l  1)  R  INV0} -{ INV1  INV0} -{ emp } -{ (l  0)  R  INV0}

Examples: locks l B(l) = Q l 0/1 R   (l) = R INV1:  b, ( l  b)  (b=0  emp  b=1  R) acquire_1(l): cli; while ([l] == 0) block l; [l] := 0; sti; return; release_1(l): local x; cli; unblock l x; [l] := 1; sti; return; -{ emp } -{ R } -{ emp }  (l) = emp

Examples : Condition Variables wait()/notify() Hoare Style / Brinch-Hanson Style Mesa style See the technical report:

Conclusion AIM machine –low-level –can implement interrupt handlers and thread libraries A program logic –following local reasoning in separation logic –modeling cli/sti, switch, block/unblock in terms of memory ownership transfer –can certify different implementation of locks and C.V.s

Future Work Linking layers A, B and C –operational semantics of switch and block/unblock can be used as spec. for layer C –may derive a logic for layer A as a specialization of B –expose spec. of locks and CVs to A

Future Work Linking layers A, B and C –operational semantics of switch and block/unblock can be used as spec. for layer C –may derive a logic for layer A as a specialization of B –expose spec. of locks and CVs to A Multiple interrupts Dynamic creation of block queues in B Device drivers and I/O BAAnAn A0A0 A1A1 …

Thank you! Any Questions?

A Simple Example if ([ l ] = 1) [ l ] := 0; 11 l R l R INV:  b, ( l  b)  (b=0  emp  b=1  R) 0 l R 0 l R INV