Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/uvm cosmetics. no functional changes.



details:   https://anonhg.NetBSD.org/src/rev/b6c5046ab7ba
branches:  trunk
changeset: 759834:b6c5046ab7ba
user:      yamt <yamt%NetBSD.org@localhost>
date:      Fri Dec 17 22:00:43 2010 +0000

description:
cosmetics.  no functional changes.
- constify
- wrap long lines
- assertions
- comments

diffstat:

 sys/uvm/uvm_fault.c |  161 +++++++++++++++++++++++++++------------------------
 1 files changed, 86 insertions(+), 75 deletions(-)

diffs (truncated from 480 to 300 lines):

diff -r 6a65d48647a1 -r b6c5046ab7ba sys/uvm/uvm_fault.c
--- a/sys/uvm/uvm_fault.c       Fri Dec 17 19:20:42 2010 +0000
+++ b/sys/uvm/uvm_fault.c       Fri Dec 17 22:00:43 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_fault.c,v 1.176 2010/12/15 13:44:17 pooka Exp $    */
+/*     $NetBSD: uvm_fault.c,v 1.177 2010/12/17 22:00:43 yamt Exp $     */
 
 /*
  *
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.176 2010/12/15 13:44:17 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.177 2010/12/17 22:00:43 yamt Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -98,7 +98,7 @@
  * the code is structured as follows:
  *
  *     - init the "IN" params in the ufi structure
- *   ReFault:
+ *   ReFault: (ERESTART returned to the loop in uvm_fault_internal)
  *     - do lookups [locks maps], check protection, handle needs_copy
  *     - check for case 0 fault (error)
  *     - establish "range" of fault
@@ -702,23 +702,22 @@
        bool wire_mapping;
        bool narrow;
        bool wire_paging;
-       bool maxprot;
        bool cow_now;
        bool promote;
 };
 
 static inline int      uvm_fault_check(
                            struct uvm_faultinfo *, struct uvm_faultctx *,
-                           struct vm_anon ***, struct vm_page ***);
+                           struct vm_anon ***, bool);
 
 static int             uvm_fault_upper(
                            struct uvm_faultinfo *, struct uvm_faultctx *,
                            struct vm_anon **);
 static inline int      uvm_fault_upper_lookup(
-                           struct uvm_faultinfo *, struct uvm_faultctx *,
+                           struct uvm_faultinfo *, const struct uvm_faultctx *,
                            struct vm_anon **, struct vm_page **);
 static inline void     uvm_fault_upper_neighbor(
-                           struct uvm_faultinfo *, struct uvm_faultctx *,
+                           struct uvm_faultinfo *, const struct uvm_faultctx *,
                            vaddr_t, struct vm_page *, bool);
 static inline int      uvm_fault_upper_loan(
                            struct uvm_faultinfo *, struct uvm_faultctx *,
@@ -730,25 +729,24 @@
                            struct uvm_faultinfo *, struct uvm_faultctx *,
                            struct uvm_object *, struct vm_anon *);
 static int             uvm_fault_upper_enter(
-                           struct uvm_faultinfo *, struct uvm_faultctx *,
+                           struct uvm_faultinfo *, const struct uvm_faultctx *,
                            struct uvm_object *, struct vm_anon *,
                            struct vm_page *, struct vm_anon *);
 static inline void     uvm_fault_upper_done(
-                           struct uvm_faultinfo *, struct uvm_faultctx *,
-                           struct uvm_object *, struct vm_anon *,
-                           struct vm_page *);
+                           struct uvm_faultinfo *, const struct uvm_faultctx *,
+                           struct vm_anon *, struct vm_page *);
 
 static int             uvm_fault_lower(
                            struct uvm_faultinfo *, struct uvm_faultctx *,
                            struct vm_page **);
 static inline void     uvm_fault_lower_lookup(
-                           struct uvm_faultinfo *, struct uvm_faultctx *,
+                           struct uvm_faultinfo *, const struct uvm_faultctx *,
                            struct vm_page **);
 static inline void     uvm_fault_lower_neighbor(
-                           struct uvm_faultinfo *, struct uvm_faultctx *,
+                           struct uvm_faultinfo *, const struct uvm_faultctx *,
                            vaddr_t, struct vm_page *, bool);
 static inline int      uvm_fault_lower_io(
-                           struct uvm_faultinfo *, struct uvm_faultctx *,
+                           struct uvm_faultinfo *, const struct uvm_faultctx *,
                            struct uvm_object **, struct vm_page **);
 static inline int      uvm_fault_lower_direct(
                            struct uvm_faultinfo *, struct uvm_faultctx *,
@@ -761,14 +759,13 @@
                            struct uvm_faultinfo *, struct uvm_faultctx *,
                            struct uvm_object *, struct vm_page *);
 static int             uvm_fault_lower_enter(
-                           struct uvm_faultinfo *, struct uvm_faultctx *,
+                           struct uvm_faultinfo *, const struct uvm_faultctx *,
                            struct uvm_object *,
                            struct vm_anon *, struct vm_page *,
                            struct vm_page *);
 static inline void     uvm_fault_lower_done(
-                           struct uvm_faultinfo *, struct uvm_faultctx *,
-                           struct uvm_object *, struct vm_anon *,
-                           struct vm_page *);
+                           struct uvm_faultinfo *, const struct uvm_faultctx *,
+                           struct uvm_object *, struct vm_page *);
 
 int
 uvm_fault_internal(struct vm_map *orig_map, vaddr_t vaddr,
@@ -784,9 +781,8 @@
                /* "wire" fault causes wiring of both mapping and paging */
                .wire_mapping = (fault_flag & UVM_FAULT_WIRE) != 0,
                .wire_paging = (fault_flag & UVM_FAULT_WIRE) != 0,
-
-               .maxprot = (fault_flag & UVM_FAULT_MAXPROT) != 0,
        };
+       const bool maxprot = (fault_flag & UVM_FAULT_MAXPROT) != 0;
        struct vm_anon *anons_store[UVM_MAXRANGE], **anons;
        struct vm_page *pages_store[UVM_MAXRANGE], **pages;
        int error;
@@ -810,7 +806,7 @@
                anons = anons_store;
                pages = pages_store;
 
-               error = uvm_fault_check(&ufi, &flt, &anons, &pages);
+               error = uvm_fault_check(&ufi, &flt, &anons, maxprot);
                if (error != 0)
                        continue;
 
@@ -821,7 +817,8 @@
                if (pages[flt.centeridx] == PGO_DONTCARE)
                        error = uvm_fault_upper(&ufi, &flt, anons);
                else {
-                       struct uvm_object * const uobj = ufi.entry->object.uvm_obj;
+                       struct uvm_object * const uobj =
+                           ufi.entry->object.uvm_obj;
 
                        if (uobj && uobj->pgops->pgo_fault != NULL) {
                                /*
@@ -834,10 +831,14 @@
                                    flt.centeridx, flt.access_type,
                                    PGO_LOCKED|PGO_SYNCIO);
 
-                               /* locked: nothing, pgo_fault has unlocked everything */
+                               /*
+                                * locked: nothing, pgo_fault has unlocked
+                                * everything
+                                */
 
                                /*
-                                * object fault routine responsible for pmap_update().
+                                * object fault routine responsible for
+                                * pmap_update().
                                 */
                        } else {
                                error = uvm_fault_lower(&ufi, &flt, pages);
@@ -865,12 +866,13 @@
  *
  * => called with nothing locked.
  * => if we fail (result != 0) we unlock everything.
+ * => initialize/adjust many members of flt.
  */
 
 static int
 uvm_fault_check(
        struct uvm_faultinfo *ufi, struct uvm_faultctx *flt,
-       struct vm_anon ***ranons, struct vm_page ***rpages)
+       struct vm_anon ***ranons, bool maxprot)
 {
        struct vm_amap *amap;
        struct uvm_object *uobj;
@@ -883,7 +885,8 @@
         */
 
        if (uvmfault_lookup(ufi, false) == false) {
-               UVMHIST_LOG(maphist, "<- no mapping @ 0x%x", ufi->orig_rvaddr, 0,0,0);
+               UVMHIST_LOG(maphist, "<- no mapping @ 0x%x", ufi->orig_rvaddr,
+                   0,0,0);
                return EFAULT;
        }
        /* locked: maps(read) */
@@ -902,7 +905,7 @@
         * check protection
         */
 
-       check_prot = flt->maxprot ?
+       check_prot = maxprot ?
            ufi->entry->max_protection : ufi->entry->protection;
        if ((check_prot & flt->access_type) != flt->access_type) {
                UVMHIST_LOG(maphist,
@@ -941,7 +944,7 @@
 
        if (UVM_ET_ISNEEDSCOPY(ufi->entry)) {
                if (flt->cow_now || (ufi->entry->object.uvm_obj == NULL)) {
-                       KASSERT(!flt->maxprot);
+                       KASSERT(!maxprot);
                        /* need to clear */
                        UVMHIST_LOG(maphist,
                            "  need to clear needs_copy and refault",0,0,0,0);
@@ -992,15 +995,15 @@
                KASSERT(uvmadvice[ufi->entry->advice].advice ==
                         ufi->entry->advice);
                nback = MIN(uvmadvice[ufi->entry->advice].nback,
-                           (ufi->orig_rvaddr - ufi->entry->start) >> PAGE_SHIFT);
+                   (ufi->orig_rvaddr - ufi->entry->start) >> PAGE_SHIFT);
                flt->startva = ufi->orig_rvaddr - (nback << PAGE_SHIFT);
-               nforw = MIN(uvmadvice[ufi->entry->advice].nforw,
-                           ((ufi->entry->end - ufi->orig_rvaddr) >>
-                            PAGE_SHIFT) - 1);
                /*
                 * note: "-1" because we don't want to count the
                 * faulting page as forw
                 */
+               nforw = MIN(uvmadvice[ufi->entry->advice].nforw,
+                           ((ufi->entry->end - ufi->orig_rvaddr) >>
+                            PAGE_SHIFT) - 1);
                flt->npages = nback + nforw + 1;
                flt->centeridx = nback;
 
@@ -1072,7 +1075,9 @@
         * => startva is fixed
         * => npages is fixed
         */
-
+       KASSERT(flt->startva <= ufi->orig_rvaddr);
+       KASSERT(ufi->orig_rvaddr + ufi->orig_size <=
+           flt->startva + (flt->npages << PAGE_SHIFT));
        return 0;
 }
 
@@ -1089,7 +1094,7 @@
 
 static int
 uvm_fault_upper_lookup(
-       struct uvm_faultinfo *ufi, struct uvm_faultctx *flt,
+       struct uvm_faultinfo *ufi, const struct uvm_faultctx *flt,
        struct vm_anon **anons, struct vm_page **pages)
 {
        struct vm_amap *amap = ufi->entry->aref.ar_amap;
@@ -1111,8 +1116,8 @@
        shadowed = false;
        for (lcv = 0; lcv < flt->npages; lcv++, currva += PAGE_SIZE) {
                /*
-                * dont play with VAs that are already mapped
-                * except for center)
+                * don't play with VAs that are already mapped
+                * (except for center)
                 */
                if (lcv != flt->centeridx &&
                    pmap_extract(ufi->orig_map->pmap, currva, NULL)) {
@@ -1133,7 +1138,7 @@
                 */
 
                pages[lcv] = PGO_DONTCARE;
-               if (lcv == flt->centeridx) {            /* save center for later! */
+               if (lcv == flt->centeridx) {    /* save center for later! */
                        shadowed = true;
                } else {
                        struct vm_anon *anon = anons[lcv];
@@ -1175,7 +1180,7 @@
 
 static void
 uvm_fault_upper_neighbor(
-       struct uvm_faultinfo *ufi, struct uvm_faultctx *flt,
+       struct uvm_faultinfo *ufi, const struct uvm_faultctx *flt,
        vaddr_t currva, struct vm_page *pg, bool readonly)
 {
        UVMHIST_FUNC("uvm_fault_upper_neighbor"); UVMHIST_CALLED(maphist);
@@ -1315,7 +1320,7 @@
 /*
  * uvm_fault_upper_loan: handle loaned upper page.
  *
- *     1. if not cow'ing now, just mark enter_prot as read-only.
+ *     1. if not cow'ing now, simply adjust flt->enter_prot.
  *     2. if cow'ing now, and if ref count is 1, break loan.
  */
 
@@ -1389,8 +1394,8 @@
        UVMHIST_LOG(maphist, "  case 1B: COW fault",0,0,0,0);
        uvmexp.flt_acow++;
 
-       error = uvmfault_promote(ufi, oanon, PGO_DONTCARE,
-           &anon, &flt->anon_spare);
+       error = uvmfault_promote(ufi, oanon, PGO_DONTCARE, &anon,
+           &flt->anon_spare);
        switch (error) {
        case 0:
                break;
@@ -1446,7 +1451,7 @@
 
 static int
 uvm_fault_upper_enter(
-       struct uvm_faultinfo *ufi, struct uvm_faultctx *flt,
+       struct uvm_faultinfo *ufi, const struct uvm_faultctx *flt,
        struct uvm_object *uobj, struct vm_anon *anon, struct vm_page *pg,
        struct vm_anon *oanon)
 {
@@ -1462,11 +1467,13 @@
         * now map the page in.
         */
 
-       UVMHIST_LOG(maphist, "  MAPPING: anon: pm=0x%x, va=0x%x, pg=0x%x, promote=%d",
+       UVMHIST_LOG(maphist,
+           "  MAPPING: anon: pm=0x%x, va=0x%x, pg=0x%x, promote=%d",
            ufi->orig_map->pmap, ufi->orig_rvaddr, pg, flt->promote);



Home | Main Index | Thread Index | Old Index