본문 바로가기
scheduler

CPU Scheduler implementation hints for architecture specific code

by jsh91 2023. 11. 22.

Context switch

Runqueue locking 기본적으로, switch_to Arch 함수는 runqueue가 lock 상태로 호출됩니다. switch_to가 runqueue lock 을 수행해야 하는 경우가 아니면 이는 일반적으로 문제가 되지 않습니다. 이는 일반적으로 컨텍스트 스위치의 절전 모드 해제 작업으로 인해 발생합니다.

 

runqueue unlocked상태에서  스케줄러 호출 요청 witch_to을 하려면 헤더 파일(일반적으로 switch_to가 정의된 파일)에서 #define __ARCH_WANT_UNLOCKED_CTXSW를 선언해야 합니다.

Unlocked context switches는 CONFIG_SMP 사례의 핵심 스케줄러 구현에 아주 사소한 성능 저하만을 가져옵니다.

 

CPU idle

cpu_idle 순서는 아래의 규칙을 따른다.

1. preempt는 idle routines을 무시하지 않도록 disable 해야한다. schedule()을 부를때만 enable 해야 하고 다시 disable 한다.

 

2. need_resched/TIF_NEDE_RESCHED는 실행 중인 태스크가 schedule()을 호출하기 전까지는 결코 지워지지 않습니다. idle threads는 need_resched 쿼리만 필요하며 이를 설정하거나 지울 수 없습니다

 

3. cpu_idle가 (need_resched() == 'true')를 찾으면 schedule()를 호출해야 합니다. 그렇지 않으면  schedule()를 호출해서는 안 됩니다

 

4. need_resched를 확인할 때 인터럽트를 비활성화해야 하는 유일한 시간은 다음 인터럽트가 될 때까지 프로세서를 절전 모드로 전환하는 것입니다(이는 need_resched를 보호하는 기능이 아닙니다. 인터럽트가 손실되는 것을 방지합니다

  4a. Common problem with this type of sleep appears to be:

local_irq_disable();
if (!need_resched()) {
        local_irq_enable();
        *** resched interrupt arrives here ***
        __asm__("sleep until next interrupt");
}

 

5. need_resched가 높을 때 TIF_POLLING_NRFLAG는 인터럽트가 필요 없는 idle 루틴으로 설정할 수 있습니다. 즉, 백그라운드 작업을 수행하거나 CPU 우선 순위를 낮게 입력하는 것이 합리적일 수 있지만 주기적으로 need_resched를 polling해야 합니다.

 

Possible arch/ problems

sparc - IRQs on 이 시점(?)에서 local_irq_save를 _disable로 변경합니다.
TODO: 선점을 사용하지 않도록 설정하려면 보조 CPU가 필요합니다(See #1)

 

'scheduler' 카테고리의 다른 글

Capacity Aware Scheduling  (2) 2023.11.26
Scheduler Domains  (1) 2023.11.23
CFS Scheduler  (1) 2023.11.22
CFS Bandwidth Control  (1) 2023.11.22
Completions - "wait for completion" barrier APIs  (1) 2023.11.20

댓글