Arm Linux Kernel Hacks

rousalome.egloos.com

포토로그 Kernel Crash


통계 위젯 (화이트)

33111
637
415409


[리눅스커널] 스케줄링: 런큐에 등록된 프로세스 자료구조 확인하기 - p 10. 프로세스 스케줄링

이번 소절에서는 런큐 자료구조를 소개합니다. 

런큐에 Enqueue한 프로세스 리스트 확인하기

일반 프로세스가 런큐에 Enqueue를 하면 런큐 구조체 struct rq 필드 중 연결리스트인 cfs_tasks에 자신의 태스크 디스크립터 주소(&se->group_node)를 등록합니다.

프로세스 태스크 디스크립터인 struct task_struct 구조체 &se->group_node 필드 주소를 struct rq 런큐 구조체 cfs_tasks 연결 리스트 필드에 저장하는 것입니다.

이 관계를 다음 그림을 보면서 살펴보겠습니다.
 
 [그림 10.25] 런큐에 Enqueue한 프로세스 연결 리스트 구조

여기서 한 가지 의문이 생깁니다. 

    어디서 프로세스 태스크 디스크립터를 런큐 cfs_tasks 필드에 등록할까?

정답은 언제나 소스 코드에 있습니다. 
다음 account_entity_enqueue() 함수를 같이 보겠습니다.
[https://elixir.bootlin.com/linux/v4.19.30/source/kernel/sched/fair.c]
1 static void
2 account_entity_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se)
3 {
4 update_load_add(&cfs_rq->load, se->load.weight);
5 if (!parent_entity(se))
6  update_load_add(&rq_of(cfs_rq)->load, se->load.weight);
7 #ifdef CONFIG_SMP
8 if (entity_is_task(se)) {
9  struct rq *rq = rq_of(cfs_rq);
10
11  account_numa_enqueue(rq, task_of(se));
12  list_add(&se->group_node, &rq->cfs_tasks);
13 }
#endif
14 cfs_rq->nr_running++;
15 }

위 코드에서 눈여겨볼 부분은 9~12 번째 줄입니다.

9 번째 줄은 cfs_rq란 입력으로 런큐 주소를 읽는 동작입니다.
9  struct rq *rq = rq_of(cfs_rq);

다음 12번째 줄 코드를 보겠습니다.
12  list_add(&se->group_node, &rq->cfs_tasks);

12번째 줄 코드를 실행하면, struct task_struct->se->group_node 주소를 &rq->cfs_tasks 주소에 등록합니다.


여기서 'struct task_struct->se->group_node' 자료구조에서 struct task_struct->se의 정체는 무엇일까요?

다음 코드와 같이 account_entity_enqueue() 함수 2 번째 인자인 struct sched_entity *se 는 런큐에 Enqueue하려는 프로세스 태스크 디스크립터 se 필드 주소를 담고 있습니다.
1 static void
2 account_entity_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se)

여기서 한 가지 의문이 생깁니다. 

    struct sched_entity *se 인자는 어디서 확인할 수 있을까?

다음 struct task_struct 구조체 선언부와 같이 프로세스 태스크 디스크립터 필드 중에 se가 있습니다.
[https://elixir.bootlin.com/linux/v4.19.30/source/include/linux/sched.h]
01 struct task_struct {
...
02 const struct sched_class *sched_class;
03 struct sched_entity  se;

03번째 줄과 같이 struct sched_entity 타입입니다.


"혹시 궁금한 점이 있으면 댓글로 질문 남겨주세요. 아는 한 성실히 답변 올려드리겠습니다!" 

Thanks,
Austin Kim(austindh.kim@gmail.com)

Reference(프로세스 스케줄링)

스케줄링 소개
프로세스 상태 관리
   어떤 함수가 프로세스 상태를 바꿀까?
스케줄러 클래스
런큐
CFS 스케줄러
   CFS 관련 세부 함수 분석  
선점 스케줄링(Preemptive Scheduling)   
프로세스는 어떻게 깨울까?
스케줄링 핵심 schedule() 함수 분석
컨택스트 스위칭
스케줄링 디버깅
   스케줄링 프로파일링
     CPU에 부하를 주는 테스트   
     CPU에 부하를 주지 않는 테스트


# Reference: For more information on 'Linux Kernel';

디버깅을 통해 배우는 리눅스 커널의 구조와 원리. 1

디버깅을 통해 배우는 리눅스 커널의 구조와 원리. 2


 


핑백

덧글

댓글 입력 영역