Pintos Project1 day 2

John Jean·2024년 8월 24일

pintos

목록 보기
2/7

핀토스

my job

  • timer_sleep() 고쳐보기.
  • 제출물에는 busy wating (spin) 이 없어야 합니다. thread_yield()를 콜하는 작은 루프도 busy waiting 의 하나입니다. (yield = 양보; lock이 없는 쓰레드가 기다리는동안 cpu를 양보하기위한 함수)
  • timer가 적어도 x번 tick 할때까지 thread 호출의 실행을 일시 중단합니다. 시스템이 idle(다음 thread가 없는) 상태가 아니라면, thread가 정확히 x번의 tick이 발생한 직후에 wake up 할 필요가 없습니다. thread가 적절한 시간동안 대기 한 후 ready queue에 놓이게 해주세요.
  • 억지로 깨울 필요는 없고 타이머가 끝나면 레디큐에 넣어주면 될듯.

작업중인 코드

timer_sleep()

// timer.c
void timer_sleep(int64_t ticks)
{
	// int64_t start = timer_ticks();

	// ASSERT(intr_get_level() == INTR_ON);
	// while (timer_elapsed(start) < ticks)
	// 	thread_yield();
	int64_t start = timer_ticks();
	struct thread *curr = thread_current();
	// 기상시간 정해주기
	curr->wake_time = start + ticks;
	// 일단 리스트 뒤에 넣어주자.
	list_push_back(&sleep_list, &curr->elem);
	// 이제 재우자
	thread_block();

	ASSERT(intr_get_level() == INTR_ON);
	// while을 지울거임.
	// while (timer_elapsed(start) < ticks)
	// 	thread_yield();
}

sleep_list 생성

// thread.h
// 수면리스트 생성
struct list sleep_list;
// 이런식으로 만들어줘도 되나..
  • 전역 리스트를 사용하려면 시스템 초기화 시점에 반드시 초기화해줘야 합니다. 이는 보통 thread_init() 함수에서 수행됩니다.

라고 하니 thread_init에서 초기화 해주면 될듯.


sleep_list 초기화 시키기

// thread.c
void thread_init(void)
{
	ASSERT(intr_get_level() == INTR_OFF);

	/* Reload the temporal gdt for the kernel
	 * This gdt does not include the user context.
	 * The kernel will rebuild the gdt with user context, in gdt_init (). */
	struct desc_ptr gdt_ds = {
		.size = sizeof(gdt) - 1,
		.address = (uint64_t)gdt};
	lgdt(&gdt_ds);

	/* Init the globla thread context */
	lock_init(&tid_lock);
	list_init(&ready_list);
	list_init(&destruction_req);
	// 슬립 리스트 초기화. 스레드 이닛은 보통 한 번만 실행된다는데 함 봐야 알듯.
	list_init(&sleep_list);

// 현재 틱 마다 기상시켜야 할 스레드가 있는지 체크하고 불침번이 깨워주는 함수 만들기. 
// 매 틱마다 실행되는 함수가 분명히 있을거같음. 찾아보자.

용어

thread_ticks = 0; -> 타임슬라이스 초기화
timer_ticks (void) -> 부팅되고나서 지난 시간 반환


스레드 구조체에 변수를 추가하면, 스레드를 만들 때 초기화를 해줘야 하나?

8/25 할일 : 깨우는 함수 + 재우는함수 다듬기.

profile
크래프톤 6기 정글러

0개의 댓글