SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
elliando dias
 
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
Emanuele Bonanni
 

Mais procurados (20)

Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
 
Linux DMA Engine
Linux DMA EngineLinux DMA Engine
Linux DMA Engine
 
Linux : The Common Mailbox Framework
Linux : The Common Mailbox FrameworkLinux : The Common Mailbox Framework
Linux : The Common Mailbox Framework
 
Memory management
Memory managementMemory management
Memory management
 
Applets in java
Applets in javaApplets in java
Applets in java
 
XPDDS18: Design and Implementation of Automotive: Virtualization Based on Xen...
XPDDS18: Design and Implementation of Automotive: Virtualization Based on Xen...XPDDS18: Design and Implementation of Automotive: Virtualization Based on Xen...
XPDDS18: Design and Implementation of Automotive: Virtualization Based on Xen...
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
 
U boot-boot-flow
U boot-boot-flowU boot-boot-flow
U boot-boot-flow
 
Linux boot process
Linux boot processLinux boot process
Linux boot process
 
Kernel I/O subsystem
Kernel I/O subsystemKernel I/O subsystem
Kernel I/O subsystem
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 
Operating system || Chapter 3: Process
Operating system || Chapter 3: ProcessOperating system || Chapter 3: Process
Operating system || Chapter 3: Process
 
Linux Directory Structure
Linux Directory StructureLinux Directory Structure
Linux Directory Structure
 
Linux watchdog timer
Linux watchdog timerLinux watchdog timer
Linux watchdog timer
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Yocto - Embedded Linux Distribution Maker
Yocto - Embedded Linux Distribution MakerYocto - Embedded Linux Distribution Maker
Yocto - Embedded Linux Distribution Maker
 
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
 
Distributed operating system amoeba case study
Distributed operating system  amoeba case studyDistributed operating system  amoeba case study
Distributed operating system amoeba case study
 
Introduction to firewalls through Iptables
Introduction to firewalls through IptablesIntroduction to firewalls through Iptables
Introduction to firewalls through Iptables
 
Interrupts
InterruptsInterrupts
Interrupts
 

Destaque

Destaque (7)

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

Semelhante a Tasklet vs work queues (Deferrable functions in linux)

Performance schema and_ps_helper
Performance schema and_ps_helperPerformance schema and_ps_helper
Performance schema and_ps_helper
Mark Leith
 
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
Indhujeni
 
SMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docxSMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docx
pbilly1
 

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

Mais de RajKumar Rampelli

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

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.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