Page 1. Lab 5 Logistics. Implicit Threads. Explicit Thread Semantics. Problem not enough interrupt pins CS/ECE 6780/5780. Al Davis

Similar documents
CS/ECE 6780/5780. Al Davis

Interrupts on the 6812

Introduction to Embedded Systems. Lab Logistics

Lecture notes Lectures 1 through 5 (up through lecture 5 slide 63) Book Chapters 1-4

Preview. Process Scheduler. Process Scheduling Algorithms for Batch System. Process Scheduling Algorithms for Interactive System

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

CSE 153 Design of Operating Systems

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

Chapter 2 Processes and Threads

CS 326: Operating Systems. CPU Scheduling. Lecture 6

Sample Questions. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Main Points of the Computer Organization and System Software Module

CPU Scheduling (1) CPU Scheduling (Topic 3) CPU Scheduling (2) CPU Scheduling (3) Resources fall into two classes:

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

Lecture 9: Midterm Review

SAMPLE MIDTERM QUESTIONS

CS3733: Operating Systems

Preview. The Thread Model Motivation of Threads Benefits of Threads Implementation of Thread

CPU Scheduling. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Introduction to Real-Time Operating Systems

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

CS418 Operating Systems

CS370 Operating Systems

Lecture 3: Concurrency & Tasking

A Predictable RTOS. Mantis Cheng Department of Computer Science University of Victoria

آنستیتیوت تکنالوجی معلوماتی و مخابراتی ICTI

Scheduling. The Basics

Scheduling of processes

CSCI-GA Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke

CPU Scheduling. Daniel Mosse. (Most slides are from Sherif Khattab and Silberschatz, Galvin and Gagne 2013)

Starting the Threads

CS370 Operating Systems

Embedded Systems. 5. Operating Systems. Lothar Thiele. Computer Engineering and Networks Laboratory

Midterm Exam. October 20th, Thursday NSC

Operating System Review Part

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

ALL the assignments (A1, A2, A3) and Projects (P0, P1, P2) we have done so far.

CS-537: Midterm Exam (Spring 2001)

SMD149 - Operating Systems

CHAPTER 2: PROCESS MANAGEMENT

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

PROCESSES & THREADS. Charles Abzug, Ph.D. Department of Computer Science James Madison University Harrisonburg, VA Charles Abzug

CS370 Operating Systems

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

Operating Systems Overview

CPU Scheduling: Objectives

Job Scheduling. CS170 Fall 2018

CPU Scheduling Algorithms

(MCQZ-CS604 Operating Systems)

Operating Systems. Scheduling

8: Scheduling. Scheduling. Mark Handley

Tasks. Task Implementation and management

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

CS 322 Operating Systems Practice Midterm Questions

Chapter 5: CPU Scheduling

Operating Systems ECE344. Ding Yuan

Scheduling. Scheduling. Scheduling. Scheduling Criteria. Priorities. Scheduling

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

Processes, Context Switching, and Scheduling. Kevin Webb Swarthmore College January 30, 2018

ECE 462 Object-Oriented Programming using C++ and Java. Scheduling and Critical Section

CS 318 Principles of Operating Systems

CS370 Operating Systems Midterm Review

CS370 Operating Systems

Preemptive Scheduling


UNIT:2. Process Management

CSE 153 Design of Operating Systems Fall 2018

Lecture 4: Memory Management & The Programming Interface

EECS 482 Introduction to Operating Systems

Operating Systems. Lecture Process Scheduling. Golestan University. Hossein Momeni

CS140 Operating Systems and Systems Programming Midterm Exam

CMPS 111 Spring 2003 Midterm Exam May 8, Name: ID:

Process Scheduling. Copyright : University of Illinois CS 241 Staff

Threads and Too Much Milk! CS439: Principles of Computer Systems February 6, 2019

Cs703 Current Midterm papers solved by Naina_Mailk. Q: 1 what are the Characteristics of Real-Time Operating system?

Process Scheduling Part 2

Real-Time Programming

MARUTHI SCHOOL OF BANKING (MSB)

Processes and Threads. Processes: Review

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

Module 20: Multi-core Computing Multi-processor Scheduling Lecture 39: Multi-processor Scheduling. The Lecture Contains: User Control.

CSE 153 Design of Operating Systems

(5) Question 2. Give the two most important factors for effective debugging. Jonathan W. Valvano

Back to RTOS. CSE466 Autumn 00-1

Advanced Operating Systems (CS 202) Scheduling (1)

AC OB S. Multi-threaded FW framework (OS) for embedded ARM systems Torsten Jaekel, June 2014

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

CSI3131 Final Exam Review

Chapter 5: CPU Scheduling. Operating System Concepts 8 th Edition,

Announcements. Program #1. Reading. Due 2/15 at 5:00 pm. Finish scheduling Process Synchronization: Chapter 6 (8 th Ed) or Chapter 7 (6 th Ed)

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

Chapter 6: CPU Scheduling

Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts. Scheduling Criteria Scheduling Algorithms

Properties of Processes

Concurrent activities in daily life. Real world exposed programs. Scheduling of programs. Tasks in engine system. Engine system

CSCE Operating Systems Scheduling. Qiang Zeng, Ph.D. Fall 2018

Transcription:

Lab 5 Logistics CS/ECE 6780/5780 Al Davis Today s topics: Threads basic control block scheduling semaphores Midterm (next Tues) covers Chaps & Labs 1-5 sample on the web Problem not enough interrupt pins our mistake for not noticing this Solution sense a change on the column pins send to IRQ run the column pins to input ports on interrupt» ISR checks the input ports to see what happened iffy bit» do we have the discrete logic in stock to pull this off? checking 1 CS 5780 2 CS 5780 Implicit Threads We ve already seen them in a sense main (foreground thread) & ISR s (background threads)» hardware support for interrupts and control path change» on IRQ or XIRQ control is handed to the ISR RTI returns control back to main 3 common types» input some input triggers IRQ or XIRQ» output some ready to receive signal acts as the trigger» periodic periodic: employ a timer based interrupt Often this is enough when applications are primarily I or O directed» typical when system is small ISR s do most of the work main is just there to wait for an event to happen Larger projects w/ multiple modules single foreground thread becomes more of a limitation» so we ll focus on multiple foreground thread issues today Explicit Thread Semantics In general CPU land threads share memory» threads are concurrent hence shared memory access require ordering threads have private registers and stack thread scheduling» supported by a multi-threaded OS scheduler In embedded land microcontrollers do not have multi-threading support in the hardware hence threads become independent control flows in concept» but only one is running at any one time all resources are shared OS may not do the scheduling for you» necessary OS functions may be in application code 3 CS 5780 4 CS 5780 Page 1

Thread Model Illustrated Private vs. Shared Resources Illusion or reality? 6812: it s an illusion» trick is to implement the abstraction to make it real» all physical resources are global 5 CS 5780 6 CS 5780 Why Use Threads? 3 Thread States Can improve program responsiveness if done right and there is a functional need similar to interrupt model Can improve program modularity each threads function is self-contained inherent decoupling from other thread actions still need to appropriately synchronize the shared resources» only one thread is every running at a time on the 6812 hence mutual exclusion is guaranteed but ordering and state save/restore become critical issues Blocking is a convenient abstraction for programmers thread blocks when it needs something that is not available» could be a physical resource» or it could be based on time e.g. thread gets a certain amount of time to be active OS for ES systems may just be a scheduler 7 CS 5780 8 CS 5780 Page 2

Thread Management Simple Printer Example Fully featured CPU you don t have to worry about it too much just use normal thread semantics (Pthreads for example)» and let the OS do it s thing Single threaded hardware such as the 6812 then thread management has to be done in software common tactic linked lists» single running thread single RunPT pointer into the list of ACTIVE threads RunPT points to the only one that is in RUN state rest in ACTIVE state» other lists for BLOCKED threads may be useful to have multiple BLOCKED lists one for each resource that is causing the blocked state Threads send output to a printer threads get input from a FIFO» we re ignoring print order here printf debug scenario each print statement Tn is at xx 9 CS 5780 10 CS 5780 Scheduling Scheduling Metrics Process to determine which thread to run next decision points» when RUN BLOCK state change is made» or when threads are created or killed Scheduler types Nonpreemptive» when new thread is chosen ONLY when the current thread terminates or blocks Preemptive» scheduler may choose to run a new thread when the current thread is still active.» can result in more responsive systems but require more programmer effort to create a correct system Minimize CPU utilization minimizing busy waiting Maximize throughput complete the most thread jobs per unit of time» common metric for web servers Minimize turnaround time minimize time from job request to job done Minimize wait time e.g. minimize the time in the ACTIVE state Minimize response time time from job request to job ACTIVE Maintain QoS guarantee critical in real time systems see any conflicting constraints? What s missing? what do you care about average, per thread,? 11 CS 5780 12 CS 5780 Page 3

Scheduling Strategies/Policies Round-Robin Scheduler In order simple donut shop mode first come first served» which metrics does this strategy serve? Shortest job first how do you determine job length? Priority based on what» deadline» simple predetermined value» others? Round-Robin simple yet reasonably fair policy Multi-Level Queue & Hybrids e.g. priority levels» within each level round robin, shortest job first, 13 CS 5780 14 CS 5780 Thread Control Block TCB Model TCB stores thread management information must contain» pointer slot so the linked list can be formed» value of it s stack pointer» stack area for local variables and saved registers might also contain» thread number, type, or name» some sort of age information how long it s been active how long it s been in the run state to be used in time based priority scheduling» resources that this thread has been granted if these resources are shared does it makes sense to hold them when blocked or active? why? 15 CS 5780 16 CS 5780 Page 4

Thread Code Setting up the TCB Admittedly somewhat silly PTM assignment used to provide external visibility of the running thread Use of one-hot code on PortM pins is just a random choice Key is that both ProgA & ProgB threads run forever Hence preemptive scheduler is needed see anything fishy so far? 17 CS 5780 18 CS 5780 Port M vs. Port T Defining 3 Threads Essential difference between program & thread program is just the code» note that code has no state» it s just a specification of what will happen if it is executed thread is an execution instance» inherently has state in this case initial state can be seen in the code subsequent state will depend TCB values if the thread isn t running TCB values and registers if the thread is running In this simple example Port M is used to show which Program is being executed Port T is used to show which Thread is being executed in this case» M will be the same for threads 1 & 2» in general a thread could run more than 1 program in different thread phases Thread n = sys[n] threads 1 & 2 are the same code but work on different local data CCR = 0x40 XIRQ disabled IRQ enabled Note all TCB variables values here influence only what happens the FIRST time the thread is executed Why will these variables need to be changed for subsequent executions? 19 CS 5780 20 CS 5780 Page 5

Preemptive Thread Scheduler in C Preemptive Thread Switch see any mistakes? 21 CS 5780 22 CS 5780 Dynamic Thread Allocator Concluding Remarks Implementation of a very simple thread system e.g. round robin preemptive it s not that hard» but note the tricks for setting the PC to the appropriate thread code start Preemptive scheduling lies at the heart of an RTOS» but in this case we didn t consider real time issues making things significantly easier The hard part designing correct embedded codes that use threads Note this code shows the general idea there are parts missing that will need to be coded for a full solution future lab? 23 CS 5780 24 CS 5780 Page 6