context switching accounting mechanism

70
Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 1 Context Switching Accounting Mechanism T. Castillo Girona <[email protected]> Miquel Angel Senar Rosell

Upload: others

Post on 04-Feb-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Context switching accounting mechanism

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 1

Context Switching Accounting Mechanism

T. Castillo Girona<[email protected]>

Miquel Angel Senar Rosell

Page 2: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 2

Context Switching Basis

• Every single process p

runs either in Ring 0 orRing 3.◦ Ring 0: low-level or

hardware tasks.◦ Ring 3: user-space

tasks.

Page 3: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 2

Context Switching Basis

• Every single process p

runs either in Ring 0 orRing 3.◦ Ring 0: low-level or

hardware tasks.◦ Ring 3: user-space

tasks.

Page 4: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 2

Context Switching Basis

• Every single process p

runs either in Ring 0 orRing 3.◦ Ring 0: low-level or

hardware tasks.◦ Ring 3: user-space

tasks.

Page 5: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 2

Context Switching Basis

• Every single process p

runs either in Ring 0 orRing 3.◦ Ring 0: low-level or

hardware tasks.◦ Ring 3: user-space

tasks.• p runs only for a

measurable time t.

Page 6: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 2

Context Switching Basis

• Every single process p

runs either in Ring 0 orRing 3.◦ Ring 0: low-level or

hardware tasks.◦ Ring 3: user-space

tasks.• p runs only for a

measurable time t.• The GNU/Linux

Scheduler is in charge ofmaking p yield the cpu.◦ Modern GNU/Linux

Kernels implements theCFS scheduler.

◦ The Kernel executesschedule() to call theScheduler.

Page 7: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 2

Context Switching Basis

• Every single process p

runs either in Ring 0 orRing 3.◦ Ring 0: low-level or

hardware tasks.◦ Ring 3: user-space

tasks.• p runs only for a

measurable time t.• The GNU/Linux

Scheduler is in charge ofmaking p yield the cpu.◦ Modern GNU/Linux

Kernels implements theCFS scheduler.

◦ The Kernel executesschedule() to call theScheduler.

Page 8: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 2

Context Switching Basis

• Every single process p

runs either in Ring 0 orRing 3.◦ Ring 0: low-level or

hardware tasks.◦ Ring 3: user-space

tasks.• p runs only for a

measurable time t.• The GNU/Linux

Scheduler is in charge ofmaking p yield the cpu.◦ Modern GNU/Linux

Kernels implements theCFS scheduler.

◦ The Kernel executesschedule() to call theScheduler.

Page 9: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 3

Context Switching Basis

• Whenever p yields the processor, there is a ContextSwitch.

Page 10: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 3

Context Switching Basis

• Whenever p yields the processor, there is a ContextSwitch.◦ Voluntary :

◦ p has issued a System Call, and now the Kernel isreturning from it.

◦ p has issued an explicit call to schedule(), by meansof calling sched_yield().

◦ p has ended its execution.

Page 11: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 3

Context Switching Basis

• Whenever p yields the processor, there is a ContextSwitch.◦ Voluntary :

◦ p has issued a System Call, and now the Kernel isreturning from it.

◦ p has issued an explicit call to schedule(), by meansof calling sched_yield().

◦ p has ended its execution.

Page 12: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 3

Context Switching Basis

• Whenever p yields the processor, there is a ContextSwitch.◦ Voluntary :

◦ p has issued a System Call, and now the Kernel isreturning from it.

◦ p has issued an explicit call to schedule(), by meansof calling sched_yield().

◦ p has ended its execution.

Page 13: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 3

Context Switching Basis

• Whenever p yields the processor, there is a ContextSwitch.◦ Voluntary :

◦ p has issued a System Call, and now the Kernel isreturning from it.

◦ p has issued an explicit call to schedule(), by meansof calling sched_yield().

◦ p has ended its execution.

Page 14: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 3

Context Switching Basis

• Whenever p yields the processor, there is a ContextSwitch.◦ Voluntary :

◦ p has issued a System Call, and now the Kernel isreturning from it.

◦ p has issued an explicit call to schedule(), by meansof calling sched_yield().

◦ p has ended its execution.◦ Involuntary :

◦ p has been preempted by an Interrupt Handler.◦ p has exhausted its processor’s time proportion.◦ p has been preempted in favour of a recently waken up

task with a higher priority.

Page 15: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 3

Context Switching Basis

• Whenever p yields the processor, there is a ContextSwitch.◦ Voluntary :

◦ p has issued a System Call, and now the Kernel isreturning from it.

◦ p has issued an explicit call to schedule(), by meansof calling sched_yield().

◦ p has ended its execution.◦ Involuntary :

◦ p has been preempted by an Interrupt Handler.◦ p has exhausted its processor’s time proportion.◦ p has been preempted in favour of a recently waken up

task with a higher priority.

Page 16: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 3

Context Switching Basis

• Whenever p yields the processor, there is a ContextSwitch.◦ Voluntary :

◦ p has issued a System Call, and now the Kernel isreturning from it.

◦ p has issued an explicit call to schedule(), by meansof calling sched_yield().

◦ p has ended its execution.◦ Involuntary :

◦ p has been preempted by an Interrupt Handler.◦ p has exhausted its processor’s time proportion.◦ p has been preempted in favour of a recently waken up

task with a higher priority.

Page 17: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 3

Context Switching Basis

• Whenever p yields the processor, there is a ContextSwitch.◦ Voluntary :

◦ p has issued a System Call, and now the Kernel isreturning from it.

◦ p has issued an explicit call to schedule(), by meansof calling sched_yield().

◦ p has ended its execution.◦ Involuntary :

◦ p has been preempted by an Interrupt Handler.◦ p has exhausted its processor’s time proportion.◦ p has been preempted in favour of a recently waken up

task with a higher priority.

Page 18: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 3

Context Switching Basis

• Whenever p yields the processor, there is a ContextSwitch.◦ Voluntary :

◦ p has issued a System Call, and now the Kernel isreturning from it.

◦ p has issued an explicit call to schedule(), by meansof calling sched_yield().

◦ p has ended its execution.◦ Involuntary :

◦ p has been preempted by an Interrupt Handler.◦ p has exhausted its processor’s time proportion.◦ p has been preempted in favour of a recently waken up

task with a higher priority.• Modern GNU/Linux operating systems does not have

counters for all these particular Context Switchingsub-types.

Page 19: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 3

Context Switching Basis

• Whenever p yields the processor, there is a ContextSwitch.◦ Voluntary :

◦ p has issued a System Call, and now the Kernel isreturning from it.

◦ p has issued an explicit call to schedule(), by meansof calling sched_yield().

◦ p has ended its execution.◦ Involuntary :

◦ p has been preempted by an Interrupt Handler.◦ p has exhausted its processor’s time proportion.◦ p has been preempted in favour of a recently waken up

task with a higher priority.• Modern GNU/Linux operating systems does not have

counters for all these particular Context Switchingsub-types.

• Our project does add these new counters.

Page 20: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 4

Tools, APIs & ABIS

• Tools◦ Based on the /proc interface.◦ Gather cumulative statistics for total amount of

Voluntary and Involuntary Context Switches.◦ atsar, reads /proc/stat◦ pidstat, reads /proc/PID/stat, works with

averages.

Page 21: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 4

Tools, APIs & ABIS

• Tools◦ Based on the /proc interface.◦ Gather cumulative statistics for total amount of

Voluntary and Involuntary Context Switches.◦ atsar, reads /proc/stat◦ pidstat, reads /proc/PID/stat, works with

averages.

Page 22: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 4

Tools, APIs & ABIS

• Tools◦ Based on the /proc interface.◦ Gather cumulative statistics for total amount of

Voluntary and Involuntary Context Switches.◦ atsar, reads /proc/stat◦ pidstat, reads /proc/PID/stat, works with

averages.

Page 23: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 4

Tools, APIs & ABIS

• Tools◦ Based on the /proc interface.◦ Gather cumulative statistics for total amount of

Voluntary and Involuntary Context Switches.◦ atsar, reads /proc/stat◦ pidstat, reads /proc/PID/stat, works with

averages.

Page 24: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 4

Tools, APIs & ABIS

• Tools◦ Based on the /proc interface.◦ Gather cumulative statistics for total amount of

Voluntary and Involuntary Context Switches.◦ atsar, reads /proc/stat◦ pidstat, reads /proc/PID/stat, works with

averages.

Page 25: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 4

Tools, APIs & ABIS

• Tools◦ Based on the /proc interface.◦ Gather cumulative statistics for total amount of

Voluntary and Involuntary Context Switches.◦ atsar, reads /proc/stat◦ pidstat, reads /proc/PID/stat, works with

averages.

• Kernel ABIs◦ /proc/PID/sched interface.◦ taskstats facility, using Netlink infrastructure.

Page 26: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 4

Tools, APIs & ABIS

• Tools◦ Based on the /proc interface.◦ Gather cumulative statistics for total amount of

Voluntary and Involuntary Context Switches.◦ atsar, reads /proc/stat◦ pidstat, reads /proc/PID/stat, works with

averages.

• Kernel ABIs◦ /proc/PID/sched interface.◦ taskstats facility, using Netlink infrastructure.

Page 27: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 4

Tools, APIs & ABIS

• Tools◦ Based on the /proc interface.◦ Gather cumulative statistics for total amount of

Voluntary and Involuntary Context Switches.◦ atsar, reads /proc/stat◦ pidstat, reads /proc/PID/stat, works with

averages.

• Kernel ABIs◦ /proc/PID/sched interface.◦ taskstats facility, using Netlink infrastructure.

Page 28: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 5

Tools, APIs & ABIS

• Advantages of using the taskstats interface.◦ Easy to communicate with the GNU/Linux Kernel.◦ There is no need to develop a Linux Kernel Module.◦ A client tool written in C running in user-space,getcw.c.

Page 29: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 5

Tools, APIs & ABIS

• Advantages of using the taskstats interface.◦ Easy to communicate with the GNU/Linux Kernel.◦ There is no need to develop a Linux Kernel Module.◦ A client tool written in C running in user-space,getcw.c.

Page 30: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 5

Tools, APIs & ABIS

• Advantages of using the taskstats interface.◦ Easy to communicate with the GNU/Linux Kernel.◦ There is no need to develop a Linux Kernel Module.◦ A client tool written in C running in user-space,getcw.c.

Page 31: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 5

Tools, APIs & ABIS

• Advantages of using the taskstats interface.◦ Easy to communicate with the GNU/Linux Kernel.◦ There is no need to develop a Linux Kernel Module.◦ A client tool written in C running in user-space,getcw.c.

Page 32: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 5

Tools, APIs & ABIS

• Advantages of using the taskstats interface.◦ Easy to communicate with the GNU/Linux Kernel.◦ There is no need to develop a Linux Kernel Module.◦ A client tool written in C running in user-space,getcw.c.

• Extending the taskstats interface...

Page 33: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 5

Tools, APIs & ABIS

• Advantages of using the taskstats interface.◦ Easy to communicate with the GNU/Linux Kernel.◦ There is no need to develop a Linux Kernel Module.◦ A client tool written in C running in user-space,getcw.c.

• Extending the taskstats interface...• ... and reading it back from user-space.

Page 34: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 5

Tools, APIs & ABIS

• Advantages of using the taskstats interface.◦ Easy to communicate with the GNU/Linux Kernel.◦ There is no need to develop a Linux Kernel Module.◦ A client tool written in C running in user-space,getcw.c.

• Extending the taskstats interface...• ... and reading it back from user-space.• The task_struct data structure has to be altered

accordingly.

Page 35: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 6

Design & Implementation

• We have added new counters to the GNU/Linux Kernel.

Page 36: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 6

Design & Implementation

• We have added new counters to the GNU/Linux Kernel.• We have extended the task_struct and taskstats

data structures to implement them.

Page 37: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 6

Design & Implementation

• We have added new counters to the GNU/Linux Kernel.• We have extended the task_struct and taskstats

data structures to implement them.• In order to read their data, we have implemented a client C

program communicating with the Kernel via NetLink, calledgetcsw.c.

Page 38: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 6

Design & Implementation

• We have added new counters to the GNU/Linux Kernel.• We have extended the task_struct and taskstats

data structures to implement them.• In order to read their data, we have implemented a client C

program communicating with the Kernel via NetLink, calledgetcsw.c.

• Our counters can ...◦ account the total amount of syscalls per task.◦ account the total amount of calls to the sched_yield()

function.◦ account the total feasible amount of context switches

whilst returning from a system call.◦ account preemption due to Interrupts.◦ account preemption due to try_to_wake_up().◦ determine whether p has ended its execution on its own

accord or not.

Page 39: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 6

Design & Implementation

• We have added new counters to the GNU/Linux Kernel.• We have extended the task_struct and taskstats

data structures to implement them.• In order to read their data, we have implemented a client C

program communicating with the Kernel via NetLink, calledgetcsw.c.

• Our counters can ...◦ account the total amount of syscalls per task.◦ account the total amount of calls to the sched_yield()

function.◦ account the total feasible amount of context switches

whilst returning from a system call.◦ account preemption due to Interrupts.◦ account preemption due to try_to_wake_up().◦ determine whether p has ended its execution on its own

accord or not.

Page 40: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 6

Design & Implementation

• We have added new counters to the GNU/Linux Kernel.• We have extended the task_struct and taskstats

data structures to implement them.• In order to read their data, we have implemented a client C

program communicating with the Kernel via NetLink, calledgetcsw.c.

• Our counters can ...◦ account the total amount of syscalls per task.◦ account the total amount of calls to the sched_yield()

function.◦ account the total feasible amount of context switches

whilst returning from a system call.◦ account preemption due to Interrupts.◦ account preemption due to try_to_wake_up().◦ determine whether p has ended its execution on its own

accord or not.

Page 41: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 6

Design & Implementation

• We have added new counters to the GNU/Linux Kernel.• We have extended the task_struct and taskstats

data structures to implement them.• In order to read their data, we have implemented a client C

program communicating with the Kernel via NetLink, calledgetcsw.c.

• Our counters can ...◦ account the total amount of syscalls per task.◦ account the total amount of calls to the sched_yield()

function.◦ account the total feasible amount of context switches

whilst returning from a system call.◦ account preemption due to Interrupts.◦ account preemption due to try_to_wake_up().◦ determine whether p has ended its execution on its own

accord or not.

Page 42: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 6

Design & Implementation

• We have added new counters to the GNU/Linux Kernel.• We have extended the task_struct and taskstats

data structures to implement them.• In order to read their data, we have implemented a client C

program communicating with the Kernel via NetLink, calledgetcsw.c.

• Our counters can ...◦ account the total amount of syscalls per task.◦ account the total amount of calls to the sched_yield()

function.◦ account the total feasible amount of context switches

whilst returning from a system call.◦ account preemption due to Interrupts.◦ account preemption due to try_to_wake_up().◦ determine whether p has ended its execution on its own

accord or not.

Page 43: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 6

Design & Implementation

• We have added new counters to the GNU/Linux Kernel.• We have extended the task_struct and taskstats

data structures to implement them.• In order to read their data, we have implemented a client C

program communicating with the Kernel via NetLink, calledgetcsw.c.

• Our counters can ...◦ account the total amount of syscalls per task.◦ account the total amount of calls to the sched_yield()

function.◦ account the total feasible amount of context switches

whilst returning from a system call.◦ account preemption due to Interrupts.◦ account preemption due to try_to_wake_up().◦ determine whether p has ended its execution on its own

accord or not.

Page 44: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 6

Design & Implementation

• We have added new counters to the GNU/Linux Kernel.• We have extended the task_struct and taskstats

data structures to implement them.• In order to read their data, we have implemented a client C

program communicating with the Kernel via NetLink, calledgetcsw.c.

• Our counters can ...◦ account the total amount of syscalls per task.◦ account the total amount of calls to the sched_yield()

function.◦ account the total feasible amount of context switches

whilst returning from a system call.◦ account preemption due to Interrupts.◦ account preemption due to try_to_wake_up().◦ determine whether p has ended its execution on its own

accord or not.

Page 45: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 6

Design & Implementation

• We have added new counters to the GNU/Linux Kernel.• We have extended the task_struct and taskstats

data structures to implement them.• In order to read their data, we have implemented a client C

program communicating with the Kernel via NetLink, calledgetcsw.c.

• Our counters can ...◦ account the total amount of syscalls per task.◦ account the total amount of calls to the sched_yield()

function.◦ account the total feasible amount of context switches

whilst returning from a system call.◦ account preemption due to Interrupts.◦ account preemption due to try_to_wake_up().◦ determine whether p has ended its execution on its own

accord or not.• To enable these counters, a patch has to be applied to the

GNU/Linux Kernel.

Page 46: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 7

Execution Examples

• Our main interface to the Kernel is getcsw.c.

Page 47: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 7

Execution Examples

• Our main interface to the Kernel is getcsw.c.

Having a peak at the counters

Page 48: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 7

Execution Examples

• Our main interface to the Kernel is getcsw.c.

Reading the Involuntary Context Switches extended counters

Page 49: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 7

Execution Examples

• Our main interface to the Kernel is getcsw.c.

Reading the counters at infinite intervals of time t = 10

seconds.

Page 50: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 7

Execution Examples

• Our main interface to the Kernel is getcsw.c.

Waiting for a task to end

Page 51: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 7

Execution Examples

• Our main interface to the Kernel is getcsw.c.

• We have written some trivial scripts to add morefunctionality:

Page 52: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 7

Execution Examples

• Our main interface to the Kernel is getcsw.c.

• We have written some trivial scripts to add morefunctionality:◦ fschedyield.sh, in charge of looking for running

tasks that are calling the sched_yield() function.

Page 53: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 7

Execution Examples

• Our main interface to the Kernel is getcsw.c.

• We have written some trivial scripts to add morefunctionality:◦ fschedyield.sh, in charge of looking for running

tasks that are calling the sched_yield() function.◦ fcalltable.sh, in charge of building a table of calls to

the scheduler per each system call during their return.

Page 54: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 8

Generating Hardware Interrupts at will

• An Interrupt always preempts p.

Page 55: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 8

Generating Hardware Interrupts at will

• An Interrupt always preempts p.• Whenever an Interrupt is raised, the GNU/Linux Kernel

handles it by calling do_IRQ().

Page 56: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 8

Generating Hardware Interrupts at will

• An Interrupt always preempts p.• Whenever an Interrupt is raised, the GNU/Linux Kernel

handles it by calling do_IRQ().• Most Interrupts are maskable: they can be ignored.

Page 57: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 8

Generating Hardware Interrupts at will

• An Interrupt always preempts p.• Whenever an Interrupt is raised, the GNU/Linux Kernel

handles it by calling do_IRQ().• Most Interrupts are maskable: they can be ignored.• NMIs cannot be ignored; they are ideal to test our project.

Page 58: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 8

Generating Hardware Interrupts at will

• An Interrupt always preempts p.• Whenever an Interrupt is raised, the GNU/Linux Kernel

handles it by calling do_IRQ().• Most Interrupts are maskable: they can be ignored.• NMIs cannot be ignored; they are ideal to test our project.

• To generate NMIs at will, we need to alter the Kernel IDT,so that int $0x2 can be executed with DPL = 3.

Page 59: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 9

Preliminary Results

• By accounting preemption due to do_IRQ(), we candetermine whenever there is an external problemaffecting p’s throughput.

Page 60: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 9

Preliminary Results

• By accounting preemption due to do_IRQ(), we candetermine whenever there is an external problemaffecting p’s throughput.

• As IRQS −→ ∞, the time spent by p increases.

Page 61: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 9

Preliminary Results

• By accounting preemption due to do_IRQ(), we candetermine whenever there is an external problemaffecting p’s throughput.

• As IRQS −→ ∞, the time spent by p increases.• IRQ-balance can help to diminish this time by reducing

the number of interrupts preempting p.

Page 62: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 9

Preliminary Results

• By accounting preemption due to do_IRQ(), we candetermine whenever there is an external problemaffecting p’s throughput.

• As IRQS −→ ∞, the time spent by p increases.• IRQ-balance can help to diminish this time by reducing

the number of interrupts preempting p.

Page 63: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 10

Preliminary Results

• Whenever there is a hardware malfunction, the datastarts being chaotic.

Page 64: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 10

Preliminary Results

• Whenever there is a hardware malfunction, the datastarts being chaotic.

• It’s proved that, whenever p yields the processor due to araised interrupt, at some measurable intervals of time ti,its time spent in doing its job increases.

Page 65: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 11

Future Work

• Architecture-independent,• Re-ran the experiments

adding some entropy forlarger values of n,

• Extend getcsw tointegrate it with plotfacilities,

• Analyse the real impact ofour counters inside theScheduler,

• ...

Page 66: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 11

Future Work

• Architecture-independent,• Re-ran the experiments

adding some entropy forlarger values of n,

• Extend getcsw tointegrate it with plotfacilities,

• Analyse the real impact ofour counters inside theScheduler,

• ...

Page 67: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 11

Future Work

• Architecture-independent,• Re-ran the experiments

adding some entropy forlarger values of n,

• Extend getcsw tointegrate it with plotfacilities,

• Analyse the real impact ofour counters inside theScheduler,

• ...

Page 68: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 11

Future Work

• Architecture-independent,• Re-ran the experiments

adding some entropy forlarger values of n,

• Extend getcsw tointegrate it with plotfacilities,

• Analyse the real impact ofour counters inside theScheduler,

• ...

Page 69: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 11

Future Work

• Architecture-independent,• Re-ran the experiments

adding some entropy forlarger values of n,

• Extend getcsw tointegrate it with plotfacilities,

• Analyse the real impact ofour counters inside theScheduler,

• ...

Page 70: Context switching accounting mechanism

•Context Switching Basis

•Tools, APIs & ABIS

•Design & Implementation

•Execution Examples

•Generating Hardware

Interrupts at will•Preliminary Results

•Future Work

•Thanks for coming!

Context Switching Accounting Mechanism 2012 Toni Castillo Girona - <[email protected]> - p. 12

Thanks for coming!

[email protected]