#define barrier() asm volatile ("" : : : "memory") /* 순서를 보장하기 위해 사용 */

Timer(devices > timer.c)

#if TIMER_FREQ < 19
#error 8254 timer requires TIMER_FREQ >= 19 /* TIMER_FREQ < 19일 경우 에러 */
#endif

#if TIMER_FREQ > 1000
#error TIMER_FREQ <= 1000 recommended /* TIMER_FREQ > 1000일 경우 에러 */
#endif

static int64_t ticks; /* OS 부팅 이후 타이머 틱 수 */

static unsigned loops_per_tick; /* 각 타이머 틱마다 수행해야 하는 반복문의 횟수 */

static intr_handler_func timer_interrupt; /* 인터럽트가 발생했을 때 호출될 함수 */
/* typedef void intr_handler_func (struct intr_frame *); 인터럽트 핸들러 함수를 선언 */

timer

Thread(threads > thread.c)

#define THREAD_MAGIC 0xcd6abf4b

#define THREAD_BASIC 0xd42df210

static struct list ready_list;
static struct thread *idle_thread;
static struct thread *initial_thread;
static struct lock tid_lock;
static struct list destruction_req;

/* Statistics. */
static long long idle_ticks;    /* # of timer ticks spent idle. */
static long long kernel_ticks;  /* # of timer ticks in kernel threads. */
static long long user_ticks;    /* # of timer ticks in user programs. */

/* Scheduling. */
#define TIME_SLICE 4            /* # of timer ticks to give each thread. */
static unsigned thread_ticks;   /* # of timer ticks since last yield. */

bool thread_mlfqs; /* false(기본값) => round-robin scheduler
											true => multi-level feedback queue scheduler
											`-o mlfqs`로 제어 */

/* GDT 엔트리 초기화: 운영 체제에서 메모리 보호 및 가상 메모리 관리와 같은 기능을 수행하는 데 필요 */
static uint64_t gdt[3] = { 0, 0x00af9a000000ffff, 0x00cf92000000ffff };

thread


Synch(threads > synch.c)

/* include > threads > synch.h */

/* counting semaphore */
struct semaphore {
	unsigned value;             /* 현재 값 */
	struct list waiters;        /* List of waiting threads. */
};

/* lock */
struct lock {
	struct thread *holder;      /* 디버깅을 위해 락을 보유하는 스레드 */
	struct semaphore semaphore; /* Binary semaphore controlling access. */
};

Interrupt(threads > interrupt.c)

#define INTR_CNT 256 /* 인터럽트 번호의 최대값 */