X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fthreads%2Fthread.c;h=afb2006bc1aa8a51ebffc002f80d29e766470e96;hb=838c30d0075a3ee0413ba4909944b37f4970a10d;hp=eb9646520de0e2b0b2af7c3254451ff5f86eefe1;hpb=35d96421c3bdd3911dc679918ae3d81ab7479797;p=pintos-anon diff --git a/src/threads/thread.c b/src/threads/thread.c index eb96465..afb2006 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -41,6 +41,11 @@ struct kernel_thread_frame void *aux; /* Auxiliary data for function. */ }; +/* 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. */ + static void kernel_thread (thread_func *, void *aux); static void idle (void *aux UNUSED); @@ -86,6 +91,30 @@ thread_start (void) intr_enable (); } +/* Called by the timer interrupt handler at each timer tick to + update statistics. */ +void +thread_tick (void) +{ + struct thread *t = thread_current (); + if (t == idle_thread) + idle_ticks++; +#ifdef USERPROG + else if (t->pagedir != NULL) + user_ticks++; +#endif + else + kernel_ticks++; +} + +/* Prints thread statistics. */ +void +thread_print_stats (void) +{ + printf ("Thread: %lld idle ticks, %lld kernel ticks, %lld user ticks\n", + idle_ticks, kernel_ticks, user_ticks); +} + /* Creates a new kernel thread named NAME with the given initial PRIORITY, which executes FUNCTION passing AUX as the argument, and adds it to the ready queue. If thread_start() has been @@ -112,7 +141,7 @@ thread_create (const char *name, int priority, ASSERT (function != NULL); /* Allocate thread. */ - t = palloc_get (PAL_ZERO); + t = palloc_get_page (PAL_ZERO); if (t == NULL) return TID_ERROR; @@ -370,7 +399,7 @@ schedule_tail (struct thread *prev) { ASSERT (prev != cur); if (prev != initial_thread) - palloc_free (prev); + palloc_free_page (prev); } }