Author: jhb
Date: Mon Aug 31 18:41:13 2009
New Revision: 196707
URL: http://svn.freebsd.org/changeset/base/196707

Log:
  Simplify pmap_change_attr() a bit:
  - Always calculate the cache bits instead of doing it on-demand.
  - Always set changed to TRUE rather than only doing it if it is false.
  
  Discussed with:       alc
  MFC after:    3 days

Modified:
  head/sys/amd64/amd64/pmap.c
  head/sys/i386/i386/pmap.c

Modified: head/sys/amd64/amd64/pmap.c
==============================================================================
--- head/sys/amd64/amd64/pmap.c Mon Aug 31 17:50:33 2009        (r196706)
+++ head/sys/amd64/amd64/pmap.c Mon Aug 31 18:41:13 2009        (r196707)
@@ -4476,7 +4476,8 @@ pmap_change_attr_locked(vm_offset_t va, 
        if (base < DMAP_MIN_ADDRESS)
                return (EINVAL);
 
-       cache_bits_pde = cache_bits_pte = -1;
+       cache_bits_pde = pmap_cache_bits(mode, 1);
+       cache_bits_pte = pmap_cache_bits(mode, 0);
        changed = FALSE;
 
        /*
@@ -4493,8 +4494,6 @@ pmap_change_attr_locked(vm_offset_t va, 
                         * memory type, then we need not demote this page. Just
                         * increment tmpva to the next 1GB page frame.
                         */
-                       if (cache_bits_pde < 0)
-                               cache_bits_pde = pmap_cache_bits(mode, 1);
                        if ((*pdpe & PG_PDE_CACHE) == cache_bits_pde) {
                                tmpva = trunc_1gpage(tmpva) + NBPDP;
                                continue;
@@ -4522,8 +4521,6 @@ pmap_change_attr_locked(vm_offset_t va, 
                         * memory type, then we need not demote this page. Just
                         * increment tmpva to the next 2MB page frame.
                         */
-                       if (cache_bits_pde < 0)
-                               cache_bits_pde = pmap_cache_bits(mode, 1);
                        if ((*pde & PG_PDE_CACHE) == cache_bits_pde) {
                                tmpva = trunc_2mpage(tmpva) + NBPDR;
                                continue;
@@ -4557,12 +4554,9 @@ pmap_change_attr_locked(vm_offset_t va, 
        for (tmpva = base; tmpva < base + size; ) {
                pdpe = pmap_pdpe(kernel_pmap, tmpva);
                if (*pdpe & PG_PS) {
-                       if (cache_bits_pde < 0)
-                               cache_bits_pde = pmap_cache_bits(mode, 1);
                        if ((*pdpe & PG_PDE_CACHE) != cache_bits_pde) {
                                pmap_pde_attr(pdpe, cache_bits_pde);
-                               if (!changed)
-                                       changed = TRUE;
+                               changed = TRUE;
                        }
                        if (tmpva >= VM_MIN_KERNEL_ADDRESS) {
                                if (pa_start == pa_end) {
@@ -4588,12 +4582,9 @@ pmap_change_attr_locked(vm_offset_t va, 
                }
                pde = pmap_pdpe_to_pde(pdpe, tmpva);
                if (*pde & PG_PS) {
-                       if (cache_bits_pde < 0)
-                               cache_bits_pde = pmap_cache_bits(mode, 1);
                        if ((*pde & PG_PDE_CACHE) != cache_bits_pde) {
                                pmap_pde_attr(pde, cache_bits_pde);
-                               if (!changed)
-                                       changed = TRUE;
+                               changed = TRUE;
                        }
                        if (tmpva >= VM_MIN_KERNEL_ADDRESS) {
                                if (pa_start == pa_end) {
@@ -4616,13 +4607,10 @@ pmap_change_attr_locked(vm_offset_t va, 
                        }
                        tmpva = trunc_2mpage(tmpva) + NBPDR;
                } else {
-                       if (cache_bits_pte < 0)
-                               cache_bits_pte = pmap_cache_bits(mode, 0);
                        pte = pmap_pde_to_pte(pde, tmpva);
                        if ((*pte & PG_PTE_CACHE) != cache_bits_pte) {
                                pmap_pte_attr(pte, cache_bits_pte);
-                               if (!changed)
-                                       changed = TRUE;
+                               changed = TRUE;
                        }
                        if (tmpva >= VM_MIN_KERNEL_ADDRESS) {
                                if (pa_start == pa_end) {

Modified: head/sys/i386/i386/pmap.c
==============================================================================
--- head/sys/i386/i386/pmap.c   Mon Aug 31 17:50:33 2009        (r196706)
+++ head/sys/i386/i386/pmap.c   Mon Aug 31 18:41:13 2009        (r196707)
@@ -4635,7 +4635,8 @@ pmap_change_attr(vm_offset_t va, vm_size
        if (base < VM_MIN_KERNEL_ADDRESS)
                return (EINVAL);
 
-       cache_bits_pde = cache_bits_pte = -1;
+       cache_bits_pde = pmap_cache_bits(mode, 1);
+       cache_bits_pte = pmap_cache_bits(mode, 0);
        changed = FALSE;
 
        /*
@@ -4656,8 +4657,6 @@ pmap_change_attr(vm_offset_t va, vm_size
                         * demote this page.  Just increment tmpva to
                         * the next 2/4MB page frame.
                         */
-                       if (cache_bits_pde < 0)
-                               cache_bits_pde = pmap_cache_bits(mode, 1);
                        if ((*pde & PG_PDE_CACHE) == cache_bits_pde) {
                                tmpva = trunc_4mpage(tmpva) + NBPDR;
                                continue;
@@ -4688,8 +4687,6 @@ pmap_change_attr(vm_offset_t va, vm_size
        }
        PMAP_UNLOCK(kernel_pmap);
 
-       changed = FALSE;
-
        /*
         * Ok, all the pages exist, so run through them updating their
         * cache mode if required.
@@ -4697,22 +4694,16 @@ pmap_change_attr(vm_offset_t va, vm_size
        for (tmpva = base; tmpva < base + size; ) {
                pde = pmap_pde(kernel_pmap, tmpva);
                if (*pde & PG_PS) {
-                       if (cache_bits_pde < 0)
-                               cache_bits_pde = pmap_cache_bits(mode, 1);
                        if ((*pde & PG_PDE_CACHE) != cache_bits_pde) {
                                pmap_pde_attr(pde, cache_bits_pde);
-                               if (!changed)
-                                       changed = TRUE;
+                               changed = TRUE;
                        }
                        tmpva = trunc_4mpage(tmpva) + NBPDR;
                } else {
-                       if (cache_bits_pte < 0)
-                               cache_bits_pte = pmap_cache_bits(mode, 0);
                        pte = vtopte(tmpva);
                        if ((*pte & PG_PTE_CACHE) != cache_bits_pte) {
                                pmap_pte_attr(pte, cache_bits_pte);
-                               if (!changed)
-                                       changed = TRUE;
+                               changed = TRUE;
                        }
                        tmpva += PAGE_SIZE;
                }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to