#include "threads/thread.h"
#include <debug.h>
#include <stddef.h>
#include <random.h>
#include <stdio.h>
#include <string.h>
#include "threads/flags.h"
#include "threads/interrupt.h"
#include "threads/intr-stubs.h"
#include "threads/palloc.h"
#include "threads/switch.h"
#include "threads/synch.h"
#include "threads/vaddr.h"
Go to the source code of this file.
Data Structures | |
struct | kernel_thread_frame |
Defines | |
#define | THREAD_MAGIC 0xcd6abf4b |
#define | TIME_SLICE 4 |
Functions | |
static void | kernel_thread (thread_func *, void *aux) |
static void | idle (void *aux UNUSED) |
static struct thread * | running_thread (void) |
static struct thread * | next_thread_to_run (void) |
static void | init_thread (struct thread *, const char *name, int priority) |
static bool | is_thread (struct thread *) |
void | thread_start (void) |
void | thread_tick (void) |
void | thread_print_stats (void) |
tid_t | thread_create (const char *name, int priority, thread_func *function, void *aux) |
void | thread_block (void) |
void | thread_unblock (struct thread *t) |
const char * | thread_name (void) |
struct thread * | thread_current (void) |
tid_t | thread_tid (void) |
void | thread_exit (void) |
void | thread_yield (void) |
void | thread_foreach (thread_action_func *func, void *aux) |
void | thread_set_priority (int new_priority) |
int | thread_get_priority (void) |
void | thread_set_nice (int nice UNUSED) |
int | thread_get_nice (void) |
int | thread_get_load_avg (void) |
int | thread_get_recent_cpu (void) |
static void | idle (void *idle_started_ UNUSED) |
static void * | alloc_frame (struct thread *t, size_t size) |
void | schedule_tail (struct thread *prev) |
static void | schedule (void) |
static tid_t | allocate_tid (void) |
Variables | |
static struct list | ready_list |
static struct list | all_list |
static struct thread * | idle_thread |
static struct thread * | initial_thread |
static struct lock | tid_lock |
static long long | idle_ticks |
static long long | kernel_ticks |
static long long | user_ticks |
static unsigned | thread_ticks |
bool | thread_mlfqs |
uint32_t | thread_stack_ofs = offsetof (struct thread, stack) |
#define THREAD_MAGIC 0xcd6abf4b |
#define TIME_SLICE 4 |
Definition at line 479 of file thread.c.
References ASSERT, is_thread(), and thread::stack.
Referenced by thread_create().
static tid_t allocate_tid | ( | void | ) | [static] |
Definition at line 574 of file thread.c.
References lock_acquire(), lock_release(), thread::tid, and tid_lock.
Referenced by is_thread(), and thread_create().
static void idle | ( | void *idle_started_ | UNUSED | ) | [static] |
Definition at line 398 of file thread.c.
References intr_disable(), sema_up(), thread_block(), and thread_current().
static void idle | ( | void *aux | UNUSED | ) | [static] |
Referenced by thread_start().
static void init_thread | ( | struct thread * | t, | |
const char * | name, | |||
int | priority | |||
) | [static] |
Definition at line 461 of file thread.c.
References all_list, thread::allelem, ASSERT, list_push_back(), thread::magic, memset(), thread::name, NULL, PGSIZE, PRI_MAX, PRI_MIN, thread::priority, thread::stack, thread::status, strlcpy(), THREAD_BLOCKED, and THREAD_MAGIC.
Referenced by is_thread(), and thread_create().
static bool is_thread | ( | struct thread * | t | ) | [static] |
Definition at line 69 of file thread.c.
References all_list, allocate_tid(), ASSERT, init_thread(), intr_get_level(), INTR_OFF, list_init(), lock_init(), PRI_DEFAULT, ready_list, running_thread(), thread::status, THREAD_RUNNING, thread::tid, and tid_lock.
Referenced by alloc_frame(), schedule(), thread_current(), and thread_unblock().
static void kernel_thread | ( | thread_func * | function, | |
void * | aux | |||
) | [static] |
Definition at line 428 of file thread.c.
References ASSERT, intr_enable(), NULL, and thread_exit().
Referenced by thread_create().
static struct thread * next_thread_to_run | ( | void | ) | [static, read] |
Definition at line 495 of file thread.c.
References thread::elem, list_empty(), list_entry, list_pop_front(), and ready_list.
Referenced by schedule().
struct thread * running_thread | ( | void | ) | [static, read] |
Definition at line 439 of file thread.c.
References pg_round_down().
Referenced by is_thread(), schedule(), schedule_tail(), and thread_current().
static void schedule | ( | void | ) | [static] |
Definition at line 557 of file thread.c.
References ASSERT, intr_get_level(), INTR_OFF, is_thread(), next(), next_thread_to_run(), NULL, running_thread(), schedule_tail(), thread::status, switch_threads(), and THREAD_RUNNING.
Referenced by thread_block(), thread_exit(), and thread_yield().
void schedule_tail | ( | struct thread * | prev | ) |
Definition at line 520 of file thread.c.
References ASSERT, intr_get_level(), INTR_OFF, NULL, palloc_free_page(), process_activate(), running_thread(), thread::status, THREAD_DYING, THREAD_RUNNING, and thread_ticks.
Referenced by schedule().
void thread_block | ( | void | ) |
Definition at line 223 of file thread.c.
References ASSERT, intr_context(), intr_get_level(), INTR_OFF, schedule(), thread::status, THREAD_BLOCKED, and thread_current().
Referenced by idle(), sema_down(), and wait().
tid_t thread_create | ( | const char * | name, | |
int | priority, | |||
thread_func * | function, | |||
void * | aux | |||
) |
Definition at line 167 of file thread.c.
References alloc_frame(), allocate_tid(), ASSERT, kernel_thread_frame::aux, switch_threads_frame::ebp, switch_threads_frame::eip, switch_entry_frame::eip, kernel_thread_frame::eip, kernel_thread_frame::function, init_thread(), intr_disable(), intr_set_level(), kernel_thread(), NULL, PAL_ZERO, palloc_get_page(), switch_entry(), thread_unblock(), thread::tid, and TID_ERROR.
Referenced by process_execute(), sema_self_test(), test_alarm_priority(), test_mlfqs_block(), test_mlfqs_fair(), test_mlfqs_load_60(), test_mlfqs_load_avg(), test_priority_change(), test_priority_condvar(), test_priority_donate_chain(), test_priority_donate_lower(), test_priority_donate_multiple(), test_priority_donate_multiple2(), test_priority_donate_nest(), test_priority_donate_one(), test_priority_donate_sema(), test_priority_fifo(), test_priority_preempt(), test_priority_sema(), test_sleep(), and thread_start().
struct thread* thread_current | ( | void | ) | [read] |
Definition at line 265 of file thread.c.
References ASSERT, is_thread(), running_thread(), thread::status, and THREAD_RUNNING.
Referenced by idle(), install_page(), load(), lock_acquire(), lock_held_by_current_thread(), lock_try_acquire(), print_stacktrace(), process_activate(), process_exit(), sema_down(), thread_block(), thread_exit(), thread_get_priority(), thread_name(), thread_set_priority(), thread_tick(), thread_tid(), thread_yield(), tss_update(), and wait().
void thread_exit | ( | void | ) |
Definition at line 290 of file thread.c.
References thread::allelem, ASSERT, intr_context(), intr_disable(), list_remove(), NOT_REACHED, process_exit(), schedule(), thread::status, thread_current(), and THREAD_DYING.
Referenced by kernel_thread(), kill(), main(), start_process(), and syscall_handler().
void thread_foreach | ( | thread_action_func * | func, | |
void * | aux | |||
) |
Definition at line 329 of file thread.c.
References all_list, thread::allelem, ASSERT, intr_get_level(), INTR_OFF, list_begin(), list_end(), list_entry, and list_next().
Referenced by debug_backtrace_all().
int thread_get_load_avg | ( | void | ) |
Definition at line 374 of file thread.c.
Referenced by test_mlfqs_load_1(), test_mlfqs_load_60(), test_mlfqs_load_avg(), and test_mlfqs_recent_1().
int thread_get_priority | ( | void | ) |
Definition at line 352 of file thread.c.
References thread::priority, and thread_current().
Referenced by donor_thread_func(), medium_thread_func(), test_priority_donate_chain(), test_priority_donate_lower(), test_priority_donate_multiple(), test_priority_donate_multiple2(), test_priority_donate_nest(), test_priority_donate_one(), test_priority_donate_sema(), test_priority_fifo(), and test_priority_preempt().
int thread_get_recent_cpu | ( | void | ) |
const char* thread_name | ( | void | ) |
Definition at line 256 of file thread.c.
References thread::name, and thread_current().
Referenced by alarm_priority_thread(), donor_thread_func(), interloper_thread_func(), kill(), priority_condvar_thread(), priority_sema_thread(), simple_thread_func(), and test_priority_donate_chain().
void thread_print_stats | ( | void | ) |
Definition at line 145 of file thread.c.
References idle_ticks, kernel_ticks, printf(), and user_ticks.
Referenced by print_stats().
void thread_set_nice | ( | int nice | UNUSED | ) |
Definition at line 359 of file thread.c.
Referenced by load_thread(), test_mlfqs_fair(), and test_mlfqs_load_avg().
void thread_set_priority | ( | int | new_priority | ) |
Definition at line 345 of file thread.c.
References thread::priority, and thread_current().
Referenced by changing_thread(), test_alarm_priority(), test_priority_change(), test_priority_condvar(), test_priority_donate_chain(), test_priority_donate_lower(), test_priority_fifo(), and test_priority_sema().
void thread_start | ( | void | ) |
Definition at line 107 of file thread.c.
References idle(), intr_enable(), PRI_MIN, sema_down(), sema_init(), and thread_create().
Referenced by main().
void thread_tick | ( | void | ) |
Definition at line 124 of file thread.c.
References idle_ticks, intr_yield_on_return(), kernel_ticks, NULL, thread_current(), thread_ticks, TIME_SLICE, and user_ticks.
Referenced by timer_interrupt().
tid_t thread_tid | ( | void | ) |
void thread_unblock | ( | struct thread * | t | ) |
Definition at line 241 of file thread.c.
References ASSERT, thread::elem, intr_disable(), intr_set_level(), is_thread(), list_push_back(), ready_list, thread::status, THREAD_BLOCKED, and THREAD_READY.
Referenced by sema_up(), signal(), and thread_create().
void thread_yield | ( | void | ) |
Definition at line 311 of file thread.c.
References ASSERT, thread::elem, intr_context(), intr_disable(), intr_set_level(), list_push_back(), ready_list, schedule(), thread::status, thread_current(), and THREAD_READY.
Referenced by intr_handler(), medium_thread_func(), simple_thread_func(), sleeper(), test_priority_donate_nest(), and timer_sleep().
Definition at line 30 of file thread.c.
Referenced by init_thread(), is_thread(), and thread_foreach().
struct thread* idle_thread [static] |
long long idle_ticks [static] |
struct thread* initial_thread [static] |
long long kernel_ticks [static] |
struct list ready_list [static] |
Definition at line 26 of file thread.c.
Referenced by is_thread(), next_thread_to_run(), thread_unblock(), and thread_yield().
bool thread_mlfqs |
Definition at line 61 of file thread.c.
Referenced by parse_options(), test_alarm_priority(), test_mlfqs_block(), test_mlfqs_fair(), test_mlfqs_load_1(), test_mlfqs_load_60(), test_mlfqs_load_avg(), test_mlfqs_recent_1(), test_priority_change(), test_priority_condvar(), test_priority_donate_chain(), test_priority_donate_lower(), test_priority_donate_multiple(), test_priority_donate_multiple2(), test_priority_donate_nest(), test_priority_donate_one(), test_priority_donate_sema(), test_priority_fifo(), test_priority_preempt(), test_priority_sema(), and test_sleep().
uint32_t thread_stack_ofs = offsetof (struct thread, stack) |
unsigned thread_ticks [static] |
long long user_ticks [static] |