Home
Explore
Submit Search
Upload
Login
Signup
Advertisement
Kernel Timing Management
Report
SysPlay eLearning Academy for You
Follow
SysPlay eLearning Academy for You
Mar. 20, 2021
•
0 likes
0 likes
×
Be the first to like this
Show More
•
2,953 views
views
×
Total views
0
On Slideshare
0
From embeds
0
Number of embeds
0
Check these out next
Embedded C
Anil Kumar Pugalia
Kernel Programming
Anil Kumar Pugalia
Kernel Debugging & Profiling
Anil Kumar Pugalia
POSIX Threads
SysPlay eLearning Academy for You
Platform Drivers
SysPlay eLearning Academy for You
Shell Scripting
Anil Kumar Pugalia
Network Drivers
Anil Kumar Pugalia
Video Drivers
Anil Kumar Pugalia
1
of
29
Top clipped slide
Kernel Timing Management
Mar. 20, 2021
•
0 likes
0 likes
×
Be the first to like this
Show More
•
2,953 views
views
×
Total views
0
On Slideshare
0
From embeds
0
Number of embeds
0
Report
Technology
Linux Kernel Timing Architecture
SysPlay eLearning Academy for You
Follow
SysPlay eLearning Academy for You
Advertisement
Advertisement
Advertisement
Recommended
Linux DMA Engine
SysPlay eLearning Academy for You
5.8K views
•
23 slides
Introduction to Linux Drivers
Anil Kumar Pugalia
64.1K views
•
29 slides
Serial Drivers
SysPlay eLearning Academy for You
16.7K views
•
13 slides
Block Drivers
Anil Kumar Pugalia
37.9K views
•
21 slides
SPI Drivers
SysPlay eLearning Academy for You
9.8K views
•
20 slides
Interrupts
Anil Kumar Pugalia
47.1K views
•
18 slides
More Related Content
Slideshows for you
(20)
Embedded C
Anil Kumar Pugalia
•
25.6K views
Kernel Programming
Anil Kumar Pugalia
•
24.2K views
Kernel Debugging & Profiling
Anil Kumar Pugalia
•
5.8K views
POSIX Threads
SysPlay eLearning Academy for You
•
4.1K views
Platform Drivers
SysPlay eLearning Academy for You
•
17.2K views
Shell Scripting
Anil Kumar Pugalia
•
6.1K views
Network Drivers
Anil Kumar Pugalia
•
38.6K views
Video Drivers
Anil Kumar Pugalia
•
23K views
Architecture Porting
Anil Kumar Pugalia
•
4.9K views
BeagleBoard-xM Booting Process
SysPlay eLearning Academy for You
•
3.7K views
Kernel Debugging & Profiling
Anil Kumar Pugalia
•
18.8K views
Bootloaders
Anil Kumar Pugalia
•
9.7K views
Low-level Accesses
Anil Kumar Pugalia
•
24.9K views
Introduction to Linux
Anil Kumar Pugalia
•
3.8K views
Processes
Anil Kumar Pugalia
•
6.8K views
Processes
Anil Kumar Pugalia
•
7.5K views
Audio Drivers
Anil Kumar Pugalia
•
20.4K views
PCI Drivers
Anil Kumar Pugalia
•
43.9K views
BeagleBone Black Bootloaders
SysPlay eLearning Academy for You
•
3.9K views
I2C Drivers
SysPlay eLearning Academy for You
•
28.4K views
Similar to Kernel Timing Management
(20)
Embedded Software Design
Anil Kumar Pugalia
•
6.9K views
101 1.3 runlevels , shutdown, and reboot
Acácio Oliveira
•
246 views
101 1.3 runlevels, shutdown, and reboot v2
Acácio Oliveira
•
303 views
리눅스 드라이버 #2
Sangho Park
•
1.1K views
Process scheduling
Hao-Ran Liu
•
344 views
1.3 runlevels, shutdown, and reboot v3
Acácio Oliveira
•
441 views
OUGLS 2016: How profiling works in MySQL
Georgi Kodinov
•
496 views
Character Drivers
Anil Kumar Pugalia
•
56.3K views
Timers in Unix/Linux
geeksrik
•
3.8K views
Vx works RTOS
Sai Malleswar
•
22.5K views
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Anne Nicolas
•
43.2K views
VTU 5TH SEM CSE OPERATING SYSTEMS SOLVED PAPERS
vtunotesbysree
•
19.6K views
Adaptive Replication for Elastic Data Stream Processing
Zbigniew Jerzak
•
1K views
13-scheduling.ppt
PankajRawat390153
•
21 views
Tips Tricks and Little known features in SAP ASE
SAP Technology
•
7K views
Module 3-cpu-scheduling
Hesham Elmasry
•
123 views
Real-Time Query for Data Guard
Uwe Hesse
•
3.5K views
Lecture18-19 (1).ppt
ssuserf67e3a
•
3 views
Embedded systems unit4
baskaransece
•
107 views
ch6.ppt
Umesh Hengaju
•
3 views
Advertisement
More from SysPlay eLearning Academy for You
(11)
Linux Internals Part - 3
SysPlay eLearning Academy for You
•
116 views
Linux Internals Part - 2
SysPlay eLearning Academy for You
•
57 views
Linux Internals Part - 1
SysPlay eLearning Academy for You
•
84 views
Understanding the BBB
SysPlay eLearning Academy for You
•
9.5K views
Cache Management
SysPlay eLearning Academy for You
•
1.7K views
Introduction to BeagleBone Black
SysPlay eLearning Academy for You
•
8.1K views
Introduction to BeagleBoard-xM
SysPlay eLearning Academy for You
•
3.2K views
BeagleBone Black Bootloaders
SysPlay eLearning Academy for You
•
4.4K views
BeagleBone Black Booting Process
SysPlay eLearning Academy for You
•
18K views
BeagleBoard-xM Bootloaders
SysPlay eLearning Academy for You
•
7.2K views
Linux System
SysPlay eLearning Academy for You
•
851 views
Recently uploaded
(20)
Computer Security Chapter III.pdf
Harrisentertainment
•
4 views
Chapter 3 - ET.pdf
Habtamu Yetwale
•
3 views
chatgpt-privacy and security.pptx
Deepak Kumar
•
7 views
AI PROJECT .... (1).pptx
VishnuDubey14
•
0 views
INT 1010 05-3.pdf
Luis R Castellanos
•
5 views
Voice-over-LTE-Optimization.docx.pdf
AhmadEmara1
•
4 views
无法毕业?澳大利亚新英格兰大学毕业证书和学位证书办理
ynexeyb
•
0 views
INT 1010 01.pdf
Luis R Castellanos
•
6 views
DLL_MAPEH 6_Q1_W1.docx
JovhelTibay
•
0 views
INT 1010 10-3.pdf
Luis R Castellanos
•
0 views
Exploring How Blockchain Technology Enables Smart Contract Security
SecureDAppTechnologi
•
13 views
ZINC PLATING.pptx
PrakashBehera40
•
2 views
SELinux workshop
johseg
•
20 views
INT 1010 03.pdf
Luis R Castellanos
•
4 views
Test Presentation.pptx
Abiral Neupane
•
7 views
Unit - 11 File Management.pptx
SatephwarGaming
•
0 views
INT 1010 02.pdf
Luis R Castellanos
•
4 views
Japan VPS Server
JapanCloudServers
•
5 views
Week1Lec03-Dimensional Analysis.pptx.pdf
AlakhKumar6
•
4 views
1-DC16_Ch01_Ch 1 Introducing Today_s Technologies Computers, Devices, and the...
rajaqr
•
2 views
Advertisement
Kernel Timing Management
© 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Kernel Timing Management
2 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? Timing Architecture Ticking in jiffies Delaying the process Kernel Timers Tasklets Work Queues
3 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Timing Architecture
4 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. W's of Time Keeping User space deals with the absolute time 4 'O clock for back up 12 'O clock shutdown Kernel space deals with relative timing Data transfer should finish in 5 msecs Operations mostly in msecs, worst case seconds
5 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Unit of Time in Kernel HZ – ticks per second Varies from 50 to 1000 Typically 1000 for desktops & 100 for embedded Systems Defined in <linux/params.h> 1 tick = 1ms (desktop), 10ms (embedded systems) Jiffy Internal kernel counter Increments with each timer tick jiffies & jiffies_64
6 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. API's #include <linux/jiffies.h> get_jiffies_64() For accessing the 64 bit jiffies Direct access not recommended Comparison of time values int time_before(a, b) int time_after(a, b) int time_before_eq(a, b) int time_after_eq(a,b)
7 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Dealing with User space #include <linux/time.h> unsigned long timespec_to_jiffies(struct timespec *) void jiffies_to_timespec(jiffies, struct timespec *) unsigned long timeval_to_jiffies(struct timeval *) void jiffies_to_timespec(jiffies, struct timeval *)
8 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Resolution lesser than jiffies Platform specific “Time Stamp Counter” On x86 Header: <asm/msr.h> API: rdtsc(ul low_tsc_ticks, ul high_tsc_ticks); Getting it generically Header: <linux/timex.h> API: read_current_timer(unsigned long *timer_val);
9 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Absolute Time Header: <linux/time.h> APIs mktime(y, m, d, h, m, s) – Seconds since Epoch void do_gettimeofday(struct timeval *tv); struct timespec current_kernel_time(void);
10 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Delays
11 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Long Delays Busy wait: cpu_relax while (time_before(jiffies, j1)) cpu_relax(); Yielding: schedule/schedule_timeout while (time_before(jiffies, j1)) schedule();
12 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Hands On Timing/busy_wait.c Modify example above to use schedule().
13 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Waiting for an event or timeout #include <linux/wait.h> wait_queue_head_t wq_head; init_waitqueue_head(&wq_head); wait_interruptible_timeout(wq, condition, timeout) 0 if process if timeout expires Remaining delay, if event occured schedule_timeout(delay_in_jiffies) No condition to wait for Returns 0, if timeout has expired
14 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Hands On Modify Timing/busy_wait to use wait queues & sched_timeout
15 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Short Delays but Busy Waiting Header: <linux/delay.h> Arch. specific Header: <asm/delay.h> APIs void ndelay(unsigned long ndelays); void udelay(unsigned long udelays); void mdelay(unsigned long mdelays);
16 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Long Delays: Back to Yielding Header: <linux/delay.h> APIs void msleep(unsigned int millisecs); unsigned long msleep_interruptible(unsigned int millisecs); void ssleep(unsigned int secs);
17 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Timers
18 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. W's of Kernel Timers Allows to schedule a task, sometime in future Executes a user defined function at user defined time Example usage Elimination of bouncing in a key press Finishing some lengthy shutdowns Execute asynchronously & in interrupt context. So, scheduling out is not allowed
19 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Kernel Timer Data structures Back end of the various delays Header: <linux/timer.h> Type: struct timer_list APIs void init_timer(struct timer_list *); /* Nullifies */ struct timer_list TIMER_INITIALIZER(f, t, p); void add_timer(struct timer_list *); void del_timer(struct timer_list *); int mod_timer(struct timer_list *, unsigned long); int del_timer_sync(struct timer_list *);
20 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Hands On Timing/timers.c Create a thread which will wake up & blink the led every 1 sec Modify select.c to wake up the user space application periodically
21 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Tasklets Tasklets mean baby tasks Tasks to be executed later with no specific time requirement Normally, scheduled by interrupt handler to finish the rest of the task such as data processing Executes in interrupt context
22 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Data Structures Header: <linux/interrupt.h> Type: struct tasklet_struct APIs void tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long), unsigned long data); DECLARE_TASKLET(name, func, data); DECLARE_TASKLET_DISABLED(name, func, data); tasklet_enable(t); tasklet_disable(t); tasklet_disable_nosync(t); tasklet_[hi_]schedule(t); tasklet_kill(t);
23 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Tasklet Features Runs on the same CPU that schedules it Kernel maintains a disable count for tasklet & re-enables the tasklet only when enable is called as many times as disables Can be executed at higher priority Execute latest by next timer tick Tasklets is serialized with respect to itself Runs in atomic context, so blocking is not allowed
24 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Hands On BottomHalves/tasklet.c Schedule the tasklet normal & high from the timer handler Reschedule the tasklet from itself
25 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Work Queues Similar to tasklets, allow the task to be carried out later Work queues run in a context of special kernel process Its legitimate to sleep in work queues Run on the processor from which they were scheduled, by default
26 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Data Structures Header: <linux/workqueue.h> Types: struct workqueue_struct, struct work_struct Work Queue APIs q = create_workqueue(name); q = create_singlethread_workqueue(name); flush_workqueue(q); destroy_workqueue(q); Work APIs DECLARE_WORK(w, void (*function)(struct work_struct *)); INIT_WORK(w, void (*function)(struct work_struct *)); Combined APIs int queue_work(q, &w); int queue_delayed_work(q, &w, d); int cancel_delayed_work(&w);
27 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Hands On BottomHalves/work_queue.c Modify the above example to create a delayed work Try with cancel_delayed_work & flush_workqueue Use the shared work queue
28 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. What have we learnt? Timing Architecture Ticking in jiffies Delaying the process Kernel Timers Tasklets Work Queues
29 © 2014-15 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?
Advertisement