f9 microkernel code reading part 2 scheduling

28
Part 2 : Code Reading of F9 Microkernel ben6 20131118 Scheduling

Upload: benux-wei

Post on 10-Jun-2015

1.968 views

Category:

Technology


16 download

DESCRIPTION

Discuss scheduling which one of core function within F9 Microkernel

TRANSCRIPT

Page 1: F9 Microkernel code reading part 2 scheduling

Part  2  :  Code  Reading  of  

F9  Microkernel  

ben6  2013-­‐11-­‐18  

Scheduling  

Page 2: F9 Microkernel code reading part 2 scheduling

Agenda  

•  Brief  of  F9  Microkernel  Scheduling  

•  All  about  Algorithms  

•  Scheduling  Code  reading  

F9  

Page 3: F9 Microkernel code reading part 2 scheduling

Agenda  

•  Brief  of  F9  Microkernel  Scheduling  

•  All  about  Algorithms  

•  Scheduling  Code  reading  

F9  

Page 4: F9 Microkernel code reading part 2 scheduling

F9  Microkernel  Overview  

•  an  experimental  microkernel  used  to  construct  flexible  embedded  systems  inspired  by  famous  L4  microkernel.    

•  The  moMvaMon  of  F9  microkernel  is  to  deploy  modern  kernel  techniques  to  support    –  running  real-­‐Mme  and  Mme-­‐sharing  applicaMons  (ex:    wireless  communicaMons)  for  ARM  Cortex-­‐M  series  microprocessors  with  efficiency  (performance  +  power  consumpMon)    

–  security  (memory  protecMon  +  isolated  execuMon)  

Page 5: F9 Microkernel code reading part 2 scheduling

CharacterisMcs  

•  Energy  efficient  scheduling  •  Tickless  Mmer  

Page 6: F9 Microkernel code reading part 2 scheduling

Mckless  scheduler   •  F9  implements  a  Mckless  scheduler  which  implies  the  dynamic  Mmer.  

•  You  can  track  the  development  here:    hWps://github.com/southernbear/RIOT/wiki/Development  

•  F9  follows  some  concepts  about  TiROS  for  Mckless:  

       hWp://Mros.sourceforge.net/

Page 7: F9 Microkernel code reading part 2 scheduling

Agenda  

•  Brief  of  F9  Microkernel  Scheduling  

•  All  about  Algorithms  

•  Scheduling  Code  reading  

F9  

Page 8: F9 Microkernel code reading part 2 scheduling

Tickless  Scheduling

•  Reference  concept  of  TiROS  •  TiROS  avoids  most  context-­‐switching  overhead  costs  by  eliminaMng  periodic  Mcks.  

•  Most  embedded  real-­‐Mme  OSes,  a  trade  off  between  high  Mme-­‐resoluMon  (by  increasing  Mck  frequency)  and  overhead.  

•  TiROS  does  not  use  Mcks  and  achieves  high-­‐Mme  resoluMon  with  very  low  overhead.

Page 9: F9 Microkernel code reading part 2 scheduling

Agenda  

•  Brief  of  F9  Microkernel  Scheduling  

•  All  about  Algorithms  

•  Scheduling  Code  reading  

F9  

Page 10: F9 Microkernel code reading part 2 scheduling

Scheduling  related  code  

•  ipc.c  •  kMmer.c  •  sched.c          (most  important)  •  so]irq.c  •  syscall.c  •  systhread.c  •  thread.c  

Page 11: F9 Microkernel code reading part 2 scheduling

KMmer_handler  

Timer  handler  in  ISR  vector  table  

Page 12: F9 Microkernel code reading part 2 scheduling

kMmer_handler  Hardware  interrupt  

trigger  ktmer_handler  

Page 13: F9 Microkernel code reading part 2 scheduling

Plaborm/irq.h:  schedule_in_irq  

Trigger  point  of  scheduling  which  while  

IRQ  event  occurs  

include/plaborm/irq.h  

Page 14: F9 Microkernel code reading part 2 scheduling

IRQ_HANDLER  

include/plaborm/irq.h  

Page 15: F9 Microkernel code reading part 2 scheduling

context_switch  

include/plaborm/irq.h  

Page 16: F9 Microkernel code reading part 2 scheduling

Scheduler  slots •  sched.h

ss_scheduled  ss_handler

sched_slot_t  

 26  typedef  struct  sched_slot  {    27          tcb_t  *ss_scheduled;    28          sched_handler_t  ss_handler;    29  }  sched_slot_t;  

sched.h  

Priority  in  order  

Page 17: F9 Microkernel code reading part 2 scheduling

Schedule  handler  

typedef  tcb_t  *(*sched_handler_t)(struct  sched_slot  *slot);  

Page 18: F9 Microkernel code reading part 2 scheduling

Select  target  thread  

ss_handler  is  used  while  currnt  slot  thread  is  empty  or  

not  runnable  

Page 19: F9 Microkernel code reading part 2 scheduling

thread_state_t  

Only  scheduling  for  T_RUNNABLE  State  

Page 20: F9 Microkernel code reading part 2 scheduling

Thread  control  block  

TCB  using  by  schedule  slots  

Page 21: F9 Microkernel code reading part 2 scheduling

__NAKED  

•  __aWribute__((naked))  Use  this  aWribute  on  the  ARM,  AVR,  MCORE,  MSP430,  NDS32,  RL78,  RX  and  SPU  ports  to  indicate  that  the  specified  funcMon  does  not  need  prologue/epilogue  sequences  generated  by  the  compiler.      It  is  up  to  the  programmer  to  provide  these  sequences.      The  only  statements  that  can  be  safely  included  in  naked  funcMons  are  asm  statements  that  do  not  have  operands.      All  other  statements,  including  declaraMons  of  local  variables,  if  statements,  and  so  forth,  should  be  avoided.  Naked  funcMons  should  be  used  to  implement  the  body  of  an  assembly  funcMon,  while  allowing  the  compiler  to  construct  the  requisite  funcMon  declaraMon  for  the  assembler.    

Using  While  IRQ  funcMon  

Page 22: F9 Microkernel code reading part 2 scheduling

kMmer  event  scheduling  

Page 23: F9 Microkernel code reading part 2 scheduling

schedule_slot_set_handler  

Page 24: F9 Microkernel code reading part 2 scheduling

thread.c  

Page 25: F9 Microkernel code reading part 2 scheduling

Conclusion  

•  F9  Microkernel  uses  following  concepts  – Tickless  Scheduling  – Dynamic  Timer  To  archive  energy  efficiency  scheduling  

Page 26: F9 Microkernel code reading part 2 scheduling

Discussions  

?  

F9  

Page 27: F9 Microkernel code reading part 2 scheduling

Kernel  line  of  code  for  reading  

Kernel  C  code  line:  2183  Git  head:  4d87f204252d57525f9cd93f163ca5225cc34bb7  

Page 28: F9 Microkernel code reading part 2 scheduling

References  •  F9  Microkernel  source  code  and  introducMon  

•  hWps://github.com/southernbear/RIOT/wiki/Development  

•  TiROS  for  Mckless  hWp://Mros.sourceforge.net/  

•  GCC  Naked  AWribute