MLFQS(Multi-Level Feedback Queue Scheduler)
스레드 구조체를 확장합니다.
struct thread {
// 동일 코드...
int nice; // nice 값
int64_t recent_cpu; // recent_cpu 값
struct list_elem all_elem; // all_list에 들어갈 때 쓰이는 원소
// 동일 코드...
};
// 17.14 고정소수점 연산 매크로
#define F (1 << 14) // 17.14 고정 소수점 방식 사용
// 정수 → 고정소수점
#define INT_TO_FP(n) ((n) * F)
// 고정소수점 → 정수 (내림)
#define FP_TO_INT(x) ((x) / F)
// 고정소수점 → 정수 (반올림)
#define FP_TO_INT_ROUND(x) (((x) + F / 2) / F)
// 고정소수점 × 정수
#define FP_MUL_INT(x, n) ((x) * (n))
// 고정소수점 ÷ 정수
#define FP_DIV_INT(x, n) ((x) / (n))
// 고정소수점 × 고정소수점
#define FP_MUL(x, y) (((int64_t)(x)) * (y) / F)
// 고정소수점 ÷ 고정소수점
#define FP_DIV(x, y) (((int64_t)(x)) * F / (y))
static int64_t load_avg; // load_avg 값
static struct list all_list; // 모든 스레드를 담는 리스트(priority 재계산 용도)