Successfully reported this slideshow.
Your SlideShare is downloading. ×

Kernel Timing Management

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Kernel Process Management
Kernel Process Management
Loading in …3
×

Check these out next

1 of 11 Ad

More Related Content

Slideshows for you (20)

Similar to Kernel Timing Management (20)

Advertisement

Recently uploaded (20)

Kernel Timing Management

  1. 1. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Kernel Timing Management
  2. 2. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved What to Expect ● Timing Architecture ● Ticking in jiffies ● Delaying the process ● Kernel Timers
  3. 3. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved What is Time keeping? ● User spaces deals with the absolute time ● 2 ‘O clock for back up ● 12 ‘O clock for shutdown ● Kernel space deals with relative timing ● Data transfer should finish in 5 msecs ● Operations mostly in mses, worst case seconds
  4. 4. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved ● HZ – ticks per second – Varies from 50 to 1000 – Typically 1000 for desktops & 100 for embedded systems – Can be modified using the kernel configuration – 1 tick = 1ms (Desktop), 10ms (embedded systems) ● Jiffy – Internal kernel counter – Increments with each timer tick – jiffies & jiffies_64 Unit of time in kernel
  5. 5. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved API’s ● #include <linux/jiffies.h> ● get_jiffies_64() – For accessing the 64 bit jiffies – Direct access not recommended ● Comparison – int time_before(a, b) – int time_after(a, b) – int time_before_eq(a, b) – int time_after_eq(a, b)
  6. 6. @ 2021-21 Embitude Trainings <info@embitude.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()
  7. 7. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved ● Header: <linux/delay.h> ● Arch specific header: <asm/delay.h> ● APIs – void ndelay(unsigned long delays) – void udelay(unsigned long udelays) – void mdelay(unsigned long mdelays) Short delays but busy waiting
  8. 8. @ 2021-21 Embitude Trainings <info@embitude.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)
  9. 9. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Kernel Timers ● Allows to schedule a task sometime in future ● Executes a user defined function at user defined time ● Example usage – Monitoring the button in absence of interrupts – Finishing some lengthy shutdowns ● Executes asynchronously & in interrupt context. So, schedule out is not allowed
  10. 10. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Data Structures for Kernel Timers ● Back end of the various delays ● Header: <linux/timer.h> ● Type: struct timer_list ● APIs – DEFINE_TIMER(my_timer, fn) – Void add_timer(struct timer_list *) – timer_setup(struct timer_list *t, fn, flags); – void del_timer(struct timer_list *) – mod_timer(struct timer_list *, unsigned long); – int del_timer_sync(struct timer_list *)
  11. 11. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved What all did we learn? ● Timing Architecture ● Ticking in jiffies ● Delaying the process ● Kernel Timers

×