SlideShare a Scribd company logo
Tasklet Vs Work queues
By
Rajkumar Rampelli
Outline
•
•
•
•
•
•

Deferrable functions
Top Half Vs Bottom Half
Tasklet
Work queue
Tasklet Vs Work queue
Conclusion

12/6/2013

Raj Kumar Rampelli

2
Deferrable function
• Mechanism for supporting the delayed execution of any function in
Interrupt handlers (Interrupt context)
• Interrupt Context
– Kernel enters Interrupt context when hardware interrupt received
– Kernel enters Process/Kernel context from Interrupt context after
servicing the hardware interrupt
– Execution of tasks in Interrupt context should be minimized
• Why - Majority of Interrupts are disabled, therefore latency to handle other
interrupts will be increased
• Solution: Move execution of not urgent function (piece of code) into process
context (Deferrable function)
• Add deferrable functions in Interrupt Handlers

• Deferrable functions: can be executed in process context
– Tasklet
– Work queues

12/6/2013

Raj Kumar Rampelli

3
Top Half Vs Bottom Half
Top Half

Bottom Half

Processing of tasks in Interrupt Handler
(Interrupt context)

Processing of tasks in Kernel context

Interrupts are disabled

Interrupts are not disabled

Add Deferrable functions for delayed
execution

Handles Deferrable functions

Processing time should be less

-NA-

Uses Tasklets and work queue APIs for deferrable mechanism

12/6/2013

Raj Kumar Rampelli

4
Tasklet: To schedule the work (function) to run later point of time
so that reducing the amount of work done in interrupt handlers.
Tasklet Initialization APIs

Usage

void tasklet_function (unsigned
long data);

Deferrable function i.e. actual Task

DECLARE_TASKLET
(tasklet_name,
tasklet_function, tasklet_data);

• Initializes the tasklet structure (tasklet_struct)
with passing argument list
• Tasklets are enabled by default
• Next step: Schedule the task

DECLARE_TASKLET_DISABLED
(tasklet_name,
tasklet_function, tasklet_data);

• Initializes the tasklet structure
• Tasklets are disabled
• Next step: Enable Tasklet before schedule the
task

void tasklet_init(struct
tasklet_struct *, void (*func)
(unsigned long), unsigned long
data);

• Initializes the tasklet structure (tasklet_struct)
with passing argument list

12/6/2013

Raj Kumar Rampelli

5
Tasklet (contd.)
Tasklet Enable/Disable APIs

Usage

void tasklet_enable (struct tasklet_struct *);

/* Enable normal priority scheduling */

void tasklet_disable (struct tasklet_struct *);

/* returns after disabling the tasklet */

void tasklet_hi_enable (struct tasklet_struct *); /* Enabling High priority scheduling */
void tasklet_disable_nosync (struct
tasklet_struct *);

12/6/2013

/* May returns before termination i.e.
no synchronization with disabling of
tasklet */

Raj Kumar Rampelli

6
Tasklet (contd.)
Tasklet Schedule APIs

Usage

void tasklet_schedule (struct tasklet_struct *);

/* Normal priority scheduling */

void tasklet_hi_schedule (struct tasklet_struct *);

/* Higher priority scheduling */

CPU maintains the normal and high priority softirq vectors lists (normal priority vector
list and high priority vector list) where these functions are queued.
If the function is higher priority function then it is en-queued in higher priority softirq
vector list and similar case for normal priority functions.

Kill a Tasklet

Usage

void tasklet_kill (struct tasklet_struct *);

/* Kill a tasklet */

void tasklet_hi_kill (struct tasklet_struct *);

/* Kill the tasklet and ensure they
would never run */

12/6/2013

Raj Kumar Rampelli

7
Work queue
• Added in linux kernel 2.6 version
• Use two data structures
– struct workqueue_struct
• Work is queued here in Interrupt context
• The same work is executed in Kernel context
– struct work_struct
• Identifies the work and deferrable function
• Kernel threads named "events/X" will extract work from the core work
queue and activates the work's handler function.
Tasklet
Added in linux kernel 2.3
version

In 2.6 kernel version

Sleep in Handler function 
Not possible
12/6/2013

Work queue

Possible.

Latency is less

Raj Kumar Rampelli

More compared to Tasklet

8
Work queue APIs
Create and destroy work queue structure

Usage

struct workqueue_struct
*create_workqueue(name);

/* Creates core workqueue */

void destroy_workqueue(struct
workqueue_struct *);

/* Destroy the workqueue */

Initialization of work structure

Usage

INIT_WORK(work, function);

/* Initializes the work structure with
function handler */

INIT_DELAYED_WORK(work, function);
/* Add any delay before adding this work
INIT_DELAYED_WORK_DEFERRABLE(work, into work queue structure */
function);

12/6/2013

Raj Kumar Rampelli

9
Work queue APIs (contd.)
•

Add work on to work queue
– int queue_work (struct workqueue_struct *wq, struct work_struct *work);
– /* specify the CPU on which the handler should run */
int queue_work_on (int cpu, struct workqueue_struct *wq, struct work_struct *work);
– /* Queue specified work on to specified work queue after delay */
int queue_delayed_work (struct workqueue_struct *wq, struct delayed_work *work, unsigned
long delay);
– int queue_delayed_work_on (int cpu, struct workqueue_struct *wq, struct delayed_work
*work), unsigned long delay);

•

The below functions doesn't require workqueue structure defined. Since, they
uses kernel-global work queue. So, no need to pass workqueue_struct in the
argument list.
–
–
–
–

12/6/2013

int schedule_work (struct work_struct *):
int schedule_work_on (int cpu, struct work_struct *):
int scheduled_delayed_work (struct delayed_work *, unsigned long delay);
int scheduled_delayed_work_on (int cpu, struct delayed_work *, unsigned long delay);

Raj Kumar Rampelli

10
Work queue APIs (contd.)
• Cancel work
/* terminate work in the queue, which is not already executing in the handler */
int cancel_work_sync (struct work_struct *);
int cancel_delayed_work_sync (struct delayed_work *);
• Flush work
Below functions are used to flush the work and works in the specified workqueue.
/* Flush a particular work and block until it is completed */
int flush_work (struct work_struct *);
/* Flush all works in given workqueue and block until it is completed */
int flush_workqueue (struct workqueue_struct *);
/* Flush kernel-global work queue */
void flush_scheduled_work (void);
• Status of work
We can use below two functions to know whether the given work is pending i.e. its handler function is
not yet started.
work_pending(work);
delayed_work_pending (work);

12/6/2013

Raj Kumar Rampelli

11
Conclusion
• Reduce the execution time in Interrupt context by using deferrable
function mechanism
• Top Half: Processing of tasks in Interrupt Handler (Interrupt
context)
• Bottom Half: Processing of tasks in Kernel/Process context
• Two type of deferrable functions
– Tasklet
– Work queue

• Aim: To schedule the work/function (not urgent piece of code) in
interrupt handler to run later point of time (in bottom half) so that
reducing the amount of work done in interrupt handlers.
• Tasklet and Work queue both do the above task using their own set
of APIs
• For more details visit: www.practicepeople.blogspot.com
12/6/2013

Raj Kumar Rampelli

12
THANK YOU 

12/6/2013

Raj Kumar Rampelli

13

More Related Content

What's hot

Anatomy of the loadable kernel module (lkm)
Anatomy of the loadable kernel module (lkm)Anatomy of the loadable kernel module (lkm)
Anatomy of the loadable kernel module (lkm)Adrian Huang
 
Memory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelMemory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelAdrian Huang
 
Process' Virtual Address Space in GNU/Linux
Process' Virtual Address Space in GNU/LinuxProcess' Virtual Address Space in GNU/Linux
Process' Virtual Address Space in GNU/LinuxVarun Mahajan
 
linux file sysytem& input and output
linux file sysytem& input and outputlinux file sysytem& input and output
linux file sysytem& input and outputMythiliA5
 
The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421Linaro
 
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingTushar B Kute
 
File permission in linux
File permission in linuxFile permission in linux
File permission in linuxPrakash Poudel
 
basic linux command (questions)
basic linux command (questions)basic linux command (questions)
basic linux command (questions)Sukhraj Singh
 
Access control list acl - permissions in linux
Access control list acl  - permissions in linuxAccess control list acl  - permissions in linux
Access control list acl - permissions in linuxSreenatha Reddy K R
 
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
 
Linux process management
Linux process managementLinux process management
Linux process managementRaghu nath
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Adrian Huang
 
Linux architecture
Linux architectureLinux architecture
Linux architecturemcganesh
 
Debugging linux kernel tools and techniques
Debugging linux kernel tools and  techniquesDebugging linux kernel tools and  techniques
Debugging linux kernel tools and techniquesSatpal Parmar
 

What's hot (20)

BusyBox for Embedded Linux
BusyBox for Embedded LinuxBusyBox for Embedded Linux
BusyBox for Embedded Linux
 
Linux file system
Linux file systemLinux file system
Linux file system
 
Anatomy of the loadable kernel module (lkm)
Anatomy of the loadable kernel module (lkm)Anatomy of the loadable kernel module (lkm)
Anatomy of the loadable kernel module (lkm)
 
Memory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelMemory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux Kernel
 
Process' Virtual Address Space in GNU/Linux
Process' Virtual Address Space in GNU/LinuxProcess' Virtual Address Space in GNU/Linux
Process' Virtual Address Space in GNU/Linux
 
Ipc in linux
Ipc in linuxIpc in linux
Ipc in linux
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
linux file sysytem& input and output
linux file sysytem& input and outputlinux file sysytem& input and output
linux file sysytem& input and output
 
The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421
 
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module Programming
 
File permission in linux
File permission in linuxFile permission in linux
File permission in linux
 
basic linux command (questions)
basic linux command (questions)basic linux command (questions)
basic linux command (questions)
 
Access control list acl - permissions in linux
Access control list acl  - permissions in linuxAccess control list acl  - permissions in linux
Access control list acl - permissions in linux
 
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
 
Linux process management
Linux process managementLinux process management
Linux process management
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...
 
spinlock.pdf
spinlock.pdfspinlock.pdf
spinlock.pdf
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Debugging linux kernel tools and techniques
Debugging linux kernel tools and  techniquesDebugging linux kernel tools and  techniques
Debugging linux kernel tools and techniques
 

Viewers also liked

Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginnersRajKumar Rampelli
 
Introduction to Kernel and Device Drivers
Introduction to Kernel and Device DriversIntroduction to Kernel and Device Drivers
Introduction to Kernel and Device DriversRajKumar Rampelli
 
System Booting Process overview
System Booting Process overviewSystem Booting Process overview
System Booting Process overviewRajKumar Rampelli
 
Network security and cryptography
Network security and cryptographyNetwork security and cryptography
Network security and cryptographyRajKumar Rampelli
 
Learn python - for beginners - part-2
Learn python - for beginners - part-2Learn python - for beginners - part-2
Learn python - for beginners - part-2RajKumar Rampelli
 

Viewers also liked (8)

Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginners
 
Introduction to Kernel and Device Drivers
Introduction to Kernel and Device DriversIntroduction to Kernel and Device Drivers
Introduction to Kernel and Device Drivers
 
Linux GIT commands
Linux GIT commandsLinux GIT commands
Linux GIT commands
 
Linux watchdog timer
Linux watchdog timerLinux watchdog timer
Linux watchdog timer
 
System Booting Process overview
System Booting Process overviewSystem Booting Process overview
System Booting Process overview
 
Network security and cryptography
Network security and cryptographyNetwork security and cryptography
Network security and cryptography
 
Linux Kernel I/O Schedulers
Linux Kernel I/O SchedulersLinux Kernel I/O Schedulers
Linux Kernel I/O Schedulers
 
Learn python - for beginners - part-2
Learn python - for beginners - part-2Learn python - for beginners - part-2
Learn python - for beginners - part-2
 

Similar to Tasklet vs work queues (Deferrable functions in linux)

Concurrent Programming in Java
Concurrent Programming in JavaConcurrent Programming in Java
Concurrent Programming in JavaRuben Inoto Soto
 
.NET Multithreading/Multitasking
.NET Multithreading/Multitasking.NET Multithreading/Multitasking
.NET Multithreading/MultitaskingSasha Kravchuk
 
Java util concurrent
Java util concurrentJava util concurrent
Java util concurrentRoger Xia
 
Parallel Programming With Dot Net
Parallel Programming With Dot NetParallel Programming With Dot Net
Parallel Programming With Dot NetNeeraj Kaushik
 
Performance schema and_ps_helper
Performance schema and_ps_helperPerformance schema and_ps_helper
Performance schema and_ps_helperMark Leith
 
Quick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android DevQuick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android DevShuhei Shogen
 
Analysing in depth work manager
Analysing in depth work managerAnalysing in depth work manager
Analysing in depth work managerlpu
 
How eBay does Automatic Outage Planning
How eBay does Automatic Outage PlanningHow eBay does Automatic Outage Planning
How eBay does Automatic Outage PlanningCA | Automic Software
 
Big data unit iv and v lecture notes qb model exam
Big data unit iv and v lecture notes   qb model examBig data unit iv and v lecture notes   qb model exam
Big data unit iv and v lecture notes qb model examIndhujeni
 
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...Flink Forward
 
Oracle’ın parallel execution yetenekleri ve performans
Oracle’ın parallel execution yetenekleri ve performansOracle’ın parallel execution yetenekleri ve performans
Oracle’ın parallel execution yetenekleri ve performansEmrah METE
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basicsnitin anjankar
 
Sprint 133
Sprint 133Sprint 133
Sprint 133ManageIQ
 
SMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docxSMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docxpbilly1
 

Similar to Tasklet vs work queues (Deferrable functions in linux) (20)

Concurrent Programming in Java
Concurrent Programming in JavaConcurrent Programming in Java
Concurrent Programming in Java
 
.NET Multithreading/Multitasking
.NET Multithreading/Multitasking.NET Multithreading/Multitasking
.NET Multithreading/Multitasking
 
Java util concurrent
Java util concurrentJava util concurrent
Java util concurrent
 
RTX Kernal
RTX KernalRTX Kernal
RTX Kernal
 
Parallel Programming With Dot Net
Parallel Programming With Dot NetParallel Programming With Dot Net
Parallel Programming With Dot Net
 
Performance schema and_ps_helper
Performance schema and_ps_helperPerformance schema and_ps_helper
Performance schema and_ps_helper
 
unit5 uc.pptx
unit5 uc.pptxunit5 uc.pptx
unit5 uc.pptx
 
Quick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android DevQuick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android Dev
 
Analysing in depth work manager
Analysing in depth work managerAnalysing in depth work manager
Analysing in depth work manager
 
How eBay does Automatic Outage Planning
How eBay does Automatic Outage PlanningHow eBay does Automatic Outage Planning
How eBay does Automatic Outage Planning
 
Big data unit iv and v lecture notes qb model exam
Big data unit iv and v lecture notes   qb model examBig data unit iv and v lecture notes   qb model exam
Big data unit iv and v lecture notes qb model exam
 
Free oracle performance tools
Free oracle performance toolsFree oracle performance tools
Free oracle performance tools
 
Quartz Scheduler
Quartz SchedulerQuartz Scheduler
Quartz Scheduler
 
FreeRTOS Slides annotations.pdf
FreeRTOS Slides annotations.pdfFreeRTOS Slides annotations.pdf
FreeRTOS Slides annotations.pdf
 
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
 
Oracle’ın parallel execution yetenekleri ve performans
Oracle’ın parallel execution yetenekleri ve performansOracle’ın parallel execution yetenekleri ve performans
Oracle’ın parallel execution yetenekleri ve performans
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
 
Sprint 133
Sprint 133Sprint 133
Sprint 133
 
Completable future
Completable futureCompletable future
Completable future
 
SMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docxSMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docx
 

More from RajKumar Rampelli

Writing Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxWriting Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxRajKumar Rampelli
 
Introduction to Python - Running Notes
Introduction to Python - Running NotesIntroduction to Python - Running Notes
Introduction to Python - Running NotesRajKumar Rampelli
 
Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewRajKumar Rampelli
 

More from RajKumar Rampelli (7)

Writing Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxWriting Character driver (loadable module) in linux
Writing Character driver (loadable module) in linux
 
Introduction to Python - Running Notes
Introduction to Python - Running NotesIntroduction to Python - Running Notes
Introduction to Python - Running Notes
 
Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver Overview
 
Sql injection attack
Sql injection attackSql injection attack
Sql injection attack
 
Turing awards seminar
Turing awards seminarTuring awards seminar
Turing awards seminar
 
Higher education importance
Higher education importanceHigher education importance
Higher education importance
 
C compilation process
C compilation processC compilation process
C compilation process
 

Recently uploaded

Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Celine George
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryEugene Lysak
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxjmorse8
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxCeline George
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17Celine George
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxJenilouCasareno
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfDr. M. Kumaresan Hort.
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Mohamed Rizk Khodair
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/siemaillard
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointELaRue0
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17Celine George
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticspragatimahajan3
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resourcesaileywriter
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxheathfieldcps1
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxCapitolTechU
 

Recently uploaded (20)

Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdf
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 

Tasklet vs work queues (Deferrable functions in linux)

  • 1. Tasklet Vs Work queues By Rajkumar Rampelli
  • 2. Outline • • • • • • Deferrable functions Top Half Vs Bottom Half Tasklet Work queue Tasklet Vs Work queue Conclusion 12/6/2013 Raj Kumar Rampelli 2
  • 3. Deferrable function • Mechanism for supporting the delayed execution of any function in Interrupt handlers (Interrupt context) • Interrupt Context – Kernel enters Interrupt context when hardware interrupt received – Kernel enters Process/Kernel context from Interrupt context after servicing the hardware interrupt – Execution of tasks in Interrupt context should be minimized • Why - Majority of Interrupts are disabled, therefore latency to handle other interrupts will be increased • Solution: Move execution of not urgent function (piece of code) into process context (Deferrable function) • Add deferrable functions in Interrupt Handlers • Deferrable functions: can be executed in process context – Tasklet – Work queues 12/6/2013 Raj Kumar Rampelli 3
  • 4. Top Half Vs Bottom Half Top Half Bottom Half Processing of tasks in Interrupt Handler (Interrupt context) Processing of tasks in Kernel context Interrupts are disabled Interrupts are not disabled Add Deferrable functions for delayed execution Handles Deferrable functions Processing time should be less -NA- Uses Tasklets and work queue APIs for deferrable mechanism 12/6/2013 Raj Kumar Rampelli 4
  • 5. Tasklet: To schedule the work (function) to run later point of time so that reducing the amount of work done in interrupt handlers. Tasklet Initialization APIs Usage void tasklet_function (unsigned long data); Deferrable function i.e. actual Task DECLARE_TASKLET (tasklet_name, tasklet_function, tasklet_data); • Initializes the tasklet structure (tasklet_struct) with passing argument list • Tasklets are enabled by default • Next step: Schedule the task DECLARE_TASKLET_DISABLED (tasklet_name, tasklet_function, tasklet_data); • Initializes the tasklet structure • Tasklets are disabled • Next step: Enable Tasklet before schedule the task void tasklet_init(struct tasklet_struct *, void (*func) (unsigned long), unsigned long data); • Initializes the tasklet structure (tasklet_struct) with passing argument list 12/6/2013 Raj Kumar Rampelli 5
  • 6. Tasklet (contd.) Tasklet Enable/Disable APIs Usage void tasklet_enable (struct tasklet_struct *); /* Enable normal priority scheduling */ void tasklet_disable (struct tasklet_struct *); /* returns after disabling the tasklet */ void tasklet_hi_enable (struct tasklet_struct *); /* Enabling High priority scheduling */ void tasklet_disable_nosync (struct tasklet_struct *); 12/6/2013 /* May returns before termination i.e. no synchronization with disabling of tasklet */ Raj Kumar Rampelli 6
  • 7. Tasklet (contd.) Tasklet Schedule APIs Usage void tasklet_schedule (struct tasklet_struct *); /* Normal priority scheduling */ void tasklet_hi_schedule (struct tasklet_struct *); /* Higher priority scheduling */ CPU maintains the normal and high priority softirq vectors lists (normal priority vector list and high priority vector list) where these functions are queued. If the function is higher priority function then it is en-queued in higher priority softirq vector list and similar case for normal priority functions. Kill a Tasklet Usage void tasklet_kill (struct tasklet_struct *); /* Kill a tasklet */ void tasklet_hi_kill (struct tasklet_struct *); /* Kill the tasklet and ensure they would never run */ 12/6/2013 Raj Kumar Rampelli 7
  • 8. Work queue • Added in linux kernel 2.6 version • Use two data structures – struct workqueue_struct • Work is queued here in Interrupt context • The same work is executed in Kernel context – struct work_struct • Identifies the work and deferrable function • Kernel threads named "events/X" will extract work from the core work queue and activates the work's handler function. Tasklet Added in linux kernel 2.3 version In 2.6 kernel version Sleep in Handler function  Not possible 12/6/2013 Work queue Possible. Latency is less Raj Kumar Rampelli More compared to Tasklet 8
  • 9. Work queue APIs Create and destroy work queue structure Usage struct workqueue_struct *create_workqueue(name); /* Creates core workqueue */ void destroy_workqueue(struct workqueue_struct *); /* Destroy the workqueue */ Initialization of work structure Usage INIT_WORK(work, function); /* Initializes the work structure with function handler */ INIT_DELAYED_WORK(work, function); /* Add any delay before adding this work INIT_DELAYED_WORK_DEFERRABLE(work, into work queue structure */ function); 12/6/2013 Raj Kumar Rampelli 9
  • 10. Work queue APIs (contd.) • Add work on to work queue – int queue_work (struct workqueue_struct *wq, struct work_struct *work); – /* specify the CPU on which the handler should run */ int queue_work_on (int cpu, struct workqueue_struct *wq, struct work_struct *work); – /* Queue specified work on to specified work queue after delay */ int queue_delayed_work (struct workqueue_struct *wq, struct delayed_work *work, unsigned long delay); – int queue_delayed_work_on (int cpu, struct workqueue_struct *wq, struct delayed_work *work), unsigned long delay); • The below functions doesn't require workqueue structure defined. Since, they uses kernel-global work queue. So, no need to pass workqueue_struct in the argument list. – – – – 12/6/2013 int schedule_work (struct work_struct *): int schedule_work_on (int cpu, struct work_struct *): int scheduled_delayed_work (struct delayed_work *, unsigned long delay); int scheduled_delayed_work_on (int cpu, struct delayed_work *, unsigned long delay); Raj Kumar Rampelli 10
  • 11. Work queue APIs (contd.) • Cancel work /* terminate work in the queue, which is not already executing in the handler */ int cancel_work_sync (struct work_struct *); int cancel_delayed_work_sync (struct delayed_work *); • Flush work Below functions are used to flush the work and works in the specified workqueue. /* Flush a particular work and block until it is completed */ int flush_work (struct work_struct *); /* Flush all works in given workqueue and block until it is completed */ int flush_workqueue (struct workqueue_struct *); /* Flush kernel-global work queue */ void flush_scheduled_work (void); • Status of work We can use below two functions to know whether the given work is pending i.e. its handler function is not yet started. work_pending(work); delayed_work_pending (work); 12/6/2013 Raj Kumar Rampelli 11
  • 12. Conclusion • Reduce the execution time in Interrupt context by using deferrable function mechanism • Top Half: Processing of tasks in Interrupt Handler (Interrupt context) • Bottom Half: Processing of tasks in Kernel/Process context • Two type of deferrable functions – Tasklet – Work queue • Aim: To schedule the work/function (not urgent piece of code) in interrupt handler to run later point of time (in bottom half) so that reducing the amount of work done in interrupt handlers. • Tasklet and Work queue both do the above task using their own set of APIs • For more details visit: www.practicepeople.blogspot.com 12/6/2013 Raj Kumar Rampelli 12
  • 13. THANK YOU  12/6/2013 Raj Kumar Rampelli 13