21#define THREAD_MAGIC 0xcd6abf4b 
  131  else if (t->pagedir != 
NULL)
 
  146  printf (
"Thread: %lld idle ticks, %lld kernel ticks, %lld user ticks\n",
 
  391  struct semaphore *idle_started = idle_started_;
 
  413      asm volatile (
"sti; hlt" : : : 
"memory");
 
  438  asm (
"mov %%esp, %0" : 
"=g" (esp));
 
  572  static tid_t next_tid = 1;
 
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
 
#define NOT_REACHED()
lib/debug.h
 
#define UNUSED
GCC lets us add "attributes" to functions, function parameters, etc.
 
void intr_yield_on_return(void)
During processing of an external interrupt, directs the interrupt handler to yield to a new process j...
 
enum intr_level intr_enable(void)
Enables interrupts and returns the previous interrupt status.
 
bool intr_context(void)
Returns true during processing of an external interrupt and false at all other times.
 
enum intr_level intr_disable(void)
Disables interrupts and returns the previous interrupt status.
 
enum intr_level intr_get_level(void)
Returns the current interrupt status.
 
enum intr_level intr_set_level(enum intr_level level)
Enables or disables interrupts as specified by LEVEL and returns the previous interrupt status.
 
intr_level
Interrupts on or off?
 
@ INTR_OFF
Interrupts disabled.
 
static int next(int pos)
Returns the position after POS within an intq.
 
struct list_elem * list_begin(struct list *list)
Returns the beginning of LIST.
 
struct list_elem * list_remove(struct list_elem *elem)
Removes ELEM from its list and returns the element that followed it.
 
struct list_elem * list_pop_front(struct list *list)
Removes the front element from LIST and returns it.
 
struct list_elem * list_end(struct list *list)
Returns LIST's tail.
 
bool list_empty(struct list *list)
Returns true if LIST is empty, false otherwise.
 
void list_init(struct list *list)
Initializes LIST as an empty list.
 
void list_push_back(struct list *list, struct list_elem *elem)
Inserts ELEM at the end of LIST, so that it becomes the back in LIST.
 
struct list_elem * list_next(struct list_elem *elem)
Returns the element after ELEM in its list.
 
int printf(const char *format,...)
Writes formatted output to the console.
 
#define list_entry(LIST_ELEM, STRUCT, MEMBER)
Converts pointer to list element LIST_ELEM into a pointer to the structure that LIST_ELEM is embedded...
 
void * palloc_get_page(enum palloc_flags flags)
Obtains a single free page and returns its kernel virtual address.
 
void palloc_free_page(void *page)
Frees the page at PAGE.
 
@ PAL_ZERO
Zero page contents.
 
void process_activate(void)
Sets up the CPU for running user code in the current thread.
 
void process_exit(void)
Free the current process's resources.
 
#define offsetof(TYPE, MEMBER)
 
void * memset(void *dst_, int value, size_t size)
Sets the SIZE bytes in DST to VALUE.
 
size_t strlcpy(char *dst, const char *src, size_t size)
Copies string SRC to DST.
 
Stack frame for kernel_thread().
 
void * aux
Auxiliary data for function.
 
thread_func * function
Function to call.
 
void * eip
Return address.
 
Stack frame for switch_entry().
 
switch_thread()'s stack frame.
 
void(* eip)(void)
16: Return address.
 
uint32_t ebp
8: Saved ebp.
 
A kernel thread or user process.
 
uint8_t * stack
Saved stack pointer.
 
struct list_elem allelem
List element for all threads list.
 
unsigned magic
Detects stack overflow.
 
struct list_elem elem
List element.
 
char name[16]
Name (for debugging purposes).
 
tid_t tid
Thread identifier.
 
enum thread_status status
Thread state.
 
struct thread * switch_threads(struct thread *cur, struct thread *next)
Switches from CUR, which must be the running thread, to NEXT, which must also be running switch_threa...
 
void lock_release(struct lock *lock)
Releases LOCK, which must be owned by the current thread.
 
void sema_init(struct semaphore *sema, unsigned value)
This file is derived from source code for the Nachos instructional operating system.
 
void sema_up(struct semaphore *sema)
Up or "V" operation on a semaphore.
 
void lock_init(struct lock *lock)
Initializes LOCK.
 
void lock_acquire(struct lock *lock)
Acquires LOCK, sleeping until it becomes available if necessary.
 
void sema_down(struct semaphore *sema)
Down or "P" operation on a semaphore.
 
struct thread * thread_current(void)
Returns the running thread.
 
void thread_start(void)
Starts preemptive thread scheduling by enabling interrupts.
 
void thread_unblock(struct thread *t)
Transitions a blocked thread T to the ready-to-run state.
 
static long long user_ticks
 
static void * alloc_frame(struct thread *t, size_t size)
Allocates a SIZE-byte frame at the top of thread T's stack and returns a pointer to the frame's base.
 
int thread_get_nice(void)
Returns the current thread's nice value.
 
bool thread_mlfqs
If false (default), use round-robin scheduler.
 
static void init_thread(struct thread *, const char *name, int priority)
Does basic initialization of T as a blocked thread named NAME.
 
static tid_t allocate_tid(void)
Returns a tid to use for a new thread.
 
static struct thread * running_thread(void)
Returns the running thread.
 
static long long idle_ticks
Statistics.
 
static struct thread * idle_thread
Idle thread.
 
static void idle(void *aux UNUSED)
 
uint32_t thread_stack_ofs
Offset of ‘stack’ member within ‘struct thread’.
 
static void schedule(void)
Schedules a new process.
 
static unsigned thread_ticks
 
int thread_get_priority(void)
Returns the current thread's priority.
 
static bool is_thread(struct thread *)
Initializes the threading system by transforming the code that's currently running into a thread.
 
const char * thread_name(void)
Returns the name of the running thread.
 
void thread_exit(void)
Deschedules the current thread and destroys it.
 
static struct list ready_list
List of processes in THREAD_READY state, that is, processes that are ready to run but not actually ru...
 
tid_t thread_create(const char *name, int priority, thread_func *function, void *aux)
Creates a new kernel thread named NAME with the given initial PRIORITY, which executes FUNCTION passi...
 
int thread_get_recent_cpu(void)
Returns 100 times the current thread's recent_cpu value.
 
void thread_set_priority(int new_priority)
Sets the current thread's priority to NEW_PRIORITY.
 
void thread_tick(void)
Called by the timer interrupt handler at each timer tick.
 
static struct list all_list
List of all processes.
 
void thread_yield(void)
Yields the CPU.
 
void thread_set_nice(int nice UNUSED)
Sets the current thread's nice value to NICE.
 
static void kernel_thread(thread_func *, void *aux)
Function used as the basis for a kernel thread.
 
tid_t thread_tid(void)
Returns the running thread's tid.
 
static long long kernel_ticks
 
void thread_schedule_tail(struct thread *prev)
Completes a thread switch by activating the new thread's page tables, and, if the previous thread is ...
 
static struct thread * next_thread_to_run(void)
Chooses and returns the next thread to be scheduled.
 
void thread_block(void)
Puts the current thread to sleep.
 
static struct thread * initial_thread
Initial thread, the thread running init.c:main().
 
#define TIME_SLICE
Scheduling.
 
static struct lock tid_lock
Lock used by allocate_tid().
 
#define THREAD_MAGIC
Random value for struct thread's ‘magic’ member.
 
int thread_get_load_avg(void)
Returns 100 times the system load average.
 
void thread_print_stats(void)
Prints thread statistics.
 
void thread_foreach(thread_action_func *func, void *aux)
Invoke function 'func' on all threads, passing along 'aux'.
 
@ THREAD_BLOCKED
Waiting for an event to trigger.
 
@ THREAD_DYING
About to be destroyed.
 
@ THREAD_RUNNING
Running thread.
 
@ THREAD_READY
Not running but ready to run.
 
void thread_action_func(struct thread *t, void *aux)
Performs some operation on thread t, given auxiliary data AUX.
 
#define PRI_MAX
Highest priority.
 
#define PRI_DEFAULT
Default priority.
 
#define TID_ERROR
Error value for tid_t.
 
int tid_t
Thread identifier type.
 
void thread_func(void *aux)
 
#define PRI_MIN
Thread priorities.
 
static void * pg_round_down(const void *va)
Round down to nearest page boundary.
 
#define PGSIZE
Bytes in a page.