SlideShare a Scribd company logo
1 of 13
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

Bottom half in linux kernel
Bottom half in linux kernelBottom half in linux kernel
Bottom half in linux kernelKrishnaPrasad630
 
“Linux Kernel CPU Hotplug in the Multicore System”
“Linux Kernel CPU Hotplug in the Multicore System”“Linux Kernel CPU Hotplug in the Multicore System”
“Linux Kernel CPU Hotplug in the Multicore System”GlobalLogic Ukraine
 
Continguous Memory Allocator in the Linux Kernel
Continguous Memory Allocator in the Linux KernelContinguous Memory Allocator in the Linux Kernel
Continguous Memory Allocator in the Linux KernelKernel TLV
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesChris Simmonds
 
Linux Kernel Startup Code In Embedded Linux
Linux    Kernel    Startup  Code In  Embedded  LinuxLinux    Kernel    Startup  Code In  Embedded  Linux
Linux Kernel Startup Code In Embedded LinuxEmanuele Bonanni
 
Ext4 write barrier
Ext4 write barrierExt4 write barrier
Ext4 write barrierSomdutta Roy
 
Introduction to Kernel and Device Drivers
Introduction to Kernel and Device DriversIntroduction to Kernel and Device Drivers
Introduction to Kernel and Device DriversRajKumar Rampelli
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelDivye Kapoor
 
Linux Preempt-RT Internals
Linux Preempt-RT InternalsLinux Preempt-RT Internals
Linux Preempt-RT Internals哲豪 康哲豪
 
A Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry PiA Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry PiJian-Hong Pan
 
Linux process management
Linux process managementLinux process management
Linux process managementRaghu nath
 
Linux Ethernet device driver
Linux Ethernet device driverLinux Ethernet device driver
Linux Ethernet device driver艾鍗科技
 

What's hot (20)

Linux DMA Engine
Linux DMA EngineLinux DMA Engine
Linux DMA Engine
 
Bottom half in linux kernel
Bottom half in linux kernelBottom half in linux kernel
Bottom half in linux kernel
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
 
“Linux Kernel CPU Hotplug in the Multicore System”
“Linux Kernel CPU Hotplug in the Multicore System”“Linux Kernel CPU Hotplug in the Multicore System”
“Linux Kernel CPU Hotplug in the Multicore System”
 
Boot process: BIOS vs UEFI
Boot process: BIOS vs UEFIBoot process: BIOS vs UEFI
Boot process: BIOS vs UEFI
 
Continguous Memory Allocator in the Linux Kernel
Continguous Memory Allocator in the Linux KernelContinguous Memory Allocator in the Linux Kernel
Continguous Memory Allocator in the Linux Kernel
 
Qemu Introduction
Qemu IntroductionQemu Introduction
Qemu Introduction
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 
Linux Kernel Startup Code In Embedded Linux
Linux    Kernel    Startup  Code In  Embedded  LinuxLinux    Kernel    Startup  Code In  Embedded  Linux
Linux Kernel Startup Code In Embedded Linux
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
 
Ext4 write barrier
Ext4 write barrierExt4 write barrier
Ext4 write barrier
 
Introduction to Kernel and Device Drivers
Introduction to Kernel and Device DriversIntroduction to Kernel and Device Drivers
Introduction to Kernel and Device Drivers
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
 
Linux Preempt-RT Internals
Linux Preempt-RT InternalsLinux Preempt-RT Internals
Linux Preempt-RT Internals
 
A Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry PiA Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry Pi
 
Linux process management
Linux process managementLinux process management
Linux process management
 
I/O System
I/O SystemI/O System
I/O System
 
Linux Ethernet device driver
Linux Ethernet device driverLinux Ethernet device driver
Linux Ethernet device driver
 
Board Bringup
Board BringupBoard Bringup
Board Bringup
 
Linux device drivers
Linux device driversLinux device drivers
Linux device drivers
 

Viewers also liked

Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginnersRajKumar 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 (7)

Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginners
 
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
 

More from RajKumar Rampelli (6)

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
 
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

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.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