SlideShare una empresa de Scribd logo
1 de 59
Descargar para leer sin conexión
Lab 6: Scheduling
Advanced Operating Systems

Zubair Nabi
zubair.nabi@itu.edu.pk

March 6, 2013
Introduction

1

An operating system runs more processes than it has processors
Introduction

1

An operating system runs more processes than it has processors

2

Needs some plan to time share the processors between the
processes
Introduction

1

An operating system runs more processes than it has processors

2

Needs some plan to time share the processors between the
processes

3

A common approach is to provide each process with a virtual
processor – An illusion that it has exclusive access to the
processor
Introduction

1

An operating system runs more processes than it has processors

2

Needs some plan to time share the processors between the
processes

3

A common approach is to provide each process with a virtual
processor – An illusion that it has exclusive access to the
processor

4

It is then the job of the OS to multiplex these multiple virtual
processors on the underlying physical processors
Scheduling triggers

1

A process does I/O, put it to sleep, and schedule another process
Scheduling triggers

1

A process does I/O, put it to sleep, and schedule another process

2

Use timer interrupts to stop running on a processor after a fixed
time quantum (100 msec)
Context switching

• Used to achieve multiplexing
Context switching

• Used to achieve multiplexing
• Internally two low-level context switches are performed
Context switching

• Used to achieve multiplexing
• Internally two low-level context switches are performed
1

Process’s kernel thread to the current CPU’s scheduler thread
Context switching

• Used to achieve multiplexing
• Internally two low-level context switches are performed
1
2

Process’s kernel thread to the current CPU’s scheduler thread
Scheduler’s thread to a process’s kernel thread
Context switching

• Used to achieve multiplexing
• Internally two low-level context switches are performed
1
2

Process’s kernel thread to the current CPU’s scheduler thread
Scheduler’s thread to a process’s kernel thread

• No direct switching from one user-space process to another
Context switching

• Used to achieve multiplexing
• Internally two low-level context switches are performed
1
2

Process’s kernel thread to the current CPU’s scheduler thread
Scheduler’s thread to a process’s kernel thread

• No direct switching from one user-space process to another
• Each process has its own kernel stack and register set (its
context)
Context switching

• Used to achieve multiplexing
• Internally two low-level context switches are performed
1
2

Process’s kernel thread to the current CPU’s scheduler thread
Scheduler’s thread to a process’s kernel thread

• No direct switching from one user-space process to another
• Each process has its own kernel stack and register set (its
context)
• Each CPU has its own scheduler thread
Context switching

• Used to achieve multiplexing
• Internally two low-level context switches are performed
1
2

Process’s kernel thread to the current CPU’s scheduler thread
Scheduler’s thread to a process’s kernel thread

• No direct switching from one user-space process to another
• Each process has its own kernel stack and register set (its
context)
• Each CPU has its own scheduler thread
• Context switch involves saving the old thread’s CPU registers and
restoring previously-saved registers of the new thread (enabled
by swtch)
swtch
• Saves and restores contexts
swtch
• Saves and restores contexts
• Takes two arguments: struct context **old and

struct context *new
swtch
• Saves and restores contexts
• Takes two arguments: struct context **old and

struct context *new
• Replaces the former with the latter
swtch
• Saves and restores contexts
• Takes two arguments: struct context **old and

struct context *new
• Replaces the former with the latter

• Each time a process has to give up the CPU, its kernel thread
invokes swtch to save its own context and switch to the
scheduler context
swtch
• Saves and restores contexts
• Takes two arguments: struct context **old and

struct context *new
• Replaces the former with the latter

• Each time a process has to give up the CPU, its kernel thread
invokes swtch to save its own context and switch to the
scheduler context
• Flow in case of an interrupt:
swtch
• Saves and restores contexts
• Takes two arguments: struct context **old and

struct context *new
• Replaces the former with the latter

• Each time a process has to give up the CPU, its kernel thread
invokes swtch to save its own context and switch to the
scheduler context
• Flow in case of an interrupt:
1 trap handles the interrupt and the calls yield
swtch
• Saves and restores contexts
• Takes two arguments: struct context **old and

struct context *new
• Replaces the former with the latter

• Each time a process has to give up the CPU, its kernel thread
invokes swtch to save its own context and switch to the
scheduler context
• Flow in case of an interrupt:
1 trap handles the interrupt and the calls yield
2 yield makes a call to sched
swtch
• Saves and restores contexts
• Takes two arguments: struct context **old and

struct context *new
• Replaces the former with the latter

• Each time a process has to give up the CPU, its kernel thread
invokes swtch to save its own context and switch to the
scheduler context
• Flow in case of an interrupt:
1 trap handles the interrupt and the calls yield
2 yield makes a call to sched
3 sched invokes swtch(&proc->context,
cpu->scheduler)
swtch
• Saves and restores contexts
• Takes two arguments: struct context **old and

struct context *new
• Replaces the former with the latter

• Each time a process has to give up the CPU, its kernel thread
invokes swtch to save its own context and switch to the
scheduler context
• Flow in case of an interrupt:
1 trap handles the interrupt and the calls yield
2 yield makes a call to sched
3 sched invokes swtch(&proc->context,
cpu->scheduler)
4 Control returns to the scheduler thread
Scheduling mechanism

• Each process that wants to give up the processor:
Scheduling mechanism

• Each process that wants to give up the processor:
1 Acquires ptable.lock (process table lock)
Scheduling mechanism

• Each process that wants to give up the processor:
1 Acquires ptable.lock (process table lock)
2

Releases any other locks that it is holding
Scheduling mechanism

• Each process that wants to give up the processor:
1 Acquires ptable.lock (process table lock)
2
3

Releases any other locks that it is holding
Updates proc->state (its own state)
Scheduling mechanism

• Each process that wants to give up the processor:
1 Acquires ptable.lock (process table lock)
Releases any other locks that it is holding
Updates proc->state (its own state)
4 Calls sched

2

3
Scheduling mechanism

• Each process that wants to give up the processor:
1 Acquires ptable.lock (process table lock)
Releases any other locks that it is holding
Updates proc->state (its own state)
4 Calls sched

2

3

• Mechanism followed by yield, and sleep and exit
Scheduling mechanism

• Each process that wants to give up the processor:
1 Acquires ptable.lock (process table lock)
Releases any other locks that it is holding
Updates proc->state (its own state)
4 Calls sched

2

3

• Mechanism followed by yield, and sleep and exit
• sched ensures that these steps are followed
sched
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

void sched (void) {
int intena ;

if(! holding (& ptable .lock ))
panic (" sched ptable .lock");
if(cpu−>ncli != 1)
panic (" sched locks ");
if(proc−>state == RUNNING )
panic (" sched running ");
if( readeflags ()& FL_IF )
panic (" sched interruptible ");
intena = cpu−>intena ;
swtch (& proc−>context , cpu−>scheduler );
cpu−>intena = intena ;
}
yield

1
2
3
4
5
6

void yield (void) {
acquire (& ptable .lock );
proc−>state = RUNNABLE ;
sched ();
release (& ptable .lock );
}
Scheduling mechanism (2)

• Why must a process acquire ptable.lock before a call to
swtch?
• Breaks the convention that the thread that acquires a lock is also
responsible for releasing the lock
Scheduling mechanism (2)

• Why must a process acquire ptable.lock before a call to
swtch?
• Breaks the convention that the thread that acquires a lock is also
responsible for releasing the lock

• Without acquiring ptable.lock, two CPUs might want to
schedule the same process because they can access ptable
scheduler
• Simple loop: find a process to run, run it until it stops, repeat
scheduler
• Simple loop: find a process to run, run it until it stops, repeat
• Acquires and releases ptable.lock, and enables interrupts
on every iteration. Why?
scheduler
• Simple loop: find a process to run, run it until it stops, repeat
• Acquires and releases ptable.lock, and enables interrupts
on every iteration. Why?
• If CPU is idle (no RUNNABLE)
scheduler
• Simple loop: find a process to run, run it until it stops, repeat
• Acquires and releases ptable.lock, and enables interrupts
on every iteration. Why?
• If CPU is idle (no RUNNABLE)
1

Idle looping while holding a lock would not allow any other CPU to
access the process table
scheduler
• Simple loop: find a process to run, run it until it stops, repeat
• Acquires and releases ptable.lock, and enables interrupts
on every iteration. Why?
• If CPU is idle (no RUNNABLE)
Idle looping while holding a lock would not allow any other CPU to
access the process table
2 Idle looping (all processes are waiting for I/O) while interrupts are
disabled would not allow any I/O to arrive

1
scheduler
• Simple loop: find a process to run, run it until it stops, repeat
• Acquires and releases ptable.lock, and enables interrupts
on every iteration. Why?
• If CPU is idle (no RUNNABLE)
Idle looping while holding a lock would not allow any other CPU to
access the process table
2 Idle looping (all processes are waiting for I/O) while interrupts are
disabled would not allow any I/O to arrive

1

• The first process with p->state == RUNNABLE is selected
scheduler
• Simple loop: find a process to run, run it until it stops, repeat
• Acquires and releases ptable.lock, and enables interrupts
on every iteration. Why?
• If CPU is idle (no RUNNABLE)
Idle looping while holding a lock would not allow any other CPU to
access the process table
2 Idle looping (all processes are waiting for I/O) while interrupts are
disabled would not allow any I/O to arrive

1

• The first process with p->state == RUNNABLE is selected
• The process is assigned to the per-CPU proc
scheduler
• Simple loop: find a process to run, run it until it stops, repeat
• Acquires and releases ptable.lock, and enables interrupts
on every iteration. Why?
• If CPU is idle (no RUNNABLE)
Idle looping while holding a lock would not allow any other CPU to
access the process table
2 Idle looping (all processes are waiting for I/O) while interrupts are
disabled would not allow any I/O to arrive

1

• The first process with p->state == RUNNABLE is selected
• The process is assigned to the per-CPU proc
• The process’s page table is switched to via switchuvm
scheduler
• Simple loop: find a process to run, run it until it stops, repeat
• Acquires and releases ptable.lock, and enables interrupts
on every iteration. Why?
• If CPU is idle (no RUNNABLE)
Idle looping while holding a lock would not allow any other CPU to
access the process table
2 Idle looping (all processes are waiting for I/O) while interrupts are
disabled would not allow any I/O to arrive

1

• The first process with p->state == RUNNABLE is selected
• The process is assigned to the per-CPU proc
• The process’s page table is switched to via switchuvm
• The process is marked as RUNNING
scheduler
• Simple loop: find a process to run, run it until it stops, repeat
• Acquires and releases ptable.lock, and enables interrupts
on every iteration. Why?
• If CPU is idle (no RUNNABLE)
Idle looping while holding a lock would not allow any other CPU to
access the process table
2 Idle looping (all processes are waiting for I/O) while interrupts are
disabled would not allow any I/O to arrive

1

• The first process with p->state == RUNNABLE is selected
• The process is assigned to the per-CPU proc
• The process’s page table is switched to via switchuvm
• The process is marked as RUNNING
• swtch is called to start running it
scheduler
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

void scheduler (void) {
struct proc

∗p;

for (;;){
sti ();
acquire (& ptable .lock );
for(p = ptable .proc; p < & ptable .proc[ NPROC ]; p++){
if(p−>state != RUNNABLE )
continue ;
proc = p;
switchuvm (p);
p−>state = RUNNING ;
swtch (&cpu−>scheduler , proc−>context );
switchkvm ();
proc = 0;
}
Sleep and wakeup

• sleep and wakeup enable an IPC mechanism
Sleep and wakeup

• sleep and wakeup enable an IPC mechanism
• Enable sequence coordination or conditional synchronization
Sleep and wakeup

• sleep and wakeup enable an IPC mechanism
• Enable sequence coordination or conditional synchronization
• sleep allows one process to sleep waiting for an event
Sleep and wakeup

• sleep and wakeup enable an IPC mechanism
• Enable sequence coordination or conditional synchronization
• sleep allows one process to sleep waiting for an event
• wakeup allows another process to wake up processes sleeping
on an event
Queue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

struct q {
void

∗ptr;

};
void∗ send( struct q

∗q,

void

∗q)

{

while(q−>ptr != 0)
;
q−>ptr = p;
}
void∗ recv( struct q
void

∗p;

while ((p = q−>ptr) == 0)
;
q−>ptr = 0;
return p;
}

∗p)

{
Queue with sleep and wakeup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

void∗ send( struct q

∗q,

void

∗q)

{

while(q−>ptr != 0)
;
q−>ptr = p;
wakeup (q);
}
void∗ recv( struct q
void

∗p;

while ((p = q−>ptr) == 0)
sleep (q);
q−>ptr = 0;
return p;
}

∗p)

{
Queue with sleep and wakeup and locking

1
2
3
4

struct q {
struct spinlock lock;
void
};

∗ptr;
Queue with sleep and wakeup and locking (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

void∗ send( struct q

∗q,

void

acquire (&q−>lock );
while(q−>ptr != 0)
;
q−>ptr = p;
wakeup (q);
release (&q−>lock ); }
void∗ recv( struct q
void

∗q)

{

∗p;

acquire (&q−>lock );
while ((p = q−>ptr) == 0)
sleep (q);
q−>ptr = 0;
release (&q−>lock );
return p; }

∗p)

{
Queue with sleep and wakeup and implicit locking
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

void∗ send( struct q

∗q,

void

acquire (&q−>lock );
while(q−>ptr != 0)
;
q−>ptr = p;
wakeup (q);
release (&q−>lock ); }
void∗ recv( struct q
void

∗q)

{

∗p;

acquire (&q−>lock );
while ((p = q−>ptr) == 0)
sleep (q, &q−>lock );
q−>ptr = 0;
release (&q−>lock );
return p; }

∗p)

{
sleep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

void sleep (void

∗chan ,

struct spinlock

if(proc == 0)
panic (" sleep ");
if(lk == 0)
panic (" sleep without lk");
if(lk != & ptable .lock ){
acquire (& ptable .lock );
release (lk ); }
proc−>chan = chan;
proc−>state = SLEEPING ;
sched ();
proc−>chan = 0;
if(lk != & ptable .lock ){
release (& ptable .lock );
acquire (lk ); } }

∗lk)

{
wakeup
1
2
3
4
5
6
7
8
9
10
11
12

static void wakeup1 (void
struct proc

∗chan)

{

∗p;

for(p = ptable .proc; p < & ptable .proc[ NPROC ]; p++)
if(p−>state == SLEEPING && p−>chan == chan)
p−>state = RUNNABLE ;
}

void wakeup (void

∗chan)

acquire (& ptable .lock );
wakeup1 (chan );
release (& ptable .lock );
}

{
Today’s Task

• ptable.lock is a very coarse-grained lock which protects the
entire process table
• Design a mechanism (in terms of pseudocode) that splits it up
into multiple locks
• Explain why your solution will improve performance while
ensuring protection
Reading(s)

• Chapter 5, “Scheduling” from “xv6: a simple, Unix-like teaching
operating system”

Más contenido relacionado

La actualidad más candente

Linux Interrupts
Linux InterruptsLinux Interrupts
Linux InterruptsKernel TLV
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing LandscapeKernel TLV
 
Kernel Recipes 2015: Kernel packet capture technologies
Kernel Recipes 2015: Kernel packet capture technologiesKernel Recipes 2015: Kernel packet capture technologies
Kernel Recipes 2015: Kernel packet capture technologiesAnne Nicolas
 
The Linux Scheduler: a Decade of Wasted Cores
The Linux Scheduler: a Decade of Wasted CoresThe Linux Scheduler: a Decade of Wasted Cores
The Linux Scheduler: a Decade of Wasted Coresyeokm1
 
Kernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkKernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkAnne Nicolas
 
LinuxCon_2013_NA_Eckermann_Filesystems_btrfs.pdf
LinuxCon_2013_NA_Eckermann_Filesystems_btrfs.pdfLinuxCon_2013_NA_Eckermann_Filesystems_btrfs.pdf
LinuxCon_2013_NA_Eckermann_Filesystems_btrfs.pdfdegarden
 
SecureCore RTAS2013
SecureCore RTAS2013SecureCore RTAS2013
SecureCore RTAS2013mkyoon83
 
Block I/O Layer Tracing: blktrace
Block I/O Layer Tracing: blktraceBlock I/O Layer Tracing: blktrace
Block I/O Layer Tracing: blktraceBabak Farrokhi
 
Windows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel DevelopersWindows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel DevelopersKernel TLV
 
Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016Brendan Gregg
 
Linux Preempt-RT Internals
Linux Preempt-RT InternalsLinux Preempt-RT Internals
Linux Preempt-RT Internals哲豪 康哲豪
 
High Performance Storage Devices in the Linux Kernel
High Performance Storage Devices in the Linux KernelHigh Performance Storage Devices in the Linux Kernel
High Performance Storage Devices in the Linux KernelKernel TLV
 
What Linux can learn from Solaris performance and vice-versa
What Linux can learn from Solaris performance and vice-versaWhat Linux can learn from Solaris performance and vice-versa
What Linux can learn from Solaris performance and vice-versaBrendan Gregg
 
HKG15-305: Real Time processing comparing the RT patch vs Core isolation
HKG15-305: Real Time processing comparing the RT patch vs Core isolationHKG15-305: Real Time processing comparing the RT patch vs Core isolation
HKG15-305: Real Time processing comparing the RT patch vs Core isolationLinaro
 
DTrace Topics: Introduction
DTrace Topics: IntroductionDTrace Topics: Introduction
DTrace Topics: IntroductionBrendan Gregg
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageKernel TLV
 
Linux Performance Profiling and Monitoring
Linux Performance Profiling and MonitoringLinux Performance Profiling and Monitoring
Linux Performance Profiling and MonitoringGeorg Schönberger
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and moreBrendan Gregg
 

La actualidad más candente (20)

Linux Interrupts
Linux InterruptsLinux Interrupts
Linux Interrupts
 
Tuned
TunedTuned
Tuned
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing Landscape
 
Kernel Recipes 2015: Kernel packet capture technologies
Kernel Recipes 2015: Kernel packet capture technologiesKernel Recipes 2015: Kernel packet capture technologies
Kernel Recipes 2015: Kernel packet capture technologies
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
 
The Linux Scheduler: a Decade of Wasted Cores
The Linux Scheduler: a Decade of Wasted CoresThe Linux Scheduler: a Decade of Wasted Cores
The Linux Scheduler: a Decade of Wasted Cores
 
Kernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkKernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver framework
 
LinuxCon_2013_NA_Eckermann_Filesystems_btrfs.pdf
LinuxCon_2013_NA_Eckermann_Filesystems_btrfs.pdfLinuxCon_2013_NA_Eckermann_Filesystems_btrfs.pdf
LinuxCon_2013_NA_Eckermann_Filesystems_btrfs.pdf
 
SecureCore RTAS2013
SecureCore RTAS2013SecureCore RTAS2013
SecureCore RTAS2013
 
Block I/O Layer Tracing: blktrace
Block I/O Layer Tracing: blktraceBlock I/O Layer Tracing: blktrace
Block I/O Layer Tracing: blktrace
 
Windows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel DevelopersWindows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel Developers
 
Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016
 
Linux Preempt-RT Internals
Linux Preempt-RT InternalsLinux Preempt-RT Internals
Linux Preempt-RT Internals
 
High Performance Storage Devices in the Linux Kernel
High Performance Storage Devices in the Linux KernelHigh Performance Storage Devices in the Linux Kernel
High Performance Storage Devices in the Linux Kernel
 
What Linux can learn from Solaris performance and vice-versa
What Linux can learn from Solaris performance and vice-versaWhat Linux can learn from Solaris performance and vice-versa
What Linux can learn from Solaris performance and vice-versa
 
HKG15-305: Real Time processing comparing the RT patch vs Core isolation
HKG15-305: Real Time processing comparing the RT patch vs Core isolationHKG15-305: Real Time processing comparing the RT patch vs Core isolation
HKG15-305: Real Time processing comparing the RT patch vs Core isolation
 
DTrace Topics: Introduction
DTrace Topics: IntroductionDTrace Topics: Introduction
DTrace Topics: Introduction
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 
Linux Performance Profiling and Monitoring
Linux Performance Profiling and MonitoringLinux Performance Profiling and Monitoring
Linux Performance Profiling and Monitoring
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
 

Destacado

AOS Lab 7: Page tables
AOS Lab 7: Page tablesAOS Lab 7: Page tables
AOS Lab 7: Page tablesZubair Nabi
 
Topic 13: Cloud Stacks
Topic 13: Cloud StacksTopic 13: Cloud Stacks
Topic 13: Cloud StacksZubair Nabi
 
AOS Lab 10: File system -- Inodes and beyond
AOS Lab 10: File system -- Inodes and beyondAOS Lab 10: File system -- Inodes and beyond
AOS Lab 10: File system -- Inodes and beyondZubair Nabi
 
AOS Lab 9: File system -- Of buffers, logs, and blocks
AOS Lab 9: File system -- Of buffers, logs, and blocksAOS Lab 9: File system -- Of buffers, logs, and blocks
AOS Lab 9: File system -- Of buffers, logs, and blocksZubair Nabi
 
AOS Lab 2: Hello, xv6!
AOS Lab 2: Hello, xv6!AOS Lab 2: Hello, xv6!
AOS Lab 2: Hello, xv6!Zubair Nabi
 
Topic 14: Operating Systems and Virtualization
Topic 14: Operating Systems and VirtualizationTopic 14: Operating Systems and Virtualization
Topic 14: Operating Systems and VirtualizationZubair Nabi
 
Topic 15: Datacenter Design and Networking
Topic 15: Datacenter Design and NetworkingTopic 15: Datacenter Design and Networking
Topic 15: Datacenter Design and NetworkingZubair Nabi
 
MapReduce and DBMS Hybrids
MapReduce and DBMS HybridsMapReduce and DBMS Hybrids
MapReduce and DBMS HybridsZubair Nabi
 
AOS Lab 1: Hello, Linux!
AOS Lab 1: Hello, Linux!AOS Lab 1: Hello, Linux!
AOS Lab 1: Hello, Linux!Zubair Nabi
 
The Anatomy of Web Censorship in Pakistan
The Anatomy of Web Censorship in PakistanThe Anatomy of Web Censorship in Pakistan
The Anatomy of Web Censorship in PakistanZubair Nabi
 
Raabta: Low-cost Video Conferencing for the Developing World
Raabta: Low-cost Video Conferencing for the Developing WorldRaabta: Low-cost Video Conferencing for the Developing World
Raabta: Low-cost Video Conferencing for the Developing WorldZubair Nabi
 
MapReduce Application Scripting
MapReduce Application ScriptingMapReduce Application Scripting
MapReduce Application ScriptingZubair Nabi
 
The Big Data Stack
The Big Data StackThe Big Data Stack
The Big Data StackZubair Nabi
 

Destacado (14)

AOS Lab 7: Page tables
AOS Lab 7: Page tablesAOS Lab 7: Page tables
AOS Lab 7: Page tables
 
Topic 13: Cloud Stacks
Topic 13: Cloud StacksTopic 13: Cloud Stacks
Topic 13: Cloud Stacks
 
AOS Lab 10: File system -- Inodes and beyond
AOS Lab 10: File system -- Inodes and beyondAOS Lab 10: File system -- Inodes and beyond
AOS Lab 10: File system -- Inodes and beyond
 
AOS Lab 9: File system -- Of buffers, logs, and blocks
AOS Lab 9: File system -- Of buffers, logs, and blocksAOS Lab 9: File system -- Of buffers, logs, and blocks
AOS Lab 9: File system -- Of buffers, logs, and blocks
 
AOS Lab 2: Hello, xv6!
AOS Lab 2: Hello, xv6!AOS Lab 2: Hello, xv6!
AOS Lab 2: Hello, xv6!
 
Topic 14: Operating Systems and Virtualization
Topic 14: Operating Systems and VirtualizationTopic 14: Operating Systems and Virtualization
Topic 14: Operating Systems and Virtualization
 
Topic 15: Datacenter Design and Networking
Topic 15: Datacenter Design and NetworkingTopic 15: Datacenter Design and Networking
Topic 15: Datacenter Design and Networking
 
MapReduce and DBMS Hybrids
MapReduce and DBMS HybridsMapReduce and DBMS Hybrids
MapReduce and DBMS Hybrids
 
AOS Lab 1: Hello, Linux!
AOS Lab 1: Hello, Linux!AOS Lab 1: Hello, Linux!
AOS Lab 1: Hello, Linux!
 
The Anatomy of Web Censorship in Pakistan
The Anatomy of Web Censorship in PakistanThe Anatomy of Web Censorship in Pakistan
The Anatomy of Web Censorship in Pakistan
 
Raabta: Low-cost Video Conferencing for the Developing World
Raabta: Low-cost Video Conferencing for the Developing WorldRaabta: Low-cost Video Conferencing for the Developing World
Raabta: Low-cost Video Conferencing for the Developing World
 
MapReduce Application Scripting
MapReduce Application ScriptingMapReduce Application Scripting
MapReduce Application Scripting
 
The Big Data Stack
The Big Data StackThe Big Data Stack
The Big Data Stack
 
scheduling
schedulingscheduling
scheduling
 

Similar a AOS Lab 6: Scheduling

XPDDS19: Core Scheduling in Xen - Jürgen Groß, SUSE
XPDDS19: Core Scheduling in Xen - Jürgen Groß, SUSEXPDDS19: Core Scheduling in Xen - Jürgen Groß, SUSE
XPDDS19: Core Scheduling in Xen - Jürgen Groß, SUSEThe Linux Foundation
 
Concurrency 2010
Concurrency 2010Concurrency 2010
Concurrency 2010敬倫 林
 
Operating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingOperating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingVaibhav Khanna
 
Process scheduling &amp; time
Process scheduling &amp; timeProcess scheduling &amp; time
Process scheduling &amp; timeYojana Nanaware
 
Training Slides: Intermediate 202: Performing Cluster Maintenance with Zero-D...
Training Slides: Intermediate 202: Performing Cluster Maintenance with Zero-D...Training Slides: Intermediate 202: Performing Cluster Maintenance with Zero-D...
Training Slides: Intermediate 202: Performing Cluster Maintenance with Zero-D...Continuent
 
Process scheduling
Process schedulingProcess scheduling
Process schedulingHao-Ran Liu
 
Multithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdfMultithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdfHarika Pudugosula
 
CPU Scheduling.pptx
CPU Scheduling.pptxCPU Scheduling.pptx
CPU Scheduling.pptxyashu23
 
Dead Lock Analysis of spin_lock() in Linux Kernel (english)
Dead Lock Analysis of spin_lock() in Linux Kernel (english)Dead Lock Analysis of spin_lock() in Linux Kernel (english)
Dead Lock Analysis of spin_lock() in Linux Kernel (english)Sneeker Yeh
 
Oracle real application clusters system tests with demo
Oracle real application clusters system tests with demoOracle real application clusters system tests with demo
Oracle real application clusters system tests with demoAjith Narayanan
 
RTAI - Earliest Deadline First
RTAI - Earliest Deadline FirstRTAI - Earliest Deadline First
RTAI - Earliest Deadline FirstStefano Bragaglia
 
operating system (1).pdf
operating system (1).pdfoperating system (1).pdf
operating system (1).pdfAliyanAbbas1
 
CIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docx
CIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docxCIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docx
CIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docxclarebernice
 
Process Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux KernelProcess Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux KernelHaifeng Li
 
Scheduler activations
Scheduler activationsScheduler activations
Scheduler activationsVin Voro
 

Similar a AOS Lab 6: Scheduling (20)

Ch6 cpu scheduling
Ch6   cpu schedulingCh6   cpu scheduling
Ch6 cpu scheduling
 
XPDDS19: Core Scheduling in Xen - Jürgen Groß, SUSE
XPDDS19: Core Scheduling in Xen - Jürgen Groß, SUSEXPDDS19: Core Scheduling in Xen - Jürgen Groß, SUSE
XPDDS19: Core Scheduling in Xen - Jürgen Groß, SUSE
 
Concurrency 2010
Concurrency 2010Concurrency 2010
Concurrency 2010
 
Operating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingOperating system 28 fundamental of scheduling
Operating system 28 fundamental of scheduling
 
Process scheduling &amp; time
Process scheduling &amp; timeProcess scheduling &amp; time
Process scheduling &amp; time
 
Training Slides: Intermediate 202: Performing Cluster Maintenance with Zero-D...
Training Slides: Intermediate 202: Performing Cluster Maintenance with Zero-D...Training Slides: Intermediate 202: Performing Cluster Maintenance with Zero-D...
Training Slides: Intermediate 202: Performing Cluster Maintenance with Zero-D...
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Multithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdfMultithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdf
 
CPU Scheduling.pptx
CPU Scheduling.pptxCPU Scheduling.pptx
CPU Scheduling.pptx
 
Unit 5 ppt
Unit 5 pptUnit 5 ppt
Unit 5 ppt
 
Threads in Java
Threads in JavaThreads in Java
Threads in Java
 
Section05 scheduling
Section05 schedulingSection05 scheduling
Section05 scheduling
 
Ch5 process synchronization
Ch5   process synchronizationCh5   process synchronization
Ch5 process synchronization
 
Dead Lock Analysis of spin_lock() in Linux Kernel (english)
Dead Lock Analysis of spin_lock() in Linux Kernel (english)Dead Lock Analysis of spin_lock() in Linux Kernel (english)
Dead Lock Analysis of spin_lock() in Linux Kernel (english)
 
Oracle real application clusters system tests with demo
Oracle real application clusters system tests with demoOracle real application clusters system tests with demo
Oracle real application clusters system tests with demo
 
RTAI - Earliest Deadline First
RTAI - Earliest Deadline FirstRTAI - Earliest Deadline First
RTAI - Earliest Deadline First
 
operating system (1).pdf
operating system (1).pdfoperating system (1).pdf
operating system (1).pdf
 
CIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docx
CIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docxCIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docx
CIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docx
 
Process Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux KernelProcess Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux Kernel
 
Scheduler activations
Scheduler activationsScheduler activations
Scheduler activations
 

Más de Zubair Nabi

Lab 5: Interconnecting a Datacenter using Mininet
Lab 5: Interconnecting a Datacenter using MininetLab 5: Interconnecting a Datacenter using Mininet
Lab 5: Interconnecting a Datacenter using MininetZubair Nabi
 
Topic 12: NoSQL in Action
Topic 12: NoSQL in ActionTopic 12: NoSQL in Action
Topic 12: NoSQL in ActionZubair Nabi
 
Lab 4: Interfacing with Cassandra
Lab 4: Interfacing with CassandraLab 4: Interfacing with Cassandra
Lab 4: Interfacing with CassandraZubair Nabi
 
Topic 10: Taxonomy of Data and Storage
Topic 10: Taxonomy of Data and StorageTopic 10: Taxonomy of Data and Storage
Topic 10: Taxonomy of Data and StorageZubair Nabi
 
Topic 11: Google Filesystem
Topic 11: Google FilesystemTopic 11: Google Filesystem
Topic 11: Google FilesystemZubair Nabi
 
Lab 3: Writing a Naiad Application
Lab 3: Writing a Naiad ApplicationLab 3: Writing a Naiad Application
Lab 3: Writing a Naiad ApplicationZubair Nabi
 
Topic 8: Enhancements and Alternative Architectures
Topic 8: Enhancements and Alternative ArchitecturesTopic 8: Enhancements and Alternative Architectures
Topic 8: Enhancements and Alternative ArchitecturesZubair Nabi
 
Topic 7: Shortcomings in the MapReduce Paradigm
Topic 7: Shortcomings in the MapReduce ParadigmTopic 7: Shortcomings in the MapReduce Paradigm
Topic 7: Shortcomings in the MapReduce ParadigmZubair Nabi
 
Lab 1: Introduction to Amazon EC2 and MPI
Lab 1: Introduction to Amazon EC2 and MPILab 1: Introduction to Amazon EC2 and MPI
Lab 1: Introduction to Amazon EC2 and MPIZubair Nabi
 
Topic 6: MapReduce Applications
Topic 6: MapReduce ApplicationsTopic 6: MapReduce Applications
Topic 6: MapReduce ApplicationsZubair Nabi
 

Más de Zubair Nabi (11)

Lab 5: Interconnecting a Datacenter using Mininet
Lab 5: Interconnecting a Datacenter using MininetLab 5: Interconnecting a Datacenter using Mininet
Lab 5: Interconnecting a Datacenter using Mininet
 
Topic 12: NoSQL in Action
Topic 12: NoSQL in ActionTopic 12: NoSQL in Action
Topic 12: NoSQL in Action
 
Lab 4: Interfacing with Cassandra
Lab 4: Interfacing with CassandraLab 4: Interfacing with Cassandra
Lab 4: Interfacing with Cassandra
 
Topic 10: Taxonomy of Data and Storage
Topic 10: Taxonomy of Data and StorageTopic 10: Taxonomy of Data and Storage
Topic 10: Taxonomy of Data and Storage
 
Topic 11: Google Filesystem
Topic 11: Google FilesystemTopic 11: Google Filesystem
Topic 11: Google Filesystem
 
Lab 3: Writing a Naiad Application
Lab 3: Writing a Naiad ApplicationLab 3: Writing a Naiad Application
Lab 3: Writing a Naiad Application
 
Topic 9: MR+
Topic 9: MR+Topic 9: MR+
Topic 9: MR+
 
Topic 8: Enhancements and Alternative Architectures
Topic 8: Enhancements and Alternative ArchitecturesTopic 8: Enhancements and Alternative Architectures
Topic 8: Enhancements and Alternative Architectures
 
Topic 7: Shortcomings in the MapReduce Paradigm
Topic 7: Shortcomings in the MapReduce ParadigmTopic 7: Shortcomings in the MapReduce Paradigm
Topic 7: Shortcomings in the MapReduce Paradigm
 
Lab 1: Introduction to Amazon EC2 and MPI
Lab 1: Introduction to Amazon EC2 and MPILab 1: Introduction to Amazon EC2 and MPI
Lab 1: Introduction to Amazon EC2 and MPI
 
Topic 6: MapReduce Applications
Topic 6: MapReduce ApplicationsTopic 6: MapReduce Applications
Topic 6: MapReduce Applications
 

Último

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Último (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

AOS Lab 6: Scheduling

  • 1. Lab 6: Scheduling Advanced Operating Systems Zubair Nabi zubair.nabi@itu.edu.pk March 6, 2013
  • 2. Introduction 1 An operating system runs more processes than it has processors
  • 3. Introduction 1 An operating system runs more processes than it has processors 2 Needs some plan to time share the processors between the processes
  • 4. Introduction 1 An operating system runs more processes than it has processors 2 Needs some plan to time share the processors between the processes 3 A common approach is to provide each process with a virtual processor – An illusion that it has exclusive access to the processor
  • 5. Introduction 1 An operating system runs more processes than it has processors 2 Needs some plan to time share the processors between the processes 3 A common approach is to provide each process with a virtual processor – An illusion that it has exclusive access to the processor 4 It is then the job of the OS to multiplex these multiple virtual processors on the underlying physical processors
  • 6. Scheduling triggers 1 A process does I/O, put it to sleep, and schedule another process
  • 7. Scheduling triggers 1 A process does I/O, put it to sleep, and schedule another process 2 Use timer interrupts to stop running on a processor after a fixed time quantum (100 msec)
  • 8. Context switching • Used to achieve multiplexing
  • 9. Context switching • Used to achieve multiplexing • Internally two low-level context switches are performed
  • 10. Context switching • Used to achieve multiplexing • Internally two low-level context switches are performed 1 Process’s kernel thread to the current CPU’s scheduler thread
  • 11. Context switching • Used to achieve multiplexing • Internally two low-level context switches are performed 1 2 Process’s kernel thread to the current CPU’s scheduler thread Scheduler’s thread to a process’s kernel thread
  • 12. Context switching • Used to achieve multiplexing • Internally two low-level context switches are performed 1 2 Process’s kernel thread to the current CPU’s scheduler thread Scheduler’s thread to a process’s kernel thread • No direct switching from one user-space process to another
  • 13. Context switching • Used to achieve multiplexing • Internally two low-level context switches are performed 1 2 Process’s kernel thread to the current CPU’s scheduler thread Scheduler’s thread to a process’s kernel thread • No direct switching from one user-space process to another • Each process has its own kernel stack and register set (its context)
  • 14. Context switching • Used to achieve multiplexing • Internally two low-level context switches are performed 1 2 Process’s kernel thread to the current CPU’s scheduler thread Scheduler’s thread to a process’s kernel thread • No direct switching from one user-space process to another • Each process has its own kernel stack and register set (its context) • Each CPU has its own scheduler thread
  • 15. Context switching • Used to achieve multiplexing • Internally two low-level context switches are performed 1 2 Process’s kernel thread to the current CPU’s scheduler thread Scheduler’s thread to a process’s kernel thread • No direct switching from one user-space process to another • Each process has its own kernel stack and register set (its context) • Each CPU has its own scheduler thread • Context switch involves saving the old thread’s CPU registers and restoring previously-saved registers of the new thread (enabled by swtch)
  • 16. swtch • Saves and restores contexts
  • 17. swtch • Saves and restores contexts • Takes two arguments: struct context **old and struct context *new
  • 18. swtch • Saves and restores contexts • Takes two arguments: struct context **old and struct context *new • Replaces the former with the latter
  • 19. swtch • Saves and restores contexts • Takes two arguments: struct context **old and struct context *new • Replaces the former with the latter • Each time a process has to give up the CPU, its kernel thread invokes swtch to save its own context and switch to the scheduler context
  • 20. swtch • Saves and restores contexts • Takes two arguments: struct context **old and struct context *new • Replaces the former with the latter • Each time a process has to give up the CPU, its kernel thread invokes swtch to save its own context and switch to the scheduler context • Flow in case of an interrupt:
  • 21. swtch • Saves and restores contexts • Takes two arguments: struct context **old and struct context *new • Replaces the former with the latter • Each time a process has to give up the CPU, its kernel thread invokes swtch to save its own context and switch to the scheduler context • Flow in case of an interrupt: 1 trap handles the interrupt and the calls yield
  • 22. swtch • Saves and restores contexts • Takes two arguments: struct context **old and struct context *new • Replaces the former with the latter • Each time a process has to give up the CPU, its kernel thread invokes swtch to save its own context and switch to the scheduler context • Flow in case of an interrupt: 1 trap handles the interrupt and the calls yield 2 yield makes a call to sched
  • 23. swtch • Saves and restores contexts • Takes two arguments: struct context **old and struct context *new • Replaces the former with the latter • Each time a process has to give up the CPU, its kernel thread invokes swtch to save its own context and switch to the scheduler context • Flow in case of an interrupt: 1 trap handles the interrupt and the calls yield 2 yield makes a call to sched 3 sched invokes swtch(&proc->context, cpu->scheduler)
  • 24. swtch • Saves and restores contexts • Takes two arguments: struct context **old and struct context *new • Replaces the former with the latter • Each time a process has to give up the CPU, its kernel thread invokes swtch to save its own context and switch to the scheduler context • Flow in case of an interrupt: 1 trap handles the interrupt and the calls yield 2 yield makes a call to sched 3 sched invokes swtch(&proc->context, cpu->scheduler) 4 Control returns to the scheduler thread
  • 25. Scheduling mechanism • Each process that wants to give up the processor:
  • 26. Scheduling mechanism • Each process that wants to give up the processor: 1 Acquires ptable.lock (process table lock)
  • 27. Scheduling mechanism • Each process that wants to give up the processor: 1 Acquires ptable.lock (process table lock) 2 Releases any other locks that it is holding
  • 28. Scheduling mechanism • Each process that wants to give up the processor: 1 Acquires ptable.lock (process table lock) 2 3 Releases any other locks that it is holding Updates proc->state (its own state)
  • 29. Scheduling mechanism • Each process that wants to give up the processor: 1 Acquires ptable.lock (process table lock) Releases any other locks that it is holding Updates proc->state (its own state) 4 Calls sched 2 3
  • 30. Scheduling mechanism • Each process that wants to give up the processor: 1 Acquires ptable.lock (process table lock) Releases any other locks that it is holding Updates proc->state (its own state) 4 Calls sched 2 3 • Mechanism followed by yield, and sleep and exit
  • 31. Scheduling mechanism • Each process that wants to give up the processor: 1 Acquires ptable.lock (process table lock) Releases any other locks that it is holding Updates proc->state (its own state) 4 Calls sched 2 3 • Mechanism followed by yield, and sleep and exit • sched ensures that these steps are followed
  • 32. sched 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 void sched (void) { int intena ; if(! holding (& ptable .lock )) panic (" sched ptable .lock"); if(cpu−>ncli != 1) panic (" sched locks "); if(proc−>state == RUNNING ) panic (" sched running "); if( readeflags ()& FL_IF ) panic (" sched interruptible "); intena = cpu−>intena ; swtch (& proc−>context , cpu−>scheduler ); cpu−>intena = intena ; }
  • 33. yield 1 2 3 4 5 6 void yield (void) { acquire (& ptable .lock ); proc−>state = RUNNABLE ; sched (); release (& ptable .lock ); }
  • 34. Scheduling mechanism (2) • Why must a process acquire ptable.lock before a call to swtch? • Breaks the convention that the thread that acquires a lock is also responsible for releasing the lock
  • 35. Scheduling mechanism (2) • Why must a process acquire ptable.lock before a call to swtch? • Breaks the convention that the thread that acquires a lock is also responsible for releasing the lock • Without acquiring ptable.lock, two CPUs might want to schedule the same process because they can access ptable
  • 36. scheduler • Simple loop: find a process to run, run it until it stops, repeat
  • 37. scheduler • Simple loop: find a process to run, run it until it stops, repeat • Acquires and releases ptable.lock, and enables interrupts on every iteration. Why?
  • 38. scheduler • Simple loop: find a process to run, run it until it stops, repeat • Acquires and releases ptable.lock, and enables interrupts on every iteration. Why? • If CPU is idle (no RUNNABLE)
  • 39. scheduler • Simple loop: find a process to run, run it until it stops, repeat • Acquires and releases ptable.lock, and enables interrupts on every iteration. Why? • If CPU is idle (no RUNNABLE) 1 Idle looping while holding a lock would not allow any other CPU to access the process table
  • 40. scheduler • Simple loop: find a process to run, run it until it stops, repeat • Acquires and releases ptable.lock, and enables interrupts on every iteration. Why? • If CPU is idle (no RUNNABLE) Idle looping while holding a lock would not allow any other CPU to access the process table 2 Idle looping (all processes are waiting for I/O) while interrupts are disabled would not allow any I/O to arrive 1
  • 41. scheduler • Simple loop: find a process to run, run it until it stops, repeat • Acquires and releases ptable.lock, and enables interrupts on every iteration. Why? • If CPU is idle (no RUNNABLE) Idle looping while holding a lock would not allow any other CPU to access the process table 2 Idle looping (all processes are waiting for I/O) while interrupts are disabled would not allow any I/O to arrive 1 • The first process with p->state == RUNNABLE is selected
  • 42. scheduler • Simple loop: find a process to run, run it until it stops, repeat • Acquires and releases ptable.lock, and enables interrupts on every iteration. Why? • If CPU is idle (no RUNNABLE) Idle looping while holding a lock would not allow any other CPU to access the process table 2 Idle looping (all processes are waiting for I/O) while interrupts are disabled would not allow any I/O to arrive 1 • The first process with p->state == RUNNABLE is selected • The process is assigned to the per-CPU proc
  • 43. scheduler • Simple loop: find a process to run, run it until it stops, repeat • Acquires and releases ptable.lock, and enables interrupts on every iteration. Why? • If CPU is idle (no RUNNABLE) Idle looping while holding a lock would not allow any other CPU to access the process table 2 Idle looping (all processes are waiting for I/O) while interrupts are disabled would not allow any I/O to arrive 1 • The first process with p->state == RUNNABLE is selected • The process is assigned to the per-CPU proc • The process’s page table is switched to via switchuvm
  • 44. scheduler • Simple loop: find a process to run, run it until it stops, repeat • Acquires and releases ptable.lock, and enables interrupts on every iteration. Why? • If CPU is idle (no RUNNABLE) Idle looping while holding a lock would not allow any other CPU to access the process table 2 Idle looping (all processes are waiting for I/O) while interrupts are disabled would not allow any I/O to arrive 1 • The first process with p->state == RUNNABLE is selected • The process is assigned to the per-CPU proc • The process’s page table is switched to via switchuvm • The process is marked as RUNNING
  • 45. scheduler • Simple loop: find a process to run, run it until it stops, repeat • Acquires and releases ptable.lock, and enables interrupts on every iteration. Why? • If CPU is idle (no RUNNABLE) Idle looping while holding a lock would not allow any other CPU to access the process table 2 Idle looping (all processes are waiting for I/O) while interrupts are disabled would not allow any I/O to arrive 1 • The first process with p->state == RUNNABLE is selected • The process is assigned to the per-CPU proc • The process’s page table is switched to via switchuvm • The process is marked as RUNNING • swtch is called to start running it
  • 46. scheduler 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 void scheduler (void) { struct proc ∗p; for (;;){ sti (); acquire (& ptable .lock ); for(p = ptable .proc; p < & ptable .proc[ NPROC ]; p++){ if(p−>state != RUNNABLE ) continue ; proc = p; switchuvm (p); p−>state = RUNNING ; swtch (&cpu−>scheduler , proc−>context ); switchkvm (); proc = 0; }
  • 47. Sleep and wakeup • sleep and wakeup enable an IPC mechanism
  • 48. Sleep and wakeup • sleep and wakeup enable an IPC mechanism • Enable sequence coordination or conditional synchronization
  • 49. Sleep and wakeup • sleep and wakeup enable an IPC mechanism • Enable sequence coordination or conditional synchronization • sleep allows one process to sleep waiting for an event
  • 50. Sleep and wakeup • sleep and wakeup enable an IPC mechanism • Enable sequence coordination or conditional synchronization • sleep allows one process to sleep waiting for an event • wakeup allows another process to wake up processes sleeping on an event
  • 51. Queue 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 struct q { void ∗ptr; }; void∗ send( struct q ∗q, void ∗q) { while(q−>ptr != 0) ; q−>ptr = p; } void∗ recv( struct q void ∗p; while ((p = q−>ptr) == 0) ; q−>ptr = 0; return p; } ∗p) {
  • 52. Queue with sleep and wakeup 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 void∗ send( struct q ∗q, void ∗q) { while(q−>ptr != 0) ; q−>ptr = p; wakeup (q); } void∗ recv( struct q void ∗p; while ((p = q−>ptr) == 0) sleep (q); q−>ptr = 0; return p; } ∗p) {
  • 53. Queue with sleep and wakeup and locking 1 2 3 4 struct q { struct spinlock lock; void }; ∗ptr;
  • 54. Queue with sleep and wakeup and locking (2) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 void∗ send( struct q ∗q, void acquire (&q−>lock ); while(q−>ptr != 0) ; q−>ptr = p; wakeup (q); release (&q−>lock ); } void∗ recv( struct q void ∗q) { ∗p; acquire (&q−>lock ); while ((p = q−>ptr) == 0) sleep (q); q−>ptr = 0; release (&q−>lock ); return p; } ∗p) {
  • 55. Queue with sleep and wakeup and implicit locking 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 void∗ send( struct q ∗q, void acquire (&q−>lock ); while(q−>ptr != 0) ; q−>ptr = p; wakeup (q); release (&q−>lock ); } void∗ recv( struct q void ∗q) { ∗p; acquire (&q−>lock ); while ((p = q−>ptr) == 0) sleep (q, &q−>lock ); q−>ptr = 0; release (&q−>lock ); return p; } ∗p) {
  • 56. sleep 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 void sleep (void ∗chan , struct spinlock if(proc == 0) panic (" sleep "); if(lk == 0) panic (" sleep without lk"); if(lk != & ptable .lock ){ acquire (& ptable .lock ); release (lk ); } proc−>chan = chan; proc−>state = SLEEPING ; sched (); proc−>chan = 0; if(lk != & ptable .lock ){ release (& ptable .lock ); acquire (lk ); } } ∗lk) {
  • 57. wakeup 1 2 3 4 5 6 7 8 9 10 11 12 static void wakeup1 (void struct proc ∗chan) { ∗p; for(p = ptable .proc; p < & ptable .proc[ NPROC ]; p++) if(p−>state == SLEEPING && p−>chan == chan) p−>state = RUNNABLE ; } void wakeup (void ∗chan) acquire (& ptable .lock ); wakeup1 (chan ); release (& ptable .lock ); } {
  • 58. Today’s Task • ptable.lock is a very coarse-grained lock which protects the entire process table • Design a mechanism (in terms of pseudocode) that splits it up into multiple locks • Explain why your solution will improve performance while ensuring protection
  • 59. Reading(s) • Chapter 5, “Scheduling” from “xv6: a simple, Unix-like teaching operating system”