X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pintos-anon;a=blobdiff_plain;f=src%2Fuserprog%2Fexception.c;h=8b2e8b641adf7b90168b7b3ff4b3ae81e2bf4d6c;hp=f31f7a884a323b12b48c6c598d1fa6689fc57fa3;hb=838c30d0075a3ee0413ba4909944b37f4970a10d;hpb=cc409b1863cc91b6a2dbfc963d221ab548132762 diff --git a/src/userprog/exception.c b/src/userprog/exception.c index f31f7a8..8b2e8b6 100644 --- a/src/userprog/exception.c +++ b/src/userprog/exception.c @@ -5,6 +5,9 @@ #include "threads/interrupt.h" #include "threads/thread.h" +/* Number of page faults processed. */ +static long long page_fault_cnt; + static void kill (struct intr_frame *); static void page_fault (struct intr_frame *); @@ -54,6 +57,13 @@ exception_init (void) intr_register (14, 0, INTR_OFF, page_fault, "#PF Page-Fault Exception"); } +/* Prints exception statistics. */ +void +exception_print_stats (void) +{ + printf ("Exception: %lld page faults\n", page_fault_cnt); +} + /* Handler for an exception (probably) caused by a user process. */ static void kill (struct intr_frame *f) @@ -129,6 +139,9 @@ page_fault (struct intr_frame *f) be assured of reading CR2 before it changed). */ intr_enable (); + /* Count page faults. */ + page_fault_cnt++; + /* Determine cause. */ not_present = (f->error_code & PF_P) == 0; write = (f->error_code & PF_W) != 0;