CS 423 Operating System Design: MP2 Walkthrough Professor Adam - - PowerPoint PPT Presentation

β–Ά
cs 423 operating system design mp2 walkthrough
SMART_READER_LITE
LIVE PREVIEW

CS 423 Operating System Design: MP2 Walkthrough Professor Adam - - PowerPoint PPT Presentation

CS 423 Operating System Design: MP2 Walkthrough Professor Adam Bates Spring 2018 CS 423: Operating Systems Design 1 MP2: Rate-Monotonic Scheduling MP2 will be out at the end of the week We are currently grading MP1 Reminder


slide-1
SLIDE 1

CS 423: Operating Systems Design

Professor Adam Bates Spring 2018

CS 423 Operating System Design: MP2 Walkthrough

1

slide-2
SLIDE 2

CS 423: Operating Systems Design

MP2: Rate-Monotonic Scheduling

  • MP2 will be out at the end of the week
  • We are currently grading MP1
  • Reminder
  • Plea

lease se do

  • not
  • t tou
  • uch

ch you your r VMs s until il MP2 2 is is ou

  • ut

2

slide-3
SLIDE 3

CS 423: Operating Systems Design

A Note About Piazza

  • β€œMy code is not running, why?” is not very helpful
  • Be more specific when dealing with failures so we can help
  • Use private posts if you are not comfortable

sharing details of your implementation

  • Or office hours
  • Be careful not to remove /var/log/sssd as

this is will brick authentication

3

slide-4
SLIDE 4

CS 423: Operating Systems Design

Purpose of MP2

  • Underst

erstand real time scheduling concepts

  • Desig

esign a real time schedule module in the Linux kernel

  • Lea

earn rn how to use the kernel scheduling API, timer, procfs

  • Test

est your scheduler by implementation a user level application

4

slide-5
SLIDE 5

CS 423: Operating Systems Design

Reuse of MP1

  • MP1 was focused on getting you familiar with

kernel programming

  • Cod
  • de/

e/Makefile efile from rom MP1 1 ca can be e reu reused sed for

  • r MP2
  • MP2 is aimed at developing usef

seful kernel code

  • Develop a sch

sched eduler ler as a kernel module

  • Implement a task admission

mission con control rol policy

  • licy
  • Use procf

rocfs to communicate with user programs

5

slide-6
SLIDE 6

CS 423: Operating Systems Design

Introduction

  • Real-time systems have requirements in terms of

response time and predictability

  • Think video surveillance systems
  • We will be dealing with periodic tasks
  • Constant period
  • Constant running time
  • We will assume tasks are independent

6

slide-7
SLIDE 7

CS 423: Operating Systems Design

Periodic Tasks Model

  • Liu and Layland [1973] model, each task 𝑗 has
  • Period ​𝑄↓𝑗
  • Deadline ​𝐸↓𝑗
  • Runtime ​𝐷↓𝑗

7

slide-8
SLIDE 8

CS 423: Operating Systems Design

Rate Monotonic Scheduler (RMS)

  • A static scheduler has comp

complet lete e in informa

  • rmation

ion about all the incoming tasks

  • Arrival time, deadline, runtime, etc.
  • RMS assigns hig

igher er priorit riority y for tasks with higher rate/sh short

  • rter

er period eriod

  • It always picks the task with the highest priority
  • It is preemp

reemptiv ive

8

slide-9
SLIDE 9

CS 423: Operating Systems Design

Optimality of RMS

  • RMS is optimal for hard-real time systems
  • If RMS cannot schedule it, then no other algorithm

can!

  • If any other scheduler algorithm can scheduler a

set of tasks, then RMS can do it too!

9

slide-10
SLIDE 10

CS 423: Operating Systems Design

MP2 Overview

  • We will implement RMS with an admission control

policy as a kernel module

  • The scheduler provides the following interface
  • Reg

egist istra ration ion: save process info like pid, P, D, etc.

  • Yield

Yield: process notifies RMS that is has completed its period

  • De-R

e-Reg egist istra ration ion: process notifies RMS that it has completed all its tasks

  • We will use procf

rocfs to communicate between the modules and the processes

10

slide-11
SLIDE 11

CS 423: Operating Systems Design

Admission Control

  • We only register a process if it passes admission

control

  • The module will answer this question every time
  • Can

an the he ne new se set of f pro processe sses s st still be a a sc sche hedul uled on n a a si sing ngle pro processo ssor r ?

  • Yes iff
  • Assume always that

X

i∈T

Ci Pi ≀ 0.693 Ci < Pi

11

slide-12
SLIDE 12

CS 423: Operating Systems Design

Admission Control

  • We only register a process if it passes admission

control

  • The module will answer this question every time
  • Can

an the he ne new se set of f pro processe sses s st still be a a sc sche hedul uled on n a a si sing ngle pro processo ssor r ?

  • Yes iff
  • Assume always that

X

i∈T

Ci Pi ≀ 0.693 Ci < Pi

Recall that floating point operations are very expensive in the kernel. You should NOT use them. Instead use Fixed-Point arithmetic Fixed-Point arithmetic

12

slide-13
SLIDE 13

CS 423: Operating Systems Design

MP2 Building Blocks

13

slide-14
SLIDE 14

CS 423: Operating Systems Design

MP2 User Process Behavior

14

slide-15
SLIDE 15

CS 423: Operating Systems Design

MP2 User Process Behavior

15

slide-16
SLIDE 16

CS 423: Operating Systems Design

MP2 User Process Behavior

16

slide-17
SLIDE 17

CS 423: Operating Systems Design

MP2 User Process Behavior

17

slide-18
SLIDE 18

CS 423: Operating Systems Design

MP2 User Process Behavior

18

slide-19
SLIDE 19

CS 423: Operating Systems Design

MP2 Dispatching Thread

19

slide-20
SLIDE 20

CS 423: Operating Systems Design

MP2 User Process Behavior

20

slide-21
SLIDE 21

CS 423: Operating Systems Design

MP2 User Process Behavior

21

slide-22
SLIDE 22

CS 423: Operating Systems Design

MP2 User Process Behavior

22

slide-23
SLIDE 23

CS 423: Operating Systems Design

MP2 Process State

  • A process in MP2 can be in one of three states

1.

  • 1. READ

ADY: : a new job is ready to be scheduled

2.

  • 2. RUNNING

NNING: a job is currently running and using the CPU

3.

  • 3. SLEEPING

ING: job has finished execution and process is waiting for the next period

  • A job is not allowed to run before its appropriate

period

23

slide-24
SLIDE 24

CS 423: Operating Systems Design

MP2 Process Control Block

  • PCB is defined by task_struct
  • PCB is manager by a circular doubly linked list
  • Maintain pointer to cu

curren rrent ru runnin ing st state

task_truct

state pid ... list_head next prev ...

task_truct

state pid ... list_head next prev ...

task_truct

state pid ... list_head next prev ...

24

slide-25
SLIDE 25

CS 423: Operating Systems Design

MP2 Extending the PCB

  • Extend PCB to hold MP2-specific information,

example,

25

slide-26
SLIDE 26

CS 423: Operating Systems Design

MP2 Scheduling Logic

  • We will use a kern

ernel el threa read to handle the scheduling logic

  • It will handle context switches as needed
  • There are two cases in which a context switch is

needed

  • 1. Received a YIE

YIELD message from an application

  • 2. The wa

wakeu eup timer imer of a process has expired, i.e., its new period has started

26

slide-27
SLIDE 27

CS 423: Operating Systems Design

MP2 Scheduling Logic

  • Update timer;
  • State = sleep;
  • Wake up

scheduler;

  • Sleep;

Yield handler

  • Select highest

priority task (smallest period)

  • State = running
  • Wake up process
  • sleep

scheduler

  • State = ready
  • Wake up scheduler

Timer interrupt

27

slide-28
SLIDE 28

CS 423: Operating Systems Design

MP2 Context Switching

  • We will use the kernel scheduling API
  • schedule(): trigger the kernel scheduler
  • wake_up_process (struct task_struct *)
  • sched_setscheduler(): set scheduling parameters
  • FIFO for real time scheduling, NORMAL for regular processes, etc.
  • set_current_state()
  • set_task_state()

28

slide-29
SLIDE 29

CS 423: Operating Systems Design

MP2 Scheduler API Example

  • To sleep and trigger a context switch

set_current_state(TASK_INTERRUPTIBLE); schedule();

  • To wake up a process

struct task_struct * sleeping_task; ... wake_up_process(sleeping_task);

29

slide-30
SLIDE 30

CS 423: Operating Systems Design

MP2 A Note About Kthreads

  • You will need to exp

explicit licitly ly put the e kern ernel el threa read to

  • sleep

sleep when you’re done with your work

  • Otherwise it will keep running forever
  • You also need to exp

explicit licitly ly ch check eck for

  • r sig

signals ls

  • Check if should stop working
  • kthread_should_stop()

30

slide-31
SLIDE 31

CS 423: Operating Systems Design

MP2 Timer and Scheduler

Top Half Bottom Half

31

slide-32
SLIDE 32

CS 423: Operating Systems Design

MP2 Final Notes

  • Develop things incrementally, follow the mp2

description

  • Test things one at a time
  • Use fixed point arithmetic
  • Use global variables for persistent state
  • Remember to cleanup everything
  • Failure to do so may not allow you to insert your module

again

32