Comments.
[pintos-anon] / src / userprog / exception.c
index f31f7a884a323b12b48c6c598d1fa6689fc57fa3..745adaa086e4614245748ddd3cbc6c6262b1f5de 100644 (file)
@@ -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) 
@@ -122,13 +132,19 @@ page_fault (struct intr_frame *f)
   /* Obtain faulting address, the virtual address that was
      accessed to cause the fault.  It may point to code or to
      data.  It is not necessarily the address of the instruction
-     that caused the fault (that's f->eip).  */
+     that caused the fault (that's f->eip).
+     See [IA32-v2a] "MOV--Move to/from Control Registers" and
+     [IA32-v3] 5.14 "Interrupt 14--Page Fault Exception
+     (#PF)". */
   asm ("movl %%cr2, %0" : "=r" (fault_addr));
 
   /* Turn interrupts back on (they were only off so that we could
      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;