hrtimers and beyond transformation of the linux time r
play

hrtimers and beyond - transformation of the Linux time(r) system - PowerPoint PPT Presentation

hrtimers and beyond - transformation of the Linux time(r) system Thomas Gleixner Douglas Niehaus OLS 2006 Original time(r) system Arch 1 Timekeeping TOD Clock source HW Tick ISR Clock event source HW Arch 2 Process acc. TOD Clock


  1. hrtimers and beyond - transformation of the Linux time(r) system Thomas Gleixner Douglas Niehaus OLS 2006

  2. Original time(r) system Arch 1 Timekeeping TOD Clock source HW Tick ISR Clock event source HW Arch 2 Process acc. TOD Clock source HW Profiling ISR Clock event source HW Jiffies Arch 3 Timer wheel TOD Clock source HW ISR Clock event source HW

  3. History ● double linked list sorted by expiry time ● UTIME (1996) ● timer wheel (1997) ● HRT (2001) ● hrtimers (2006)

  4. Timer Wheel ● periodic tick necessary ● O(1) insertion / deletion ● recascading in bursts (can cause high latencies) ● higher tick frequencies don't scale due to long lasting timer callbacks and increased recascading

  5. Cascading

  6. Cascading 100 250 1000 HZ [1] 256 10 4 1 ms [2] 64 2560 1024 256 ms [3] 64 164 66 16 s [4] 64 175 70 17 m [5] 64 186 75 19 h

  7. Cascading CONFIG_BASE_SMALL=y 100 250 1000 HZ [1] 64 10 4 1 ms [2] 16 640 256 64 ms [3] 16 10240 4096 1024 ms [4] 16 164 66 16 s [5] 16 44 17 4 m

  8. Cascading ● array sizes have to be chosen carefully taking tick frequency into account ● rare (multiple) cascades increase latency – use cases have to be analysed to avoid problematic cascading ● separating timers with high accuracy requirement from coarse grained timeouts will relax the situation

  9. timers vs. timeouts timers timeouts ● precise event ● report error scheduling conditions ● accurate ● coarser grained ● likely to expire ● likely to be removed before expiration

  10. History of high resolution timers ● UTIME – KURT-Linux – University of Kansas ● HRT – fork of UTIME – Monta Vista ● Hrtimers – Linutronix

  11. Why hrtimers ? ● UTIME and HRT added a subjiffy field – Kept jiffy ticks by design to avoid broader kernel change impact – Modes: on top of the timer wheel or separate high-resolution event list ● HRT moved high resolution timers into a separate list one tick before expiry – Suffered from timer wheel latencies

  12. hrtimers ● timers inserted into a red-black tree sorted by expiration time ● separate queue for each base clock, which allowed simplifying POSIX timers ● base code is still tick driven (softirq is called in the timer softirq context) ● time values are kept in new data type ktime_t (using nanosecond base)

  13. ktime_t ● optimizable data type for both 32 and 64 bit machines ● plain nanosecond value on 64 bit CPU ● (seconds, nanoseconds) pair on 32 bit CPUs with field order allowing (depending on the endianess) 64 bit add, subtract, compare operations.

  14. hrtimer users ● nanosleep ● itimer ● POSIX timers ● timed futex operations

  15. hrtimers Arch 1 Timekeeping TOD Clock source HW hrtimers Tick ISR Clock event source HW Arch 2 Process acc. TOD Clock source HW Profiling ISR Clock event source HW Jiffies Arch 3 Timer wheel TOD Clock source HW ISR Clock event source HW

  16. how to get high resolution timers ? ● solve the tick (jiffy) dependency of timekeeping ● create a generic framework for next event interrupt programming ● replace the periodic tick interrupt by timers under hrtimers

  17. Timekeeping ● Make use of John Stultz's Generic Time of Day framework – architecture independent – generic framework replaces duplicated architecture code – better decoupling from tick

  18. hrtimers + GTOD Shared HW Clock source Clock synchr. TOD Arch 1 Timekeeping HW hrtimers Tick ISR Clock event source HW Process acc. Arch 2 HW Profiling ISR Clock event source HW Jiffies Arch 3 Timer wheel HW ISR Clock event source HW

  19. clockevents ● Generic infrastructure to distribute timer related events – architecture independent – generic framework replaces duplicated architecture code – allows quality based selection of clock event hardware

  20. hrtimers + GTOD + clockevents Shared HW Clock source Clock synchr. TOD Timekeeping Arch 1 HW hrtimers Shared HW Clock events HW ISR Arch 2 HW Tick Event distribution HW Process acc. Profiling Arch 3 HW Jiffies ISR HW Timer wheel

  21. tick emulation ● Use a per-CPU hrtimer to emulate tick – update jiffies and NTP adjustments – per-CPU calls ● process accounting and profiling ● Allows high resolution timers and/or dynamic ticks

  22. hrtimers + GTOD + clockevents + tick emulation Shared HW Clock source Clock synchr. TOD Arch 1 Timekeeping HW hrtimers Shared HW Clock events HW Next event ISR Dynamic tick Arch 2 HW Event distribution HW Process acc. hrtimers Profiling Arch 3 HW Jiffies ISR HW Timer wheel

  23. high resolution performance clock_nanosleep(ABS_TIME) interval: 10ms 10000 loops no load Kernel min max avg 2.6.16 24 4042 1989 µs 2.6.16-hrt 12 94 20 µs 2.6.16-rt 6 40 10 µs

  24. high resolution performance clock_nanosleep(ABS_TIME) interval 10ms 10000 loops 100% load Kernel min max avg 2.6.16 55 4280 2198 µs 2.6.16-hrt 11 458 55 µs 2.6.16-rt 16 55 20 µs

  25. dynamic tick idle behaviour ● timer interrupts reduced to ~1 per second. – instrumentation to identify the timer (ab)users to improve the idle sleep length

  26. timer wheel batching ● run the timer wheel at a lower frequency than the scheduler tick by skipping timer wheel processing for a user space configurable number of ticks ● improves interactivity

  27. things to be done ● get it merged (target is 2.6.19) ● support more architectures (prototypes for ARM and PPC available) ● tighter integration into power management

  28. Conclusions ● significant changes are necessary but the benefit is significant increases in: – architecture independent code – ease of using wide range of time keeping and timer event hardware – increased resolution for scheduled events when desired

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend