O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

f9-microkernel-ktimer

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Próximos SlideShares
Trace kernel code tips
Trace kernel code tips
Carregando em…3
×

Confira estes a seguir

1 de 45 Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (20)

Semelhante a f9-microkernel-ktimer (20)

Anúncio

Mais recentes (20)

Anúncio

f9-microkernel-ktimer

  1. 1. Your Logo Here Viller Hsiao <villerhsiao@gmail.com> F9 Microkernel ktimer
  2. 2. Rights to Copy LOGO copyright © 2014 Viller Hsiao Attribution – ShareAlike 3.0 You are free ● to copy, distribute, display, and perform the work ● to make derivative works ● Corrections, suggestions, contributions and translations are welcome! to make commercial use of the work Under the following conditions Attribution. You must give the original author credit. – Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. – ● Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above. License text: http://creativecommons.org/licenses/by-sa/3.0/legalcode Place, 04/02/14 villerhsiao
  3. 3. F9 Microkernel [1] ● New open source implementation built from scratch, which deploys modern kernel techniques, derived from L4 microkernel designs, to deep embedded devices. ● ● BSD License Characteristics of F9 microkernel ● Efficiency: performance + power consumption – Tickless ● Security: memory protection + isolated execution ● ● LOGO Flexible development environment Repository ● https://github.com/f9micro Place, 04/02/14 villerhsiao
  4. 4. Agenda ● ● LOGO Concept about operating system kernel time subsystem F9 Microkernel ktimer introduction Place, 04/02/14 villerhsiao
  5. 5. LOGO Concept about Operating System Kernel Time Subsystem Place, 04/02/14 villerhsiao
  6. 6. OS Kernel Time Subsystem ● Current Time ● System time, UTC/GMP time, … etc ● Alarm, the time event ● Process timeslice ● Timeout ● Time delay Place, 04/02/14 villerhsiao LOGO
  7. 7. System Time and Tick ● LOGO From Wikipedia [2], “System time represents a computer system's notion of the passing of time.“ “System time is measured by a system clock, which is typically implemented as a simple count of the number of ticks that have transpired since some arbitrary starting date, called the epoch.” Place, 04/02/14 villerhsiao
  8. 8. How Is Tick Implemented? ● LOGO Hardware timer device ● Assert interrupt after a programmable inteval – Handling tick stuff in Timeout Interrupt Service Routine (ISR) HW Timer CPU Adjust system time Handle timeout event …. Timeout interrupt Control Read Counts Setup timeout value Place, 04/02/14 villerhsiao
  9. 9. How Is Tick Implemented? (Cont.) ● Type 1: Incremental timer ● Example: Cortex-A9 MP Global Timer Place, 04/02/14 villerhsiao LOGO
  10. 10. How Is Tick Implemented? (Cont.) ● LOGO Incremental timer functionality 1 Current Value + 0x12abc = Incremental value 0x36000 Compare Value + 0x36000 Y Place, 04/02/14 Y Auto Increament? villerhsiao Interrupt
  11. 11. How Is Tick Implemented? (Cont.) ● Type 2: Counting down timer ● Example: Cortex-M4 SysTick Place, 04/02/14 villerhsiao LOGO
  12. 12. How Is Tick Implemented? (Cont.) ● LOGO Counting down timer functionality 0 = 1 - Reload value = 0x36000 Current Value 0x12abc Y Place, 04/02/14 Y Auto Load? villerhsiao Interrupt
  13. 13. How Is Tick Implemented? (Cont.) ● Prescaler ● Tweak HW tick period Timer Module clk Place, 04/02/14 Prescaler val clk/val villerhsiao Counting Part LOGO
  14. 14. How Is Tick Implemented? (cont.) ● Timeout ISR ● Increase system ticks ● Execute handler of timeout event ● Re-schedule if required Place, 04/02/14 villerhsiao LOGO
  15. 15. Simple Graph of CPU Operating States LOGO INT Processes Threads Tasks ISR Softirq CTX INT CTX CTX Idle thread CTX INT INT T sleep T Deep sleep Place, 04/02/14 villerhsiao INT : interrupt CTX: context switch T : after a while
  16. 16. Time Diagram of Legacy Ticks event1 event2 event3 LOGO event4 HW Timer interrupt CPU activities Place, 04/02/14 villerhsiao
  17. 17. Where Is the Problem? ● LOGO Context switch overhead INT Processes Threads Tasks ISR Softirq CTX INT CTX CTX Idle thread T sleep T Deep sleep Place, 04/02/14 villerhsiao CTX INT INT
  18. 18. Where Is the Problem? ● LOGO Unecessary power consumed INT Processes Threads Tasks ISR Softirq CTX INT CTX CTX Idle thread T sleep T Deep sleep Place, 04/02/14 villerhsiao CTX INT INT
  19. 19. Where Is the Problem? ● Tick resolution ● Performance, power v.s. timer precision Place, 04/02/14 villerhsiao LOGO
  20. 20. Time Diagram of Legacy Ticks event1 event2 event3 LOGO event4 HW Timer interrupt CPU activities CPU waken up for timekeeping only Place, 04/02/14 villerhsiao
  21. 21. Solution: Tickless event1 event2 event3 LOGO event4 Timer interrupt New CPU activities Previous CPU activities Place, 04/02/14 villerhsiao
  22. 22. Drawback of Tickless ● LOGO Tickless is not free [3], “It increases the number of instructions executed on the path to and from the idle loop.” “On many architectures, dyntick-idle mode also increases the number of expensive clockreprogramming operations” ● Systems with aggressive real-time response constraints often run periodic tick Place, 04/02/14 villerhsiao
  23. 23. Example: Linux Time Subsystem ● Device level ● clocksource – ● ● jiffies clockevent High resolution kernel timer ● hrtimers Place, 04/02/14 villerhsiao LOGO
  24. 24. Example: Linux Time Subsystem (Cont.) ● LOGO Tickless ● (Nearly) Full tickless operation after 3.10 ● dyntick-idle – ● adaptive-tick – ● CONFIG_NO_HZ_IDLE CONFIG_NO_HZ_FULL periodic – CONFIG_HZ_PERIODIC – Consumes battery power 2-3 times as fast as dyntick-idle one. [3] Place, 04/02/14 villerhsiao
  25. 25. LOGO F9 Microkernel ktimer Introduction Place, 04/02/14 villerhsiao
  26. 26. Example Hardware Device ● STM32F4Discovery board ● Cortex-M4 EVB – Use Cortex-M4 SysTick as the tick HW ● ● ● Place, 04/02/14 24-bit system timer Counting down Please refer to [4] for more detail villerhsiao LOGO
  27. 27. ktimer Features ● System time ● Time event ● Tickless Place, 04/02/14 villerhsiao LOGO
  28. 28. ktimer Configurations ● CONFIG_KTIMER_HEARTBEAT ● ● CONFIG_KTIMER_MINTICKS ● ● HW cycles per ktimer tick Minimum ktimer ticks unit for time event CONFIG_KTIMER_TICKLESS ● Enable tickless Place, 04/02/14 villerhsiao LOGO
  29. 29. ktimer Event Utility ● LOGO ktimer_event_create() ● Arguments – – Timeout handler – ● Timeout ticks Pointer to arguments for timeout handler Return Non-zero to reschedule event again – Freed automatically if not be re-scheduled Place, 04/02/14 villerhsiao
  30. 30. ktimer Anotomy ● System time ● ● ktime_now ktimer event list ● event_queue ● Managed by ktable Place, 04/02/14 villerhsiao LOGO
  31. 31. ktimer Anotomy (Cont.) ● LOGO ktable ● Basic kernel library in F9 Microkernel ● Fast objects pool management – To allocate/free objects of pre-defined size and numbers easiler ktable ktable_free() ktable_init() Used Unused Place, 04/02/14 ktable_alloc() villerhsiao
  32. 32. ktimer Anotomy (Cont.) ● Life cycle of time event ● One-shot ● ● LOGO Continuous How to control life cycle in ktimer? ● The return value of handler is treated as next timeout delta Place, 04/02/14 villerhsiao
  33. 33. ktimer Anotomy (Cont.) ● HW Timer ISR ● __ktimer_handler() – Increase tick – Arrange Softirq for handling timer events Place, 04/02/14 villerhsiao LOGO
  34. 34. ktimer Anotomy (Cont.) ● LOGO Two-stage interrupt handling ● ISR – ● IRQ context Softirq – Thread context ● ● – Real time preemptive characteristic. Can be scheduled like any other threads in the system [5]. Handled in kernel thread Place, 04/02/14 villerhsiao
  35. 35. ktimer Anotomy (Cont.) ● HW Timer ISR ● __ktimer_handler() – Increase tick – Arrange Softirq for handling timer events Place, 04/02/14 villerhsiao LOGO
  36. 36. ktimer Anotomy (Cont.) ● HW timer softirq handler ● ktimer_event_handler() – Find timeout event and executing its handler – Re-insert event if required Place, 04/02/14 villerhsiao LOGO
  37. 37. ktimer Anotomy (Cont.) ● LOGO Tickless ● ● Enter tickless right before going to CPU idle state Set interval of next timer interrupt as delta of next event – ● Or KTIMER_MAXTICKS Adjust system time after waked up Place, 04/02/14 villerhsiao
  38. 38. ktimer Anotomy (Cont.) ● LOGO Tickless Compensation ● SysTick frequency distortion when enter/exit standby mode tickless active idle handle other interrupt Timer interrupt idle active CPU Activity systick Place, 04/02/14 villerhsiao
  39. 39. ktimer Anotomy (Cont.) ● LOGO Tickless Compensation tickless active idle handle other interrupt Timer interrupt idle active CPU Activity systick Place, 04/02/14 villerhsiao
  40. 40. ktimer Anotomy (Cont.) ● LOGO Tickless Compensation ● Pre-defined value – CONFIG_KTIMER_TICKLESS_COMPENSATION ● – CONFIG_KTIMER_TICKLESS_INT_COMPENSATION ● ● Compensation value before entering idle Compensation value when CPU is waked up by non-timer interrupt. But how much to set these value to? Place, 04/02/14 villerhsiao
  41. 41. ktimer Anotomy (Cont.) ● LOGO Tickless Compensation ● But how much to set these value to? – Get average compensation from general pupose timer ● (total diff / count of entering tickless) SYSTICK HW timer TIM2 Place, 04/02/14 villerhsiao
  42. 42. ktimer Anotomy (Cont.) ● LOGO Tickless Compensation ● How to calibrate the compensation value? – CONFIG_KTIMER_TICKLESS_VERIFY – CONFIG_KDB Set compensation To 0 Place, 04/02/14 Get average Compensation from KDB villerhsiao Re-define Compensation value
  43. 43. ktimer Anotomy (Cont.) ● LOGO KDB ● Kernel debugger ## KDB ## commands: K: print kernel tables e: dump ktimer events n: show timer (now) s: show softirqs t: dump threads m: dump memory pools a: dump address spaces p: show sampling v: show tickless scheduling stat ---------------- Place, 04/02/14 ## KDB ## -------NOW-----Now is 70993 Ktimer T=1297 D=0 -------------------- villerhsiao
  44. 44. Reference: LOGO [1] Jim Huang (Dec 9, 2013), “F9: A Secure and Efficient Microkernel Built for Deep Embedded Systems” [2] Wikipedia, “System time” [3] P. E. McKenney (May 14, 2013), “NO_HZ: Reducing Scheduling-Clock Ticks” [4] ST Mcroelectronics, STM32F3xxx and STM32F4xxx Cortex-M4 programming manual [5] J. Altenberg, “Using the Realtime Preemption Patch on ARM CPUs” Place, 04/02/14 villerhsiao
  45. 45. LOGO THE END Place, 04/02/14 villerhsiao

×