Your SlideShare is downloading. ×
Linux Process & CF scheduling
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Linux Process & CF scheduling

1,458
views

Published on


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,458
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • wake_up_new_task; in other words, the task structure is added to the scheduler queue뒤쪽에서 스케줄링에서 설명하겠지만 생성된 프로세스는 무조건 한번은 수행되도록 보장함
  • Check flag – for clone system call parameterDup_task_struct – 실제 복사가 이루어짐Sched_fork – 스케줄링에 관련된 내용이 복사됨(확인요함)
  • Vruntime – 실제 수행된 시간에 prority별로 가중치를 둔 이후, 가장 수행시간이 적은 task 위주로 수행함
  • Prio, normal_proi – 동적으로 변함Static_proi- 고정됨Rt_prioroty – realtime인 경우만설정, 그렇지 않은 경우 0,max 99Sched_entity를 갖는 것은 모든지 스케줄링이 될 수 있음Policy는 cpu에 동작할 때의 정책 –sched_normalCpus_allows – bitfield로 특정 cpu에서 동작하는 것을 제한Tile_slice for realtimeß
  • Nr_running – 현재 큐에 들어있는 태스크 갯수Load – 가중치를 고려한 테스크의 워크로드Clock은 해당 런큐가 주기적으로 스케줄링을 받도록 계산하기 위하여 사용됨Cpu_load는 이전의 워크로드를 기록 – 로드벨런싱, 그룹핑에 쓰임\\
  • 전체 큐의 워크로드런큐 내부적으로 rb를 이용하기 때문에, 그에 필요한 노드On_rq – 현재 스케줄링이 되고 있는지 확인CFS를 구현하기 위하여 필요한 시간 값Task_struct가 sched_entity를 가지고 있기 때문에 스케줄링을 받을 수 있음
  • weight는 load 즉, 우선순위에 대한 가중치이고 inv_weight는 이의 역수(1/weight)에 해당하는 값이다.weight 값은 nice를 통해 지정할 수 있는 우선순위에 대응하는 값이며 (nice level 0일 때: 1024)sched.c 파일의 prio_to_weight[] 배열에 저장되어 있다.참고로 nice (우선순위) 값의 1 차이는 weight 값의 1.25 배 차이이며이는 프로세스가 CPU를 사용하는 시간에 10% 정도 영향을 준다.inv_weight값은 단지 계산을 간편하게 하기 위한 목적으로 도입된 것으로가중치 계산을 위한 나눗셈을 피하기 위해 미리 정해진 충분히 큰 수(2^32)에 나눗셈을 미리 계산해 둔 값이다.
  • Transcript

    • 1. Process & CFS
    • 2. Process
    • 3. Process
      Program in the midst of execution
      How to create new process
      fork(), vfork()
      exec()
    • 4. Data structure
      task_struct
      Process descriptor http://lxr.linux.no/linux+v2.6.39/include/linux/sched.h#L1193
      Priority(prio, static_prio, normal_prio)
      Scheduling class(sched_class)
      Scheduling policy(policy)
      Link parent, child, sibling, group_leader
    • 5. Data structure
      thread_infohttp://lxr.linux.no/linux+v2.6.39/arch/arm/include/asm/thread_info.h#L50
      Describe process data accessed by architecture specific code
      Difference among other CPUs
      Managed information
      task_struct
      flags for scheduling(TIF_SIGPANDING, TIF_NEED_RESCHED)
      cpu number (for multi processor)
      preempt_count
    • 6. Data structure
      thread_unionhttp://lxr.linux.no/linux+v2.6.39/include/linux/sched.h#L2011
      Kernel stack & thread_info
      1 or 2 pages(8KB)
      Kernel stack size is less then 8K
    • 7. Process states
    • 8. Process creation system call
      fork()
      Duplicate of the parent's page tables
      Create unique process descriptor for child(pidetc)
      Copy-on-Write
      Delay the copying pages
      exec() is called right after fork()
      vfork()
      Same as fork() except copying of parent page table
      Share parent's address space
      Child first scheme
      Parent is blocked until the child calls exec() or exits
    • 9. do_fork()
      Start point of fork
    • 10. copy_process()
    • 11. Thread
      Implementation threads as same as standard processes
      One thread has own task_struct
      pid/ tgid
      Create clone() system call
      clone(CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND, 0);
      clone(SIGCHLD, 0); // fork()
      clone(CLONE_VFORK | CLONE_VM | SIGCHLD, 0); // vfork()
    • 12. Kernel Threads
      Standard processes running in kernel space
      Do not have an address space(task_struct.mm is NULL)
      Schedulable, preemptable like normal process
      kthread_create() for creation
    • 13. Process Termination
      exit()
      wait(), waitpid()
    • 14. Scheduling
    • 15. Scheduling
      CoopreativevsPreemptive
      yield
      timeslice
      IO bound vs CPU bound
      Low latency vsHigh throughput
    • 16. Process priority
      nice
      Integer value(-20~19, default 0)
      High nice value correspond to low priority
      renice, setpriority()
      Realtime priority
      Always higher priority than normal processes
      Integer value(0~99)
    • 17. Process priority
      Priority kernel internal
      Integer value (0~139)
      nice values[-20~19] are map to [100~139]
      [0~99] for realtime processes
    • 18. Fairness scheduling
      RR on static timeslice
      100ms(0 nice) vs 95ms(1 nice)
      10ms(19 nice) vs 5ms (20 nice)
      A user’s 100 processes vs B user’s 1process
      Per user based scheduling
      Enable when kernel build
      Per thread level scheduling
      One nice value down gets 10% more CPU power
      vruntime(virtual clock)
      Support CGroupscheduling
      http://www.mjmwired.net/kernel/Documentation/scheduler/sched-design-CFS.txt
    • 19. Overview
      schedule()
      Core
      T
      T
      T
      Ruequene
      do_fork()
      wake_up_new_task()
      T

      T
      Waitqueue
      Core
      T
      Ruequene
      Core
      T
      T
      Ruequene
      Core
      T
      T
      Ruequene
    • 20. tast_struct
      sched_class
      seched_entity
      sched_class
      Sched_entity
      load_weight
      on_rq
      vruntime
      rq
      load_weight
      cfs_rq
      rt_rq
      load_weight
    • 21. CFS policy
      Soft real-time policy
      Posix standard
      Priority scheduling
      One nice level down gets 10% more CPU power
      Virtual clock
      Conceptual time considering priority
      Task waiting most of time will be scheduled to run
      Time order is managed by Runqueue
    • 22. Data struct
      task_struct
      http://lxr.linux.no/linux+v2.6.39/include/linux/sched.h#L1193
      SCHED_NORMAL
      SCHED_BATCH
      SCHED_IDLE
      SCHED_FIFO
      SCHED_RR
    • 23. Data struct
      sched_class
      http://lxr.linux.no/linux+v2.6.39/include/linux/sched.h#L1056
    • 24. Data struct
      rq
      http://lxr.linux.no/linux+v2.6.39/kernel/sched.c#L447
    • 25. Data struct
      sched_entity
      http://lxr.linux.no/linux+v2.6.39/include/linux/sched.h#L1142
    • 26. Dealing with priority
      Basic
      static_prio
      Value inherited by parent or set
      prio,normal_prio
      Dynamically changed
    • 27. Dealing with priority
      Code
    • 28. Computing Load weights
      load_weight
    • 29. Remaining
      How to determine
      vruntime
      Process selection
      When schedule() function is called
      Context switching
      Sleep and Wake up
      Cgroup
      Hard to understand