[ros-diffs] [sir_richard] 45557: [NTOS]: Factor out SecondaryColor computations into MiComputeColorInformation. [NTOS]: Fix SecondaryColor computations. If the KPCR has no deta, use the default colors of 8, not just 1. Also handle cases where there is more L2 cache than we'd like -- set the secondary colors to a maximum of 1024 in that case. Finally, if the colors are not a power of two, or there are not enough (due to a registry setting), use the default of 8.

sir_richard at svn.reactos.org sir_richard at svn.reactos.org
Wed Feb 10 19:10:04 CET 2010


Author: sir_richard
Date: Wed Feb 10 19:10:04 2010
New Revision: 45557

URL: http://svn.reactos.org/svn/reactos?rev=45557&view=rev
Log:
[NTOS]: Factor out SecondaryColor computations into MiComputeColorInformation.
[NTOS]: Fix SecondaryColor computations. If the KPCR has no deta, use the default colors of 8, not just 1. Also handle cases where there is more L2 cache than we'd like -- set the secondary colors to a maximum of 1024 in that case. Finally, if the colors are not a power of two, or there are not enough (due to a registry setting), use the default of 8.

Modified:
    trunk/reactos/ntoskrnl/mm/ARM3/i386/init.c
    trunk/reactos/ntoskrnl/mm/ARM3/miarm.h

Modified: trunk/reactos/ntoskrnl/mm/ARM3/i386/init.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/i386/init.c?rev=45557&r1=45556&r2=45557&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/i386/init.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/i386/init.c [iso-8859-1] Wed Feb 10 19:10:04 2010
@@ -156,6 +156,59 @@
             }    
         }
     }
+}
+
+VOID
+NTAPI
+MiComputeColorInformation(VOID)
+{
+    ULONG L2Associativity;
+    
+    /* Check if no setting was provided already */
+    if (!MmSecondaryColors)
+    {
+        /* Get L2 cache information */
+        L2Associativity = KeGetPcr()->SecondLevelCacheAssociativity;
+        
+        /* The number of colors is the number of cache bytes by set/way */
+        MmSecondaryColors = KeGetPcr()->SecondLevelCacheSize;
+        if (L2Associativity) MmSecondaryColors /= L2Associativity;
+    }
+    
+    /* Now convert cache bytes into pages */
+    MmSecondaryColors >>= PAGE_SHIFT;
+    if (!MmSecondaryColors)
+    {
+        /* If there was no cache data from the KPCR, use the default colors */
+        MmSecondaryColors = MI_SECONDARY_COLORS;
+    }
+    else
+    {
+        /* Otherwise, make sure there aren't too many colors */
+        if (MmSecondaryColors > MI_MAX_SECONDARY_COLORS)
+        {
+            /* Set the maximum */
+            MmSecondaryColors = MI_MAX_SECONDARY_COLORS;
+        }
+        
+        /* Make sure there aren't too little colors */
+        if (MmSecondaryColors < MI_MIN_SECONDARY_COLORS)
+        {
+            /* Set the default */
+            MmSecondaryColors = MI_SECONDARY_COLORS;
+        }
+        
+        /* Finally make sure the colors are a power of two */
+        if (MmSecondaryColors & (MmSecondaryColors - 1))
+        {
+            /* Set the default */
+            MmSecondaryColors = MI_SECONDARY_COLORS;
+        }
+    }
+    
+    /* Compute the mask and store it */
+    MmSecondaryColorMask = MmSecondaryColors - 1;
+    KeGetCurrentPrcb()->SecondaryColorMask = MmSecondaryColorMask;    
 }
 
 NTSTATUS
@@ -169,7 +222,7 @@
     PMMPTE StartPde, EndPde, PointerPte, LastPte;
     MMPTE TempPde, TempPte;
     PVOID NonPagedPoolExpansionVa;
-    ULONG OldCount, L2Associativity;
+    ULONG OldCount;
     PFN_NUMBER FreePage, FreePageCount, PagesLeft, BasePage, PageCount;
 
     /* Check for kernel stack size that's too big */
@@ -316,24 +369,8 @@
     /* Compute non paged pool limits and size */
     MiComputeNonPagedPoolVa(FreePages);
     
-    //
-    // Get L2 cache information
-    //
-    L2Associativity = KeGetPcr()->SecondLevelCacheAssociativity;
-    MmSecondaryColors = KeGetPcr()->SecondLevelCacheSize;
-    if (L2Associativity) MmSecondaryColors /= L2Associativity;
-    
-    //
-    // Compute final color mask and count
-    //
-    MmSecondaryColors >>= PAGE_SHIFT;
-    if (!MmSecondaryColors) MmSecondaryColors = 1;
-    MmSecondaryColorMask = MmSecondaryColors - 1;
-    
-    //
-    // Store it
-    //
-    KeGetCurrentPrcb()->SecondaryColorMask = MmSecondaryColorMask;
+    /* Compute color information (L2 cache-separated paging lists) */
+    MiComputeColorInformation();
     
     //
     // Calculate the number of bytes for the PFN database

Modified: trunk/reactos/ntoskrnl/mm/ARM3/miarm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/miarm.h?rev=45557&r1=45556&r2=45557&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] Wed Feb 10 19:10:04 2010
@@ -30,6 +30,10 @@
 #define MI_PAGED_POOL_START                    (PVOID)0xE1000000
 #define MI_NONPAGED_POOL_END                   (PVOID)0xFFBE0000
 #define MI_DEBUG_MAPPING                       (PVOID)0xFFBFF000
+
+#define MI_MIN_SECONDARY_COLORS                 8
+#define MI_SECONDARY_COLORS                     64
+#define MI_MAX_SECONDARY_COLORS                 1024
 
 #define MM_HIGHEST_VAD_ADDRESS \
     (PVOID)((ULONG_PTR)MM_HIGHEST_USER_ADDRESS - (16 * PAGE_SIZE))




More information about the Ros-diffs mailing list