/* UW specific code - This won't be needed or used until assignment 3 */ /* belongs in kern/vm/uw-vmstats.c */ /* NOTE !!!!!! WARNING !!!!! * All of the functions whose names begin with '_' * assume that atomicity is ensured elsewhere * (i.e., outside of these routines) by acquiring stats_lock. * All of the functions whose names do not begin * with '_' ensure atomicity locally. */ #include #include #include #include #include /* Counters for tracking statistics */ static unsigned int stats_counts[VMSTAT_COUNT]; struct spinlock stats_lock = SPINLOCK_INITIALIZER; /* Strings used in printing out the statistics */ static const char *stats_names[] = { /* 0 */ "TLB Faults", /* 1 */ "TLB Faults with Free", /* 2 */ "TLB Faults with Replace", /* 3 */ "TLB Invalidations", /* 4 */ "TLB Reloads", /* 5 */ "Page Faults (Zeroed)", /* 6 */ "Page Faults (Disk)", /* 7 */ "Page Faults from ELF", /* 8 */ "Page Faults from Swapfile", /* 9 */ "Swapfile Writes", }; /* ---------------------------------------------------------------------- */ /* Assumes vmstat_init has already been called */ void vmstats_inc(unsigned int index) { spinlock_acquire(&stats_lock); _vmstats_inc(index); spinlock_release(&stats_lock); } /* ---------------------------------------------------------------------- */ void vmstats_init(void) { /* Although the spinlock is initialized at declaration time we do it here * again in case we want use/reset these stats repeatedly without shutting down the kernel. */ spinlock_init(&stats_lock); spinlock_acquire(&stats_lock); _vmstats_init(); spinlock_release(&stats_lock); } /* ---------------------------------------------------------------------- */ void _vmstats_inc(unsigned int index) { KASSERT(index < VMSTAT_COUNT); stats_counts[index]++; } /* ---------------------------------------------------------------------- */ void _vmstats_init(void) { int i = 0; if (sizeof(stats_names) / sizeof(char *) != VMSTAT_COUNT) { kprintf("vmstats_init: number of stats_names = %d != VMSTAT_COUNT = %d\n", (sizeof(stats_names) / sizeof(char *)), VMSTAT_COUNT); panic("Should really fix this before proceeding\n"); } for (i=0; i